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

Add get_item_schema function to WP_REST_Widget_Areas_Controller #15981

Conversation

jorgefilipecosta
Copy link
Member

Description

Fixes: #15902

This PR implements the get_item_schema function for WP_REST_Widget_Areas_Controller class.

This fixes a problem where warnings were being displayed during wp-cli usage.
Props to @n9yty, @TimothyBJacobs, and @lkraav for providing valuable information that allowed this fix.

How has this been tested?

I executed wp CLI shell again a WordPress instance running Gutenberg master. Using wp shell --path=/MY/WP/PATH
I verified no error were thrown on master I got:
Warning: Invalid argument supplied for foreach() in /Users/pc/dev/core/wordpres-develop/build/wp-includes/rest-api/endpoints/class-wp-rest-controller.php on line 287
Warning: Invalid argument supplied for foreach() in /Users/pc/dev/core/wordpres-develop/build/wp-includes/rest-api/endpoints/class-wp-rest-controller.php on line 287

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Widgets Screen The block-based screen that replaced widgets.php. labels Jun 4, 2019
Copy link
Member

@TimothyBJacobs TimothyBJacobs left a comment

Choose a reason for hiding this comment

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

Since the endpoint now has a schema, the args should ideally be provided by ::get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ) when registering the update_item route.

lib/class-wp-rest-widget-areas-controller.php Outdated Show resolved Hide resolved
lib/class-wp-rest-widget-areas-controller.php Outdated Show resolved Hide resolved
@jorgefilipecosta jorgefilipecosta force-pushed the add/get-item-schema-function-to-WP_REST_Widget_Areas_Controller branch from 6bcaa78 to 3145ffb Compare June 4, 2019 22:01
@aduth
Copy link
Member

aduth commented Jul 2, 2019

@TimothyBJacobs Would you be able to give a fresh review here after the latest changes?

@TimothyBJacobs
Copy link
Member

The schema looks good to me, but the register_rest_route call should use that schema for the $args option when registering the edit route. This can be done by calling $this→get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ).

@jorgefilipecosta jorgefilipecosta force-pushed the add/get-item-schema-function-to-WP_REST_Widget_Areas_Controller branch 3 times, most recently from 09b67ed to 79467ce Compare July 3, 2019 16:57
@jorgefilipecosta
Copy link
Member Author

Hi @TimothyBJacobs thank you for the feedback your suggestion was applied 👍

@TimothyBJacobs
Copy link
Member

@jorgefilipecosta I think there is an issue with the update_item method call. The code only accounts for when content is a string, but it should also check whether it is an object with the raw property.

$sidebar_content = $request->get_param( 'content' );

An example from the posts controller.

if ( is_string( $request['content'] ) ) {
	$prepared_post->post_content = $request['content'];
} elseif ( isset( $request['content']['raw'] ) ) {
	$prepared_post->post_content = $request['content']['raw'];
}

@TimothyBJacobs
Copy link
Member

@jorgefilipecosta Do you want me to push the changes up for this?

@jorgefilipecosta
Copy link
Member Author

Hi @TimothyBJacobs sorry for the delay I had some AFK days, I will soon update this PR.

@jorgefilipecosta jorgefilipecosta force-pushed the add/get-item-schema-function-to-WP_REST_Widget_Areas_Controller branch from 79467ce to 46b93b7 Compare August 20, 2019 15:46
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Aug 20, 2019

Hi @TimothyBJacobs, thank you for the review. The issue identified was fixed.
We now handle the raw property for content.
It is possible to test this using the following code:

wp.apiFetch({
    path: '/__experimental/widget-areas/sidebar-1',
    data: { content: { raw: '<!-- wp:columns --><div class="wp-block-columns has-2-columns"><!-- wp:column --><div class="wp-block-column"><!-- wp:paragraph --><p>1</p><!-- /wp:paragraph --></div><!-- /wp:column --><!-- wp:column --><div class="wp-block-column"><!-- wp:paragraph --><p>2</p><!-- /wp:paragraph --></div><!-- /wp:column --></div><!-- /wp:columns -->' } },
    method: 'POST',
}).then(console.log);

@jorgefilipecosta jorgefilipecosta dismissed TimothyBJacobs’s stale review August 20, 2019 17:23

Suggestions were applied.

@TimothyBJacobs TimothyBJacobs self-requested a review August 25, 2019 17:12
Copy link
Member

@TimothyBJacobs TimothyBJacobs left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@jorgefilipecosta jorgefilipecosta merged commit 2e45a8b into master Aug 26, 2019
@jorgefilipecosta jorgefilipecosta deleted the add/get-item-schema-function-to-WP_REST_Widget_Areas_Controller branch August 26, 2019 11:05
donmhico pushed a commit to donmhico/gutenberg that referenced this pull request Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Widgets Screen The block-based screen that replaced widgets.php. REST API Interaction Related to REST API [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Release 5.8.0 introduced PHP Warnings, at least in 'wp shell'
3 participants