WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jun 11 2012

Limit Admin Page Editing Capabilities to Page Owners by Capability

Currently, WordPress does a great job displaying pages on the Edit Pages admin area for users with the capability edit_others_pages. However, if a user has edit_others_pages and has not yet authored any pages, WordPress defaults to listing all the pages removing edit actions, etc. Recently I had the need to list NO PAGES/POSTS except what the person has authored.

[php]<?php
add_action( 'pre_get_posts', 'wps_admin_exclude_pages' );
/*
* Modifies the admin query for a specific author for the Edit Posts
* and Pages admin pages checking capability.
*
* @param WP_Query Object $query Original Query Object
* @return WP_Query Object $query Original/Modified Query Object
*/
function wps_admin_exclude_pages( $query ) {
if( ! is_admin() )
return $query;

global $pagenow, $user_ID;
if( 'edit.php' == $pagenow && 'page' == get_query_var( 'post_type' ) && ! current_user_can( 'edit_others_pages' ) )
$query->set( 'author', $user_ID );

if( 'edit.php' == $pagenow && 'post' == get_query_var( 'post_type' ) && ! current_user_can( 'edit_others_posts' ) )
$query->set( 'author', $user_ID );

return $query;
}
[/php]

Written by Travis Smith · Categorized: WordPress

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in