Skip to content

Instantly share code, notes, and snippets.

@shirokoweb
Last active April 30, 2020 21:13
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 shirokoweb/cdaec0d159994cb26b764d35e1ad20c1 to your computer and use it in GitHub Desktop.
Save shirokoweb/cdaec0d159994cb26b764d35e1ad20c1 to your computer and use it in GitHub Desktop.
opti-plug.php
<?php
/**
* @snippet Conditional plugin load.
* @author Agence WebPlus
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$is_admin = strpos( $request_uri, '/wp-admin/' );
// add filter in front pages only
if( false === $is_admin ){
add_filter( 'option_active_plugins', 'webplus_option_active_plugins' );
}
function webplus_option_active_plugins( $plugins ){
global $request_uri;
$unnecessary_plugins = array();
$plugin_keep = array(
// 'booked/booked.php' => array('/promo-essai-gratuit/', '/promo-ouverture-7-7/', '/celebration-ouverture-le-dimanche/' ),
// 'timetable/timetable.php' => array('/programmes-de-crossfit/'),
'modern-events-calendar-lite/modern-events-calendar-lite.php' => array('/evenements/', '/events/' )
);
foreach ( $plugin_keep as $key => $value ) {
$n=count($value);
$i=0;
while( ($i<$n) && (strpos($request_uri, $value[$i]) === false) ) {
$i++;
}
if($i === $n) {
$unnecessary_plugins[] = $key;
}
}
foreach ( $unnecessary_plugins as $plugin ) {
$k = array_search( $plugin, $plugins );
if( false !== $k ){
unset( $plugins[$k] );
}
}
return $plugins;
}
//plugin to exclude name
// exclude from everywhere but NOT array[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment