Ticket #22249: 22249-3.diff
| File 22249-3.diff, 21.2 KB (added by , 11 years ago) |
|---|
-
wp-includes/class.wp-scripts.php
diff --git wp-includes/class.wp-scripts.php wp-includes/class.wp-scripts.php index b0077a2..62e1f56 100644
class WP_Scripts extends WP_Dependencies { 82 82 } 83 83 84 84 public function do_item( $handle, $group = false ) { 85 if ( !parent::do_item( $handle) )85 if ( !parent::do_item( $handle ) ) { 86 86 return false; 87 } 87 88 88 if ( 0 === $group && $this->groups[ $handle] > 0 ) {89 if ( 0 === $group && $this->groups[ $handle ] > 0 ) { 89 90 $this->in_footer[] = $handle; 90 91 return false; 91 92 } 92 93 93 if ( false === $group && in_array($handle, $this->in_footer, true) ) 94 if ( false === $group && in_array($handle, $this->in_footer, true) ) { 94 95 $this->in_footer = array_diff( $this->in_footer, (array) $handle ); 96 } 95 97 96 if ( null === $this->registered[ $handle]->ver )98 if ( null === $this->registered[ $handle ]->ver ) { 97 99 $ver = ''; 98 else 99 $ver = $this->registered[$handle]->ver ? $this->registered[$handle]->ver : $this->default_version; 100 } else { 101 $ver = $this->registered[ $handle ]->ver ? $this->registered[ $handle ]->ver : $this->default_version; 102 } 100 103 101 if ( isset($this->args[$handle]) ) 102 $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; 104 if ( isset( $this->args[ $handle ] ) ) { 105 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; 106 } 103 107 104 $src = $this->registered[ $handle]->src;108 $src = $this->registered[ $handle ]->src; 105 109 106 110 if ( $this->do_concat ) { 107 111 /** … … class WP_Scripts extends WP_Dependencies { 113 117 * @param string $handle Script handle. 114 118 */ 115 119 $srce = apply_filters( 'script_loader_src', $src, $handle ); 116 if ( $this->in_default_dir( $srce) ) {120 if ( $this->in_default_dir( $srce ) ) { 117 121 $this->print_code .= $this->print_extra_script( $handle, false ); 118 122 $this->concat .= "$handle,"; 119 123 $this->concat_version .= "$handle$ver"; … … class WP_Scripts extends WP_Dependencies { 124 128 } 125 129 } 126 130 127 $this->print_extra_script( $handle );128 if ( !preg_match( '|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {129 $src = $this->base_url . $src;130 }131 $this->print_extra_script( $handle ); 132 if ( !preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { 133 $src = $this->base_url . $src; 134 } 131 135 132 if ( !empty($ver) ) 133 $src = add_query_arg('ver', $ver, $src); 136 if ( !empty( $ver ) ) { 137 $src = add_query_arg( 'ver', $ver, $src ); 138 } 134 139 135 140 /** This filter is documented in wp-includes/class.wp-scripts.php */ 136 141 $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); 137 142 138 if ( ! $src ) 143 if ( ! $src ) { 139 144 return true; 145 } 146 140 147 141 $tag = "<script type='text/javascript' src='$src'></script>\n"; 148 $attributes = $this->get_script_attributes( $handle, $src ); 149 $script_tag = "<script$attributes></script>\n"; 142 150 143 /** 151 /** 144 152 * Filter the HTML script tag of an enqueued script. 145 153 * 146 154 * @since 4.1.0 147 155 * 148 * @param string $ tagThe `<script>` tag for the enqueued script.149 * @param string $handle The script's registered handle.150 * @param string $src The script's source URL.156 * @param string $script_tag The `<script>` tag for the enqueued script. 157 * @param string $handle The script's registered handle. 158 * @param string $src The script's source URL. 151 159 */ 152 $ tag = apply_filters( 'script_loader_tag', $tag, $handle, $src );160 $script_tag = apply_filters( 'script_loader_tag', $script_tag, $handle, $src ); 153 161 154 162 if ( $this->do_concat ) { 155 $this->print_html .= $ tag;163 $this->print_html .= $script_tag; 156 164 } else { 157 echo $ tag;165 echo $script_tag; 158 166 } 159 167 160 return true; 168 return true; 169 } 170 171 /** 172 * Concatenates attributes for the script tag 173 * 174 * @since 4.0.0 175 * 176 * @param string $handle Script registered handle 177 * @param string $src Script registered src 178 * 179 * @return string Concatenated attributes string 180 */ 181 public function get_script_attributes( $handle, $src ) { 182 183 $default_attributes = array( 184 'type' => 'text/javascript', 185 'src' => $src 186 ); 187 188 $attributes = isset( $this->registered[ $handle ]->args['attributes'] ) 189 ? (array) $this->registered[ $handle ]->args['attributes'] 190 : array(); 191 192 $attributes = wp_parse_args( $attributes, $default_attributes ); 193 194 /** 195 * Filter the script loader attributes. 196 * 197 * @since 4.1.0 198 * 199 * @param array $attributes Array of script tag attributes. 200 * @param string $handle Script handle. 201 * @param string $src Script loader source path. 202 */ 203 $attributes = apply_filters( 'script_loader_attributes', $attributes, $handle, $src ); 204 // Ensure source is set 205 $attributes['src'] = isset( $attributes['src'] ) ? $attributes['src'] : $src; 206 207 $concat_attributes = ''; 208 foreach ( $attributes as $attribute => $attribute_value ) { 209 if ( ! is_null( $attribute ) && ! is_null( $attribute_value ) ) { 210 $concat_attributes .= ' '. esc_attr( $attribute ) .'="'. esc_attr( $attribute_value ) .'"'; 211 } 212 } 213 214 return $concat_attributes; 161 215 } 162 216 163 217 /** -
wp-includes/class.wp-styles.php
diff --git wp-includes/class.wp-styles.php wp-includes/class.wp-styles.php index 5147926..00a31f2 100644
class WP_Styles extends WP_Dependencies { 40 40 } 41 41 42 42 public function do_item( $handle ) { 43 if ( !parent::do_item( $handle) )43 if ( !parent::do_item( $handle ) ) 44 44 return false; 45 45 46 $obj = $this->registered[ $handle];46 $obj = $this->registered[ $handle ]; 47 47 if ( null === $obj->ver ) 48 48 $ver = ''; 49 49 else 50 50 $ver = $obj->ver ? $obj->ver : $this->default_version; 51 51 52 if ( isset( $this->args[$handle]) )53 $ver = $ver ? $ver . '&' . $this->args[ $handle] : $this->args[$handle];52 if ( isset( $this->args[ $handle ] ) ) 53 $ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ]; 54 54 55 55 if ( $this->do_concat ) { 56 if ( $this->in_default_dir( $obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) {56 if ( $this->in_default_dir( $obj->src ) && !isset( $obj->extra['conditional'] ) && !isset( $obj->extra['alt'] ) ) { 57 57 $this->concat .= "$handle,"; 58 58 $this->concat_version .= "$handle$ver"; 59 59 … … class WP_Styles extends WP_Dependencies { 63 63 } 64 64 } 65 65 66 if ( isset($obj->args) )67 $media = esc_attr( $obj->args );68 else69 $media = 'all';70 71 66 $href = $this->_css_href( $obj->src, $ver, $handle ); 72 67 if ( empty( $href ) ) { 73 68 // Turns out there is nothing to print. 74 69 return true; 75 70 } 76 $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; 77 $ title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : '';71 72 $attributes = $this->get_style_attributes( $handle, $href ); 78 73 79 74 /** 80 75 * Filter the HTML link tag of an enqueued style. … … class WP_Styles extends WP_Dependencies { 84 79 * @param string The link tag for the enqueued style. 85 80 * @param string $handle The style's registered handle. 86 81 */ 87 $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media'/>\n", $handle );88 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl']) && $obj->extra['rtl'] ) {82 $tag = apply_filters( 'style_loader_tag', "<link$attributes/>\n", $handle ); 83 if ( 'rtl' === $this->text_direction && isset( $obj->extra['rtl'] ) && $obj->extra['rtl'] ) { 89 84 if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { 90 85 $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; 91 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ) );86 $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" ) ); 92 87 } else { 93 88 $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); 94 89 } 95 90 91 $rtl_attributes = $this->get_style_attributes( $handle, $rtl_href, true ); 96 92 /** This filter is documented in wp-includes/class.wp-styles.php */ 97 $rtl_tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media'/>\n", $handle );93 $rtl_tag = apply_filters( 'style_loader_tag', "<link$rtl_attributes/>\n", $handle ); 98 94 99 95 if ( $obj->extra['rtl'] === 'replace' ) { 100 96 $tag = $rtl_tag; … … class WP_Styles extends WP_Dependencies { 119 115 return true; 120 116 } 121 117 118 /** 119 * Concatenates attributes for the style tag 120 * 121 * @since 4.1.0 122 * 123 * @param string $handle style registered handle 124 * @param string $href style registered href 125 * 126 * @return string Concatenated attributes string 127 */ 128 public function get_style_attributes( $handle, $href, $rtl = false ) { 129 130 $default_attributes = array( 131 "id" => "$handle-css", 132 "rel" => "stylesheet", 133 "type" => "text/css", 134 "media" => "all", 135 ); 136 137 if ( $rtl ) { 138 $default_attributes["id"] = "$handle-rtl-css"; 139 } 140 141 $obj = $this->registered[ $handle ]; 142 143 $attributes = isset( $obj->args ) 144 ? (array) $obj->args 145 : array(); 146 147 $attributes = wp_parse_args( $attributes, $default_attributes ); 148 149 if ( isset( $obj->extra['alt'] ) && $obj->extra['alt'] ) { 150 $attributes['rel'] = 'alternate stylesheet'; 151 } 152 153 if ( isset( $obj->extra['title'] ) ) { 154 $attributes['title'] = esc_attr( $obj->extra['title'] ); 155 } 156 157 /** 158 * Filter the style loader attributes. 159 * 160 * @since 4.1.0 161 * 162 * @param array $attributes Array of style tag attributes. 163 * @param string $handle Style handle. 164 * @param string $href Style loader source path. 165 */ 166 $attributes = apply_filters( 'style_loader_attributes', $attributes, $handle, $href ); 167 168 // Ensure href is set 169 $attributes['href'] = isset( $attributes['href'] ) ? $attributes['href'] : $href; 170 171 $concat_attributes = ''; 172 foreach ( $attributes as $attribute => $attribute_value ) { 173 if ( ! is_null( $attribute ) && ! is_null( $attribute_value ) ) { 174 $concat_attributes .= ' '. esc_attr( $attribute ) .'="'. esc_attr( $attribute_value ) .'"'; 175 } 176 } 177 178 return $concat_attributes; 179 } 180 122 181 public function add_inline_style( $handle, $code ) { 123 182 if ( ! $code ) { 124 183 return false; -
wp-includes/functions.wp-scripts.php
diff --git wp-includes/functions.wp-scripts.php wp-includes/functions.wp-scripts.php index 8c3151c..876f2eb 100644
function wp_print_scripts( $handles = false ) { 67 67 * to end of path as a query string. If no version is specified or set to false, a version 68 68 * number is automatically added equal to current installed WordPress version. 69 69 * If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'. 70 * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. 71 * Default 'false'. Accepts 'false' or 'true'. 70 * @param array $args Optional script arguments. 71 * - bool - in_footer - Whether to enqueue the script before </head> or before </body>. Default 'false'. Accepts 'false' or 'true'. 72 * - array - attributes - Array of script tag attributes. Default: array( 'type' => 'text/javascript' ) 72 73 */ 73 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $ in_footer = false) {74 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args = array() ) { 74 75 global $wp_scripts; 76 77 // For back-compat. If it's not an array, convert to boolean. 78 $args = ! is_array( $args ) ? array( 'in_footer' => (bool) $args ) : $args; 79 $args = wp_parse_args( $args, array( 80 'in_footer' => false, 81 'attributes' => array(), 82 ) ); 83 84 $attributes = wp_parse_args( $args['attributes'], array( 'type' => 'text/javascript' ) ); 85 75 86 if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { 76 87 if ( ! did_action( 'init' ) ) 77 88 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), … … function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f 79 90 $wp_scripts = new WP_Scripts(); 80 91 } 81 92 82 $wp_scripts->add( $handle, $src, $deps, $ver );83 if ( $ in_footer )93 $wp_scripts->add( $handle, $src, $deps, $ver, array( 'attributes' => $attributes ) ); 94 if ( $args['in_footer'] ) { 84 95 $wp_scripts->add_data( $handle, 'group', 1 ); 96 } 85 97 } 86 98 87 99 /** … … function wp_deregister_script( $handle ) { 184 196 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 185 197 * 186 198 * @since 2.6.0 187 199 * 188 200 * @param string $handle Name of the script. 189 201 * @param string|bool $src Path to the script from the root directory of WordPress. Example: '/js/myscript.js'. 190 202 * @param array $deps An array of registered handles this script depends on. Default empty array. 191 203 * @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter 192 204 * is used to ensure that the correct version is sent to the client regardless of caching, 193 205 * and so should be included if a version number is available and makes sense for the script. 194 * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. 195 * Default 'false'. Accepts 'false' or 'true'. 206 * @param array $args Optional script arguments. 207 * - bool - in_footer - Whether to enqueue the script before </head> or before </body>. Default 'false'. Accepts 'false' or 'true'. 208 * - array - attributes - Array of script tag attributes. Default: array( 'type' => 'text/javascript' ) 196 209 */ 197 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $ in_footer = false) {210 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $args = array() ) { 198 211 global $wp_scripts; 212 213 // For back-compat. If it's not an array, convert to boolean. 214 $args = ! is_array( $args ) ? array( 'in_footer' => (bool) $args ) : $args; 215 $args = wp_parse_args( $args, array( 216 'in_footer' => false, 217 'attributes' => array(), 218 ) ); 219 220 $attributes = wp_parse_args( $args['attributes'], array( 'type' => 'text/javascript' ) ); 221 199 222 if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { 200 223 if ( ! did_action( 'init' ) ) 201 224 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), … … function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false 205 228 206 229 if ( $src ) { 207 230 $_handle = explode('?', $handle); 208 $wp_scripts->add( $_handle[0], $src, $deps, $ver );209 if ( $ in_footer )231 $wp_scripts->add( $_handle[0], $src, $deps, $ver, array( 'attributes' => $attributes ) ); 232 if ( $args['in_footer'] ) { 210 233 $wp_scripts->add_data( $_handle[0], 'group', 1 ); 234 } 211 235 } 212 236 $wp_scripts->enqueue( $handle ); 213 237 } -
wp-includes/functions.wp-styles.php
diff --git wp-includes/functions.wp-styles.php wp-includes/functions.wp-styles.php index 83db482..4fad854 100644
function wp_add_inline_style( $handle, $data ) { 91 91 * 92 92 * @since 2.6.0 93 93 * 94 * @param string $handle Name of the stylesheet. 95 * @param string|bool $src Path to the stylesheet from the WordPress root directory. Example: '/css/mystyle.css'. 96 * @param array $deps An array of registered style handles this stylesheet depends on. Default empty array. 97 * @param string|bool $ver String specifying the stylesheet version number. Used to ensure that the correct version 98 * is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'. 99 * @param string $media Optional. The media for which this stylesheet has been defined. 100 * Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', 101 * 'screen', 'tty', or 'tv'. 94 * @param string $handle Name of the stylesheet. 95 * @param string|bool $src Path to the stylesheet from the WordPress root directory. Example: '/css/mystyle.css'. 96 * @param array $deps An array of registered style handles this stylesheet depends on. Default empty array. 97 * @param string|bool $ver String specifying the stylesheet version number. Used to ensure that the correct version 98 * is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'. 99 * @param string|array $atts Optional style link tag attributes or string. If an array sets the attributes for the style link 100 * tag. Default: array( "rel" => "stylesheet", "type" => "text/css", "media" => "all" ) 101 * If a string sets the media for which this stylesheet has been defined. Default 'all'. Accepts 'all', 102 * 'aural', 'braille', 'handheld', 'projection', 'print', 'screen', 'tty', or 'tv'. 102 103 */ 103 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $ media = 'all') {104 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $atts = array() ) { 104 105 global $wp_styles; 106 107 // For back-compat. If it's not an array, convert to media string. 108 $atts = ! is_array( $atts ) ? array( 'media' => (bool) $atts ) : $atts; 109 $atts = wp_parse_args( $atts, array( 110 "rel" => "stylesheet", 111 "type" => "text/css", 112 "media" => "all", 113 ) ); 114 105 115 if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { 106 116 if ( ! did_action( 'init' ) ) 107 117 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), … … function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media 109 119 $wp_styles = new WP_Styles(); 110 120 } 111 121 112 $wp_styles->add( $handle, $src, $deps, $ver, $ media);122 $wp_styles->add( $handle, $src, $deps, $ver, $atts ); 113 123 } 114 124 115 125 /** … … function wp_deregister_style( $handle ) { 145 155 * 146 156 * @since 2.6.0 147 157 * 148 * @param string $handle Name of the stylesheet. 149 * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'. 150 * @param array $deps An array of registered style handles this stylesheet depends on. Default empty array. 151 * @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used 152 * to ensure that the correct version is sent to the client regardless of caching, and so 153 * should be included if a version number is available and makes sense for the stylesheet. 154 * @param string $media Optional. The media for which this stylesheet has been defined. 155 * Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', 156 * 'screen', 'tty', or 'tv'. 158 * @param string $handle Name of the stylesheet. 159 * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'. 160 * @param array $deps An array of registered style handles this stylesheet depends on. Default empty array. 161 * @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used 162 * to ensure that the correct version is sent to the client regardless of caching, and so 163 * should be included if a version number is available and makes sense for the stylesheet. 164 * @param string|array $atts Optional style link tag attributes or string. If an array sets the attributes for the style link 165 * tag. Default: array( "rel" => "stylesheet", "type" => "text/css", "media" => "all" ) 166 * If a string sets the media for which this stylesheet has been defined. Default 'all'. Accepts 'all', 167 * 'aural', 'braille', 'handheld', 'projection', 'print', 'screen', 'tty', or 'tv'. 157 168 */ 158 function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $ media = 'all') {169 function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $atts = array() ) { 159 170 global $wp_styles; 171 172 // For back-compat. If it's not an array, convert to media string. 173 $atts = ! is_array( $atts ) ? array( 'media' => $atts ) : $atts; 174 $atts = wp_parse_args( $atts, array( 175 "rel" => "stylesheet", 176 "type" => "text/css", 177 "media" => "all", 178 ) ); 179 160 180 if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { 161 181 if ( ! did_action( 'init' ) ) 162 182 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), … … function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, 166 186 167 187 if ( $src ) { 168 188 $_handle = explode('?', $handle); 169 $wp_styles->add( $_handle[0], $src, $deps, $ver, $ media);189 $wp_styles->add( $_handle[0], $src, $deps, $ver, $atts ); 170 190 } 171 191 $wp_styles->enqueue( $handle ); 172 192 }