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


PHP WP_REST_Request::set_url_params方法代码示例

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


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

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

示例2:

 /**
  * Test getting published items.
  */
 function test_get_collection_published()
 {
     wp_set_current_user($this->factory()->user->create(array('role' => 'administrator')));
     $request = new \WP_REST_Request('GET', '/wp/v2/customize_snapshots');
     $request->set_param('context', 'edit');
     $response = $this->server->dispatch($request);
     $this->assertEquals(200, $response->get_status());
     $items = $response->get_data();
     $this->assertCount(1, $items);
     $this->assertEquals('publish', $items[0]['status']);
     $this->assertArrayHasKey('content', $items[0]);
     $this->assertArrayHasKey('blogname', $items[0]['content']);
     $this->assertArrayHasKey('value', $items[0]['content']['blogname']);
     $request = new \WP_REST_Request('GET', '/wp/v2/customize_snapshots');
     $request->set_param('context', 'edit');
     $request->set_url_params(array('status' => 'publish'));
     $response = $this->server->dispatch($request);
     $this->assertEquals($items, $response->get_data());
 }
开发者ID:xwp,项目名称:wp-customize-snapshots,代码行数:22,代码来源:test-class-snapshot-rest-api-controller.php

示例3: test_handle_request_get_one__cannot_access

 public function test_handle_request_get_one__cannot_access()
 {
     $e = $this->new_model_obj_with_dependencies('Event', array('status' => 'draft'));
     $req = new \WP_REST_Request('GET', \EED_Core_Rest_Api::ee_api_namespace . '4.8.29/events/' . $e->ID());
     $req->set_url_params(array('id' => $e->ID()));
     $response = Read::handle_request_get_one($req);
     $this->assertInstanceOf('WP_REST_Response', $response);
     $this->assertEquals(403, $response->get_status());
 }
开发者ID:teemuoksanen,项目名称:event-espresso-core,代码行数:9,代码来源:Read_Test.php


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