Bricks 中文文档:bricks/password_protection/is_active

📄 原始资料  |  展开查看原始 JSON(bricks-password_protection-is_active.json){ “name”: “bricks/password_protection/is_active”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/filter-bricks-password_protection-is_active/”, “scraped_at”: “2026-08-29”, “hook_name”: “bri…

📄 原始资料  |  展开查看原始 JSON(bricks-password_protection-is_active.json)
{
  "name": "bricks/password_protection/is_active",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/filter-bricks-password_protection-is_active/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/password_protection/is_active",
  "description": {
    "en": "Use this filter to add custom rules that determine whether a password protection template should be active. By default, the template’s visibility is controlled by settings such as logged-in status, valid password cookies, and scheduling through the password protection template settings in the builder. This filter allows you to extend those checks, adding more dynamic criteria once the default settings have been applied. In this example, any user with the manage_options capability (typically administrators) will bypass the password protection, while other users will follow the default settings. Parameters: Return:",
    "zh": "使用此筛选器可添加自定义规则,以确定是否应激活密码保护模板。默认情况下,模板的可见性由登录状态、有效密码 cookie 以及通过构建器中的密码保护模板设置进行调度等设置控制。此筛选器允许你扩展这些检查,在应用默认设置后添加更多动态条件。在下面的示例中,任何拥有 manage_options 权限的用户(通常是管理员)将绕过密码保护,而其他用户将遵循默认设置。参数:返回值:"
  },
  "example_usage": "add_filter( 'bricks/password_protection/is_active', function( $is_active, $template_id, $settings ) {\n    // Bypass password protection for users with the 'manage_options' capability\n    if ( current_user_can( 'manage_options' ) ) {\n        return false;\n    }\n\n\n    // Maintain default logic for other cases\n    return $is_active;\n}, 10, 3 );"
}

前言

使用此筛选器可添加自定义规则,以确定是否应激活密码保护模板。默认情况下,模板的可见性由登录状态、有效密码 cookie 以及通过构建器中的密码保护模板设置进行调度等设置控制。此筛选器允许你扩展这些检查,在应用默认设置后添加更多动态条件。在下面的示例中,任何拥有 manage_options 权限的用户(通常是管理员)将绕过密码保护,而其他用户将遵循默认设置。参数:返回值:

用法

将代码加入子主题的 functions.php

add_filter( 'bricks/password_protection/is_active', function( $is_active, $template_id, $settings ) {
    // Bypass password protection for users with the 'manage_options' capability
    if ( current_user_can( 'manage_options' ) ) {
        return false;
    }


    // Maintain default logic for other cases
    return $is_active;
}, 10, 3 );

示例代码

筛选返回值

add_filter( 'bricks/password_protection/is_active', function( $is_active, $template_id, $settings ) {
    // Bypass password protection for users with the 'manage_options' capability
    if ( current_user_can( 'manage_options' ) ) {
        return false;
    }


    // Maintain default logic for other cases
    return $is_active;
}, 10, 3 );

补充说明

更多细节可参考 官方文档