Changeset 36633 for trunk/src/wp-includes/class.wp-scripts.php
- Timestamp:
- 02/23/2016 04:43:41 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class.wp-scripts.php
r36550 r36633 26 26 public $do_concat = false; 27 27 public $print_html = ''; 28 public $print_html_before = ''; 28 29 public $print_code = ''; 29 30 public $ext_handles = ''; … … 143 144 $cond_before = "<!--[if {$conditional}]>\n"; 144 145 $cond_after = "<![endif]-->\n"; 146 } 147 148 $before_handle = $this->print_inline_script( $handle, 'before', false ); 149 $after_handle = $this->print_inline_script( $handle, 'after', false ); 150 151 if ( $before_handle ) { 152 $before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle ); 153 } 154 155 if ( $after_handle ) { 156 $after_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $after_handle ); 145 157 } 146 158 … … 155 167 */ 156 168 $srce = apply_filters( 'script_loader_src', $src, $handle ); 157 if ( $this->in_default_dir( $srce ) && ! $conditional ) { 169 170 if ( $before_handle && ! $conditional ) { 171 $this->print_html_before .= $before_handle; 172 } 173 174 if ( $this->in_default_dir( $srce ) && ! $conditional && ! $after_handle ) { 158 175 $this->print_code .= $this->print_extra_script( $handle, false ); 159 176 $this->concat .= "$handle,"; … … 196 213 return true; 197 214 198 $tag = "{$cond_before} <script type='text/javascript' src='$src'></script>\n{$cond_after}";215 $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}"; 199 216 200 217 /** … … 210 227 211 228 if ( $this->do_concat ) { 212 $this->print_html .= $tag; 229 if ( $after_handle ) { 230 $this->print_html_before .= $tag; 231 } else { 232 $this->print_html .= $tag; 233 } 213 234 } else { 214 235 echo $tag; … … 216 237 217 238 return true; 239 } 240 241 /** 242 * Add extra code to a registered script. 243 * 244 * @since 4.5.0 245 * 246 * @param string $handle Name of the script to add the inline script to. Must be lowercase. 247 * @param string $data String containing the javascript to be added. 248 * @param string $position Optional. Whether to add the inline script before the handle 249 * or after. Default 'after'. 250 * 251 * @return bool True on success, false on failure. 252 */ 253 public function add_inline_script( $handle, $data, $position = 'after' ) { 254 if ( ! $data ) { 255 return false; 256 } 257 258 if ( 'after' !== $position ) { 259 $position = 'before'; 260 } 261 262 $script = (array) $this->get_data( $handle, $position ); 263 $script[] = $data; 264 265 return $this->add_data( $handle, $position, $script ); 266 } 267 268 /** 269 * Print inline scripts registered for a specific handle. 270 * 271 * @since 4.5.0 272 * 273 * @param string $handle Name of the script to add the inline script to. Must be lowercase. 274 * @param string $position Optional. Whether to add the inline script before the handle 275 * or after. Default 'after'. 276 * @param bool $echo Optional. Whether to echo the script instead of just returning it. 277 * Default true. 278 * @return string|false Script on success, false otherwise. 279 */ 280 public function print_inline_script( $handle, $position = 'after', $echo = true ) { 281 $output = $this->get_data( $handle, $position ); 282 283 if ( empty( $output ) ) { 284 return false; 285 } 286 287 $output = trim( implode( "\n", $output ), "\n" ); 288 289 if ( $echo ) { 290 printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); 291 } 292 293 return $output; 218 294 } 219 295 … … 340 416 $this->concat_version = ''; 341 417 $this->print_html = ''; 418 $this->print_html_before = ''; 342 419 $this->ext_version = ''; 343 420 $this->ext_handles = '';
Note: See TracChangeset
for help on using the changeset viewer.