Skip to content

Commit

Permalink
Listen for requests at init hook, instead of plugins_loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Sep 6, 2015
1 parent e1aef14 commit 16ef7e8
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions edd-helpscout.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,19 @@ class Plugin {
* Constructor
*/
public function __construct() {
}

// Load autoloader
require __DIR__ . '/vendor/autoload.php';

// Register activation hook
register_activation_hook( __FILE__, array( 'EDD_HelpScout\\Admin', 'plugin_activation' ) );

// Instantiate the plugin on a later hook
add_action( 'plugins_loaded', array( $this, 'init' ), 90 );
/**
* Add hooks
*/
public function add_hooks() {
add_action( 'init', array( $this, 'listen' ) );
}

/**
* Initialise the rest of the plugin
*/
public function init() {

// do nothing if EDD is not activated
if( ! class_exists( 'Easy_Digital_Downloads', false ) ) {
return;
}
public function listen() {

// if this is a HelpScout Request, load the Endpoint class
if ( $this->is_helpscout_request() && ! is_admin() ) {
Expand All @@ -80,8 +73,6 @@ public function init() {

if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
new AJAX();
} elseif( is_admin() ) {
new Admin();
}
}

Expand All @@ -108,7 +99,30 @@ private function is_helpscout_request() {

}

new Plugin();
/**
* Bootstrap the plugin at `plugins_loaded` (after EDD)
*/
add_action( 'plugins_loaded', function() {
// do nothing if EDD is not activated
if( ! class_exists( 'Easy_Digital_Downloads' ) ) {
return;
}

// Load autoloader
require __DIR__ . '/vendor/autoload.php';

// Register activation hook
register_activation_hook( __FILE__, array( 'EDD_HelpScout\\Admin', 'plugin_activation' ) );

// Instantiate plugin
$plugin = new Plugin();
$plugin->add_hooks();

// Load Admin stuff
if( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
$admin = new Admin();
}
}, 90 );



0 comments on commit 16ef7e8

Please sign in to comment.