Support » Plugins » Need posts to only have draft or private status

  • I’m working on a blog, and have found plugins for everything that I’ve needed so far, but a last feature needs to be implemented.

    I’m not the person running/writing on the blog, and they are a little challenged by WordPress usage. They are requesting that every post be private, without having the difficult task of remembering to set the visibility, however, pages need to remain visible by everyone.

    I’ve only been using WordPress for a couple of weeks, so I need help with a suggestion on how to go about making the posts always private.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Well, I tried to install it, but the menus don’t show up as indicated in the plugin description. WP Sentry says that it only works up to V2.7, and I’m using the current version. Maybe there is a conflict with the other plugins that are installed. I don’t know.

    If I could just have the private option selected=”selected” as default, this would be all that is necessary, but I’m not sure yet what to change. I don’t mind hacking this. It doesn’t necessarily need to be a plugin.

    actually, I mean checked=”checked”, sorry

    If you can’t find a plugin that does what you want, the only sensible way to do it is to write one. You don’t want to go messing around with core WP code – that would be ridiculous and unsustainable.

    On activation, the plugin should set post_status to “draft” or “pending” where post_type == ‘post’ in the $wpdb->prefix.’posts’ table.

    The plugin should also register an action hook on the ‘wp_insert_post’ tag. ( ) and in your action handler, set ‘post_status’ to “draft” or “pending” ( ).

    I haven’t tested this out, but i think the above is a viable approach to it.

    I’m trying to make the plugin. I think this might be all I need, but it doesn’t work:

    function make_all_posts_private(){
    	return $post->visibility = 'private';
    add_action( 'save_post', 'make_all_posts_private' );

    I don’t need to convert all posts in the database to private. This is only for new posts, or posts that are edited. That’s why I chose to register the action hook on ‘save_post’. What am I doing wrong?

    OK, well I got this to work, and all posts are private when saved or edited. Draft status is still available for posts. The problem now is that since all of the posts are private, the sidebar widget that lists categories no longer shows that any categories are available.

    Don’t know if this is the worst coding you’ve seen today, but here’s what I’ve got:

    if($_POST['post_type'] != 'page'){
    function make_all_new_posts_private($post_status){
    	if($post_status != 'draft'){
    		$post_status = 'private';
    	return $post_status;
    add_filter( 'status_save_pre', 'make_all_new_posts_private' );

    Edit: This is a reply to the response before last, not the one immediately above.

    Well, it looks to me like what you’re returning doesn’t make sense. But, anyway, i don’t think you can return anything from an action hook handler.

    If you want to return something, you need a filter.

    Reading through the wp_includes/post.php source code, it looks to me like your best bet is to filter on wp_insert_post_data . From the source code:

    @uses apply_filters() Calls 'wp_insert_post_data' passing $data,
    $postarr prior to database update or insert.

    $data is:

    $data = compact( array( 'post_author', 'post_date', 'post_date_gmt',
    'post_content', 'post_content_filtered', 'post_title', 'post_excerpt',
    'post_status', 'post_type', 'comment_status', 'ping_status',
    'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified',
    'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) );

    However, if you’d rather use the save_post action hook, that will be called after the post has been written to the database, so you could just set the status to draft in the posts table.

    I was writing my reply while you were posting yours, so i didn’t see yours till after i’d posted mine.

    So, you can see that I have what I need, with the exception that the categories no longer show up in the sidebar. I was able to make them show up by using wp_list_categories() with hide_empty=0. I just added this to mytheme/sidebar.php. What’s odd is that with another theme I dont see a post count, and with the theme I need to use I see a post count of zero appended to the category name.

    Category Name(0)

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Need posts to only have draft or private status’ is closed to new replies.