Skip to content

Commit

Permalink
Revert "Frontend: Do not include files if plugins have been force dis…
Browse files Browse the repository at this point in the history
…abled."

After discussing things over with @boonebgorges, we've decided that
commit c107038 is over-engineering a solution to something that is an
edge-case scenario.

Will add a simpler fix to address bbPress load issues in the next commit.

See #105.
  • Loading branch information
r-a-y committed Dec 16, 2014
1 parent 85d9ba2 commit 45bd26b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 83 deletions.
4 changes: 4 additions & 0 deletions includes/frontend-bbpress.php
Expand Up @@ -13,6 +13,10 @@
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// setup globals for bbPress
cbox()->plugins->bbpress = new stdClass;
cbox()->plugins->bbpress->is_setup = function_exists( 'bbpress' );

/**
* Hotfixes and workarounds for bbPress.
*
Expand Down
4 changes: 4 additions & 0 deletions includes/frontend-bp.php
Expand Up @@ -14,6 +14,10 @@
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// setup globals for BuddyPress
cbox()->plugins->bp = new stdClass;
cbox()->plugins->bp->is_setup = function_exists( 'bp_include' );

/**
* Changes the default tab on a BP member page from 'Activity' to 'Profile'
*
Expand Down
4 changes: 4 additions & 0 deletions includes/frontend-cpf.php
Expand Up @@ -13,6 +13,10 @@
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// setup globals for bbPress
cbox()->plugins->cpf = new stdClass;
cbox()->plugins->cpf->is_setup = function_exists( 'custom_profile_filters_for_buddypress_init' );

/**
* Hotfixes and workarounds for CPF.
*
Expand Down
4 changes: 4 additions & 0 deletions includes/frontend-ges.php
Expand Up @@ -13,6 +13,10 @@
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// setup globals for GES
cbox()->plugins->ges = new stdClass;
cbox()->plugins->ges->is_setup = function_exists( 'ass_loader' );

/**
* Changes the default group subscription to "All Mail" from "No Email".
*
Expand Down
5 changes: 5 additions & 0 deletions includes/frontend-wp.php
Expand Up @@ -13,6 +13,11 @@
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// setup globals for WordPress
// not technically a plugin, but we sometimes need to modify WP core behavior
cbox()->plugins->wp = new stdClass;
cbox()->plugins->wp->is_setup = true; // WordPress is always available :)

/**
* Modifies the 'Updates' menu item in the WP Toolbar to omit numbers.
*
Expand Down
111 changes: 28 additions & 83 deletions includes/frontend.php
Expand Up @@ -29,10 +29,27 @@ public function __construct() {
if ( empty( $this->settings ) )
return;

add_action( 'plugins_loaded', array( $this, 'includes' ), 99 );
add_action( 'plugins_loaded', array( $this, 'setup_hooks' ), 100 );
add_action( 'init', array( $this, 'includes' ), 99 );
add_action( 'init', array( $this, 'setup_hooks' ), 100 );
// setup our CBOX plugins object
// this will hold some plugin-specific references
cbox()->plugins = new stdClass;

add_action( 'plugins_loaded', array( $this, 'setup' ), 100 );
}

/**
* Include the plugin mods and set up any necessary hooks
*
* Hooked to plugins_loaded to ensure that plugins have had a chance
* to fully initialize
*
* @since 1.0.5
*/
public function setup() {
// setup includes
$this->includes();

// setup our hooks
$this->setup_hooks();
}

/**
Expand All @@ -49,9 +66,6 @@ private function setup_globals() {

// merge admin settings with autoloaded ones
$this->settings = array_merge_recursive( $this->settings, $this->autoload );

// setup plugins
$this->setup_plugins();
}

/**
Expand Down Expand Up @@ -81,81 +95,17 @@ private function setup_autoload() {
$this->autoload['cpf'][] = 'CBox_CPF_Rehook_Social_Fields';
}

/**
* Setup plugins.
*
* What we're doing here is adding some properties so we can check for the
* plugin's existence later on in CBOX_Frontend::includes().
*
* @since 1.0.9.1
*/
private function setup_plugins() {
// setup our CBOX plugins object
// this will hold some plugin-specific references
$this->plugins = new stdClass;

$plugins = array_keys( $this->settings );

// we're adding the string of the function name to each plugin so we can check
// for its existence later on a hook that is specified below.
foreach ( $plugins as $plugin ) {
switch ( $plugin ) {
// buddypress
case 'bp' :
$this->plugins->$plugin = new stdClass;
$this->plugins->$plugin->active_check = 'bp_include';
$this->plugins->$plugin->on_action = 'plugins_loaded';
break;

// bbpress
case 'bbpress' :
$this->plugins->$plugin = new stdClass;
$this->plugins->$plugin->active_check = 'bbp_activation';
$this->plugins->$plugin->on_action = 'plugins_loaded';
break;

// custom profile filters for buddypress
case 'cpf' :
$this->plugins->$plugin = new stdClass;
$this->plugins->$plugin->active_check = 'cpfb_add_social_networking_links';
$this->plugins->$plugin->on_action = 'init';
break;

// group email subscription
case 'ges' :
$this->plugins->$plugin = new stdClass;
$this->plugins->$plugin->active_check = 'ass_activate_extension';
$this->plugins->$plugin->on_action = 'plugins_loaded';
break;

// wordpress
case 'wp' :
$this->plugins->$plugin = new stdClass;
$this->plugins->$plugin->active_check = 'wp';
$this->plugins->$plugin->on_action = 'plugins_loaded';
break;
}
}
}

/**
* Includes.
*
* We conditionally load up specific PHP files depending if a setting was
* saved under the CBOX admin settings page.
*/
public function includes() {
foreach ( $this->settings as $plugin => $classes ) {
// do not do this if we're not firing on the plugin's specific hook
if ( $this->plugins->$plugin->on_action !== current_filter() ) {
continue;
}

// if our plugin is not setup, do not load file
if ( ! function_exists( $this->plugins->$plugin->active_check ) ) {
continue;
}
private function includes() {
// get plugins from CBOX settings
$plugins = array_keys( $this->settings );

foreach ( $plugins as $plugin ) {
if ( file_exists( cbox()->plugin_dir . "includes/frontend-{$plugin}.php" ) ) {
require( cbox()->plugin_dir . "includes/frontend-{$plugin}.php" );
}
Expand All @@ -168,17 +118,12 @@ public function includes() {
* We conditionally add our hooks depending if a setting was saved under the
* CBOX admin settings page or if it is explicitly autoloaded by CBOX.
*/
public function setup_hooks() {
foreach( $this->settings as $plugin => $classes ) {
// do not do this if we're not firing on the plugin's specific hook
if ( $this->plugins->$plugin->on_action !== current_filter() ) {
continue;
}
private function setup_hooks() {

foreach( $this->settings as $plugin => $classes ) {
// if our plugin is not setup, stop loading hooks now!
if ( ! function_exists( $this->plugins->$plugin->active_check ) ) {
if ( empty( cbox()->plugins->$plugin->is_setup ) )
continue;
}

// sanity check
$classes = array_unique( $classes );
Expand Down

0 comments on commit 45bd26b

Please sign in to comment.