Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Add a new endpoint that exposes block editor settings through the REST API #25226

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/class-wp-rest-block-editor-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,18 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' )
)
'permission_callback' => array( $this, 'get_items_permissions_check' ),
),
)
);
}

/**
* Checks whether a given request has permission to read block editor settings
*
* @since 5.5.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
*/
public function get_items_permissions_check( $request ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geriux I think You might still need this when I pull in this commit I get:

Warning: Declaration of WP_REST_Block_Editor_Settings_Controller::get_items() should be compatible with WP_REST_Controller::get_items($request) in /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php on line 59 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-includes/functions.php on line 6362 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-admin/includes/misc.php on line 1310 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-admin/admin-header.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-includes/option.php on line 1051 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-includes/option.php on line 1052

public function get_items_permissions_check() {
if ( ! current_user_can( 'edit_posts' ) ) {
$error = __( 'Sorry, you are not allowed to read the block editor settings.', 'gutenberg' );
return new WP_Error( 'rest_cannot_read_settings', $error, array( 'status' => rest_authorization_required_code() ) );
Expand All @@ -58,13 +54,9 @@ public function get_items_permissions_check( $request ) {
/**
* Return all block editor settings
*
* @since 5.5.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geriux I think You might still need this when I pull in this commit I get:

Warning: Declaration of WP_REST_Block_Editor_Settings_Controller::get_items() should be compatible with WP_REST_Controller::get_items($request) in /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php on line 59 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-includes/functions.php on line 6362 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-admin/includes/misc.php on line 1310 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-admin/admin-header.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-includes/option.php on line 1051 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/plugins/gutenberg/lib/class-wp-rest-block-editor-settings-controller.php:0) in /var/www/html/wp-includes/option.php on line 1052

public function get_items() {
$settings = apply_filters( 'block_editor_settings', array() );

return rest_ensure_response( $settings );
Expand Down