当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_REST_Response::add_link方法代码示例

本文整理汇总了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);
 }
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:34,代码来源:class-wp-rest-server.php

示例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]);
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:12,代码来源:rest-server.php

示例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']);
 }
开发者ID:nathansh,项目名称:gifzone,代码行数:21,代码来源:test-rest-server.php


注:本文中的WP_REST_Response::add_link方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。