src/WPametu/API/Rewrite.php
public function pre_get_posts( \WP_Query &$wp_query ){
        if( !is_admin() && $wp_query->is_main_query() && ($api_class = $wp_query->get($this->api_class)) ){
            // Detect class is valid
            try{
                // Fix escaped namespace delimiter
                $api_class = str_replace('\\\\', '\\', $api_class);
                // Check class existence
                if( !$this->is_valid_class($api_class) ){
                    throw new \Exception($this->__('Specified URL is invalid.'), 404);
                }
                /** @var RestBase $instance */
                $instance = $api_class::get_instance();
                $instance->parse_request($wp_query->get($this->api_vars), $wp_query);
            }catch ( \Exception $e ){
                switch( $e->getCode() ){
                    case 404:
                        $wp_query->set_404();
                        break;
                    case 200:
                    case 201:
                        // If status is O.K.
                        // Do nothing.
                        break;
                    default:
                        wp_die($e->getMessage(), get_status_header_desc($e->getCode()), [
                            'response' => $e->getCode(),
                            'back_link' => true,
                        ]);
                        break;
                }
            }
        }
    }
public function pre_get_posts( \WP_Query &$wp_query ){
        if( !is_admin() && $wp_query->is_main_query() && ($api_class = $wp_query->get($this->api_class)) ){
            // Detect class is valid
            try{
                // Fix escaped namespace delimiter
                $api_class = str_replace('\\\\', '\\', $api_class);
                // Check class existence
                if( !$this->is_valid_class($api_class) ){
                    throw new \Exception($this->__('Specified URL is invalid.'), 404);
                }
                /** @var RestBase $instance */
                $instance = $api_class::get_instance();
                $instance->parse_request($wp_query->get($this->api_vars), $wp_query);
            }catch ( \Exception $e ){
                switch( $e->getCode() ){
                    case 404:
                        $wp_query->set_404();
                        break;
                    case 200:
                    case 201:
                        // If status is O.K.
                        // Do nothing.
                        break;
                    default:
                        wp_die($e->getMessage(), get_status_header_desc($e->getCode()), [
                            'response' => $e->getCode(),
                            'back_link' => true,
                        ]);
                        break;
                }
            }
        }
    }
public function pre_get_posts ( \ WP_Query & $ wp_query ) { if ( ! is_admin ( ) && $ wp_query -> is_main_query ( ) && ( $ api_class = $ wp_query -> get ( $ this -> api_class ) ) ) { // Detect class is valid try { // Fix escaped namespace delimiter $ api_class = str_replace ( '\\\\' , '\\' , $ api_class ) ; // Check class existence if ( ! $ this -> is_valid_class ( $ api_class ) ) { throw new \ Exception ( $ this -> __ ( 'Specified URL is invalid.' ) , 404 ) ; } /** @var RestBase $instance */ $ instance = $ api_class :: get_instance ( ) ; $ instance -> parse_request ( $ wp_query -> get ( $ this -> api_vars ) , $ wp_query ) ; } catch ( \ Exception $ e ) { switch ( $ e -> getCode ( ) ) { case 404 : $ wp_query -> set_404 ( ) ; break ; case 200 : case 201 : // If status is O.K. // Do nothing. break ; default : wp_die ( $ e -> getMessage ( ) , get_status_header_desc ( $ e -> getCode ( ) ) , [ 'response' => $ e -> getCode ( ) , 'back_link' => true , ] ) ; break ; } } } }
Parse request and invoke REST class if possible

@param \WP_Query $wp_query
Parse request and invoke REST class if possible