Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




How do I test if current user has access to pages?

UserPost

2:24 pm
August 31, 2009


Daniel

Member

posts 4

1

Hi Kevin,

Excellent plugin thanks - I just moving over to it from two other plugins. I am  working on developing a plugin for the first time, and I'll like / need it  to work with yours. My plugin creates user-defined graphical menus (normally for use in the page header).

All I need is a way to test if the current user (whether anonymous or logged in) has acess to each of the pages as a I loop through them creating the graphical menu. I looked in your documentation and tried:

!(function_exists( 'is_restricted_rs'))  ||  !is_restricted_rs( $menu_array[$i]['page_id'] )

but to no avail, so now I am wondering instead it should be current_user-> somethingorother. I guess this should be simple, but as mentioned I am a first-timer and amatuer and so haven't been able to figure out how your excellent code works. 

Any help would be highly appreciated, and thanks again for the great plugin.

Daniel

12:51 pm
September 3, 2009


Daniel

Member

posts 4

2

okay, I figured out a way to do it, but it is not particularly elegant, so if anyone has a better suggestion, I'd appreciate it. The following expression returns true if the user can view the page, and false if not:

(strlen(wp_list_pages("include=$Page_ID&echo=0″))>0)

It has the advantage of working with any self-respecting page restriction plugin, but it seems to me I am executing a lot of code to perform a simple test.


8:25 am
September 7, 2009


Kevin

Admin

posts 2402

3

Glad you got something working. I'm eager to correspond with you more on RS plugin compat, but am in the middle of some consulting for a tight-deadline project at the moment.

10:02 am
September 7, 2009


Daniel

Member

posts 4

4

No worries, my day job is keeping me very busy at the moment too. Let's explore options when we both have more time. I'll check back here again in a couple of weeks.

2:23 pm
December 20, 2009


Daniel

Member

posts 4

5

Kevin said:

Glad you got something working. I'm eager to correspond with you more on RS plugin compat, but am in the middle of some consulting for a tight-deadline project at the moment.


Hey Kevin, how are you doing? Any thoughts on a better way to do this. My solution worked fine until the plugin "WP Title 2″ was installed. It looks like the problem is with that plugin (it is throwing no-such object errors when I call wp_list_pages), but I wondered do you have a more direct way that I could check with the current user can read a page?

Thanks and have a very happy Christ-filled Christmas,

Daniel

4:09 pm
December 28, 2009


Kevin

Admin

posts 2402

6

Daniel said:

Kevin said:

Glad you got something working. I'm eager to correspond with you more on RS plugin compat, but am in the middle of some consulting for a tight-deadline project at the moment.


Hey Kevin, how are you doing? Any thoughts on a better way to do this. My solution worked fine until the plugin "WP Title 2″ was installed. It looks like the problem is with that plugin (it is throwing no-such object errors when I call wp_list_pages), but I wondered do you have a more direct way that I could check with the current user can read a page?

Thanks and have a very happy Christ-filled Christmas,

Daniel


I'm doing well and yes, I did.

You can always do this (remind me if it doesn't fit your usage for some reason):

if ( current_user_can( 'read_page', $page_id ) ) {
   // conditional display code
} else {
   // alternate display code
}

That's a standard WordPress function call, but receives Role Scoper filtering.


About the Agapetry forum

Currently Online:

16 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1186

Posts: 5409

Members:

There are 1176 members

There are 1 guests


Kevin has made 2402 posts

Top Posters:

metal450 - 159

Ragnar - 105

YikYak - 70

whiteorb - 44

Daisy - 35

Administrator: Kevin | Moderators: Kevin