我正在开发一个Wordpress插件,它利用register_activation_hook()方法在激活时自动安装。但是,从不调用钩子应该处理安装的方法。这是我的代码:
音频存档/音频archive.php:
<?php
/*
Plugin Name: Audio Archive Manager
...
*/
...
define("FFI_AAM_PATH", plugin_dir_path(__FILE__));
...
require_once(FFI_AAM_PATH . "includes/FFI_AAM_Hook_Manager.php");
new FFI_AAM_Hook_Manager();
?>
音频 - 归档/包括/ FFI_AAM_Hook_Manager.php:
<?php
class FFI_AAM_Hook_Manager {
public function __construct() {
echo "Hello"; //Runs perfectly
register_activation_hook(__FILE__, array($this, "activationHandler"));
register_uninstall_hook(__FILE__, array($this, "uninstallHandler"));
}
//Never called
public function activationHandler() {
die("I've been CALLED!");
require_once(FFI_AAM_PATH . "includes/FFI_AAM_Installer.php");
new FFI_AAM_Installer();
}
//Never called
public function uninstallHandler() {
die("I've been CALLED!");
require_once(FFI_AAM_PATH . "includes/FFI_AAM_Uninstaller.php");
new FFI_AAM_Uninstaller();
}
}
?>
我认为这是与范围相关的问题,但我不确定如何克服它,因为我已经关注Wordpress's directions。
有人可以指出我的错误吗?
答案 0 :(得分:1)
如果你这样做会怎么样?
$hm = new FFI_AAM_Hook_Manager;
register_activation_hook( __FILE__, array( &$hm, 'activationHandler' );
register_uninstall_hook( __FILE__, array( &$hm, 'uninstallHandler' );
<强>类别:强>
class FFI_AAM_Hook_Manager {
public function activationHandler() {
// activation code here
}
public function uninstallHandler() {
// deactivation code here
}
}