• Resolved prokulit06

    (@prokulit06)


    Hi good day,
    Please help me or guide me how to do it. My goal is while the post status is in progress other user cannot edit this post anyone know how to do it? please help me.

    • This topic was modified 4 years, 7 months ago by prokulit06.
    • This topic was modified 4 years, 7 months ago by prokulit06.
Viewing 1 replies (of 1 total)
  • Hello,

    There are a few example on the web about how to prevent editing a post while the post meets certain conditions. Adding the following snippet to your functions.php file would prevent posts from being edited by non-admins when the post has the status “pitch”.

    function restrict_editing_by_status( $allcaps, $cap, $args ) {
    
        if( 'edit_post' != $args[0] && 'delete_post' != $args[0]
          || !empty( $allcaps['manage_options'] ) // don't restrict if the user can manage options
    	  || empty( $allcaps['edit_posts'] ) // the user already can't edit post
    	) { 
    		return $allcaps;
    	}
     
    	$post = get_post( $args[2] );
    	
    	// If the post status is pitch
    	if ( $post->post_status === 'pitch' ) {
    		$allcaps[$cap[0]] = false;
    	}
     
        return $allcaps;
    }
    
    add_filter( 'user_has_cap', 'restrict_editing_by_status', 10, 3 );

    Thanks!
    Connor

Viewing 1 replies (of 1 total)
  • The topic ‘It is possible to block a user on editing base on custom status’ is closed to new replies.