钩子文档

wp_is_application_passwords_available_for_user

💡 云策文档标注

概述

wp_is_application_passwords_available_for_user 是一个 WordPress 过滤器,用于控制应用密码功能是否对特定用户可用。它允许开发者基于用户对象自定义可用性逻辑。

关键要点

  • 这是一个过滤器,钩子名为 'wp_is_application_passwords_available_for_user'。
  • 接受两个参数:$available(布尔值,表示默认可用性)和 $user(WP_User 对象,表示要检查的用户)。
  • 返回布尔值,true 表示可用,false 表示不可用。
  • 在 WordPress 5.6.0 版本中引入。

代码示例

add_filter( 'wp_is_application_passwords_available_for_user', function( $available, $user ) {
    // 示例:仅对管理员用户启用应用密码
    if ( in_array( 'administrator', $user->roles ) ) {
        return true;
    }
    return false;
}, 10, 2 );

注意事项

  • 此过滤器通常与 wp_is_application_passwords_available_for_user() 函数结合使用,用于检查用户级别的应用密码可用性。
  • 确保在回调函数中正确处理 $user 参数,避免因用户对象无效导致错误。

📄 原文内容

Filters whether Application Passwords is available for a specific user.

Parameters

$availablebool
True if available, false otherwise.
$userWP_User
The user to check.

Source

return apply_filters( 'wp_is_application_passwords_available_for_user', true, $user );

Changelog

Version Description
5.6.0 Introduced.