-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change context depending on user caps to prevent clientside request i…
…n post editor. Sync with #66543
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* PHP and WordPress configuration compatibility functions for the Gutenberg | ||
* editor plugin changes related to REST API. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
die( 'Silence is golden.' ); | ||
} | ||
|
||
/** | ||
* Update the preload paths registered in Core (`site-editor.php` or `edit-form-blocks.php`). | ||
* | ||
* @param array $paths REST API paths to preload. | ||
* @param WP_Block_Editor_Context $context Current block editor context. | ||
* @return array Filtered preload paths. | ||
*/ | ||
function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) { | ||
// Preload theme and global styles paths. | ||
if ( 'core/edit-site' === $context->name || 'core/edit-post' === $context->name ) { | ||
$excluded_paths = array(); | ||
$global_styles_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id(); | ||
|
||
/* | ||
* Removes any edit or view context paths originating from Core, | ||
* or elsewhere, e.g., gutenberg_block_editor_preload_paths_6_6(). | ||
* This also ensures there no duplicates. block_editor_rest_api_preload() does | ||
* not dedupe, and will render request output into the HTML for all provided paths. | ||
*/ | ||
$excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id . '?context=view'; | ||
// Removes any edit context path originating from gutenberg_block_editor_preload_paths_6_6(). | ||
$excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id . '?context=edit'; | ||
foreach ( $paths as $key => $path ) { | ||
if ( in_array( $path, $excluded_paths, true ) ) { | ||
unset( $paths[ $key ] ); | ||
} | ||
} | ||
|
||
/* | ||
* Now add the global styles path with the correct context based on user caps. | ||
*/ | ||
$context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view'; | ||
$paths[] = "/wp/v2/global-styles/$global_styles_id?context=$context"; | ||
} | ||
|
||
return $paths; | ||
} | ||
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_8', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters