Changeset 57494 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
- Timestamp:
- 01/31/2024 10:39:04 AM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
r56272 r57494 48 48 * 49 49 * @since 6.3.0 50 * @since 6.5.0 Added route to fetch individual global styles revisions. 50 51 */ 51 52 public function register_routes() { … … 65 66 'permission_callback' => array( $this, 'get_item_permissions_check' ), 66 67 'args' => $this->get_collection_params(), 68 ), 69 'schema' => array( $this, 'get_public_item_schema' ), 70 ) 71 ); 72 73 register_rest_route( 74 $this->namespace, 75 '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', 76 array( 77 'args' => array( 78 'parent' => array( 79 'description' => __( 'The ID for the parent of the global styles revision.' ), 80 'type' => 'integer', 81 ), 82 'id' => array( 83 'description' => __( 'Unique identifier for the global styles revision.' ), 84 'type' => 'integer', 85 ), 86 ), 87 array( 88 'methods' => WP_REST_Server::READABLE, 89 'callback' => array( $this, 'get_item' ), 90 'permission_callback' => array( $this, 'get_item_permissions_check' ), 91 'args' => array( 92 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 93 ), 67 94 ), 68 95 'schema' => array( $this, 'get_public_item_schema' ), … … 243 270 244 271 /** 272 * Retrieves one global styles revision from the collection. 273 * 274 * @since 6.5.0 275 * 276 * @param WP_REST_Request $request Full details about the request. 277 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. 278 */ 279 public function get_item( $request ) { 280 $parent = $this->get_parent( $request['parent'] ); 281 if ( is_wp_error( $parent ) ) { 282 return $parent; 283 } 284 285 $revision = $this->get_revision( $request['id'] ); 286 if ( is_wp_error( $revision ) ) { 287 return $revision; 288 } 289 290 $response = $this->prepare_item_for_response( $revision, $request ); 291 return rest_ensure_response( $response ); 292 } 293 294 /** 295 * Gets the global styles revision, if the ID is valid. 296 * 297 * @since 6.5.0 298 * 299 * @param int $id Supplied ID. 300 * @return WP_Post|WP_Error Revision post object if ID is valid, WP_Error otherwise. 301 */ 302 protected function get_revision( $id ) { 303 $error = new WP_Error( 304 'rest_post_invalid_id', 305 __( 'Invalid global styles revision ID.' ), 306 array( 'status' => 404 ) 307 ); 308 309 if ( (int) $id <= 0 ) { 310 return $error; 311 } 312 313 $revision = get_post( (int) $id ); 314 if ( empty( $revision ) || empty( $revision->ID ) || 'revision' !== $revision->post_type ) { 315 return $error; 316 } 317 318 return $revision; 319 } 320 321 /** 245 322 * Checks the post_date_gmt or modified_gmt and prepare any post or 246 323 * modified date for single post output.
Note: See TracChangeset
for help on using the changeset viewer.