我写了那段代码
<?php
/**
* @package ppa
* @version 0.1
*/
/*
Plugin Name: PPAPlugin
Description: PPAPlugin desct
Author: Sekhmet
Version: 0.1
*/
register_activation_hook( plugin_basename( __FILE__ ), array( 'PPA', 'activate' ) );
register_deactivation_hook( plugin_basename( __FILE__ ), array( 'PPA', 'deactivate' ) );
register_uninstall_hook( plugin_basename( __FILE__ ), array( 'PPA', 'uninstall' ) );
class PPA
{
const NAME = "PPA";
public static function activate() {
self :: ppa_add_dashboard();
}
public static function deactivate() {
}
public static function uinstall() {
}
function ppa_add_dashboard() {
wp_add_dashboard_widget( 'ppa_widget', self :: NAME , array($this, 'ppa_dashboard_widget') );
}
function ppa_dashboard_widget() {
}
}
?>
但是当我尝试在ACP上启用它时,我得到了那个消息:
致命错误:调用未定义的函数wp_add_dashboard_widget() /home/muffinki/domains/muffinki.org/public_html/wp-content/plugins/ppa/ppa.php 第35行
Wordpress版本3.5.1(最新版)。
答案 0 :(得分:4)
将ppa_add_dashboard()
函数挂钩到wp_dashboard_setup
操作中,以便在正确的时间调用它。
public static function activate() {
add_action( 'wp_dashboard_setup', array( __CLASS__, 'ppa_add_dashboard' ) );
}
参考文献:
http://codex.wordpress.org/Function_Reference/wp_add_dashboard_widget