Last active
May 6, 2021 05:17
-
-
Save alexsoyes/0da94d964db3c2568b1ee0568c999905 to your computer and use it in GitHub Desktop.
WordPress Plugin : Show all enqueued assets (scripts & styles) in backend/frontend comments
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: WP Show enqueued assets | |
* Description: Show all enqueued assets (scripts & styles) in backend/frontend comments. | |
* Version: 0.0.1 | |
* Requires at least: 5.2 | |
* Requires PHP: 7.0 | |
* Author: Alex so yes | |
* Author URI: https://alexsoyes.com | |
* License: GPL v2 or later | |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
* Text Domain: asy-wp-debug | |
*/ | |
/** | |
* @see https://wordpress.stackexchange.com/questions/233140/how-can-i-get-a-list-of-all-enqueued-scripts-and-styles | |
*/ | |
add_action( 'wp_head', function () { | |
echo '<!--'; | |
global $enqueued_scripts; | |
global $enqueued_styles; | |
print_r( $enqueued_scripts ); | |
print_r( $enqueued_styles ); | |
echo '-->'; | |
} ); | |
global $enqueued_scripts; | |
global $enqueued_styles; | |
add_action( 'wp_print_scripts', 'asy_list_scripts' ); | |
function asy_list_scripts(): void { | |
global $wp_scripts; | |
global $enqueued_scripts; | |
$enqueued_scripts = array(); | |
foreach ( $wp_scripts->queue as $handle ) { | |
$enqueued_scripts[] = sprintf( | |
"[%s] : %s (%s) | v%s", | |
$wp_scripts->registered[ $handle ]->handle, | |
$wp_scripts->registered[ $handle ]->src, | |
implode( ',', $wp_scripts->registered[ $handle ]->deps ), | |
$wp_scripts->registered[ $handle ]->ver, | |
); | |
} | |
} | |
add_action( 'wp_print_styles', 'asy_list_styles' ); | |
function asy_list_styles(): void { | |
global $wp_styles; | |
global $enqueued_styles; | |
$enqueued_styles = array(); | |
foreach ( $wp_styles->queue as $handle ) { | |
$enqueued_styles[] = sprintf( | |
"[%s] : %s (%s) | v%s", | |
$wp_styles->registered[ $handle ]->handle, | |
$wp_styles->registered[ $handle ]->src, | |
implode( ',', $wp_styles->registered[ $handle ]->deps ), | |
$wp_styles->registered[ $handle ]->ver, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment