我目前正在写一个wordpress插件,我遇到了一些问题。 我的函数不会在插件激活时运行...有人可以告诉我问题在哪里吗?
class my_plugin { public $ajaxurl; public $excanvas; public $plugin_path = ''; function __construct() { register_activation_hook(__FILE__,array(&$this, 'install')); } public function wpmon_install() { //Copy my page template to current theme. $plugin_path = getcwd() . DIRECTORY_SEPARATOR . 'wp-content'. DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'wpmon' . DIRECTORY_SEPARATOR; $target_path = get_stylesheet_directory(). DIRECTORY_SEPARATOR; $target_path = str_replace('/',DIRECTORY_SEPARATOR,$target_path); $template_files = glob($plugin_path . 'page_template'.DIRECTORY_SEPARATOR.'*.php'); foreach($template_files as $files) { $basename = basename($files); try{ $target = $target_path . $basename; copy($files , $target); } catch(Exception $e){ $this->log_error( $e->getMessage()); } } }
但遗憾的是安装功能不起作用...... 但是当在外部类中,'install'func中的代码正在工作
答案 0 :(得分:0)
从发布的代码中我可以看到两个问题。安装应该更改为wpmon_install。你还应该添加一些代码来初始化你的类。
即。 $wp_mon = new my_plugin();
之后class my_plugin { }
答案 1 :(得分:0)
请检查您是否使用了软链接,该插件必须完全位于/path/to/wordpress/wp-content/plugins/yourplugin
,这意味着yourplugin
不是软链接。
答案 2 :(得分:-1)
你有Wordpress尝试在你的类中调用一个名为install
的函数,但它不存在。所以尝试改变:
register_activation_hook(__FILE__,array(&$this, 'install'));
到
register_activation_hook(__FILE__,array(&$this, 'wpmon_install'));