Ticket #22249: 22249.diff
| File 22249.diff, 4.1 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/class.wp-scripts.php
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 /** … … 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"; … … 125 129 } 126 130 127 131 $this->print_extra_script( $handle ); 128 if ( !preg_match( '|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) {132 if ( !preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { 129 133 $src = $this->base_url . $src; 130 134 } 131 135 132 if ( !empty( $ver) )136 if ( !empty( $ver ) ) { 133 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 } 140 146 141 if ( $this->do_concat ) 142 $this->print_html .= "<script type='text/javascript' src='$src'></script>\n"; 143 else 144 echo "<script type='text/javascript' src='$src'></script>\n"; 147 $attributes = $this->get_script_attributes( $handle, $src ); 148 $script_tag = "<script$attributes src='$src'></script>\n"; 145 149 150 if ( $this->do_concat ) { 151 $this->print_html .= $script_tag; 152 } else { 153 echo $script_tag; 154 } 155 146 156 return true; 147 157 } 148 158 149 159 /** 160 * Concatenates attributes for the script tag 161 * 162 * @since 4.0.0 163 * 164 * @param string $handle Script registered handle 165 * @param string $src Script registered src 166 * 167 * @return string Concatenated attributes string 168 */ 169 public function get_script_attributes( $handle, $src ) { 170 $default_attributes = array( 'type' => 'text/javascript' ); 171 172 /** 173 * Filter the script loader attributes. 174 * 175 * @since 4.0.0 176 * 177 * @param array $default_attributes Array of default script tag attributes. 178 * @param string $handle Script handle. 179 * @param string $src Script loader source path. 180 */ 181 $attributes = apply_filters( 'script_loader_attributes', $default_attributes, $handle, $src ); 182 183 $concat_attributes = ''; 184 foreach ( $attributes as $attribute => $attribute_value ) { 185 if ( ! is_null( $attribute ) && ! is_null( $attribute_value ) ) { 186 $concat_attributes .= ' '. esc_attr( $attribute ) .'="'. esc_attr( $attribute_value ) .'"'; 187 } 188 } 189 190 return $concat_attributes; 191 } 192 193 /** 150 194 * Localizes a script 151 195 * 152 196 * Localizes only if the script has already been added