Resources

My Agape try

Your Agape try


Support Forum

Current User: Guest Login Register
Please consider registering

Search 
Search Forums:


 




current_user_can errors

UserPost

11:29 am
March 3, 2010


rberrill

Member

posts 4

1

Have a strange bug, I have a site where I'm restricting access at a post level to certain users.  The restriction works if I search for the post in question, it doesn't show up, nor will it let me view the post if I type in the full address for it.  but when I use the following code:

if(current_user_can('read_post', $row['post_id'])) {

or

if(current_user_can('read', $row['post_id'])) {

It's always true, even on posts they cannot search for.  As a test though, I changed it to edit_post and gave the user editor permissions on it, it only works for posts that they have that permission on.

Any idea what might be causing this?  I'm using rolescoper 1.1.8 Dev D (I had the same behavior in 1.1.7) and wordpress 2.9.2

1:04 pm
March 3, 2010


Kevin

Admin

posts 1326

2

Hmm, I haven't been able to reproduce this error so far. Did you confirm that $row['post_id'] exists as a nonzero value in each trial? Is the current_user_can call being done in template code? Before, after or inside the posts loop?

1:27 pm
March 3, 2010


rberrill

Member

posts 4

3

Yeah it is valid each time, I put in some debug code so I could see what's going on with it each time through.  It is in template code on a custom page (using it's own template)  Before the posts loop.

1:55 pm
March 3, 2010


rberrill

Member

posts 4

4

As another piece of information, I tried exactly the same code, in single.php anywhere in the code and it always worked correctly.  I put the same code snippet in page.php and it never worked correctly with read access.

8:42 am
March 4, 2010


rberrill

Member

posts 4

5

So after a ton of testing and banging my head against a wall with this yesterday I figured it out.  I had forgotten to query_posts(); in my custom template so it had no post data to work off of.

Thanks for your time and the great plug-in Kevin.

8:57 am
March 4, 2010


Kevin

Admin

posts 1326

6

Thanks for letting me know. It's still strange that current_user_can would return true in that situation. I'll look into that.



Reply to Topic: current_user_can errors

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 4 + 3        (Required)

Topic Reply:


 

About the Agapetry forum

Currently Online:

12 Guests

Maximum Online: 88

Forums:

Groups: 2

Forums: 7

Topics: 667

Posts: 3053

Members:

There are 601 members

There are 1 guests


Kevin has made 1326 posts

Top Posters:

metal450 - 98

YikYak - 58

Ragnar - 36

Daisy - 35

LorenW - 33

Administrator: Kevin | Moderators: Kevin