Automattic\WooCommerce\Admin\Features\Settings
Init::get_script_urls
Retrieve the script URLs from the provided script handles. This will also filter out scripts from WordPress core since they only need to be loaded once.
Method of the class: Init{}
No Hooks.
Returns
Array. Array of script URLs.
Usage
$result = Init::get_script_urls( $script_handles );
- $script_handles(array) (required)
- Array of script handles.
Init::get_script_urls() Init::get script urls code WC 10.5.0
private static function get_script_urls( $script_handles ) {
global $wp_scripts;
$script_urls = array();
foreach ( $script_handles as $script ) {
$registered_script = $wp_scripts->registered[ $script ];
if ( ! isset( $registered_script->src ) ) {
continue;
}
// Skip scripts from WordPress core since they only need to be loaded once.
if ( strpos( $registered_script->src, '/' . WPINC . '/js' ) === 0 || strpos( $registered_script->src, '/wp-admin/js' ) === 0 ) {
continue;
}
$src = $registered_script->src;
$ver = $registered_script->ver ? $registered_script->ver : false;
// Add version query parameter.
if ( $ver ) {
$src = add_query_arg( 'ver', $ver, $src );
}
// Add home URL if the src is a relative path.
if ( strpos( $src, '/' ) === 0 ) {
$script_urls[] = home_url( $src );
} else {
$script_urls[] = $src;
}
}
return $script_urls;
}