/default-posts-to-private.php Secret
Last active
May 25, 2017 20:11
Star
You must be signed in to star a gist
Set WordPress posts visibility to private by default. Source: http://www.paulund.co.uk/set-wordpress-posts-to-private-by-default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Set WordPress posts visibility to private by default | |
function customprefix_default_posts_to_private() | |
{ | |
global $post; | |
if ( $post->post_status == 'publish' ) { | |
$visibility = 'public'; | |
$visibility_trans = __('Public'); | |
} elseif ( !empty( $post->post_password ) ) { | |
$visibility = 'password'; | |
$visibility_trans = __('Password protected'); | |
} elseif ( $post->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' , 'customprefix_default_posts_to_private' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment