[wp-hackers] Filter dashboard custom post listing by user

Mario Peshev mario at peshev.net
Thu Jan 12 22:04:03 UTC 2012


I think that my code used to work as well (your snippet is pretty useful
too) but I probably miss filtering the top links for All, Published etc.
This resource is really useful for my scenario -
http://blog.rutwick.com/display-only-the-posts-authored-by-the-current-wp-user-on-the-posts-page-in-the-back-end

I will have to validate the access to foreign posts via URL after the
resources are hidden. Strange, but I was unable to find a capability level
for post types that denies loading of the post edit (even though updating
is forbidden)

Mario Peshev
Training and Consulting Services @ DevriX
http://www.linkedin.com/in/mpeshev
http://devrix.com
http://peshev.net/blog



On Thu, Jan 12, 2012 at 10:27 PM, fris <fris at fris.net> wrote:

> Try something like this maybe?
>
> function posts_for_current_author($query) {
>        global $user_level;
>
>        if($query->is_admin && $user_level < 5) {
>                global $user_ID;
>                                $query->set( 'post_type', array( 'typename'
> ) );
>                $query->set('author',  $user_ID);
>                unset($user_ID);
>        }
>        unset($user_level);
>
>        return $query;
> }
>
> add_filter('pre_get_posts', 'posts_for_current_author');
>
> will only show the posts of the current user logged and a certain user
> level.
>
>
> http://codex.wordpress.org/Roles_and_Capabilities#User_Level_to_Role_Convers
> ion
>
>
>
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Mario Peshev
> Sent: Thursday, January 12, 2012 2:13 AM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Filter dashboard custom post listing by user
>
> It does the following.
>
> In the edit.php page listing I have "Mine", "All", "Published" and "Draft"
> - Mine is correct, but I can see "All" too
>
> Mario Peshev
> Training and Consulting Services @ DevriX
> http://www.linkedin.com/in/mpeshev
> http://devrix.com
> http://peshev.net/blog
>
>
>
> On Thu, Jan 12, 2012 at 5:34 AM, fris <fris at fris.net> wrote:
>
> > Try pre_get_posts
> >
> >
> >
> > -----Original Message-----
> > From: wp-hackers-bounces at lists.automattic.com
> > [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Mario
> > Peshev
> > Sent: Wednesday, January 11, 2012 4:22 PM
> > To: wp-hackers at lists.automattic.com
> > Subject: [wp-hackers] Filter dashboard custom post listing by user
> >
> > Hello everyone,
> >
> > Did some research, but I was unable to implement it after all.
> >
> > I have a custom post type accessible only by a new role. I want to
> > filter the post type listing so that each user should see only his
> > records (as Author users can see their posts only). I've tried to
> > filter parse_query but it works for the main listing only (still I can
> > see other records).
> >
> > Which is the correct filter to use in order to prevent malicious users
> > to list others' records?
> >
> >
> > Mario Peshev
> > Training and Consulting Services @ DevriX
> > http://www.linkedin.com/in/mpeshev
> > http://devrix.com
> > http://peshev.net/blog
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list