diff --git src/wp-includes/class-wp-post-type.php src/wp-includes/class-wp-post-type.php
index 0099515050..bb148067c0 100644
|
|
final class WP_Post_Type { |
343 | 343 | * @since 5.3.0 |
344 | 344 | * @var WP_REST_Controller $rest_controller |
345 | 345 | */ |
346 | | private $rest_controller; |
| 346 | public $rest_controller; |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * Constructor. |
… |
… |
final class WP_Post_Type { |
722 | 722 | $this->rest_controller = new $class( $this->name ); |
723 | 723 | } |
724 | 724 | |
| 725 | if ( ! ( $this->rest_controller instanceof $class ) ) { |
| 726 | return null; |
| 727 | } |
| 728 | |
725 | 729 | return $this->rest_controller; |
726 | 730 | } |
727 | 731 | } |
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 4a00336e34..2b71a76cb0 100644
|
|
|
15 | 15 | * @see WP_REST_Controller |
16 | 16 | */ |
17 | 17 | class WP_REST_Posts_Controller extends WP_REST_Controller { |
18 | | |
19 | | /** |
20 | | * Instances of post type controllers keyed by post type. |
21 | | * |
22 | | * @since 5.3.0 |
23 | | * @var WP_REST_Controller[] |
24 | | */ |
25 | | private static $post_type_controllers = array(); |
26 | | |
27 | 18 | /** |
28 | 19 | * Post type. |
29 | 20 | * |
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index fa7396afcc..6692aee39b 100644
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
4616 | 4616 | ); |
4617 | 4617 | } |
4618 | 4618 | |
| 4619 | /** |
| 4620 | * @ticket 45677 |
| 4621 | */ |
| 4622 | public function test_get_for_post_type_returns_null_for_invalid_provided_controller() { |
| 4623 | register_post_type( |
| 4624 | 'test', |
| 4625 | array( |
| 4626 | 'show_in_rest' => true, |
| 4627 | 'rest_controller' => new \stdClass(), |
| 4628 | ) |
| 4629 | ); |
| 4630 | |
| 4631 | $this->assertNull( get_post_type_object( 'test' )->get_rest_controller() ); |
| 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * @ticket 45677 |
| 4636 | */ |
| 4637 | public function test_get_for_post_type_returns_null_for_controller_class_mismatch() { |
| 4638 | register_post_type( |
| 4639 | 'test', |
| 4640 | array( |
| 4641 | 'show_in_rest' => true, |
| 4642 | 'rest_controller_class' => WP_REST_Posts_Controller::class, |
| 4643 | 'rest_controller' => new WP_REST_Terms_Controller( 'category' ), |
| 4644 | ) |
| 4645 | ); |
| 4646 | |
| 4647 | $this->assertNull( get_post_type_object( 'test' )->get_rest_controller() ); |
| 4648 | } |
| 4649 | |
4619 | 4650 | public function tearDown() { |
4620 | 4651 | _unregister_post_type( 'private-post' ); |
4621 | 4652 | _unregister_post_type( 'youseeme' ); |