Last active
October 28, 2024 12:28
-
-
Save ianpegg/5aa9524ea2251ba8f3afc1ba56041616 to your computer and use it in GitHub Desktop.
Any plugin that declares 'jquery' as a dependency rather than 'jquery-core' will cause jQuery Migrate to be registered too. When we know that all theme & plugin JS is compatible with the latest release of jQuery then we can safely deregister jQuery Migrate.
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 characters
<?php | |
/** | |
* Plugin Name: eggMUP: Deregister jQuery Migrate | |
* Plugin URI: https://gist.github.com/ianpegg/5aa9524ea2251ba8f3afc1ba56041616 | |
* Description: Improve WP performance by removing jQuery Migrate if it isn't needed. | |
* Version: 1.0.1 | |
* Author: Ian Pegg | |
* Author URI: https://eggcupwebdesign.com | |
* php version 8.2.14 | |
* | |
* @category Must_Use_Plugin | |
* @package WordPress_Plugin | |
* @author Ian Pegg <[email protected]> | |
* @license GNU/GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
* @link https://eggcupwebdesign.com | |
*/ | |
namespace EggCup\MUP\DeregisterJqueryMigrate; | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* Any plugin that declares 'jquery' as a dependency rather than | |
* 'jquery-core' will cause jQuery Migrate to be registered too. | |
* When we know that all theme & plugin JS is compatible with the | |
* latest release of jQuery then we can safely deregister jQuery Migrate. | |
* | |
* @param Array $Arr_scripts All scripts currently registered. | |
* | |
* @return void | |
*/ | |
add_action('wp_default_scripts', function ( $Arr_scripts ) { | |
if (!is_admin() && !empty($Arr_scripts->registered['jquery'])) { | |
$Arr_scripts->registered['jquery']->deps = array_diff( | |
$Arr_scripts->registered['jquery']->deps, | |
[ 'jquery-migrate' ] | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment