函数文档

paused_plugins_notice()

💡 云策文档标注

概述

paused_plugins_notice() 函数用于在插件因错误暂停时渲染一个管理员通知。它检查当前页面、用户权限和暂停插件状态,然后输出错误消息。

关键要点

  • 函数仅在非 plugins.php 页面、当前用户具有 resume_plugins 权限且存在暂停插件时触发。
  • 使用 wp_admin_notice() 输出错误类型的通知,包含指向插件管理页面的链接。
  • 依赖于全局变量 $_paused_plugins 来检测暂停插件。

代码示例

function paused_plugins_notice() {
    if ( 'plugins.php' === $GLOBALS['pagenow'] ) {
        return;
    }

    if ( ! current_user_can( 'resume_plugins' ) ) {
        return;
    }

    if ( ! isset( $GLOBALS['_paused_plugins'] ) || empty( $GLOBALS['_paused_plugins'] ) ) {
        return;
    }

    $message = sprintf(
        '%s%s%s',
        __( 'One or more plugins failed to load properly.' ),
        __( 'You can find more details and make changes on the Plugins screen.' ),
        esc_url( admin_url( 'plugins.php?plugin_status=paused' ) ),
        __( 'Go to the Plugins screen' )
    );
    wp_admin_notice(
        $message,
        array( 'type' => 'error' )
    );
}

注意事项

  • 函数在 WordPress 5.2.0 版本中引入。
  • 通知消息使用 __() 进行国际化处理,链接通过 esc_url() 清理。
  • 相关函数包括 wp_admin_notice()、current_user_can()、__()、esc_url() 和 admin_url()。

📄 原文内容

Renders an admin notice in case some plugins have been paused due to errors.

Source

function paused_plugins_notice() {
	if ( 'plugins.php' === $GLOBALS['pagenow'] ) {
		return;
	}

	if ( ! current_user_can( 'resume_plugins' ) ) {
		return;
	}

	if ( ! isset( $GLOBALS['_paused_plugins'] ) || empty( $GLOBALS['_paused_plugins'] ) ) {
		return;
	}

	$message = sprintf(
		'<strong>%s</strong><br>%s</p><p><a href="%s">%s</a>',
		__( 'One or more plugins failed to load properly.' ),
		__( 'You can find more details and make changes on the Plugins screen.' ),
		esc_url( admin_url( 'plugins.php?plugin_status=paused' ) ),
		__( 'Go to the Plugins screen' )
	);
	wp_admin_notice(
		$message,
		array( 'type' => 'error' )
	);
}

Changelog

Version Description
5.2.0 Introduced.