mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Add a return value to wp_register_script() and wp_register_style() which matches the return value of WP_Dependencies::add().
Props katzwebdesign, pareshradadiya, DrewAPicture. Fixes #31126 git-svn-id: https://develop.svn.wordpress.org/trunk@32483 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
099c066e24
commit
39639c79da
@ -213,7 +213,7 @@ class WP_Dependencies {
|
||||
* @param array $deps Optional. An array of item handle strings on which this item depends.
|
||||
* @param string $ver Optional. Version (used for cache busting).
|
||||
* @param mixed $args Optional. Custom property of the item. NOT the class property $args. Examples: $media, $in_footer.
|
||||
* @return bool True on success, false on failure.
|
||||
* @return bool Whether the item has been registered. True on success, false on failure.
|
||||
*/
|
||||
public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
|
||||
if ( isset($this->registered[$handle]) )
|
||||
|
||||
@ -94,6 +94,7 @@ function wp_print_scripts( $handles = false ) {
|
||||
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 4.3.0 A return value was added.
|
||||
*
|
||||
* @param string $handle Name of the script. Should be unique.
|
||||
* @param string $src Path to the script from the WordPress root directory. Example: '/js/myscript.js'.
|
||||
@ -105,15 +106,18 @@ function wp_print_scripts( $handles = false ) {
|
||||
* If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'.
|
||||
* @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
|
||||
* Default 'false'. Accepts 'false' or 'true'.
|
||||
* @return bool Whether the script has been registered. True on success, false on failure.
|
||||
*/
|
||||
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
|
||||
$wp_scripts = wp_scripts();
|
||||
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
|
||||
|
||||
$wp_scripts->add( $handle, $src, $deps, $ver );
|
||||
$registered = $wp_scripts->add( $handle, $src, $deps, $ver );
|
||||
if ( $in_footer ) {
|
||||
$wp_scripts->add_data( $handle, 'group', 1 );
|
||||
}
|
||||
|
||||
return $registered;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -98,6 +98,7 @@ function wp_add_inline_style( $handle, $data ) {
|
||||
* @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 4.3.0 A return value was added.
|
||||
*
|
||||
* @param string $handle Name of the stylesheet.
|
||||
* @param string|bool $src Path to the stylesheet from the WordPress root directory. Example: '/css/mystyle.css'.
|
||||
@ -107,11 +108,12 @@ function wp_add_inline_style( $handle, $data ) {
|
||||
* @param string $media Optional. The media for which this stylesheet has been defined.
|
||||
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
|
||||
* 'screen', 'tty', or 'tv'.
|
||||
* @return bool Whether the style has been registered. True on success, false on failure.
|
||||
*/
|
||||
function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
|
||||
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
|
||||
|
||||
wp_styles()->add( $handle, $src, $deps, $ver, $media );
|
||||
return wp_styles()->add( $handle, $src, $deps, $ver, $media );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -155,4 +155,15 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
// No scripts left to print
|
||||
$this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing 'wp_register_script' return boolean success/failure value.
|
||||
*
|
||||
* @ticket 31126
|
||||
*/
|
||||
function test_wp_register_script() {
|
||||
$this->assertTrue( wp_register_script( 'duplicate-handler', 'http://example.com' ) );
|
||||
$this->assertFalse( wp_register_script( 'duplicate-handler', 'http://example.com' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -229,4 +229,14 @@ CSS;
|
||||
$this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing 'wp_register_style' return boolean success/failure value.
|
||||
*
|
||||
* @ticket 31126
|
||||
*/
|
||||
function test_wp_register_style(){
|
||||
$this->assertTrue( wp_register_style( 'duplicate-handler', 'http://example.com' ) );
|
||||
$this->assertFalse( wp_register_style( 'duplicate-handler', 'http://example.com' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user