Skip to content

Instantly share code, notes, and snippets.

@MikeiLL
Last active December 29, 2015 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeiLL/699062ecd022962b0308 to your computer and use it in GitHub Desktop.
Save MikeiLL/699062ecd022962b0308 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Disable Event Espresso
Plugin URI: http://www.mzoo.org
Description: Disables event espresso plugin files from calls to all but specified pages
Author: mZoo/Mike iLL
Version: 1.0
Author URI: http://www.mzoo.org
*/
add_filter( 'option_active_plugins', 'mz_disable_event_espresso_plugin' );
function mz_disable_event_espresso_plugin($plugins){
$pages = array(
'tennis/tennis-calendar',
'tennis/adult-tennis/clinics',
'fitness/fitness-calendar',
'fitness/group-exercise/bodypump',
'fitness/group-exercise/buti-yoga',
'fitness/group-exercise/cross-train',
'fitness/group-exercise/herman-walkers-body-design-system',
'fitness/group-exercise/spinning',
'fitness/group-exercise/indoorwalking',
'fitness/group-exercise/insanity',
'fitness/group-exercise/barre',
'fitness/group-exercise/no-limits',
'fitness/group-exercise/physique',
'fitness/group-exercise/pilates',
'events-calendar',
'event-registration'
);
$test_pages = array(
"attendee-list",
"events-calendar",
"schedule",
"tippen-class-schedule-grid"
);
$plugins_to_disable = array(
'espresso-calendar/espresso-calendar.php',
'espresso-custom-templates/index.php',
'espresso-members/espresso-members.php',
'espresso-permissions-basic/espresso-permissions.php',
'espresso-recurring/espresso-recurring-events.php',
'espresso-social/espresso-social.php',
'event-espresso/espresso.php',
'event-espresso-core/espresso.php'
);
if(strposa($_SERVER['REQUEST_URI'], $pages) === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
foreach ($plugins_to_disable as $plugin_to_remove){
$key = array_search( $plugin_to_remove , $plugins );
if ( false !== $key ) {
unset( $plugins[$key] );
}
}
}
/*Uncomment this block to write out plugins for development
if (strposa($_SERVER['REQUEST_URI'], $test_pages) === TRUE){
mZ__write_to_file($_SERVER['REQUEST_URI']);
mZ__write_to_file($plugins);
}
*/
return $plugins;
}
function strposa($haystack, $needle, $offset=0) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $query) {
if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result
}
return false;
}
function mZ__write_to_file($message)
{
$header = "URL:\t ";
if (is_array($message)) {
$header = "\nPlugins:\n";
$message = print_r($message, true);
}
file_put_contents(
WPMU_PLUGIN_DIR . '/loaded_plugins.txt',
$header . $message,
FILE_APPEND | LOCK_EX
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment