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


PHP WP_REST_Request::get_params方法代码示例

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


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

示例1: array

 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

示例2:

 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

示例3: unset

 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

示例4:

 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

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

示例6: the_search

 /**
  * Do search and respond.
  *
  * @since 0.0.1
  *
  * @param \WP_REST_Request $request
  *
  * @return \WP_REST_Response|WP_Error
  */
 public function the_search($request)
 {
     $args = (array) $request->get_params();
     $search = new \SWP_Query($args);
     $query_result = $search->posts;
     $posts = array();
     foreach ($query_result as $post) {
         $data = $this->prepare_item_for_response($post, $request);
         $posts[] = $this->prepare_response_for_collection($data);
     }
     $response = rest_ensure_response($posts);
     return $response;
 }
开发者ID:WebDevStudios,项目名称:searchwp-api-route,代码行数:22,代码来源:route.php

示例7: get_item

 /**
  * Get one item from the collection
  *
  * @param WP_REST_Request $request Full data about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function get_item($request)
 {
     //get parameters from request
     $params = $request->get_params();
     $item = get_post($params['id']);
     //do a query, call another class, etc
     $data = $this->prepare_item_for_response($item, $request);
     //return a response or error based on some conditional
     if (1 == 1) {
         return new WP_REST_Response($data, 200);
     } else {
         return new WP_Error('code', __('message', 'text-domain'));
     }
 }
开发者ID:jpurpleman,项目名称:SportsPress,代码行数:20,代码来源:class-sp-rest-teams-controller.php

示例8: array

 function code_check(WP_REST_Request $request)
 {
     $data = $request->get_params();
     if (!$data['code']) {
         return new WP_Error('no code', __('you need to pass a code to check'), array('status' => 401));
     }
     $users = new WP_User_Query(array('meta_query' => array(array('key' => '__stripe-wp-referral-code', 'value' => $data['code']))));
     if (!empty($users->results)) {
         $user_id = $users->results[0]->ID;
         $return = array('code_valid' => true, 'user' => $user_id, 'cus_id' => get_user_meta($user_id, '__stripe_cus_id', true));
     } else {
         $return = array('code_valid' => false);
     }
     return new WP_REST_Response($return, 200);
 }
开发者ID:royboy789,项目名称:Stripe-for-WordPress-Referrals,代码行数:15,代码来源:stripe-wp-referral-endpoints.php

示例9: update

 /**
  * Update all settings
  *
  * @since 0.2.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Response
  */
 public function update($request)
 {
     $params = $request->get_params();
     foreach (array_keys($this->args()) as $setting) {
         if (isset($params[$setting])) {
             $saved = \ingot\testing\crud\settings::write($setting, $params[$setting]);
             if (is_wp_error($saved)) {
                 return rest_ensure_response($saved, 500);
             }
             $settings[$setting] = $params[$setting];
         } else {
             $settings[$setting] = \ingot\testing\crud\settings::read($setting);
         }
     }
     return $this->response($request, $settings);
 }
开发者ID:rene-hermenau,项目名称:ingot,代码行数:25,代码来源:settings.php

示例10: update_item

 /**
  * Update one item from the collection
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Request
  */
 public function update_item($request)
 {
     $params = $request->get_params();
     $color = $params[0];
     if (!array_key_exists($color, self::$lights)) {
         return new \WP_Error('cant-update', __('message', 'particle-api'), array('status' => 500));
     }
     $json = json_decode($request->get_body());
     $status = isset($json->status) ? $json->status : null;
     $string_status = $status ? 'true' : 'false';
     $data = new \stdClass();
     update_option(self::$lights[$color], $string_status);
     $data->status = $status;
     if (is_object($data)) {
         return new \WP_REST_Response($data, 200);
     }
     return new \WP_Error('cant-update', __('message', 'particle-api'), array('status' => 500));
 }
开发者ID:arippberger,项目名称:particle-api,代码行数:25,代码来源:class-particle-light-controller.php

示例11: update_item

 /**
  * Update one item from the collection
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Request
  */
 public function update_item($request)
 {
     //$item = $this->prepare_item_for_database( $request );
     $params = $request->get_params();
     $id = intval($params[0]);
     if (!array_key_exists($id, self::$switches)) {
         return new \WP_Error('cant-update', __('message', 'particle-api'), array('status' => 500));
     }
     $json = json_decode($request->get_body());
     $status = isset($json->status) ? $json->status : null;
     $data = new \stdClass();
     update_option(self::$switches[$id], $status);
     $data->status = $status;
     if (is_object($data)) {
         return new \WP_REST_Response($data, 200);
     }
     return new \WP_Error('cant-update', __('message', 'particle-api'), array('status' => 500));
 }
开发者ID:arippberger,项目名称:particle-api,代码行数:25,代码来源:class-particle-switch-controller.php

示例12: endpoint_callback

 /**
  * Callback that creates the data that send to the endpoint.
  *
  * @Override
  *
  * @param \WP_REST_Request $request The request.
  * @return array The array with the data of the endpoint
  */
 public function endpoint_callback(\WP_REST_Request $request)
 {
     $params = $request->get_params();
     $id = false === $params['id'] ? false : absint($params['id']);
     $slug = false === $params['slug'] ? false : trim($params['slug'], '/');
     if (false === $id && false === $slug) {
         return new \WP_Error(self::INVALID_PARAMS, 'The request must have either an id or a slug', ['status' => 400]);
     }
     if (false !== $id) {
         $user = get_user_by('id', $id);
     } else {
         $user = get_user_by('slug', $slug);
     }
     if ($user) {
         return $this->get_author_data($user);
     }
     return [];
 }
开发者ID:moxie-lean,项目名称:wp-endpoints-author,代码行数:26,代码来源:Author.php

示例13: update_item

 /**
  * Update settings for the settings object.
  *
  * @param  WP_REST_Request $request Full detail about the request.
  * @return WP_Error|array
  */
 public function update_item($request)
 {
     $options = $this->get_registered_options();
     $params = $request->get_params();
     foreach ($options as $name => $args) {
         if (!array_key_exists($name, $params)) {
             continue;
         }
         // A null value means reset the option, which is essentially deleting it
         // from the database and then relying on the default value.
         if (is_null($request[$name])) {
             delete_option($args['option_name']);
         } else {
             update_option($args['option_name'], $request[$name]);
         }
     }
     return $this->get_item($request);
 }
开发者ID:WP-API,项目名称:wp-api-site-endpoints,代码行数:24,代码来源:class-wp-rest-settings-controller.php

示例14: processRegister

 public function processRegister(WP_REST_Request $request)
 {
     $params = $request->get_params();
     $option = get_option('qq-app-login');
     $appid = $option['appid'];
     $openid = $params['openId'];
     $token = $params['accessToken'];
     $result = json_decode(wp_remote_get("https://api.weixin.qq.com/sns/userinfo?access_token={$token}&openid={$openid}", ['sslcertificates' => dirname(__FILE__) . '/ca-bundle.crt'])['body'], true);
     if (isset($result['errcode']) && $result['errcode'] != 0) {
         error_log(print_r($result, true));
         return new WP_Error('auth_failed', $result['errmsg'], array('status' => 403));
     }
     $params['image'] = $result['headimgurl'];
     $params['nickname'] = $result['nickname'];
     $uid = wp_app_sso_register("wechat", $openid, $token, $params);
     if (is_wp_error($uid)) {
         return $uid;
     }
     return array('ok' => 1, 'uid' => $uid);
 }
开发者ID:tdzl2003,项目名称:wp_plugin_collections,代码行数:20,代码来源:api.php

示例15: get_item

 /**
  * Get one item from the collection
  *
  * @param WP_REST_Request $request Full data about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function get_item($request)
 {
     //get parameters from request
     $params = $request->get_params();
     $allowed = apply_filters('allowed_restful_localized_scripts', $this->allowed_scripts);
     if (isset($params[0])) {
         global $wp_scripts;
         if ($wp_scripts === null) {
             $wp_scripts = wp_scripts();
         }
         foreach ($wp_scripts->registered as $script) {
             if ($script->handle == $params[0]) {
                 if (true != $allowed && !in_array($params[0], $allowed)) {
                     return new WP_Error('code', __('Script not authorized to be returned via REST API endpoint. Add script handle with allowed_restful_localized_scripts filter.', 'restful-localized-scripts'), $params[0]);
                 }
                 return new WP_REST_Response($this->prepare_item_for_response($script, $request), 200);
             }
         }
     }
     return new WP_Error('code', __('No script with the requested handle can be found', 'restful-localized-scripts'));
 }
开发者ID:shawnhooper,项目名称:restful-localized-scripts,代码行数:27,代码来源:scripts-at-rest.php


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