1

我正在开发一个 Wordpress 插件,它利用 register_activation_hook() 方法在激活时自动安装。但是,永远不会调用挂钩应该处理安装的方法。这是我的代码:

音频存档/音频存档.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 的指示

有人可以指出我的错误吗?

4

1 回答 1

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
    }
}
于 2013-02-16T02:03:32.020 回答