WordPress.org

Support

Support » Plugins and Hacks » Remove public visibility entirely

Remove public visibility entirely

  • I have a couple custom post types that I don’t want to ever be published publicly. I know that when you register a custom post type, you can set ‘public’ to ‘false’, but this simply prevents you from publishing at all.

    I would like to be able to publish these post types, but I will never set the visibility to ‘public’, and will probably never set it to ‘password’ either. Therefore, I want the only visibility option to be ‘private’ and all custom posts to be private by default.

    Can someone tell me if this is possible, and how to do it? Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi.
    Here is an article that seems to address your issue (untested).
    Cheers!

    Thanks, I think it gets me halfway there:

    function force_type_private($post)
    {
        if ($post['post_type'] == 'my_post_type')
        $post['post_status'] = 'private';
        return $post;
    }
    add_filter('wp_insert_post_data', 'force_type_private');

    Except it only accepts privately published posts. So if you go to create a new post, it’s immediately privately published. There are no drafts, and you can’t move it to the trash.

    I’ll try to tweak it from here,though. Thanks.

    This works a little better:

    function force_type_private($post)
    {
        if ($post['post_type'] == 'my_post_type' && $post['post_status'] == 'publish')
        $post['post_status'] = 'private';
        return $post;
    }
    add_filter('wp_insert_post_data', 'force_type_private');

    It’s the same as above, but is says if it’s published, it’s private. this preserves draft and trash functionality.

    This works great for private posts to remain in draft, thank you.

    This little change works for all Posts:

    /** Private posts all the way down */
    function force_type_private($post)
    {
        if ($post['post_type'] == 'is_singular' && $post['post_status'] == 'publish')
        $post['post_status'] = 'private';
        return $post;
    }
    add_filter('wp_insert_post_data', 'force_type_private');
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove public visibility entirely’ is closed to new replies.