From 7b40c7a03f399da2c096e1c0deca42cabbd59b29 Mon Sep 17 00:00:00 2001 From: azaozz Date: Mon, 28 Dec 2009 00:48:20 +0000 Subject: [PATCH] WP_Dependencies: pass NULL to disable script and style version query strings, props scribu amattie, fixes #11315 git-svn-id: http://svn.automattic.com/wordpress/trunk@12558 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class.wp-dependencies.php | 2 -- wp-includes/class.wp-scripts.php | 11 ++++++++--- wp-includes/class.wp-styles.php | 11 ++++++++--- wp-includes/functions.wp-scripts.php | 13 +++++++++---- wp-includes/functions.wp-styles.php | 7 ++++--- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/wp-includes/class.wp-dependencies.php b/wp-includes/class.wp-dependencies.php index 54afdef0b..ea607de2c 100644 --- a/wp-includes/class.wp-dependencies.php +++ b/wp-includes/class.wp-dependencies.php @@ -232,8 +232,6 @@ class _WP_Dependency { @list($this->handle, $this->src, $this->deps, $this->ver, $this->args) = func_get_args(); if ( !is_array($this->deps) ) $this->deps = array(); - if ( !$this->ver ) - $this->ver = false; } function add_data( $name, $data ) { diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php index 9fa96e9d0..ea9123695 100644 --- a/wp-includes/class.wp-scripts.php +++ b/wp-includes/class.wp-scripts.php @@ -90,9 +90,13 @@ class WP_Scripts extends WP_Dependencies { if ( false === $group && in_array($handle, $this->in_footer, true) ) $this->in_footer = array_diff( $this->in_footer, (array) $handle ); - $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; + if ( null === $this->registered[$handle]->ver ) + $ver = ''; + else + $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; + if ( isset($this->args[$handle]) ) - $ver .= '&' . $this->args[$handle]; + $ver = $ver ? $ver . '&' . $this->args[$handle] : '?' . $this->args[$handle]; $src = $this->registered[$handle]->src; @@ -114,7 +118,8 @@ class WP_Scripts extends WP_Dependencies { $src = $this->base_url . $src; } - $src = add_query_arg('ver', $ver, $src); + if ( !empty($ver) ) + $src = add_query_arg('ver', $ver, $src); $src = esc_url(apply_filters( 'script_loader_src', $src, $handle )); if ( $this->do_concat ) diff --git a/wp-includes/class.wp-styles.php b/wp-includes/class.wp-styles.php index 731ae39cf..2d8139d83 100644 --- a/wp-includes/class.wp-styles.php +++ b/wp-includes/class.wp-styles.php @@ -35,9 +35,13 @@ class WP_Styles extends WP_Dependencies { if ( !parent::do_item($handle) ) return false; - $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; + if ( null === $this->registered[$handle]->ver ) + $ver = ''; + else + $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; + if ( isset($this->args[$handle]) ) - $ver .= '&' . $this->args[$handle]; + $ver = $ver ? $ver . '&' . $this->args[$handle] : '?' . $this->args[$handle]; if ( $this->do_concat ) { if ( $this->in_default_dir($this->registered[$handle]->src) && !isset($this->registered[$handle]->extra['conditional']) && !isset($this->registered[$handle]->extra['alt']) ) { @@ -100,7 +104,8 @@ class WP_Styles extends WP_Dependencies { $src = $this->base_url . $src; } - $src = add_query_arg('ver', $ver, $src); + if ( !empty($ver) ) + $src = add_query_arg('ver', $ver, $src); $src = apply_filters( 'style_loader_src', $src, $handle ); return esc_url( $src ); } diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php index 0a60c9687..f284435ef 100644 --- a/wp-includes/functions.wp-scripts.php +++ b/wp-includes/functions.wp-scripts.php @@ -38,7 +38,12 @@ function wp_print_scripts( $handles = false ) { * Register new JavaScript file. * * @since r16 - * @see WP_Dependencies::add() For parameter information. + * @param string $handle Script name + * @param string $src Script url + * @param array $deps (optional) Array of script names on which this script depends + * @param string|bool $ver (optional) Script version (used for cache busting), set to NULL to disable + * @param bool (optional) Wether to enqueue the script before or before + * @return null */ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { global $wp_scripts; @@ -56,7 +61,7 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f * Localizes only if script has already been added. * * @since r16 - * @see WP_Script::localize() + * @see WP_Scripts::localize() */ function wp_localize_script( $handle, $object_name, $l10n ) { global $wp_scripts; @@ -86,8 +91,8 @@ function wp_deregister_script( $handle ) { * Registers the script if src provided (does NOT overwrite) and enqueues. * * @since r16 - * @see WP_Script::add(), WP_Script::enqueue() -*/ + * @see wp_register_script() For parameter information. + */ function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { global $wp_scripts; if ( !is_a($wp_scripts, 'WP_Scripts') ) diff --git a/wp-includes/functions.wp-styles.php b/wp-includes/functions.wp-styles.php index 5813763a9..af16cf160 100644 --- a/wp-includes/functions.wp-styles.php +++ b/wp-includes/functions.wp-styles.php @@ -45,9 +45,8 @@ function wp_print_styles( $handles = false ) { * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'. * @param array $deps Array of handles of any stylesheet that this stylesheet depends on. * (Stylesheets that must be loaded before this stylesheet.) Pass an empty array if there are no dependencies. - * @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter - * is used to ensure that the correct version is sent to the client regardless of caching, and so should be included - * if a version number is available and makes sense for the stylesheet. + * @param string|bool $ver String specifying the stylesheet version number. Set to NULL to disable. + * Used to ensure that the correct version is sent to the client regardless of caching. * @param string $media The media for which this stylesheet has been defined. */ function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { @@ -78,6 +77,8 @@ function wp_deregister_style( $handle ) { /** * Enqueue a CSS style file. * + * Registers the style if src provided (does NOT overwrite) and enqueues. + * * @since r79 * @see WP_Styles::add(), WP_Styles::enqueue() * @global object $wp_styles The WP_Styles object for printing styles.