diff -r 48c4eec2b7e6 -r 8c2e4d02f4ef wp/wp-admin/edit-form-blocks.php --- a/wp/wp-admin/edit-form-blocks.php Fri Sep 05 18:40:08 2025 +0200 +++ b/wp/wp-admin/edit-form-blocks.php Fri Sep 05 18:52:52 2025 +0200 @@ -51,17 +51,16 @@ $rest_path = rest_get_route_for_post( $post ); +$active_theme = get_stylesheet(); +$global_styles_endpoint_context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view'; +$template_lookup_slug = 'page' === $post->post_type ? 'page' : 'single-' . $post->post_type; +if ( ! empty( $post->post_name ) ) { + $template_lookup_slug .= '-' . $post->post_name; +} // Preload common data. $preload_paths = array( '/wp/v2/types?context=view', '/wp/v2/taxonomies?context=view', - add_query_arg( - array( - 'context' => 'edit', - 'per_page' => -1, - ), - rest_get_route_for_post_type_items( 'wp_block' ) - ), add_query_arg( 'context', 'edit', $rest_path ), sprintf( '/wp/v2/types/%s?context=edit', $post_type ), '/wp/v2/users/me', @@ -72,9 +71,44 @@ sprintf( '%s/autosaves?context=edit', $rest_path ), '/wp/v2/settings', array( '/wp/v2/settings', 'OPTIONS' ), - '/wp/v2/global-styles/themes/' . get_stylesheet(), + '/wp/v2/global-styles/themes/' . $active_theme . '?context=view', + '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view', '/wp/v2/themes?context=edit&status=active', - '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit', + array( '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id(), 'OPTIONS' ), + /* + * Preload the global styles path with the correct context based on user caps. + * NOTE: There is an equivalent conditional check in the client-side code to fetch + * the global styles entity using the appropriate context value. + * See the call to `canUser()`, under `useGlobalStylesUserConfig()` in `packages/edit-site/src/components/use-global-styles-user-config/index.js`. + * Please ensure that the equivalent check is kept in sync with this preload path. + */ + '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=' . $global_styles_endpoint_context, + // Used by getBlockPatternCategories in useBlockEditorSettings. + '/wp/v2/block-patterns/categories', + // @see packages/core-data/src/entities.js + '/?_fields=' . implode( + ',', + array( + 'description', + 'gmt_offset', + 'home', + 'name', + 'site_icon', + 'site_icon_url', + 'site_logo', + 'timezone_string', + 'url', + 'page_for_posts', + 'page_on_front', + 'show_on_front', + ) + ), + $paths[] = add_query_arg( + 'slug', + // @see https://github.com/WordPress/gutenberg/blob/e093fefd041eb6cc4a4e7f67b92ab54fd75c8858/packages/core-data/src/private-selectors.ts#L244-L254 + $template_lookup_slug, + '/wp/v2/templates/lookup' + ), ); block_editor_rest_api_preload( $preload_paths, $block_editor_context ); @@ -113,6 +147,24 @@ 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' ); +// Preload server-registered block bindings sources. +$registered_sources = get_all_registered_block_bindings_sources(); +if ( ! empty( $registered_sources ) ) { + $filtered_sources = array(); + foreach ( $registered_sources as $source ) { + $filtered_sources[] = array( + 'name' => $source->name, + 'label' => $source->label, + 'usesContext' => $source->uses_context, + ); + } + $script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) ); + wp_add_inline_script( + 'wp-blocks', + $script + ); +} + // Get admin url for handling meta boxes. $meta_box_url = admin_url( 'post.php' ); $meta_box_url = add_query_arg( @@ -130,6 +182,15 @@ 'before' ); +// Set Heartbeat interval to 10 seconds, used to refresh post locks. +wp_add_inline_script( + 'heartbeat', + 'jQuery( function() { + wp.heartbeat.interval( 10 ); + } );', + 'after' +); + /* * Get all available templates for the post/page attributes meta-box. * The "Default template" array element should only be added if the array is @@ -159,9 +220,12 @@ if ( $locked ) { $user = get_userdata( $user_id ); $user_details = array( - 'avatar' => get_avatar_url( $user_id, array( 'size' => 128 ) ), - 'name' => $user->display_name, + 'name' => $user->display_name, ); + + if ( get_option( 'show_avatars' ) ) { + $user_details['avatar'] = get_avatar_url( $user_id, array( 'size' => 128 ) ); + } } $lock_details = array(