Last active
February 24, 2025 00:33
-
-
Save carlodaniele/5b8343dd17a64c69d04459bffad2312c to your computer and use it in GitHub Desktop.
Revisions
-
carlodaniele revised this gist
Mar 23, 2019 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,14 +15,15 @@ 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 ); -
carlodaniele revised this gist
Mar 9, 2019 . 1 changed file with 45 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,44 +1,56 @@ <?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' ); if( count( $active_plugins ) > 0 ){ echo "<ul>"; foreach ( $active_plugins as $plugin ) { echo "<li>" . $plugin . "</li>"; } echo "</ul>"; } }); $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; } ); } -
carlodaniele created this gist
Apr 5, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ <?php // returns the path of the request URI without the query string // see http://php.net/manual/en/function.parse-url.php // and http://php.net/manual/en/reserved.variables.server.php // and http://php.net/manual/en/url.constants.php $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', 'kinsta_option_active_plugins' ); } /** * Filters active plugins * * @param array $plugins An array of active plugins. */ function kinsta_option_active_plugins( $plugins ){ global $request_uri; $is_contact_page = strpos( $request_uri, '/contact/' ); $unnecessary_plugins = array(); // conditions // if this is not contact page // deactivate plugins if( false === $is_contact_page ){ $unnecessary_plugins[] = 'contact-form-7/wp-contact-form-7.php'; $unnecessary_plugins[] = 'custom-post-type-ui/custom-post-type-ui.php'; $unnecessary_plugins[] = 'query-monitor/query-monitor.php'; } foreach ( $unnecessary_plugins as $plugin ) { $k = array_search( $plugin, $plugins ); if( false !== $k ){ unset( $plugins[$k] ); } } return $plugins; }