我知道我可能在做一些愚蠢的事情,但我就是不能让它运行。我正在尝试为我的插件设置一个小API,并创建一个类来更轻松地显示管理通知。以下是我所拥有的:
// Send data to class to get HTML for admin notice
$efpd=Efpdd::getInstance();
$plugin_update = $efpd->efpd_admin_notice(
$notice_info = array(
\'type\' => \'update\',
\'message\' => \'The plugin has just been updated.\',
\'button\' => \'Click for details\'
)
);
//wp_die(var_dump($plugin_update)); // Testing output of admin notice HTML code
add_action(\'admin_notices\',function(){echo $plugin_update;});
在我的课堂上,有一个函数:
public function efpd_admin_notice($data=array()){
extract($data); // Extracts $message, $type, and $button from $data array
if(empty($message) && !empty($type)){ // If no message was passed through the $data array, create one based on the type of notice passed, also begin the HTML output here
switch($type){
case \'error\':
$message = \'There\\\'s been an error!\';
$return = "<div id=\\"message\\" class=\\"error\\">\\n";
break;
case \'update\':
$message = \'There\\\'s been an update!\';
$return = "<div id=\\"message\\" class=\\"updated\\">\\n";
break;
default:
$message = \'There\\\'s something wrong with your code...\';
$return = "<div id=\\"message\\" class=\\"error\\">\\n";
break;
}
}
if(empty($button)) $button = \'Click Here\';
$return .= " <p style=\\"float: left;\\">{$message}</p>\\n";
$return .= " <p style=\\"float: left;\\"><a href=\\"{$settings_url}&clear_cache=y\\">{$button}</a></p>\\n";
$return .= "</div>\\n";
return $return;
}
所以我想我是在问,我有什么错让这个管理通知不显示?是否有一个解决方法来实现这一点?谢谢
最合适的回答,由SO网友:Brian Fegter 整理而成
试试这个。我清理了您的arg数组,并将所有内容都放在一个函数中。另外,当您的efpd\\u admin\\u通知是公开的时,为什么要使用getInstance方法?请参阅下面的代码以正确访问此方法。
function plugin_update(){
$plugin_update = Efpdd::efpd_admin_notice(array(
\'type\' => \'update\',
\'message\' => \'The plugin has just been updated.\',
\'button\' => \'Click for details\'
);
echo $plugin_update;
);
add_action(\'admin_notices\', \'plugin_update\');