Make WordPress Core

Changeset 32483


Ignore:
Timestamp:
05/10/2015 07:56:15 PM (9 years ago)
Author:
johnbillion
Message:

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

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-dependencies.php

    r30537 r32483  
    214214     * @param string $ver    Optional. Version (used for cache busting).
    215215     * @param mixed  $args   Optional. Custom property of the item. NOT the class property $args. Examples: $media, $in_footer.
    216      * @return bool True on success, false on failure.
     216     * @return bool Whether the item has been registered. True on success, false on failure.
    217217     */
    218218    public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
  • trunk/src/wp-includes/functions.wp-scripts.php

    r32124 r32483  
    9595 *
    9696 * @since 2.6.0
     97 * @since 4.3.0 A return value was added.
    9798 *
    9899 * @param string      $handle    Name of the script. Should be unique.
     
    106107 * @param bool        $in_footer Optional. Whether to enqueue the script before </head> or before </body>.
    107108 *                               Default 'false'. Accepts 'false' or 'true'.
     109 * @return bool Whether the script has been registered. True on success, false on failure.
    108110 */
    109111function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
     
    111113    _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    112114
    113     $wp_scripts->add( $handle, $src, $deps, $ver );
     115    $registered = $wp_scripts->add( $handle, $src, $deps, $ver );
    114116    if ( $in_footer ) {
    115117        $wp_scripts->add_data( $handle, 'group', 1 );
    116118    }
     119
     120    return $registered;
    117121}
    118122
  • trunk/src/wp-includes/functions.wp-styles.php

    r32041 r32483  
    9999 *
    100100 * @since 2.6.0
     101 * @since 4.3.0 A return value was added.
    101102 *
    102103 * @param string      $handle Name of the stylesheet.
     
    108109 *                            Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
    109110 *                            'screen', 'tty', or 'tv'.
     111 * @return bool Whether the style has been registered. True on success, false on failure.
    110112 */
    111113function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
    112114    _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    113115
    114     wp_styles()->add( $handle, $src, $deps, $ver, $media );
     116    return wp_styles()->add( $handle, $src, $deps, $ver, $media );
    115117}
    116118
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r31317 r32483  
    156156        $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
    157157    }
     158
     159    /**
     160     * Testing 'wp_register_script' return boolean success/failure value.
     161     *
     162     * @ticket 31126
     163     */
     164    function test_wp_register_script() {
     165        $this->assertTrue( wp_register_script( 'duplicate-handler', 'http://example.com' ) );
     166        $this->assertFalse( wp_register_script( 'duplicate-handler', 'http://example.com' ) );
     167    }
     168
    158169}
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r31733 r32483  
    230230    }
    231231
     232    /**
     233     * Testing 'wp_register_style' return boolean success/failure value.
     234     *
     235     * @ticket 31126
     236     */
     237    function test_wp_register_style(){
     238        $this->assertTrue( wp_register_style( 'duplicate-handler', 'http://example.com' ) );
     239        $this->assertFalse( wp_register_style( 'duplicate-handler', 'http://example.com' ) );
     240    }
     241
    232242}
Note: See TracChangeset for help on using the changeset viewer.