Last active
April 30, 2020 21:13
-
-
Save shirokoweb/cdaec0d159994cb26b764d35e1ad20c1 to your computer and use it in GitHub Desktop.
opti-plug.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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