| | 58 | register_rest_route( |
| | 59 | $this->namespace, |
| | 60 | '/' . $this->rest_base . '/public', |
| | 61 | array( |
| | 62 | array( |
| | 63 | 'methods' => WP_REST_Server::READABLE, |
| | 64 | 'callback' => array( $this, 'get_public_item' ), |
| | 65 | 'args' => array(), |
| | 66 | 'permission_callback' => array( $this, 'get_public_item_permissions_check' ), |
| | 67 | ), |
| | 68 | array( |
| | 69 | 'methods' => WP_REST_Server::EDITABLE, |
| | 70 | 'callback' => array( $this, 'update_public_item' ), |
| | 71 | 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
| | 72 | 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
| | 73 | ), |
| | 74 | 'schema' => array( $this, 'get_public_item_schema' ), |
| | 75 | ) |
| | 76 | ); |
| | 77 | |
| | 381 | |
| | 382 | public function filter_public_registered_options( $rest_options ){ |
| | 383 | $filtered_rest_options = array(); |
| | 384 | foreach ( $rest_options as $name => $args ) { |
| | 385 | if ( empty( $args['public'] ) ) { |
| | 386 | continue; |
| | 387 | } |
| | 388 | |
| | 389 | $filtered_rest_options[ $args['name'] ] = $args; |
| | 390 | } |
| | 391 | return $filtered_rest_options; |
| | 392 | } |
| | 393 | |
| | 394 | public function get_public_item( $request ) { |
| | 395 | add_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); |
| | 396 | return $this->get_item( $request ); |
| | 397 | remove_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); |
| | 398 | } |
| | 399 | |
| | 400 | public function update_public_item( $request ) { |
| | 401 | add_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); |
| | 402 | return $this->update_item( $request ); |
| | 403 | remove_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); |
| | 404 | } |
| | 405 | |