Make WordPress Core

Opened 9 years ago

Closed 8 months ago

Last modified 8 months ago

#32607 closed feature request (invalid)

Function for URL to registered scripts and styles

Reported by: msnewton's profile msnewton Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Script Loader Keywords: has-patch reporter-feedback close
Focuses: Cc:

Description

I would like to see a function that would return the full URL to a script or style registered with wp_register_script() or wp_register_style(), or those that are “built-in” to WP.

The reason is this: I generate all of the HTML for special pages myself but wish to include standard scripts and styles that are built in to WordPress. Rather than relying upon a fixed filepath to remain static, and assuming it won't change in future versions, I'd like to ask WP to tell me where it is.

Attachments (1)

32607.patch (3.2 KB) - added by tyxla 9 years ago.
Introducing wp_get_registered_script() and wp_get_registered_style(). Including unit tests.

Download all attachments as: .zip

Change History (8)

#1 @tyxla
9 years ago

Hi @msnewton and welcome to the WordPress Core Trac!

This sounds like a good idea IMHO. I've personally had to locate the URL or version of a registered script several times and I always had to use the global variables $wp_scripts for these instances.

So, it might be useful to be able to quickly find the URL, version or dependancies of a style/script that has been registered.

The functions for that can simply return the _WP_Dependency object (containing handle - script/style name, src - URL, deps - dependancies, ver - version, etc.), or false if the script/style hasn't been registered.

I'll attach a patch for these functions in a minute.

@tyxla
9 years ago

Introducing wp_get_registered_script() and wp_get_registered_style(). Including unit tests.

#2 @tyxla
9 years ago

  • Keywords has-patch added

Here is an example usage with the functions from my patch:

// registering a script
wp_register_script( 'handle', 'http://example.com', array( 'test-dep' ), 1 );

// retrieving various details for the 'handle' script
$script = wp_get_registered_script( 'handle' );
echo $script->src; // script URL
echo $script->ver; // script version

So this way you could easily retrieve the entire script/style dependancy object, and quickly get the URL, version, dependancies or anything else from it.

#3 @SergeyBiryukov
8 years ago

  • Component changed from General to Script Loader

#4 in reply to: ↑ description @SergeyBiryukov
8 years ago

  • Keywords reporter-feedback added
  • Summary changed from Function for URL to registers scripts and styles to Function for URL to registered scripts and styles

Replying to msnewton:

The reason is this: I generate all of the HTML for special pages myself but wish to include standard scripts and styles that are built in to WordPress.

Adding <?php wp_head(); ?> before </head> and <?php wp_footer(); ?> before </body> should do that, unless I'm missing something. Why do you need a new function?

#5 @rodrigosprimo
9 months ago

  • Keywords close added

As there's been no reply in 7 years, I'm marking this as a close candidate.

If there is no response in the next 30 days, this ticket will be closed (it can be reopened at any time in the future if needed).

#6 @rodrigosprimo
8 months ago

  • Resolution set to invalid
  • Status changed from new to closed

Closing due to lack of feedback.

#7 @swissspidy
8 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.