Skip to content

Instantly share code, notes, and snippets.

@MikeiLL
Created February 5, 2020 18:16
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/d2909a8060bbac01494a2195a0a7be2e to your computer and use it in GitHub Desktop.
Save MikeiLL/d2909a8060bbac01494a2195a0a7be2e 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/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',
'my-bookings'
);
$test_pages = array(
"attendee-list",
"events-calendar",
"schedule",
"tippen-class-schedule-grid",
"tennis-calendar"
);
$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($_SERVER['REQUEST_URI'] !== '/'):
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] );
}
}
}
endif;
/*
//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);
printMe($plugins);
printMe($_SERVER['REQUEST_URI']);
}
*/
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
);
}
function printMe($message){
echo "<pre>";
print_r($message);
echo "<pre>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment