Make WordPress Core


Ignore:
Timestamp:
02/16/2016 01:11:31 AM (9 years ago)
Author:
rmccue
Message:

REST API: Add helper function to get server instance.

This allows using rest_do_request() outside of the API itself easily.

Props danielbachhuber, swissspidy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r35773 r36529  
    1616        /** @var WP_REST_Server $wp_rest_server */
    1717        global $wp_rest_server;
    18         $this->server = $wp_rest_server = new Spy_REST_Server();
    19 
    20         do_action( 'rest_api_init', $this->server );
     18
     19        unset( $wp_rest_server );
     20        add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
     21        $this->server = rest_get_server();
     22        remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
    2123    }
    2224
     
    646648        }
    647649    }
     650
     651    public function filter_wp_rest_server_class() {
     652        return 'Spy_REST_Server';
     653    }
    648654}
Note: See TracChangeset for help on using the changeset viewer.