Make WordPress Core

Ticket #26111: 26111.2.diff

File 26111.2.diff, 4.0 KB (added by DrewAPicture, 10 years ago)

4th parameter + docs

  • src/wp-includes/class.wp-scripts.php

     
    184184        }
    185185
    186186        /**
    187          * Localizes a script
     187         * Localizes a script.
    188188         *
    189189         * Localizes only if the script has already been added
     190         *
     191         * @since 2.6.0
     192         * @since 4.2.0 The optional `$l10n_is_callable` parameter was added.
     193         *
     194         * @param string         $handle           Script handle the data will be attached to.
     195         * @param string         $object_name      Name for the JavaScript object. Passed directly, so it should be
     196         *                                         a qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
     197         * @param array|callable $l10n             The data itself. The data can be either a single or multi-dimensional
     198         *                                         array. If a callable is passed and `$l10n_is_callable` is true, it will
     199         *                                         be invoked at runtime.
     200         * @param bool           $l10n_is_callable Optional. Whether `$l10n` when passed as a string should be considered
     201         *                                         callable. Added for back-compat. Default false.
     202         * @return bool True if the script was successfully localized, false otherwise.
    190203         */
    191         public function localize( $handle, $object_name, $l10n ) {
     204        public function localize( $handle, $object_name, $l10n, $l10n_is_callable = false ) {
    192205                if ( $handle === 'jquery' )
    193206                        $handle = 'jquery-core';
    194207
    195                 if ( is_callable( $l10n ) ) {
     208                if ( is_callable( $l10n ) && true === $l10n_is_callable ) {
    196209                        $l10n = call_user_func( $l10n, $handle, $object_name );
    197210                }
    198211
  • src/wp-includes/functions.wp-scripts.php

     
    135135 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
    136136 *
    137137 * @since 2.6.0
     138 * @since 4.2.0 The optional `$l10n_is_callable` parameter was added.
    138139 *
    139140 * @todo Documentation cleanup
    140141 *
    141  * @param string         $handle       Script handle the data will be attached to.
    142  * @param string         $object_name  Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
    143  *                                     Example: '/[a-zA-Z0-9_]+/'.
    144  * @param array|callable $l10n         The data itself. The data can be either a single or multi-dimensional array. If a callable
    145  *                                     is passed, it will be invoked at runtime.
     142 * @param string         $handle           Script handle the data will be attached to.
     143 * @param string         $object_name      Name for the JavaScript object. Passed directly, so it should be qualified
     144 *                                         JS variable. Example: '/[a-zA-Z0-9_]+/'.
     145 * @param array|callable $l10n             The data itself. The data can be either a single or multi-dimensional array.
     146 *                                         If a callable is passed and `$l10n_is_callable` is true, it will be invoked
     147 *                                         at runtime.
     148 * @param bool           $l10n_is_callable Optional. Whether `$l10n` when passed as a string should be considered
     149 *                                         callable. Added for back-compat. Default false.
    146150 * @return bool True if the script was successfully localized, false otherwise.
    147151 */
    148 function wp_localize_script( $handle, $object_name, $l10n ) {
     152function wp_localize_script( $handle, $object_name, $l10n, $l10n_is_callable = false ) {
    149153        global $wp_scripts;
    150154        if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
    151155                _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
     
    152156                return false;
    153157        }
    154158
    155         return wp_scripts()->localize( $handle, $object_name, $l10n );
     159        return wp_scripts()->localize( $handle, $object_name, $l10n, $l10n_is_callable );
    156160}
    157161
    158162/**