I’m trying to create a plugin that alters the Add New Post page so the Visibility field says “Private” by default:
Status: Draft
Visibility: **Private**
Publish immediately
[Publish]
…as opposed to what WordPress normally assumes:
Status: Draft
Visibility: **Public**
Publish immediately
[Publish]
At the moment, I’m using the “wp_insert_post_data” filter, and that is allowing me to change any posts with a post_status of “auto-draft” to “private”. While this works, there is an unintended side-effect: Changing the post_status to “private” seems to publish the post automatically, changing the button in the editor to “Update”. Furthermore, if the user saves before specifying a title, the post will be published with the title “Auto-Draft”.
Is there any way I can simply change Visibility to Private by the default, in a manner that doesn’t auto-publish the post, and change the button to “Update”? In vanilla WordPress, users can manually change the visibility to Private, and the button remains as Publish… I just need to achieve that via a plugin. I also want to ensure that “public” can still be selected by the user, should they desire to.
Thanks!
since you’re developing a plug-in, I assume you don’t want to touch any files outside of wp-content/plugins or ../themes for that matter.
However, if that’s not the case, follow along:
Go to wp-admin/includes/meta-boxes.php and find:
Now change it to the obvious:
Again, this affects the meta-boxes.php file which is outside of the plugins folder. Nonetheless, I think the approach you should be taking is creating a new meta box, adding your custom visibility setting (i.e. private) and make the latter override the default WP visibility setting.
Best,
Chris
from the plugin; uses action ‘post_submitbox_misc_actions’ and some query to catch the user Publish form:
http://wordpress.org/extend/plugins/private-post-by-default/
The correct way to automatically mark a post as private is to do it with the wp_insert_post_data filter. It’s very straightforward: