Support » Fixing WordPress » How can I set a WordPress post to private by default instead of public?

  • mlaurel

    (@mlaurel)


    By default the visibility is set to public when publishing a post. I’d like to set it to private for all author level users for review.

    I searched around, but the code(s) I found don’t work. Does anyone know of a good plugin (preferably free) or even better, code that works?

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Nikhil Bhansi

    (@nikhilbhansi)

    Add the following code snippet in your theme’s function file.

    /**
     * Set Post Status to Private
     * https://wordpress.org/support/topic/post-pagination-how-to-make-two-versions-of-the-same-link/
     */
    function set_post_status_private( $status, $post_id ) {
        $status = 'private';
        return $status;
    }
    add_filter( 'status_edit_pre', 'set_post_status_private', 10, 2 );

    Post status will be set to ‘Private’ after publishing the post.

    mlaurel

    (@mlaurel)

    Thanks for this @nikhilbhansi but it doesn’t work.

    mlaurel

    (@mlaurel)

    Hi @nikhilbhansi,

    Again thanks. Unfortunately, it’s still a no go. I tried it on the sandbox as well- the posts are visible to the public.

    I’m going to try to ask the theme makers to see if they can help out (using the free version ATM)…hopefully they’ll respond

    mlaurel

    (@mlaurel)

    @nikhilbhansi Thanks for pointing me in the right direction.

    did more searching & found the following:

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

    Changed the boolean to:

    if (($post['post_type'] == 'post')&&(!current_user_can('administrator')))

    So only Admin can publish. Works as intended.

    Nikhil Bhansi

    (@nikhilbhansi)

    It’s good that the problem is now sorted. 🙂

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @nikhilbhansi Also do not setup temporary sites and post the user and password, I have archived that too.

    Nikhil Bhansi

    (@nikhilbhansi)

    @jdembowski noted 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How can I set a WordPress post to private by default instead of public?’ is closed to new replies.