prepare_date_response example


            if ( rest_is_field_included( 'styles', $fields ) ) {
                $data['styles'] = ! empty( $global_styles_config['styles'] ) ? $global_styles_config['styles'] : new stdClass();
            }
        }

        if ( rest_is_field_included( 'author', $fields ) ) {
            $data['author'] = (int) $post->post_author;
        }

        if ( rest_is_field_included( 'date', $fields ) ) {
            $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
        }

        if ( rest_is_field_included( 'date_gmt', $fields ) ) {
            $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt );
        }

        if ( rest_is_field_included( 'id', $fields ) ) {
            $data['id'] = (int) $post->ID;
        }

        if ( rest_is_field_included( 'modified', $fields ) ) {
            
setup_postdata( $post );

        $fields = $this->get_fields_for_response( $request );
        $data   = array();

        if ( in_array( 'author', $fields, true ) ) {
            $data['author'] = (int) $post->post_author;
        }

        if ( in_array( 'date', $fields, true ) ) {
            $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
        }

        if ( in_array( 'date_gmt', $fields, true ) ) {
            $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt );
        }

        if ( in_array( 'id', $fields, true ) ) {
            $data['id'] = $post->ID;
        }

        if ( in_array( 'modified', $fields, true ) ) {
            
$fields = $this->get_fields_for_response( $request );

        // Base fields for every post.         $data = array();

        if ( rest_is_field_included( 'id', $fields ) ) {
            $data['id'] = $post->ID;
        }

        if ( rest_is_field_included( 'date', $fields ) ) {
            $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
        }

        if ( rest_is_field_included( 'date_gmt', $fields ) ) {
            /* * For drafts, `post_date_gmt` may not be set, indicating that the date * of the draft should be updated each time it is saved (see #38883). * In this case, shim the value based on the `post_date` field * with the site's timezone offset applied. */
            if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
                $post_date_gmt = get_gmt_from_date( $post->post_date );
            }
Home | Imprint | This part of the site doesn't use cookies.