Description
Creating a wp_navigation in REST throws Undefined property: stdClass::$ID error.
Step-by-step reproduction instructions
Create a POST REST request on wp/v2/navigation with at least title or content parameter set.
See debug.log for an error such as:
Undefined property: stdClass::$ID
/var/www/html/wp-includes/blocks/navigation.php:1479
/var/www/html/wp-includes/class-wp-hook.php:326
/var/www/html/wp-includes/plugin.php:205
/var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:1399
/var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:650
/var/www/html/wp-includes/rest-api/class-wp-rest-server.php:1230
/var/www/html/wp-includes/rest-api/class-wp-rest-server.php:1063
/wordpress-phpunit/includes/spy-rest-server.php:71
Screenshots, screen recording, code snippet
Here is a PHPUnit test that shows the bug:
<?php
class Gutenberg_REST_Create_Navigation_Block_Test extends WP_UnitTestCase {
public function test_block_core_navigation_rest_creation() {
wp_set_current_user( 1 );
$post_type_object = get_post_type_object( 'wp_navigation' );
$request = new WP_REST_Request( 'POST', '/wp/v2/' . $post_type_object->rest_base );
$request->set_param( 'title', 'Title ' . $post_type_object->label );
$request->set_param( 'content', $post_type_object->label );
$request->set_param( '_locale', 'user' );
$response = rest_get_server()->dispatch( $request ); // Triggers the error.
// Assertions aren't reached.
$this->assertNotEmpty( $response->get_status() );
$this->assertSame( 201, $response->get_status() );
}
}
For what I understand, the bug was introduced in this PR.
During creation, there is no $post->ID set yet, so doing get_post( $post->iD ) causes the error.
Environment info
- WordPress nightly (from 6.5 RC2 I think)
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Description
Creating a
wp_navigationin REST throwsUndefined property: stdClass::$IDerror.Step-by-step reproduction instructions
Create a POST REST request on
wp/v2/navigationwith at leasttitleorcontentparameter set.See
debug.logfor an error such as:Screenshots, screen recording, code snippet
Here is a PHPUnit test that shows the bug:
For what I understand, the bug was introduced in this PR.
During creation, there is no
$post->IDset yet, so doingget_post( $post->iD )causes the error.Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes