Wordpress - How can I make it so the Add New Post page has Visibility set to Private by default?
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/
function default_post_visibility(){
global $post;
if ( 'publish' == $post->post_status ) {
$visibility = 'public';
$visibility_trans = __('Public');
} elseif ( !empty( $post->post_password ) ) {
$visibility = 'password';
$visibility_trans = __('Password protected');
} elseif ( $post_type == 'post' && is_sticky( $post->ID ) ) {
$visibility = 'public';
$visibility_trans = __('Public, Sticky');
} else {
$post->post_password = '';
$visibility = 'private';
$visibility_trans = __('Private');
} ?>
<script type="text/javascript">
(function($){
try {
$('#post-visibility-display').text('<?php echo $visibility_trans; ?>');
$('#hidden-post-visibility').val('<?php echo $visibility; ?>');
$('#visibility-radio-<?php echo $visibility; ?>').attr('checked', true);
} catch(err){}
}) (jQuery);
</script>
<?php
}
add_action( 'post_submitbox_misc_actions' , 'default_post_visibility' );
?>
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:
add_filter( 'wp_insert_post_data', 'mark_post_private' );
function mark_post_private( $data ) {
if ( 'your_post_type_goes_here' == $data['post_type'] ) {
$data['post_status'] = 'private';
}
return $data;
}