diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/functions.wp-scripts.php --- a/wp/wp-includes/functions.wp-scripts.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/functions.wp-scripts.php Mon Oct 14 18:28:13 2019 +0200 @@ -38,13 +38,17 @@ return; } - _doing_it_wrong( $function, sprintf( - /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ - __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', - 'admin_enqueue_scripts', - 'login_enqueue_scripts' - ), '3.3.0' ); + _doing_it_wrong( + $function, + sprintf( + /* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */ + __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), + 'wp_enqueue_scripts', + 'admin_enqueue_scripts', + 'login_enqueue_scripts' + ), + '3.3.0' + ); } /** @@ -89,7 +93,7 @@ /** * Adds extra code to a registered script. * - * Code will only be added if the script in already in the queue. + * Code will only be added if the script is already in the queue. * Accepts a string $data containing the Code. If two or more code blocks * are added to the same script $handle, they will be printed in the order * they were added, i.e. the latter added code can redeclare the previous. @@ -108,12 +112,16 @@ _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); if ( false !== stripos( $data, '' ) ) { - _doing_it_wrong( __FUNCTION__, sprintf( - /* translators: 1: #is', '$1', $data ) ); } @@ -132,7 +140,8 @@ * @since 4.3.0 A return value was added. * * @param string $handle Name of the script. Should be unique. - * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory. + * @param string|bool $src Full URL of the script, or path of the script relative to the WordPress root directory. + * If source is set to false, script is an alias of other scripts it depends on. * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array. * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL * as a query string for cache busting purposes. If version is set to false, a version @@ -167,7 +176,6 @@ * ... * } * - * * @see WP_Dependencies::localize() * @link https://core.trac.wordpress.org/ticket/11520 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. @@ -193,6 +201,32 @@ } /** + * Sets translated strings for a script. + * + * Works only if the script has already been added. + * + * @see WP_Scripts::set_translations() + * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. + * + * @since 5.0.0 + * @since 5.1.0 The `$domain` parameter was made optional. + * + * @param string $handle Script handle the textdomain will be attached to. + * @param string $domain Optional. Text domain. Default 'default'. + * @param string $path Optional. The full file path to the directory containing translation files. + * @return bool True if the text domain was successfully localized, false otherwise. + */ +function wp_set_script_translations( $handle, $domain = 'default', $path = null ) { + global $wp_scripts; + if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { + _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); + return false; + } + + return $wp_scripts->set_translations( $handle, $domain, $path ); +} + +/** * Remove a registered script. * * Note: there are intentional safeguards in place to prevent critical admin scripts, @@ -216,12 +250,31 @@ ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) ) { $no = array( - 'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion', - 'jquery-ui-autocomplete', 'jquery-ui-button', 'jquery-ui-datepicker', 'jquery-ui-dialog', - 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse', - 'jquery-ui-position', 'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable', - 'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-ui-spinner', 'jquery-ui-tabs', - 'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone', + 'jquery', + 'jquery-core', + 'jquery-migrate', + 'jquery-ui-core', + 'jquery-ui-accordion', + 'jquery-ui-autocomplete', + 'jquery-ui-button', + 'jquery-ui-datepicker', + 'jquery-ui-dialog', + 'jquery-ui-draggable', + 'jquery-ui-droppable', + 'jquery-ui-menu', + 'jquery-ui-mouse', + 'jquery-ui-position', + 'jquery-ui-progressbar', + 'jquery-ui-resizable', + 'jquery-ui-selectable', + 'jquery-ui-slider', + 'jquery-ui-sortable', + 'jquery-ui-spinner', + 'jquery-ui-tabs', + 'jquery-ui-tooltip', + 'jquery-ui-widget', + 'underscore', + 'backbone', ); if ( in_array( $handle, $no ) ) { @@ -266,7 +319,6 @@ _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); - if ( $src || $in_footer ) { $_handle = explode( '?', $handle ); @@ -298,7 +350,11 @@ } /** - * Check whether a script has been added to the queue. + * Determines whether a script has been added to the queue. + * + * For more information on this and similar theme functions, check out + * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ + * Conditional Tags} article in the Theme Developer Handbook. * * @since 2.8.0 * @since 3.5.0 'enqueued' added as an alias of the 'queue' list. @@ -324,13 +380,13 @@ * * @since 4.2.0 * - * @see WP_Dependency::add_data() + * @see WP_Dependencies::add_data() * * @param string $handle Name of the script. * @param string $key Name of data point for which we're storing a value. * @param mixed $value String containing the data to be added. * @return bool True on success, false on failure. */ -function wp_script_add_data( $handle, $key, $value ){ +function wp_script_add_data( $handle, $key, $value ) { return wp_scripts()->add_data( $handle, $key, $value ); }