Created
January 16, 2015 18:41
-
-
Save adrianbj/6fd1b770d9ce7a7252b6 to your computer and use it in GitHub Desktop.
PW module for hiding pages that don't match the user's name, under a certain parent page - currently hard coded parent name: visitenkarte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* | |
* ProcessWire 2.x | |
* Copyright (C) 2010 by Ryan Cramer | |
* Licensed under GNU/GPL v2, see LICENSE.TXT | |
* | |
* http://www.processwire.com | |
* http://www.ryancramer.com | |
* | |
*/ | |
class HideOtherUserPages extends WireData implements Module { | |
public static function getModuleInfo() { | |
return array( | |
'title' => 'HideOtherUserPages', | |
'author' => 'Adrian Jones', | |
'version' => 1, | |
'singular' => true, | |
'autoload' => true | |
); | |
} | |
public function init() { | |
// only add hook only if the render parameter is set | |
// (as used by ProcessPageList) | |
// or if superuser, also exit | |
if(!isset($_GET['render']) || $this->user->isSuperuser()) return; | |
$this->addHookAfter('ProcessPageList::execute', $this, 'pageListHiddenPages'); | |
} | |
public function pageListHiddenPages(HookEvent $event){ | |
// make sure it's an ajax request | |
if($this->config->ajax){ | |
// manipulate the json returned and remove any pages found from array | |
$json = json_decode($event->return, true); | |
foreach($json['children'] as $key => $child){ | |
$c = $this->pages->get($child['id']); | |
if($c->parent->name != 'visitenkarte') continue; | |
if($c->name != $this->user->name) unset($json['children'][$key]); | |
} | |
$json['children'] = array_values($json['children']); | |
$event->return = json_encode($json); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can also edit if($c->createdUser->id != $this->user->id) unset($json['children'][$key]); to
if($c->createdUser->id != $this->user->id) unset($json['children'][$key]);
this will show only those pages which a user has created.
to achieve this i used solution mentioned by adrian on processwire forum, he told me to add new permission 'Page-Edit-Created, and with this you can another module "Hideuneditablepages' with ,'hide other pages' module .
This will show only those pages that a user has created.