前言
此筛选器与其它身份验证相关的筛选器不同,因为它提供了在身份验证过程中自定义重定向的广泛范围。与针对 login、registration、lost password 或 reset password 页面的特定筛选器不同,此筛选器适用于任何与身份验证相关的 URL。功能:此筛选器允许根据不同身份验证场景下的自定义条件覆盖默认的重定向 URL。它提供了根据身份验证流程的上下文或特定要求将用户重定向到不同页面的灵活性。在下面的示例中,重定向 URL 根据当前 URL 路径变化,从而实现动态、上下文相关的重定向策略。参数:返回值:
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/auth/custom_redirect_url', function( $custom_redirect_url, $current_url_path ) {
if ( /* custom condition based on $current_url_path */ ) {
return 'https://example.com/custom-redirect';
}
return $custom_redirect_url;
}, 10, 2 );
示例代码
筛选返回值
add_filter( 'bricks/auth/custom_redirect_url', function( $custom_redirect_url, $current_url_path ) {
if ( /* custom condition based on $current_url_path */ ) {
return 'https://example.com/custom-redirect';
}
return $custom_redirect_url;
}, 10, 2 );
补充说明
更多细节可参考 官方文档。