I am developing a WordPress plugin which utilizes the register_activation_hook() method to auto install upon activation. However, the method which the hook is supposed to handle the installation is never called. Here is my code:
audio-archive/audio-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();
?>
audio-archive/includes/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();
}
}
?>
I believe this is a scope related issue, but I’m not sure how to overcome it, given that I have followed WordPress’s directions.
Could someone please point out my error?
What if you do it in this way ?
Class: