Editor: Avoid undefined index notices in the Template Parts Editor.

This changes adds a leading slash when needed in the `?context=edit` path to avoid an `undefined index` notice in the Template Parts Editor.

Follow-up to [52275].

Props kafleg, costdev, mukesh27, Boniu91.
Fixes #54558.


git-svn-id: https://develop.svn.wordpress.org/trunk@52312 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2021-12-03 15:28:21 +00:00
parent 1270c897a9
commit 108e65819a
2 changed files with 60 additions and 0 deletions

View File

@@ -468,6 +468,17 @@ function block_editor_rest_api_preload( array $preload_paths, $block_editor_cont
*/
$backup_global_post = ! empty( $post ) ? clone $post : $post;
foreach ( $preload_paths as &$path ) {
if ( is_string( $path ) && ! str_starts_with( $path, '/' ) ) {
$path = '/' . $path;
continue;
}
if ( is_array( $path ) && is_string( $path[0] ) && ! str_starts_with( $path[0], '/' ) ) {
$path[0] = '/' . $path[0];
}
}
$preload_data = array_reduce(
$preload_paths,
'rest_preload_api_request',