/** * Retrieves the site index. * * This endpoint describes the capabilities of the site. * * @since 4.4.0 * @access public * * @param array $request { * Request. * * @type string $context Context. * } * @return array Index entity */ public function get_index($request) { // General site data. $available = array('name' => get_option('blogname'), 'description' => get_option('blogdescription'), 'url' => get_option('siteurl'), 'home' => home_url(), 'namespaces' => array_keys($this->namespaces), 'authentication' => array(), 'routes' => $this->get_data_for_routes($this->get_routes(), $request['context'])); $response = new WP_REST_Response($available); $response->add_link('help', 'http://v2.wp-api.org/'); /** * Filters the API root index data. * * This contains the data describing the API. This includes information * about supported authentication schemes, supported namespaces, routes * available on the API, and a small amount of data about the site. * * @since 4.4.0 * * @param WP_REST_Response $response Response data. */ return apply_filters('rest_index', $response); }
public function test_removing_links_for_href() { $response = new WP_REST_Response(); $response->add_link('self', 'http://example.com/'); $response->add_link('self', 'https://example.com/'); $response->remove_link('self', 'https://example.com/'); $data = $this->server->response_to_data($response, false); $this->assertArrayHasKey('_links', $data); $this->assertArrayHasKey('self', $data['_links']); $self_not_filtered = array('href' => 'http://example.com/'); $this->assertEquals($self_not_filtered, $data['_links']['self'][0]); }
/** * @depends test_link_embedding_params */ public function test_link_embedding_error() { // Register our testing route $this->server->register_route('test', '/test/embeddable', array('methods' => 'GET', 'callback' => array($this, 'embedded_response_callback'))); $response = new WP_REST_Response(); $response->add_link('up', rest_url('/test/embeddable?error=1'), array('embeddable' => true)); $data = $this->server->response_to_data($response, true); $this->assertArrayHasKey('_embedded', $data); $this->assertArrayHasKey('up', $data['_embedded']); // Check that errors are embedded correctly $up = $data['_embedded']['up']; $this->assertCount(1, $up); $this->assertInstanceOf('WP_REST_Response', $up[0]); $this->assertEquals(403, $up[0]->get_status()); $up_data = $up[0]->get_data(); $this->assertEquals('wp-api-test-error', $up_data[0]['code']); $this->assertEquals('Test message', $up_data[0]['message']); }