[wp-trac] [WordPress Trac] #59132: Create two filters in wp_scripts() and wp_styles().
WordPress Trac
noreply at wordpress.org
Thu Aug 17 18:19:00 UTC 2023
#59132: Create two filters in wp_scripts() and wp_styles().
-----------------------------+-----------------------------
Reporter: salvio | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: trunk
Severity: normal | Keywords:
Focuses: javascript, css |
-----------------------------+-----------------------------
I'd like to know if it's possibile to change this:
{{{#!php
<?php
function wp_scripts() {
global $wp_scripts;
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
$wp_scripts = new WP_Scripts();
}
return $wp_scripts;
}
}}}
into:
{{{#!php
<?php
function wp_scripts() {
global $wp_scripts;
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
$wp_scripts = apply_filters( 'wp_scripts_instance', new
WP_Scripts() );
}
return $wp_scripts;
}
}}}
To extend WP_Scripts and WP_Styles, for example:
{{{#!php
<?php
add_filter( 'wp_scripts_instance', function ($wp_scripts) {
if( !class_exists('ScriptEnqueuer') )
{
return $wp_scripts;
}
return new ScriptEnqueuer();
});
}}}
Is this possible?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59132>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list