WordPress.org

Make WordPress Core

Ticket #40600: 40600.patch

File 40600.patch, 1.1 KB (added by ruud@…, 3 years ago)

get_item() with rest_pre_get_item() filter

  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    466466         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
    467467         */
    468468        public function get_item( $request ) {
     469                /**
     470                 * Allow hijacking the request before getting the single post by returning a WP_Error object.
     471                 *
     472                 * @param WP_REST_Request   $request Full details about the request.
     473                 * @return mixed $error     Should be either a WP_Error object, or null to not hijack the request.
     474                 */
     475                $error = apply_filters( 'rest_pre_get_item', null, $request );
     476
     477                if ( ! empty( $error ) ) {
     478                        return $error;
     479                }
     480
    469481                $post = $this->get_post( $request['id'] );
    470482                if ( is_wp_error( $post ) ) {
    471483                        return $post;