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


PHP WP_REST_Request::set_param方法代码示例

本文整理汇总了PHP中WP_REST_Request::set_param方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_REST_Request::set_param方法的具体用法?PHP WP_REST_Request::set_param怎么用?PHP WP_REST_Request::set_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_REST_Request的用法示例。


在下文中一共展示了WP_REST_Request::set_param方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_get_items_orderby

 public function test_get_items_orderby()
 {
     wp_set_object_terms($this->post_id, array('Banana', 'Carrot', 'Apple'), 'post_tag');
     $request = new WP_REST_Request('GET', sprintf('/wp/v2/posts/%d/terms/tag', $this->post_id));
     $request->set_param('orderby', 'term_order');
     $response = $this->server->dispatch($request);
     $data = $response->get_data();
     $this->assertEquals('Banana', $data[0]['name']);
     $this->assertEquals('Carrot', $data[1]['name']);
     $this->assertEquals('Apple', $data[2]['name']);
     $request = new WP_REST_Request('GET', sprintf('/wp/v2/posts/%d/terms/tag', $this->post_id));
     $request->set_param('orderby', 'name');
     $request->set_param('order', 'asc');
     $response = $this->server->dispatch($request);
     $data = $response->get_data();
     $this->assertEquals('Apple', $data[0]['name']);
     $this->assertEquals('Banana', $data[1]['name']);
     $this->assertEquals('Carrot', $data[2]['name']);
     $request = new WP_REST_Request('GET', sprintf('/wp/v2/posts/%d/terms/tag', $this->post_id));
     $request->set_param('orderby', 'name');
     $request->set_param('order', 'desc');
     $response = $this->server->dispatch($request);
     $data = $response->get_data();
     $this->assertEquals('Carrot', $data[0]['name']);
     $this->assertEquals('Banana', $data[1]['name']);
     $this->assertEquals('Apple', $data[2]['name']);
 }
开发者ID:misfist,项目名称:missdrepants-network,代码行数:27,代码来源:test-rest-posts-terms-controller.php

示例2: test_get_items

 public function test_get_items()
 {
     $request = new WP_REST_Request('GET', '/wp/v2/users');
     $request->set_param('context', 'view');
     $response = $this->server->dispatch($request);
     $this->assertEquals(200, $response->get_status());
 }
开发者ID:bpongvh,项目名称:wp-api-site-endpoints,代码行数:7,代码来源:test-rest-site-controller.php

示例3: test_get_taxonomies_with_types

 public function test_get_taxonomies_with_types()
 {
     $request = new WP_REST_Request('GET', '/wp/v2/taxonomies');
     $request->set_param('post_type', 'post');
     $response = $this->server->dispatch($request);
     $this->check_taxonomies_for_type_response('post', $response);
 }
开发者ID:misfist,项目名称:missdrepants-network,代码行数:7,代码来源:test-rest-taxonomies-controller.php

示例4: array

 function test_rest_pre_serve_request_headers()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('xdebug is required for this test');
     }
     $post = $this->factory()->post->create_and_get(array('post_title' => 'Hello World'));
     $request = new WP_REST_Request('GET', '/oembed/1.0/embed');
     $request->set_param('url', get_permalink($post->ID));
     $request->set_param('format', 'xml');
     $server = new WP_REST_Server();
     $response = $server->dispatch($request);
     $output = get_echo('_oembed_rest_pre_serve_request', array(true, $response, $request, $server));
     $this->assertNotEmpty($output);
     $headers = xdebug_get_headers();
     $this->assertTrue(in_array('Content-Type: text/xml; charset=' . get_option('blog_charset'), $headers));
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:16,代码来源:headers.php

示例5: it_should_return_true_if_current_user_can_edit_post

 /**
  * @test
  * it should return true if current user can edit post
  */
 public function it_should_return_true_if_current_user_can_edit_post()
 {
     $post_id = $this->factory()->post->create();
     wp_set_current_user(1);
     $sut = $this->make_instance();
     $supported_actions = $sut->supported_actions();
     $request = new \WP_REST_Request('create', '/some-path');
     $request->set_param('post_id', $post_id);
     $out = $sut->verify_auth($request, reset($supported_actions));
     $this->assertTrue($out);
 }
开发者ID:lucatume,项目名称:idlikethis,代码行数:15,代码来源:PostAdminAuthHandlerTest.php

示例6: dirname

 /**
  * Test HTTP headers set by the rest_pre_serve_request method.
  */
 function test_rest_pre_serve_request_headers()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('xdebug is required for this test');
     }
     require_once dirname(__FILE__) . '/../vendor/json-rest-api/plugin.php';
     require_once dirname(__FILE__) . '/../includes/class-wp-rest-oembed-controller.php';
     $user = $this->factory->user->create_and_get(array('display_name' => 'John Doe'));
     $post = $this->factory->post->create_and_get(array('post_author' => $user->ID, 'post_title' => 'Hello World'));
     $request = new WP_REST_Request('GET', '/wp/v2/oembed');
     $request->set_param('url', get_permalink($post->ID));
     $request->set_param('format', 'xml');
     $server = new WP_REST_Server();
     $response = $server->dispatch($request);
     ob_start();
     _oembed_rest_pre_serve_request(true, $response, $request, $server);
     $output = ob_get_clean();
     $this->assertNotEmpty($output);
     $headers = xdebug_get_headers();
     $this->assertTrue(in_array('Content-Type: text/xml; charset=' . get_option('blog_charset'), $headers));
 }
开发者ID:rmccue,项目名称:oEmbed-API,代码行数:24,代码来源:test-headers.php

示例7: get_items

 /**
  * Get all graph data items
  * @param WP_REST_Request $request The current request
  * @return Array|WP_Error
  */
 public function get_items($request)
 {
     $result = array();
     // Fetch all skills
     $request->set_param('per_page', -1);
     $allSkills = parent::get_items($request);
     // Filter all skills to only return the ones tagged as starting skills
     foreach ($allSkills->data as $skill) {
         if ($skill['starting_skill']) {
             $result[] = $skill;
         }
     }
     return $result;
 }
开发者ID:terra-arcana,项目名称:terra-arcana,代码行数:19,代码来源:starting-skills.route.php

示例8: create_item

 /**
  * Create a single Shipping Zone.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_REST_Request|WP_Error
  */
 public function create_item($request)
 {
     $zone = new WC_Shipping_Zone(null);
     if (!is_null($request->get_param('name'))) {
         $zone->set_zone_name($request->get_param('name'));
     }
     if (!is_null($request->get_param('order'))) {
         $zone->set_zone_order($request->get_param('order'));
     }
     $zone->create();
     if ($zone->get_id() !== 0) {
         $request->set_param('id', $zone->get_id());
         $response = $this->get_item($request);
         $response->set_status(201);
         $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id())));
         return $response;
     } else {
         return new WP_Error('woocommerce_rest_shipping_zone_not_created', __("Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce'), array('status' => 500));
     }
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:26,代码来源:class-wc-rest-shipping-zones-controller.php

示例9: after_wp_load

 /**
  * Register's all endpoints as commands once WP and WC have all loaded.
  */
 public static function after_wp_load()
 {
     global $wp_rest_server;
     $wp_rest_server = new WP_REST_Server();
     do_action('rest_api_init', $wp_rest_server);
     $request = new WP_REST_Request('GET', '/');
     $request->set_param('context', 'help');
     $response = $wp_rest_server->dispatch($request);
     $response_data = $response->get_data();
     if (empty($response_data)) {
         return;
     }
     // Loop through all of our endpoints and register any valid WC endpoints.
     foreach ($response_data['routes'] as $route => $route_data) {
         // Only register WC endpoints
         if (substr($route, 0, 4) !== '/wc/') {
             continue;
         }
         // Only register endpoints with schemas
         if (empty($route_data['schema']['title'])) {
             WP_CLI::debug(sprintf(__('No schema title found for %s, skipping REST command registration.', 'woocommerce'), $route), 'wc');
             continue;
         }
         // Ignore batch endpoints
         if ('batch' === $route_data['schema']['title']) {
             continue;
         }
         // Disable specific endpoints
         $route_pieces = explode('/', $route);
         $endpoint_piece = str_replace('/wc/' . $route_pieces[2] . '/', '', $route);
         if (in_array($endpoint_piece, self::$disabled_endpoints)) {
             continue;
         }
         self::register_route_commands(new WC_CLI_REST_Command($route_data['schema']['title'], $route, $route_data['schema']), $route, $route_data);
     }
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:39,代码来源:class-wc-cli-runner.php

示例10: test_delete_user_reassign_passed_as_0_reassigns_author

 public function test_delete_user_reassign_passed_as_0_reassigns_author()
 {
     $user_id = $this->factory->user->create();
     $this->allow_user_to_manage_multisite();
     wp_set_current_user(self::$user);
     $test_post = $this->factory->post->create(array('post_author' => $user_id));
     $request = new WP_REST_Request('DELETE', sprintf('/wp/v2/users/%d', $user_id));
     $request['force'] = true;
     $request->set_param('reassign', 0);
     $response = $this->server->dispatch($request);
     // Not implemented in multisite.
     if (is_multisite()) {
         $this->assertErrorResponse('rest_cannot_delete', $response, 501);
         return;
     }
     $test_post = get_post($test_post);
     $this->assertEquals(0, $test_post->post_author);
 }
开发者ID:kucrut,项目名称:wordpress,代码行数:18,代码来源:rest-users-controller.php

示例11: delete_item

 /**
  * Delete a single term from a taxonomy
  *
  * @param WP_REST_Request $request Full details about the request
  * @return WP_REST_Response|WP_Error
  */
 public function delete_item($request)
 {
     $force = isset($request['force']) ? (bool) $request['force'] : false;
     // We don't support trashing for this type, error out
     if (!$force) {
         return new WP_Error('rest_trash_not_supported', __('Terms do not support trashing.'), array('status' => 501));
     }
     $term = get_term((int) $request['id'], $this->taxonomy);
     $request->set_param('context', 'view');
     $response = $this->prepare_item_for_response($term, $request);
     $data = $response->get_data();
     $data = array('data' => $data, 'deleted' => true);
     $response->set_data($data);
     $retval = wp_delete_term($term->term_id, $term->taxonomy);
     if (!$retval) {
         return new WP_Error('rest_cannot_delete', __('The term cannot be deleted.'), array('status' => 500));
     }
     /**
      * Fires after a single term is deleted via the REST API.
      *
      * @param WP_Term         $term    The deleted term.
      * @param array           $data    The response data.
      * @param WP_REST_Request $request The request sent to the API.
      */
     do_action("rest_delete_{$this->taxonomy}", $term, $data, $request);
     return $response;
 }
开发者ID:Datartisan,项目名称:datartery-wp,代码行数:33,代码来源:class-wp-rest-terms-controller.php

示例12: test_products_filter_post_status

 public function test_products_filter_post_status()
 {
     wp_set_current_user($this->user);
     for ($i = 0; $i < 8; $i++) {
         $product = WC_Helper_Product::create_simple_product();
         if (0 === $i % 2) {
             wp_update_post(array('ID' => $product->get_id(), 'post_status' => 'draft'));
         }
     }
     // Test filtering with filter[post_status]=publish
     $request = new WP_REST_Request('GET', '/wc/v1/products');
     $request->set_param('filter', array('post_status' => 'publish'));
     $response = $this->server->dispatch($request);
     $products = $response->get_data();
     $this->assertEquals(4, count($products));
     foreach ($products as $product) {
         $this->assertEquals('publish', $product['status']);
     }
     // Test filtering with filter[post_status]=draft
     $request = new WP_REST_Request('GET', '/wc/v1/products');
     $request->set_param('filter', array('post_status' => 'draft'));
     $response = $this->server->dispatch($request);
     $products = $response->get_data();
     $this->assertEquals(4, count($products));
     foreach ($products as $product) {
         $this->assertEquals('draft', $product['status']);
     }
     // Test filtering with status=publish
     $request = new WP_REST_Request('GET', '/wc/v1/products');
     $request->set_param('status', 'publish');
     $response = $this->server->dispatch($request);
     $products = $response->get_data();
     $this->assertEquals(4, count($products));
     foreach ($products as $product) {
         $this->assertEquals('publish', $product['status']);
     }
     // Test filtering with status=draft
     $request = new WP_REST_Request('GET', '/wc/v1/products');
     $request->set_param('status', 'draft');
     $response = $this->server->dispatch($request);
     $products = $response->get_data();
     $this->assertEquals(4, count($products));
     foreach ($products as $product) {
         $this->assertEquals('draft', $product['status']);
     }
     // Test filtering with status=draft and filter[post_status]=publish
     // filter[post_status]=publish should win
     $request = new WP_REST_Request('GET', '/wc/v1/products');
     $request->set_param('status', 'draft');
     $request->set_param('filter', array('post_status' => 'publish'));
     $response = $this->server->dispatch($request);
     $products = $response->get_data();
     $this->assertEquals(4, count($products));
     foreach ($products as $product) {
         $this->assertEquals('publish', $product['status']);
     }
     // Test filtering with no filters - which should return 'any' (all 8)
     $request = new WP_REST_Request('GET', '/wc/v1/products');
     $response = $this->server->dispatch($request);
     $products = $response->get_data();
     $this->assertEquals(8, count($products));
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:62,代码来源:products.php

示例13: delete_item

 /**
  * Delete a single tax.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function delete_item($request)
 {
     global $wpdb;
     $id = (int) $request['id'];
     $force = isset($request['force']) ? (bool) $request['force'] : false;
     // We don't support trashing for this type, error out.
     if (!$force) {
         return new WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501));
     }
     $tax = WC_Tax::_get_tax_rate($id, OBJECT);
     if (empty($id) || empty($tax)) {
         return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400));
     }
     $request->set_param('context', 'edit');
     $response = $this->prepare_item_for_response($tax, $request);
     WC_Tax::_delete_tax_rate($id);
     if (0 === $wpdb->rows_affected) {
         return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
     }
     /**
      * Fires after a tax is deleted via the REST API.
      *
      * @param stdClass         $tax      The tax data.
      * @param WP_REST_Response $response The response returned from the API.
      * @param WP_REST_Request  $request  The request sent to the API.
      */
     do_action('woocommerce_rest_delete_tax', $tax, $response, $request);
     return $response;
 }
开发者ID:Biont,项目名称:woocommerce,代码行数:35,代码来源:class-wc-rest-taxes-controller.php

示例14: test_delete_item

 public function test_delete_item()
 {
     $post_id = $this->factory->post->create(array('post_title' => 'Deleted post'));
     wp_set_current_user(self::$editor_id);
     $request = new WP_REST_Request('DELETE', sprintf('/wp/v2/posts/%d', $post_id));
     $request->set_param('force', 'false');
     $response = $this->server->dispatch($request);
     $this->assertNotInstanceOf('WP_Error', $response);
     $this->assertEquals(200, $response->get_status());
     $data = $response->get_data();
     $this->assertEquals('Deleted post', $data['title']['raw']);
     $this->assertEquals('trash', $data['status']);
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:13,代码来源:rest-posts-controller.php

示例15: delete_item

 /**
  * Delete a single customer.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function delete_item($request)
 {
     $id = (int) $request['id'];
     $reassign = isset($request['reassign']) ? absint($request['reassign']) : null;
     $force = isset($request['force']) ? (bool) $request['force'] : false;
     // We don't support trashing for this type, error out.
     if (!$force) {
         return new WP_Error('woocommerce_rest_trash_not_supported', __('Customers do not support trashing.', 'woocommerce'), array('status' => 501));
     }
     $customer = get_userdata($id);
     if (!$customer) {
         return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400));
     }
     if (!empty($reassign)) {
         if ($reassign === $id || !get_userdata($reassign)) {
             return new WP_Error('woocommerce_rest_customer_invalid_reassign', __('Invalid resource id for reassignment.', 'woocommerce'), array('status' => 400));
         }
     }
     $request->set_param('context', 'edit');
     $response = $this->prepare_item_for_response($customer, $request);
     /** Include admin customer functions to get access to wp_delete_user() */
     require_once ABSPATH . 'wp-admin/includes/user.php';
     $result = wp_delete_user($id, $reassign);
     if (!$result) {
         return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
     }
     /**
      * Fires after a customer is deleted via the REST API.
      *
      * @param WP_User          $customer The customer data.
      * @param WP_REST_Response $response The response returned from the API.
      * @param WP_REST_Request  $request  The request sent to the API.
      */
     do_action('woocommerce_rest_delete_customer', $customer, $response, $request);
     return $response;
 }
开发者ID:TakenCdosG,项目名称:chefs,代码行数:42,代码来源:class-wc-rest-customers-controller.php


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