I am making a plugin and I need to get the record of all scripts and CSS utilized by different plugins.
That is my perform:
perform crunchify_print_scripts_styles() {
$outcome = [];
$outcome['scripts'] = [];
$outcome['styles'] = [];
// Print all loaded Scripts
international $wp_scripts;
foreach( $wp_scripts->queue as $script ) :
$outcome['scripts'][] = $wp_scripts->registered[$script]->src . ";";
endforeach;
// Print all loaded Types (CSS)
international $wp_styles;
foreach( $wp_styles->queue as $model ) :
$outcome['styles'][] = $wp_styles->registered[$style]->src . ";";
endforeach;
return $outcome;
}
add_action( 'wp_enqueue_scripts', 'crunchify_print_scripts_styles');
I need to get the returned worth inside a variable.
I attempted this:
$toto = do_action( 'crunchify_print_scripts_styles' );
var_dump( $toto );
And that is my outcome:
NULL
If I write echo
inside each foreach
loop, I get the proper outcomes, however find out how to retailer these values inside a variable?
[edit]
My code inside a pluginm which isn’t working too
/**
* Get all scripts and kinds from WordPress
*/
perform print_scripts_styles() {
$outcome = [];
$outcome['scripts'] = [];
$outcome['styles'] = [];
// Print all loaded Scripts
international $wp_scripts;
foreach( $wp_scripts->queue as $script ) :
$outcome['scripts'][] = $wp_scripts->registered[$script]->src . ";";
endforeach;
// Print all loaded Types (CSS)
international $wp_styles;
foreach( $wp_styles->queue as $model ) :
$outcome['styles'][] = $wp_styles->registered[$style]->src . ";";
endforeach;
return $outcome;
}
add_action( 'wp_head', 'wp_rest_assets_init');
/**
* Init JSON REST API Belongings routes.
*
* @since 1.0.0
*/
perform wp_rest_assets_init() {
$all_the_scripts_and_styles = print_scripts_styles();
if ( ! outlined( 'JSON_API_VERSION' ) &&
! in_array( 'json-rest-api/plugin.php', get_option( 'active_plugins' ) ) ) {
$class = new WP_REST_Assets();
$class::$scriptsAndStyles = $all_the_scripts_and_styles;
add_filter( 'rest_api_init', array( $class, 'register_routes' ) );
} else {
$class = new WP_JSON_Menus();
add_filter( 'json_endpoints', array( $class, 'register_routes' ) );
}
}
add_action( 'init', 'wp_rest_assets_init' );