📄 原始资料 | 展开查看原始 JSON(bricks-password_protection-cookie_expires.json){ “name”: “bricks/password_protection/cookie_expires”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/filter-bricks-password_protection-cookie-expires/”, “scraped_at”: “2026-08-29”, “h…
📄 原始资料 | 展开查看原始 JSON(bricks-password_protection-cookie_expires.json)
{
"name": "bricks/password_protection/cookie_expires",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/filter-bricks-password_protection-cookie-expires/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/password_protection/cookie_expires",
"description": {
"en": "Adjust the expiration time for the password cookie used by the password protection template . By default, when a password is set in the template settings, the cookie expires after 10 days . This filter allows you to customize how long the cookie remains valid. In this example, the password cookie will expire after 1 hour, requiring users to re-enter the password if they revisit the page after that time. Parameters: Return:",
"zh": "调整用于密码保护模板的密码 cookie 过期时间。默认情况下,当模板设置中设置了密码时,cookie 在 10 天后过期。此筛选器允许你自定义 cookie 保持有效的时间。在下面的示例中,密码 cookie 将在 1 小时后过期,要求用户在该时间后再次访问页面时重新输入密码。参数:返回值:"
},
"example_usage": "add_filter( 'bricks/password_protection/cookie_expires', function( $expire ) {\n // Set cookie expiration to 1 hour (3600 seconds)\n return time() + 3600;\n} );"
}
前言
调整用于密码保护模板的密码 cookie 过期时间。默认情况下,当模板设置中设置了密码时,cookie 在 10 天后过期。此筛选器允许你自定义 cookie 保持有效的时间。在下面的示例中,密码 cookie 将在 1 小时后过期,要求用户在该时间后再次访问页面时重新输入密码。参数:返回值:
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/password_protection/cookie_expires', function( $expire ) {
// Set cookie expiration to 1 hour (3600 seconds)
return time() + 3600;
} );
示例代码
筛选返回值
add_filter( 'bricks/password_protection/cookie_expires', function( $expire ) {
// Set cookie expiration to 1 hour (3600 seconds)
return time() + 3600;
} );
补充说明
更多细节可参考 官方文档。