posts - disable password protected page for logged users

Is it possible to add hooks on function.php for disable password protected page for back-end users (logged users)?I use

Is it possible to add hooks on function.php for disable password protected page for back-end users (logged users)?

I use beaver builder and when i modify page or post I need always to put the password of the page before to access to the builder.

Thanks.

Is it possible to add hooks on function.php for disable password protected page for back-end users (logged users)?

I use beaver builder and when i modify page or post I need always to put the password of the page before to access to the builder.

Thanks.

Share Improve this question asked May 24, 2017 at 16:11 SamuelSamuel 3541 gold badge11 silver badges32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

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 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744868621a4598123.html

相关推荐

  • posts - disable password protected page for logged users

    Is it possible to add hooks on function.php for disable password protected page for back-end users (logged users)?I use

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信