-
-
Save muiton/06434ff20895838446a0f394f347d6e0 to your computer and use it in GitHub Desktop.
A Must-use plugin to filter active plugins in on a per-page basis.
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 | |
/** | |
* @package active-plugins | |
* @version 1.0 | |
* | |
* Plugin Name: Active Plugins | |
* Plugin URI: http://wordpress.org/extend/plugins/# | |
* Description: This is a development plugin | |
* Author: Carlo Daniele | |
* Version: 1.0 | |
* Author URI: https://carlodaniele.it/ | |
*/ | |
// shortcode to list active plugins | |
add_shortcode( 'activeplugins', function(){ | |
$active_plugins = get_option( 'active_plugins' ); | |
$plugins = ""; | |
if( count( $active_plugins ) > 0 ){ | |
$plugins = "<ul>"; | |
foreach ( $active_plugins as $plugin ) { | |
$plugins .= "<li>" . $plugin . "</li>"; | |
} | |
$plugins .= "</ul>"; | |
} | |
return $plugins; | |
}); | |
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); | |
$is_admin = strpos( $request_uri, '/wp-admin/' ); | |
if( false === $is_admin ){ | |
// filter active plugins | |
add_filter( 'option_active_plugins', function( $plugins ){ | |
global $request_uri; | |
$is_contact_page = strpos( $request_uri, '/contact/' ); | |
// change elements according to your needs | |
$myplugins = array( | |
"contact-form-7/wp-contact-form-7.php", | |
"code-snippets/code-snippets.php", | |
"query-monitor/query-monitor.php", | |
"autoptimize/autoptimize.php" | |
); | |
if( false === $is_contact_page ){ | |
$plugins = array_diff( $plugins, $myplugins ); | |
} | |
return $plugins; | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment