當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WP_REST_Request::set_default_params方法代碼示例

本文整理匯總了PHP中WP_REST_Request::set_default_params方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_REST_Request::set_default_params方法的具體用法?PHP WP_REST_Request::set_default_params怎麽用?PHP WP_REST_Request::set_default_params使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WP_REST_Request的用法示例。


在下文中一共展示了WP_REST_Request::set_default_params方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: batch_items

 /**
  * Bulk create, update and delete items.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return array Of WP_Error or WP_REST_Response.
  */
 public function batch_items($request)
 {
     /** @var WP_REST_Server $wp_rest_server */
     global $wp_rest_server;
     // Get the request params.
     $items = array_filter($request->get_params());
     $response = array();
     // Check batch limit.
     $limit = $this->check_batch_limit($items);
     if (is_wp_error($limit)) {
         return $limit;
     }
     if (!empty($items['create'])) {
         foreach ($items['create'] as $item) {
             $_item = new WP_REST_Request('POST');
             // Default parameters.
             $defaults = array();
             $schema = $this->get_public_item_schema();
             foreach ($schema['properties'] as $arg => $options) {
                 if (isset($options['default'])) {
                     $defaults[$arg] = $options['default'];
                 }
             }
             $_item->set_default_params($defaults);
             // Set request parameters.
             $_item->set_body_params($item);
             $_response = $this->create_item($_item);
             if (is_wp_error($_response)) {
                 $response['create'][] = array('id' => 0, 'error' => array('code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data()));
             } else {
                 $response['create'][] = $wp_rest_server->response_to_data($_response, '');
             }
         }
     }
     if (!empty($items['update'])) {
         foreach ($items['update'] as $item) {
             $_item = new WP_REST_Request('PUT');
             $_item->set_body_params($item);
             $_response = $this->update_item($_item);
             if (is_wp_error($_response)) {
                 $response['update'][] = array('id' => $item['id'], 'error' => array('code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data()));
             } else {
                 $response['update'][] = $wp_rest_server->response_to_data($_response, '');
             }
         }
     }
     if (!empty($items['delete'])) {
         foreach ($items['delete'] as $id) {
             $_item = new WP_REST_Request('DELETE');
             $_item->set_query_params(array('id' => $id, 'force' => true));
             $_response = $this->delete_item($_item);
             if (is_wp_error($_response)) {
                 $response['delete'][] = array('id' => $id, 'error' => array('code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data()));
             } else {
                 $response['delete'][] = $wp_rest_server->response_to_data($_response, '');
             }
         }
     }
     return $response;
 }
開發者ID:woocommerce,項目名稱:woocommerce,代碼行數:66,代碼來源:abstract-wc-rest-controller.php


注:本文中的WP_REST_Request::set_default_params方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。