通过做两件事解决了问题
已从中删除主呼叫
/**
* Initialize the activation works of the plugin.
*/
function awraq_activate_plugin()
{
//removed
}
register_activation_hook(__FILE__, \'awraq_activate_plugin\');
已将呼叫添加到;plugins\\u loaded“插件加载”;
/**
* Initialize the plugin.
*/
function awraq_init_plugin()
{
if (Init::activate() != TRUE) {
deactivate_plugins(plugin_basename(__FILE__));
//added below
Notice::error(\'Plugin got Deactivated. Please check the dependencies.\', true);
}
}
add_action(\'plugins_loaded\', \'awraq_init_plugin\');
在移除的类上
__CLASS__
具有完整的命名空间和类-
private static $globalScopeName = \'Awraq\\Base\\Notice\';
, 因为它将从外部调用
namespace Awraq\\Base;
if (!defined(\'ABSPATH\')) exit;
class Notice
{
private static $globalScopeName = \'Awraq\\Base\\Notice\';
private static $class = \'\';
private static $msg = \'\';
public static function error($msg = \'error\', $is_dismissible = TRUE)
{
self::$class = ($is_dismissible == TRUE) ? \'notice notice-error is-dismissible\' : \'notice notice-error\';
self::$msg = __($msg, AWRAQ_TEXT_DOMAIN);
add_action(\'admin_notices\', array(self::$globalScopeName, \'awraq_notice\'));
}
public static function warning($msg = \'warning\', $is_dismissible = TRUE)
{
self::$class = ($is_dismissible == TRUE) ? \'notice notice-warning is-dismissible\' : \'notice notice-warning\';
self::$msg = __($msg, AWRAQ_TEXT_DOMAIN);
add_action(\'admin_notices\', array(self::$globalScopeName, \'awraq_notice\'));
}
public static function success($msg = \'success\', $is_dismissible = TRUE)
{
self::$class = ($is_dismissible == TRUE) ? \'notice notice-success is-dismissible\' : \'notice notice-success\';
self::$msg = __($msg, AWRAQ_TEXT_DOMAIN);
add_action(\'admin_notices\', array(self::$globalScopeName, \'awraq_notice\'));
}
public static function info($msg = \'info\', $is_dismissible = TRUE)
{
self::$class = ($is_dismissible == TRUE) ? \'notice notice-info is-dismissible\' : \'notice notice-info\';
self::$msg = __($msg, AWRAQ_TEXT_DOMAIN);
add_action(\'admin_notices\', array(self::$globalScopeName, \'awraq_notice\'));
}
public static function awraq_notice()
{
$class = self::$class;
$msg = self::$msg;
if ($class == \'\' and $msg == \'\') {
return;
}
printf(\'<div class="%1$s"><p>%2$s</p></div>\', esc_attr($class), esc_html($msg));
}
}