1

I'm trying to rewrite a bit of core WordPress functionality. I'm using WordPress 3.9.2 and I consider myself an intermediate in WordPress programming.

This is an image that will explain what I am trying to do:

Explanatory image

Currently, when one sets a post to "Private", it will hide the post from view, only to be accessed directly through it's link and by specially privileged users. This is not what my customer want, they want a "Member" (Norwegian: Medlemmer) functionality instead, where that option will make the posts exclusively visible for that specific access role. So for an anonymous user you would see some posts, but when logged in as a member, you would see all of those posts.

I am also trying to remove the "Password protected" option, as this does not apply to my customer's website, but this is not a priority.

So my question is: Any ideas on what I will have to do to change this from a plugin? My current thoughts are in the lines of filter hooks.

Any help appreciated.

4
  • Private posts does not show up on front page or in search or archive pages. That is the issue.
    – GauteR
    Commented Aug 22, 2014 at 10:12
  • According to codex.wordpress.org/Content_Visibility#Private_Content ".. It will not appear in the article lists ..."
    – GauteR
    Commented Aug 22, 2014 at 10:23
  • Anyways, I do have a clue to how to do this. But the main question is: how do I change it's name? And if possible, remove the password protection option?
    – GauteR
    Commented Aug 22, 2014 at 10:28
  • Ah, ok. Thanks for being patient with me. If you will put up your last comment as an answer, I will accept it.
    – GauteR
    Commented Aug 22, 2014 at 10:35

1 Answer 1

2

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'
      );
    
    });
    
2
  • Very thorough and easy to follow. Thanks a lot! If I could up-vote I would.
    – GauteR
    Commented Aug 22, 2014 at 11:23
  • N/P glad it works.
    – gmazzap
    Commented Aug 22, 2014 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.