Changeset 52733
- Timestamp:
- 02/15/2022 05:28:14 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r52544 r52733 426 426 * @since 5.8.0 427 427 * 428 * @global WP_Post $post Global post object. 428 * @global WP_Post $post Global post object. 429 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 430 * @global WP_Styles $wp_styles The WP_Styles object for printing styles. 429 431 * 430 432 * @param string[] $preload_paths List of paths to preload. … … 434 436 */ 435 437 function block_editor_rest_api_preload( array $preload_paths, $block_editor_context ) { 436 global $post ;438 global $post, $wp_scripts, $wp_styles; 437 439 438 440 /** … … 468 470 469 471 /* 470 * Ensure the global $post remains the same after API data is preloaded. 472 * Ensure the global $post, $wp_scripts, and $wp_styles remain the same after 473 * API data is preloaded. 471 474 * Because API preloading can call the_content and other filters, plugins 472 * can unexpectedly modify $post. 475 * can unexpectedly modify the global $post or enqueue assets which are not 476 * intended for the block editor. 473 477 */ 474 478 $backup_global_post = ! empty( $post ) ? clone $post : $post; 479 $backup_wp_scripts = ! empty( $wp_scripts ) ? clone $wp_scripts : $wp_scripts; 480 $backup_wp_styles = ! empty( $wp_styles ) ? clone $wp_styles : $wp_styles; 475 481 476 482 foreach ( $preload_paths as &$path ) { … … 481 487 482 488 if ( is_array( $path ) && is_string( $path[0] ) && ! str_starts_with( $path[0], '/' ) ) { 483 489 $path[0] = '/' . $path[0]; 484 490 } 485 491 } … … 493 499 ); 494 500 495 // Restore the global $post as it was before API preloading. 496 $post = $backup_global_post; 501 // Restore the global $post, $wp_scripts, and $wp_styles as they were before API preloading. 502 $post = $backup_global_post; 503 $wp_scripts = $backup_wp_scripts; 504 $wp_styles = $backup_wp_styles; 497 505 498 506 wp_add_inline_script(
Note: See TracChangeset
for help on using the changeset viewer.