[wp-trac] [WordPress Trac] #47779: Add a filter to `get_item_schema()` to be able to extend the schema of existing properties

WordPress Trac noreply at wordpress.org
Wed Oct 9 09:08:28 UTC 2019


#47779: Add a filter to `get_item_schema()` to be able to extend the schema of
existing properties
-------------------------------------------------+-------------------------
 Reporter:  luisherranz                          |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  REST API                             |     Version:  4.7
 Severity:  trivial                              |  Resolution:
 Keywords:  has-patch dev-feedback needs-unit-   |     Focuses:  rest-api
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by luisherranz):

 Ok, I had some more time today to look into this and I found the problem.

 Looking at the stack, it looks like `get_item_schema` is called on the
 `rest_api_init` hook, which is called on the
 `WP_Test_REST_Posts_Controller->setUp` method.

 That means we would need to add the filter before the `setUp`, or do the
 `setUp` or the `rest_api_init` again. I don't like either of those.

 I've tested adding the filter in the `setUp` just to check if the test is
 passing and the test is working:
 {{{#!php
 public function setUp() {
   add_filter( 'rest_post_item_schema', array( $this,
 'filter_post_item_schema' ) );
   parent::setUp(); // <- this is where the do_action( 'rest_api_ini' )
 happens.
   // the rest of the setUp...

 }}}

 Where should I add the filter? Any idea?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47779#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list