Disable the post password protection for (some) users
You can try the post_password_required
filter (4.7+) to override it for logged in users:
add_filter( 'post_password_required', function( $returned, $post )
{
// Override it for logged in users:
if( $returned && is_user_logged_in() )
$returned = false;
return $returned;
}, 10, 2 );
or disable it for users with a given capability ( e.g. manage_options) :
add_filter( 'post_password_required', function( $returned, $post )
{
// Override it for users with the 'manage_options' capability
if( $returned && current_user_can( 'manage_options' ) )
$returned = false;
return $returned;
}, 10, 2 );
We could target a given post type with:
add_filter( 'post_password_required', function( $returned, $post )
{
// Target protected posts only
if( ! $returned )
return $returned;
// Target logged in users only
if( ! is_user_logged_in() )
return $returned;
// Target 'page' post type only
if( 'page' !== get_post_type( $post ) )
return $returned;
// Override
return false;
}, 10, 2 );
Remove ‘Protected’ text from protected post titles
To remove the prepended Protected from the title, we can adjust the protected title format, for logged in users, with the protected_title_format filter:
add_filter( 'protected_title_format', function( $format, $post )
{
if( is_user_logged_in() )
$format="%s";
return $format;
}, 10, 2 );