本文整理汇总了PHP中WP_REST_Response::add_link方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Response::add_link方法的具体用法?PHP WP_REST_Response::add_link怎么用?PHP WP_REST_Response::add_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_REST_Response
的用法示例。
在下文中一共展示了WP_REST_Response::add_link方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_index
/**
* 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);
}
示例2: test_removing_links_for_href
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]);
}
示例3: test_link_embedding_error
/**
* @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']);
}