函数文档

wp_user_request_action_description()

💡 云策文档标注

概述

wp_user_request_action_description() 函数用于根据请求操作名称获取人类可读的描述字符串,支持通过过滤器进行自定义。

关键要点

  • 函数接受一个必需参数 $action_name(字符串类型),表示请求的操作名称。
  • 返回一个字符串,为人类可读的操作描述,基于 $action_name 进行 switch 匹配或默认格式化。
  • 内置对 'export_personal_data' 和 'remove_personal_data' 的特定翻译处理,其他情况使用默认描述。
  • 提供 'user_request_action_description' 过滤器,允许开发者修改描述字符串。
  • 函数自 WordPress 4.9.6 版本引入。

代码示例

function wp_user_request_action_description( $action_name ) {
    switch ( $action_name ) {
        case 'export_personal_data':
            $description = __( 'Export Personal Data' );
            break;
        case 'remove_personal_data':
            $description = __( 'Erase Personal Data' );
            break;
        default:
            /* translators: %s: Action name. */
            $description = sprintf( __( 'Confirm the "%s" action' ), $action_name );
            break;
    }

    /**
     * Filters the user action description.
     *
     * @since 4.9.6
     *
     * @param string $description The default description.
     * @param string $action_name The name of the request.
     */
    return apply_filters( 'user_request_action_description', $description, $action_name );
}

注意事项

  • 函数依赖于翻译函数 __() 和 sprintf(),确保国际化支持。
  • 过滤器 'user_request_action_description' 可用于自定义描述,需注意参数顺序和类型。
  • 相关函数包括 _wp_privacy_send_request_confirmation_notification() 和 wp_send_user_request(),用于通知和邮件发送。

📄 原文内容

Gets action description from the name and return a string.

Parameters

$action_namestringrequired
Action name of the request.

Return

string Human readable action name.

Source

function wp_user_request_action_description( $action_name ) {
	switch ( $action_name ) {
		case 'export_personal_data':
			$description = __( 'Export Personal Data' );
			break;
		case 'remove_personal_data':
			$description = __( 'Erase Personal Data' );
			break;
		default:
			/* translators: %s: Action name. */
			$description = sprintf( __( 'Confirm the "%s" action' ), $action_name );
			break;
	}

	/**
	 * Filters the user action description.
	 *
	 * @since 4.9.6
	 *
	 * @param string $description The default description.
	 * @param string $action_name The name of the request.
	 */
	return apply_filters( 'user_request_action_description', $description, $action_name );
}

Hooks

apply_filters( ‘user_request_action_description’, string $description, string $action_name )

Filters the user action description.

Changelog

Version Description
4.9.6 Introduced.