Rewriting WordPress core functionallity: Changing the private posts

First of all I have to say that private posts already fit your needs, because logged in users with proper capability will see the posts in home page, archives, searches and so on.

Proper capability is ‘read_private_posts’.

This cap is assigned by default to administrators and editors. So, your “member” users should have one of these 2 roles or maybe you can assign that capability to different roles.

In facts, you can add it to standard roles using add_cap() or you can register a custom role (see here) and assign to that role the capability you want to assign to your members.

That said to customize how the metabox is shown in the post admin page (removing option to password protect, renaming “Private” option…) most powerful way is

  1. Create a function that output the custom metabox. Create a new function, name it something like custom_post_submit_meta_box(), copy content from core post_submit_meta_box() and modify what you need.
  2. Remove the standard metabox and add the custom one:

    add_action( 'dbx_post_advanced', function( $post ) {
    
      // only for 'post' post type
      if ( $post->post_type !== 'post' ) return;
      // remove the standard
      remove_meta_box( 'submitdiv', 'post', 'side' );
      // add the custom
      add_meta_box(
        'custom_submitdiv',
        __( 'Publish' ),
        'custom_post_submit_meta_box', // the name of your custom function
        'post',
        'side',
        'core'
      );
    
    });
    

Leave a Comment