Changeset 63481
- Timestamp:
- 09/04/2026 06:35:44 PM (2 months ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 3 edited
-
admin-header.php (modified) (2 diffs)
-
includes/media.php (modified) (13 diffs)
-
includes/template.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/admin-header.php
r62649 r63481 101 101 102 102 $admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix ); 103 ?> 104 <script> 105 addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; 106 var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', 107 pagenow = '<?php echo esc_js( $current_screen->id ); ?>', 108 typenow = '<?php echo esc_js( $current_screen->post_type ); ?>', 109 adminpage = '<?php echo esc_js( $admin_body_class ); ?>', 110 thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>', 111 decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>', 112 isRtl = <?php echo (int) is_rtl(); ?>; 113 </script> 114 <?php 103 104 // Print the global admin inline scripts through the script tag API so the 105 // `wp_inline_script_attributes` filter (e.g. a CSP nonce) applies. 106 wp_print_inline_script_tag( 107 <<<'JS' 108 function addLoadEvent( func ) { 109 if ( typeof jQuery !== 'undefined' ) { 110 jQuery( function () { 111 func(); 112 } ); 113 } else if ( typeof wpOnload !== 'function' ) { 114 window.wpOnload = func; 115 } else { 116 const oldOnload = window.wpOnload; 117 window.wpOnload = function () { 118 oldOnload(); 119 func(); 120 }; 121 } 122 } 123 JS 124 ); 125 wp_print_inline_script_tag( 126 sprintf( 127 'Object.assign( window, %s );', 128 wp_json_encode( 129 array( 130 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), 131 'pagenow' => $current_screen->id, 132 'typenow' => $current_screen->post_type, 133 'adminpage' => $admin_body_class, 134 'thousandsSeparator' => $wp_locale->number_format['thousands_sep'], 135 'decimalPoint' => $wp_locale->number_format['decimal_point'], 136 'isRtl' => (int) is_rtl(), 137 ), 138 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES 139 ) 140 ) 141 ); 115 142 116 143 /** … … 254 281 ?> 255 282 <body class="wp-admin wp-core-ui no-js <?php echo esc_attr( $admin_body_classes ); ?>"> 256 <script> 257 document.body.className = document.body.className.replace('no-js','js'); 258 </script> 259 260 <?php 283 <?php 284 wp_print_inline_script_tag( 285 <<<'JS' 286 document.body.className = document.body.className.replace( 'no-js', 'js' ); 287 JS 288 ); 289 261 290 // Make sure the customize body classes are correct as early as possible. 262 291 if ( current_user_can( 'customize' ) ) { -
trunk/src/wp-admin/includes/media.php
r63381 r63481 273 273 */ 274 274 function media_send_to_editor( $html ) { 275 ?>276 <script>277 var win = window.dialogArguments || opener || parent || top;278 win.send_to_editor( <?php echo wp_json_encode( $html, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );279 </script>280 <?php275 wp_print_inline_script_tag( 276 sprintf( 277 '( window.dialogArguments || opener || parent || top ).send_to_editor( %s );', 278 wp_json_encode( $html, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) 279 ) 280 ); 281 281 exit; 282 282 } … … 568 568 } 569 569 570 ?> 571 <script> 572 addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; 573 var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', 574 isRtl = <?php echo (int) is_rtl(); ?>; 575 </script> 576 <?php 570 wp_print_inline_script_tag( 571 <<<'JS' 572 function addLoadEvent( func ) { 573 if ( typeof jQuery !== 'undefined' ) { 574 jQuery( function () { 575 func(); 576 } ); 577 } else if ( typeof wpOnload !== 'function' ) { 578 window.wpOnload = func; 579 } else { 580 const oldOnload = window.wpOnload; 581 window.wpOnload = function () { 582 oldOnload(); 583 func(); 584 }; 585 } 586 } 587 JS 588 ); 589 wp_print_inline_script_tag( 590 sprintf( 591 'Object.assign( window, %s );', 592 wp_json_encode( 593 array( 594 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), 595 'pagenow' => 'media-upload-popup', 596 'adminpage' => 'media-upload-popup', 597 'isRtl' => (int) is_rtl(), 598 ), 599 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES 600 ) 601 ) 602 ); 577 603 /** This action is documented in wp-admin/admin-header.php */ 578 604 do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); … … 631 657 </head> 632 658 <body<?php echo $body_id_attr; ?> class="wp-core-ui no-js <?php echo 'admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'modern' ); ?>"> 633 <script>634 document.body.className = document.body.className.replace('no-js', 'js');635 </script>636 659 <?php 660 wp_print_inline_script_tag( 661 <<<'JS' 662 document.body.className = document.body.className.replace( 'no-js', 'js' ); 663 JS 664 ); 637 665 638 666 call_user_func_array( $content_func, $args ); … … 641 669 do_action( 'admin_print_footer_scripts' ); 642 670 671 wp_print_inline_script_tag( 672 <<<'JS' 673 if ( typeof wpOnload === 'function' ) { 674 wpOnload(); 675 } 676 JS 677 ); 643 678 ?> 644 <script>if(typeof wpOnload==='function')wpOnload();</script>645 679 </body> 646 680 </html> … … 839 873 840 874 if ( isset( $_POST['insert-gallery'] ) || isset( $_POST['update-gallery'] ) ) { 841 ?> 842 <script> 843 var win = window.dialogArguments || opener || parent || top; 844 win.tb_remove(); 845 </script> 846 <?php 875 wp_print_inline_script_tag( 876 <<<'JS' 877 ( window.dialogArguments || opener || parent || top ).tb_remove(); 878 JS 879 ); 847 880 848 881 exit; … … 2100 2133 $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; 2101 2134 2102 echo '<script>post_id = ' . $post_id . ';</script>'; 2135 wp_print_inline_script_tag( 2136 sprintf( 'var post_id = %s;', wp_json_encode( $post_id, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) 2137 ); 2103 2138 2104 2139 if ( empty( $_GET['chromeless'] ) ) { … … 2248 2283 $plupload_init = apply_filters( 'plupload_init', $plupload_init ); 2249 2284 2250 ?>2251 <script>2252 <?php2253 2285 // Verify size is an int. If not return default value. 2254 2286 $large_size_h = absint( get_option( 'large_size_h' ) ); … … 2264 2296 } 2265 2297 2298 wp_print_inline_script_tag( 2299 sprintf( 2300 'Object.assign( window, %s );', 2301 wp_json_encode( 2302 array( 2303 'resize_height' => $large_size_h, 2304 'resize_width' => $large_size_w, 2305 'wpUploaderInit' => $plupload_init, 2306 ), 2307 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES 2308 ) 2309 ) 2310 ); 2266 2311 ?> 2267 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,2268 wpUploaderInit = <?php echo wp_json_encode( $plupload_init, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>;2269 </script>2270 2312 2271 2313 <div id="plupload-upload-ui" class="hide-if-no-js"> … … 2391 2433 <?php media_upload_form( $errors ); ?> 2392 2434 2393 <script> 2394 jQuery(function($){ 2395 var preloaded = $(".media-item.preloaded"); 2396 if ( preloaded.length > 0 ) { 2397 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); 2398 } 2399 updateMediaForm(); 2400 }); 2401 </script> 2435 <?php 2436 wp_print_inline_script_tag( 2437 <<<'JS' 2438 jQuery( function ( $ ) { 2439 var preloaded = $( '.media-item.preloaded' ); 2440 if ( preloaded.length > 0 ) { 2441 preloaded.each( function () { 2442 prepareMediaItem( { id: this.id.replace( /[^0-9]/g, '' ) }, '' ); 2443 } ); 2444 } 2445 updateMediaForm(); 2446 } ); 2447 JS 2448 ); 2449 ?> 2402 2450 <div id="media-items"> 2403 2451 <?php … … 2457 2505 <h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3> 2458 2506 2507 <?php ob_start(); ?> 2459 2508 <script> 2460 2509 var addExtImage = { … … 2550 2599 } ); 2551 2600 </script> 2601 <?php wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( (string) ob_get_clean() ) ); ?> 2552 2602 2553 2603 <div id="media-items"> … … 2597 2647 } 2598 2648 2649 wp_print_inline_script_tag( 2650 <<<'JS' 2651 jQuery( function ( $ ) { 2652 var preloaded = $( '.media-item.preloaded' ); 2653 if ( preloaded.length > 0 ) { 2654 preloaded.each( function () { 2655 prepareMediaItem( { id: this.id.replace( /[^0-9]/g, '' ) }, '' ); 2656 } ); 2657 updateMediaForm(); 2658 } 2659 } ); 2660 JS 2661 ); 2599 2662 ?> 2600 <script>2601 jQuery(function($){2602 var preloaded = $(".media-item.preloaded");2603 if ( preloaded.length > 0 ) {2604 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});2605 updateMediaForm();2606 }2607 });2608 </script>2609 2663 <div id="sort-buttons" class="hide-if-no-js"> 2610 2664 <span> … … 2926 2980 <?php wp_nonce_field( 'media-form' ); ?> 2927 2981 2928 <script> 2929 jQuery(function($){ 2930 var preloaded = $(".media-item.preloaded"); 2931 if ( preloaded.length > 0 ) { 2932 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); 2933 updateMediaForm(); 2934 } 2935 }); 2936 </script> 2982 <?php 2983 wp_print_inline_script_tag( 2984 <<<'JS' 2985 jQuery( function ( $ ) { 2986 var preloaded = $( '.media-item.preloaded' ); 2987 if ( preloaded.length > 0 ) { 2988 preloaded.each( function () { 2989 prepareMediaItem( { id: this.id.replace( /[^0-9]/g, '' ) }, '' ); 2990 } ); 2991 updateMediaForm(); 2992 } 2993 } ); 2994 JS 2995 ); 2996 ?> 2937 2997 2938 2998 <div id="media-items"> -
trunk/src/wp-admin/includes/template.php
r62934 r63481 2141 2141 <?php 2142 2142 wp_enqueue_style( 'colors' ); 2143 ?> 2144 <script> 2145 addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; 2146 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();} 2147 var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', 2148 pagenow = '<?php echo esc_js( $current_screen->id ); ?>', 2149 typenow = '<?php echo esc_js( $current_screen->post_type ); ?>', 2150 adminpage = '<?php echo esc_js( $admin_body_class ); ?>', 2151 thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>', 2152 decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>', 2153 isRtl = <?php echo (int) is_rtl(); ?>; 2154 </script> 2155 <?php 2143 2144 // Print the global admin inline scripts through the script tag API so the 2145 // `wp_inline_script_attributes` filter (e.g. a CSP nonce) applies. 2146 wp_print_inline_script_tag( 2147 <<<'JS' 2148 function addLoadEvent( func ) { 2149 if ( typeof jQuery !== 'undefined' ) { 2150 jQuery( function () { 2151 func(); 2152 } ); 2153 } else if ( typeof wpOnload !== 'function' ) { 2154 window.wpOnload = func; 2155 } else { 2156 const oldOnload = window.wpOnload; 2157 window.wpOnload = function () { 2158 oldOnload(); 2159 func(); 2160 }; 2161 } 2162 } 2163 2164 function tb_close() { 2165 ( window.dialogArguments || opener || parent || top ).tb_remove(); 2166 } 2167 JS 2168 ); 2169 wp_print_inline_script_tag( 2170 sprintf( 2171 'Object.assign( window, %s );', 2172 wp_json_encode( 2173 array( 2174 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), 2175 'pagenow' => $current_screen->id ?? '', 2176 'typenow' => $current_screen->post_type ?? '', 2177 'adminpage' => $admin_body_class, 2178 'thousandsSeparator' => $wp_locale->number_format['thousands_sep'], 2179 'decimalPoint' => $wp_locale->number_format['decimal_point'], 2180 'isRtl' => (int) is_rtl(), 2181 ), 2182 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES 2183 ) 2184 ) 2185 ); 2186 2156 2187 /** This action is documented in wp-admin/admin-header.php */ 2157 2188 do_action( 'admin_enqueue_scripts', $hook_suffix ); … … 2192 2223 ?> 2193 2224 <body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo esc_attr( $admin_body_classes ); ?>"> 2194 <script>2195 (function(){2196 var c = document.body.className;2197 c = c.replace(/no-js/, 'js');2198 document.body.className = c;2199 })();2200 </script>2201 2225 <?php 2226 wp_print_inline_script_tag( 2227 <<<'JS' 2228 document.body.className = document.body.className.replace( 'no-js', 'js' ); 2229 JS 2230 ); 2202 2231 } 2203 2232 … … 2231 2260 ?> 2232 2261 </div> 2233 <script>if(typeof wpOnload==='function')wpOnload();</script> 2262 <?php 2263 wp_print_inline_script_tag( 2264 <<<'JS' 2265 if ( typeof wpOnload === 'function' ) { 2266 wpOnload(); 2267 } 2268 JS 2269 ); 2270 ?> 2234 2271 </body> 2235 2272 </html>
Note:
See TracChangeset
for help on using the changeset viewer.