函数文档

wp_recovery_mode_nag()

💡 云策文档标注

概述

wp_recovery_mode_nag() 函数用于在用户处于恢复模式时显示一个通知。该函数检查恢复模式状态,并输出包含退出链接的管理员通知。

关键要点

  • 函数仅在 WordPress 处于恢复模式时执行,否则直接返回。
  • 生成退出恢复模式的 URL,包括添加查询参数、nonce 和安全处理。
  • 使用 wp_admin_notice() 输出一个信息类型的通知,包含翻译后的消息和退出链接。
  • 依赖于多个核心函数,如 wp_is_recovery_mode()、wp_login_url()、add_query_arg()、wp_nonce_url()、__() 和 esc_url()。

代码示例

function wp_recovery_mode_nag() {
    if ( ! wp_is_recovery_mode() ) {
        return;
    }

    $url = wp_login_url();
    $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
    $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );

    $message = sprintf(
        /* translators: %s: Recovery Mode exit link. */
        __( 'You are in recovery mode. This means there may be an error with a theme or plugin. To exit recovery mode, log out or use the Exit button. Exit Recovery Mode' ),
        esc_url( $url )
    );
    wp_admin_notice( $message, array( 'type' => 'info' ) );
}

📄 原文内容

Displays a notice when the user is in recovery mode.

Source

function wp_recovery_mode_nag() {
	if ( ! wp_is_recovery_mode() ) {
		return;
	}

	$url = wp_login_url();
	$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
	$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );

	$message = sprintf(
		/* translators: %s: Recovery Mode exit link. */
		__( 'You are in recovery mode. This means there may be an error with a theme or plugin. To exit recovery mode, log out or use the Exit button. <a href="%s">Exit Recovery Mode</a>' ),
		esc_url( $url )
	);
	wp_admin_notice( $message, array( 'type' => 'info' ) );
}

Changelog

Version Description
5.2.0 Introduced.