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


PHP WP_REST_Request类代码示例

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


在下文中一共展示了WP_REST_Request类的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: verify_session_nonce

 /**
  * Verify sessions nonce
  *
  * @since 0.3.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Response
  */
 public static function verify_session_nonce($request)
 {
     $nonce = $request->get_param('ingot_session_nonce');
     if (is_string($nonce)) {
         return ingot_verify_session_nonce($nonce);
     }
 }
开发者ID:Ramoonus,项目名称:ingot,代码行数:16,代码来源:util.php

示例3: save_settings

 function save_settings(WP_REST_Request $data)
 {
     $keys = $data->get_params();
     if (isset($keys['mode'])) {
         update_option('stripe_wp_mode', $keys['mode']);
     }
     if (isset($keys['keys']['test'])) {
         update_option('stripe_wp_test_key', $keys['keys']['test']);
     }
     if (isset($keys['keys']['prod'])) {
         update_option('stripe_wp_live_key', $keys['keys']['prod']);
     }
     if (isset($keys['confirmation']['type'])) {
         update_option('stripe_wp_confirmation_type', $keys['confirmation']['type']);
     }
     if (isset($keys['confirmation']['page_id'])) {
         update_option('stripe_wp_confirmation_page', $keys['confirmation']['page_id']);
     }
     if (isset($keys['confirmation']['message'])) {
         update_option('stripe_wp_confirmation_message', $keys['confirmation']['message']);
     }
     $settings['mode'] = get_option('stripe_wp_mode', false);
     $settings['keys']['prod'] = get_option('stripe_wp_live_key', false);
     $settings['keys']['test'] = get_option('stripe_wp_test_key', false);
     $settings['confirmation']['type'] = get_option('stripe_wp_confirmation_type', false);
     $settings['confirmation']['page_id'] = get_option('stripe_wp_confirmation_page', false);
     $settings['confirmation']['message'] = get_option('stripe_wp_confirmation_message', false);
     return new WP_REST_Response($settings, 200);
 }
开发者ID:jacobarriola,项目名称:Stripe-for-WordPress,代码行数:29,代码来源:stripe-api-settings.php

示例4: 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

示例5: get_queue

 /**
  * Retrieve the current event queue
  *
  * @subcommand get-queue
  */
 public function get_queue($args, $assoc_args)
 {
     // Build and make request
     $queue_request = new \WP_REST_Request('POST', '/' . \Automattic\WP\Cron_Control\REST_API::API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API::ENDPOINT_LIST);
     $queue_request->add_header('Content-Type', 'application/json');
     $queue_request->set_body(wp_json_encode(array('secret' => \WP_CRON_CONTROL_SECRET)));
     $queue_request = rest_do_request($queue_request);
     // Oh well
     if ($queue_request->is_error()) {
         \WP_CLI::error($queue_request->as_error()->get_error_message());
     }
     // Get the decoded JSON object returned by the API
     $queue_response = $queue_request->get_data();
     // No events, nothing more to do
     if (empty($queue_response['events'])) {
         \WP_CLI::warning(__('No events in the current queue', 'automattic-cron-control'));
         return;
     }
     // Prepare items for display
     $events_for_display = $this->format_events($queue_response['events']);
     $total_events_to_display = count($events_for_display);
     \WP_CLI::line(sprintf(_n('Displaying one event', 'Displaying %s events', $total_events_to_display, 'automattic-cron-control'), number_format_i18n($total_events_to_display)));
     // And reformat
     $format = 'table';
     if (isset($assoc_args['format'])) {
         if ('ids' === $assoc_args['format']) {
             \WP_CLI::error(__('Invalid output format requested', 'automattic-cron-control'));
         } else {
             $format = $assoc_args['format'];
         }
     }
     \WP_CLI\Utils\format_items($format, $events_for_display, array('timestamp', 'action', 'instance', 'scheduled_for', 'internal_event', 'schedule_name', 'event_args'));
 }
开发者ID:Automattic,项目名称:vip-mu-plugins-public,代码行数:38,代码来源:class-rest-api.php

示例6: delete_plan

 function delete_plan(WP_REST_Request $request)
 {
     $this->set_api_key();
     $data = $request->get_params();
     if (!isset($data['id'])) {
         return new WP_Error('data', __('No Customer ID Set'), array('status' => 404));
     }
     try {
         $plan = \Stripe\Plan::retrieve($data['id']);
         $plan->delete();
         return new WP_REST_Response($plan, 200);
     } catch (Stripe_AuthenticationError $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         return new WP_Error($err['type'], __($err['message']), array('status' => 403));
     } catch (Stripe_Error $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         return new WP_Error($err['type'], __($err['message']), array('status' => 403));
     } catch (\Stripe\Error\Base $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         return new WP_Error($err['type'], __($err['message']), array('status' => 403));
     }
 }
开发者ID:jacobarriola,项目名称:Stripe-for-WordPress,代码行数:25,代码来源:stripe-api-plans.php

示例7: 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

示例8: save_book

 function save_book(WP_REST_Request $data)
 {
     /*
      * Check if ID set & set $post
      */
     if (!$data['ID']) {
         return new WP_Error('noID', __('No Book ID', 'js-app-plugin'));
     }
     $post = $data->get_params();
     $meta = $post['meta'];
     unset($post[0]);
     /*
      * Save Post
      */
     $book['save'] = wp_update_post($post, true);
     if (is_wp_error($book['save'])) {
         return new WP_Error('saveError', __($book['save']->get_error_messages(), 'js-app-plugin'));
     }
     /*
      * Save Post Meta
      */
     foreach ($meta as $key => $value) {
         $book['meta-' . $key] = update_post_meta($post['ID'], $key, $value[0]);
     }
     /*
      * Get post and return
      */
     $book['post'] = get_post($post['ID']);
     $book['post']->meta = get_post_meta($post['ID']);
     return new WP_REST_Response($book, 200);
 }
开发者ID:WordPress-Admin-JavaScript-Boilerplate,项目名称:ReactJS-Boilerplate,代码行数:31,代码来源:admin_custom_api.php

示例9: _create_checkin_checkout_object

 /**
  * Toggles whether the user is checked in or not.
  *
  * @param \WP_REST_Request $request
  * @return \WP_Error|\WP_REST_Response
  */
 protected function _create_checkin_checkout_object(\WP_REST_Request $request)
 {
     $reg_id = $request->get_param('REG_ID');
     $dtt_id = $request->get_param('DTT_ID');
     $force = $request->get_param('force');
     if ($force == 'true') {
         $force = true;
     } else {
         $force = false;
     }
     $reg = \EEM_Registration::instance()->get_one_by_ID($reg_id);
     if (!$reg instanceof \EE_Registration) {
         return $this->send_response(new \WP_Error('rest_registration_toggle_checkin_invalid_id', sprintf(__('You cannot checkin registration with ID %1$s because it doesn\'t exist.', 'event_espresso'), $reg_id), array('status' => 422)));
     }
     if (!\EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
         return $this->send_response(new \WP_Error('rest_user_cannot_toggle_checkin', sprintf(__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), $reg_id), array('status' => 403)));
     }
     $success = $reg->toggle_checkin_status($dtt_id, !$force);
     if ($success === false) {
         //rely on EE_Error::add_error messages to have been added to give more data about hwy it failed
         return $this->send_response(new \WP_Error('rest_toggle_checkin_failed', __('Registration checkin failed. Please see additional error data.', 'event_espresso')));
     }
     $checkin = \EEM_Checkin::instance()->get_one(array(array('REG_ID' => $reg_id, 'DTT_ID' => $dtt_id), 'order_by' => array('CHK_timestamp' => 'DESC')));
     if (!$checkin instanceof \EE_Checkin) {
         return $this->send_response(new \WP_Error('rest_toggle_checkin_error', sprintf(__('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', 'event_espresso'), $reg_id, $dtt_id)));
     }
     $requested_version = $this->get_requested_version($request->get_route());
     $get_request = new \WP_REST_Request('GET', \EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID());
     $get_request->set_url_params(array('id' => $checkin->ID()));
     return Read::handle_request_get_one($get_request);
 }
开发者ID:adrianjonmiller,项目名称:hearts-being-healed,代码行数:37,代码来源:Checkin.php

示例10: e_tags

 public function e_tags(WP_REST_Request $request)
 {
     $id = $request->get_param("id");
     if (empty($id)) {
         return get_tags();
     }
     return wp_get_post_tags($id);
 }
开发者ID:judahnator,项目名称:WP-API-Categories-Tags,代码行数:8,代码来源:endpoints.class.php

示例11: verify_admin

 function verify_admin(WP_REST_Request $request)
 {
     $data = $request->get_params();
     if (!$this->verify_nonce($data)) {
         return false;
     }
     return current_user_can('edit_theme_options');
 }
开发者ID:royboy789,项目名称:Stripe-for-WordPress,代码行数:8,代码来源:wp-stripe-routes.php

示例12: update_items

 /**
  * Save new graph data to WordPress
  * @param WP_REST_Request $request The request containing the updated data
  * @return WP_REST_Response
  */
 public function update_items(\WP_REST_Request $request)
 {
     $params = $request->get_params();
     // First pass to create all new nodes and replace their temp ID with their true ID
     if (is_array($params['newNodeIndexes'])) {
         foreach ($params['newNodeIndexes'] as $nodeIndex) {
             $postID = '';
             $oldPostID = $params['nodes'][$nodeIndex]['id'];
             switch ($params['nodes'][$nodeIndex]['type']) {
                 case 'life':
                 case 'perk':
                     $postID = DataController::getInstance()->getCPT('point-node')->create($params['nodes'][$nodeIndex]);
                     break;
             }
             $params['nodes'][$nodeIndex]['id'] = $postID;
             // Replace all instances of the temp ID with the newly inserted one in link data
             if (is_array($params['links'])) {
                 foreach ($params['links'] as &$link) {
                     if ($link[0] == $oldPostID) {
                         $link[0] = $postID;
                     }
                     if ($link[1] == $oldPostID) {
                         $link[1] = $postID;
                     }
                 }
             }
         }
     }
     // Update all data on all nodes
     foreach ($params['nodes'] as $node) {
         $links = $this->get_linked_nodes_from_id($node['id'], $params['links']);
         switch ($node['type']) {
             // Skill nodes
             case 'skill':
                 DataController::getInstance()->getCPT('skill')->update_skill_graph_data($node, $links);
                 break;
                 // Upgrade nodes
             // Upgrade nodes
             case 'upgrade':
                 DataController::getInstance()->getCPT('skill')->update_upgrade_graph_data($node, $links);
                 break;
                 // Point nodes
             // Point nodes
             case 'life':
             case 'perk':
                 DataController::getInstance()->getCPT('point-node')->update_graph_data($node, $links);
                 break;
         }
     }
     // Delete removed nodes
     if (is_array($params['deletedNodes'])) {
         foreach ($params['deletedNodes'] as $node) {
             wp_delete_post($node, true);
         }
     }
     return new \WP_REST_Response('Zodiaque sauvegardé avec succès!', 200);
 }
开发者ID:terra-arcana,项目名称:terra-arcana,代码行数:62,代码来源:graph-data.route.php

示例13: push_key

 function push_key(WP_REST_Request $request)
 {
     $post_id = $request->get_param('post_id');
     $nonce = $request->get_param('nonce');
     $key = $request->get_param('key');
     if (!wp_verify_nonce($nonce, 'register_' . $key)) {
         return new WP_Error('registration', 'Validation Fail', array('status' => 404));
     }
     return update_post_meta($post_id, 'push_key', $key);
 }
开发者ID:boddienoell,项目名称:wp-json-v2-custom-endpoints,代码行数:10,代码来源:plugin.php

示例14: handle_request_models_meta

 public static function handle_request_models_meta(\WP_REST_Request $request)
 {
     $controller = new Meta();
     $matches = $controller->parse_route($request->get_route(), '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . 'resources~', array('version'));
     if ($matches instanceof \WP_REST_Response) {
         return $matches;
     }
     $controller->set_requested_version($matches['version']);
     return $controller->send_response($controller->_get_models_metadata_entity());
 }
开发者ID:teemuoksanen,项目名称:event-espresso-core,代码行数:10,代码来源:Meta.php

示例15: 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


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