0%
Loading ...

How to limit post and post-types viewing and editing to post creator only

Read the following post in order to be able to limit editing and viewing post or post-types to post creator only:

01. https://premium.wpmudev.org/blog/how-to-limit-the-wordpres-posts-screen-to-only-show-authors-their-own-posts/

02. This is the plugin:

<?php
/*
Plugin Name: Simplify Post Edit List
Description: Show only the author's posts in the edit list
Version: 0.1
License: GPL
Author: Sarah Gooding
Author URI: http://untame.net
*/

function mypo_parse_query_useronly( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
        if ( !current_user_can( 'update_core' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}

add_filter('parse_query', 'mypo_parse_query_useronly' );

03. The line in red can be modified as follows:

a. Limit to Edit: strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false
b. Limit to All admin area: strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin' ) !== false
c. Limit to All admin area: strpos( $_SERVER[ 'REQUEST_URI' ], '/[Post-Type here]' ) !== false
d. Combination of IF: 
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin' ) !== false || 
strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false || 
strpos( $_SERVER[ 'REQUEST_URI' ], '/[post-type]' ) !== false )