-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
[Block] NavigationAffects the Navigation BlockAffects the Navigation Block[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Block] NavigationAffects the Navigation BlockAffects the Navigation Block[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Type
Fields
Give feedbackNo fields configured for issues without a type.