Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




visitor current_user_can read returns false

UserPost

4:07 pm
November 30, 2010


lancehudson

Member

posts 9

1

I am using a nopriv ajax function to service visitor requests.

If the user is not logged in I call wp_set_current_user to set the anonymous user to an account I created to manage their permissions.

Then in the ajax request I have a can_current_user('read_[post|page]', $id) which returns false with role-scoper on, and true with role-scoper off. I have not configured any settings in role-scoper nor on the page's settings.

Any idea on why this isn't working?

Thanks

8:56 pm
November 30, 2010


Kevin

Admin

posts 2503

2

When does your wp_set_current_user call execute? Is there a particular hook it fires off?

Can you post (via contact form if you prefer) a code snippet to speed up my troubleshooting?

8:09 am
December 2, 2010


lancehudson

Member

posts 9

3

sure here is a boiled down code snipet

add_action('wp_ajax_nopriv_feeditor', array(__CLASS__, 'ajax_handler'));


static function ajax_handler() {

       if (isset($_REQUEST['_ajax_nonce']) || isset($_REQUEST['_wpnonce']))

            check_ajax_referer(self::$nonce); //dies('-1') if bad nonce

 else

            die('-1'); //no nonce = bad nonce

            //get action

 $action = sanitize_title($_POST['feeditor_action']);

        //get id

        $id = absint($_POST['id']);

        if (!$id)

            die('-2'); //no id

            //set user to anon if they are not logged in

 if (!is_user_logged_in()) {

            wp_set_current_user(self::$anon_user_id);

            $visitor = true;

        }

        else

            $visitor = false;

        //go

        switch ($action) {

            case 'load':

                //get post, type, and lock

                $the_post = get_post($id);

                $type = get_post_type($id);

                $lock = wp_check_post_lock($id);

//if post and( (user can read and revisionary) or user can edit)

                 if (isset($the_post) && ( (current_user_can('read_' . get_post_type($id), $id) && class_exists('Revisionary') && rvy_get_option('pending_revisions')) || current_user_can('edit_' . get_post_type($id), $id))) {

                   //generate response

                    die(json_encode($response));

                }

                else

                    die('-2');

            default:

                die('-4');

        }

    }


when i put 

 die(json_encode(array(

                    'the_post' => $the_post,

                    'current_user_can_read_'. get_post_type($id) => current_user_can('read_' . get_post_type($id), $id),

                    'class_exists' => class_exists('Revisionary'),

                    'pending_revisions' => rvy_get_option('pending_revisions'),

                    'current_user_can_edit_'. get_post_type($id) => current_user_can('edit_' . get_post_type($id), $id)

                )));

it shows current user read as false with role-scoper on.


I appreciate your help on this.

7:07 am
June 29, 2011


Kevin

Admin

posts 2503

4

This was fixed in Role Scoper 1.3.12:

BugFix : Invalid filtering results after other template/plugin code manually changed current user via call to wp_set_current_user


About the Agapetry forum

Currently Online:

14 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1249

Posts: 5659

Members:

There are 1261 members

There are 1 guests


Kevin has made 2503 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin