21288 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 262 Views |
-
Check for read access permission of specified page

12 September 2011 at 11:56pm
Hi all,
I'm trying to do this: The access to page A is limited to website readers that are members of specified groups only. The access to page B is wider, the same readers like for page A can access it but also other too. I use shortcode in the Content of page B to create link to page A (in fact it's an excerpt from the text of page A, that's why I use shortcode).
When somebody who doesn't have access to page A click on that link, he/she will see an error message and possibility to login with different username. I would like to hide completely that link for such readers (it means the shortcode will return empty string) but I can not figure out how to check whether currently logged user has privileges to access page A or not. If possible I don't want to create some additional permission for that purpose as it's already there - appropriate user groups are selected on "access" tab of page A.
Please, could someone help me with that?
-
Re: Check for read access permission of specified page

13 September 2011 at 4:53am
Well, I have found that the solution is really simple. I added into my shortcode handler something like this:
$page = DataObject::get_by_id( 'Page', $id );
if ( $page && $page->canView() ) {
... return page excerpt ...
} else {
... return nothing ...
}Where $id is ID of linked page A.
| 262 Views | ||
|
Page:
1
|
Go to Top |

