[wp-trac] [WordPress Trac] #49255: It is not possible to register field for settings endpoint.

WordPress Trac noreply at wordpress.org
Tue Jan 21 07:14:14 UTC 2020


#49255: It is not possible to register field for settings endpoint.
--------------------------+-----------------------------
 Reporter:  vavra7        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  5.3.2
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:  rest-api      |
--------------------------+-----------------------------
 Function register_rest_field() does not work for endpoint settings.  Here
 is example code which is supposed to work but it doesn't. No field is
 added.

 Used WordPress v5.3.2. No plugins.

 {{{#!php
 <?php
 function add_field_show_on_front()
 {
         $args = [
                 'get_callback' => function() {
                         return get_option('show_on_front');
                 }
         ];

         register_rest_field('setting', 'show_on_front', $args);
 }

 add_filter('rest_api_init', 'add_field_show_on_front');
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49255>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list