WordPress register_activation_hook() Callback Out of Scope?

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:

Read More
<?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?

Related posts

Leave a Reply

1 comment

  1. What if you do it in this way ?

    $hm = new FFI_AAM_Hook_Manager;
    register_activation_hook( __FILE__, array( &$hm, 'activationHandler' );
    register_uninstall_hook( __FILE__, array( &$hm, 'uninstallHandler' );
    

    Class:

    class FFI_AAM_Hook_Manager {
    
        public function activationHandler() {
            // activation code here
        }
    
        public function uninstallHandler() {
            // deactivation code here
        }
    }