Prepare the revision for the REST response

@access public

@param WP_Post         $post    Post revision object.
@param WP_REST_Request $request Request object.
@return WP_REST_Response $response
165516
public function prepare_item_for_response( $post, $request ) {

		$schema = $this->get_item_schema();

		$data = array();

		if ( ! empty( $schema['properties']['author'] ) ) {
			$data['author'] = $post->post_author;
		}

		if ( ! empty( $schema['properties']['date'] ) ) {
			$data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
		}

		if ( ! empty( $schema['properties']['date_gmt'] ) ) {
			$data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt );
		}

		if ( ! empty( $schema['properties']['id'] ) ) {
			$data['id'] = $post->ID;
		}

		if ( ! empty( $schema['properties']['modified'] ) ) {
			$data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified );
		}

		if ( ! empty( $schema['properties']['modified_gmt'] ) ) {
			$data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt );
		}

		if ( ! empty( $schema['properties']['parent'] ) ) {
			$data['parent'] = (int) $post->post_parent;
		}

		if ( ! empty( $schema['properties']['slug'] ) ) {
			$data['slug'] = $post->post_name;
		}

		if ( ! empty( $schema['properties']['guid'] ) ) {
			$data['guid'] = array(
				/** This filter is documented in wp-includes/post-template.php */
				'rendered' => apply_filters( 'get_the_guid', $post->guid ),
				'raw'      => $post->guid,
			);
		}

		if ( ! empty( $schema['properties']['title'] ) ) {
			$data['title'] = array(
				'raw'      => $post->post_title,
				'rendered' => get_the_title( $post->ID ),
			);
		}

		if ( ! empty( $schema['properties']['content'] ) ) {

			$data['content'] = array(
				'raw'      => $post->post_content,
				/** This filter is documented in wp-includes/post-template.php */
				'rendered' => apply_filters( 'the_content', $post->post_content ),
			);
		}

		if ( ! empty( $schema['properties']['excerpt'] ) ) {
			$data['excerpt'] = array(
				'raw'      => $post->post_excerpt,
				'rendered' => $this->prepare_excerpt_response( $post->post_excerpt, $post ),
			);
		}

		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$data = $this->add_additional_fields_to_object( $data, $request );
		$data = $this->filter_response_by_context( $data, $context );
		$response = rest_ensure_response( $data );

		if ( ! empty( $data['parent'] ) ) {
			$response->add_link( 'parent', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->parent_base, $data['parent'] ) ) );
		}

		/**
		 * Filter a revision returned from the API.
		 *
		 * Allows modification of the revision right before it is returned.
		 *
		 * @param WP_REST_Response  $response   The response object.
		 * @param WP_Post           $post       The original revision object.
		 * @param WP_REST_Request   $request    Request used to generate the response.
		 */
		return apply_filters( 'rest_prepare_revision', $response, $post, $request );
	}
201052
static function consolidatePost( $pid, $post ) {

		if ( false === Book::isBook() || wp_is_post_revision( $pid ) || 'auto-draft' === get_post_status( $pid ) ) {
			return false;
		}

		/** @var $wpdb \wpdb */
		global $wpdb;
		$success = true;

		// if this is a new post, set its order
		if ( empty( $post->menu_order ) ) {
			if ( 'chapter' === $post->post_type ) {
				$new = $wpdb->get_var(
					$wpdb->prepare(
						"SELECT max({$wpdb->posts}.menu_order) + 1
						FROM {$wpdb->posts}
						WHERE {$wpdb->posts}.post_type = %s
						AND NOT {$wpdb->posts}.post_status = 'trash'
						AND {$wpdb->posts}.post_parent = %s ",
						$post->post_type,
						$post->post_parent
					)
				);
			} else {
				$new = $wpdb->get_var(
					$wpdb->prepare(
						"SELECT max({$wpdb->posts}.menu_order) + 1
						FROM {$wpdb->posts}
						WHERE {$wpdb->posts}.post_type = %s
						AND NOT {$wpdb->posts}.post_status = 'trash' ",
						$post->post_type
					)
				);
			}

			if ( empty( $new ) ) {
				$new = 1;
			} else {
				$new = absint( $new );
			}

			$success = $wpdb->query(
				$wpdb->prepare(
					"UPDATE {$wpdb->posts}
					SET {$wpdb->posts}.menu_order = %d
					WHERE {$wpdb->posts}.ID = %d ",
					$new,
					$post->ID
				)
			);
			clean_post_cache( $post );

		}

		return $success ? true : false;
	}
246921
def post(self, request, *args, **kwargs):
        
        with reversion.create_revision():
            reversion.set_user(request.user)
            reversion.set_comment('created through the RESTful API from ip %s' % request.META['REMOTE_ADDR'])
            return self.create(request, *args, **kwargs)
1029968
function save_post( $post_id )
	{	
		
		// do not save if this is an auto save routine
		if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
		{
			return $post_id;
		}
		
		
		// verify nonce
		if( !isset($_POST['acf_nonce'], $_POST['fields']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
		{
			return $post_id;
		}
		
		
		// if save lock contains a value, the save_post action is already running for another post.
		// this would imply that the user is hooking into an ACF update_value or save_post action and inserting a new post
		// if this is the case, we do not want to save all the $POST data to this post.
		if( isset($GLOBALS['acf_save_lock']) && $GLOBALS['acf_save_lock'] )
		{
			return $post_id;
		}
		
		
		// update the post (may even be a revision / autosave preview)
		do_action('acf/save_post', $post_id);
        
	}
332096
public function create($user, $post)
    {
        return $this->postPolicy->create($user, $post)
            && $user->can('blog.comment.edit');
    }
461891
public function postRequest( Request $request ) {
		$response = $this->getClient()->request(
			'POST',
			$this->apiUrl,
			$this->getClientRequestOptions( $request, $this->getPostRequestEncoding( $request ) )
		);

		return $this->decodeResponse( $response );
	}
877486
public function prepare_item_for_response( $post_type, $request ) {
		$data = array(
			'capabilities' => $post_type->cap,
			'description'  => $post_type->description,
			'hierarchical' => $post_type->hierarchical,
			'labels'       => $post_type->labels,
			'name'         => $post_type->label,
			'slug'         => $post_type->name,
		);
		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$data = $this->add_additional_fields_to_object( $data, $request );
		$data = $this->filter_response_by_context( $data, $context );

		// Wrap the data in a response object.
		$response = rest_ensure_response( $data );

		$base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
		$response->add_links( array(
			'collection'              => array(
				'href'                => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
			),
			'https://api.w.org/items' => array(
				'href'                => rest_url( sprintf( 'wp/v2/%s', $base ) ),
			),
		) );

		/**
		 * Filter a post type returned from the API.
		 *
		 * Allows modification of the post type data right before it is returned.
		 *
		 * @param WP_REST_Response  $response   The response object.
		 * @param object            $item       The original post type object.
		 * @param WP_REST_Request   $request    Request used to generate the response.
		 */
		return apply_filters( 'rest_prepare_post_type', $response, $post_type, $request );
	}
745153
public function formFields($fields, $post)
    {
        // Bail if its not edit attachment page
        if (!isset($_GET['post']) || $post->post_type !== 'attachment') {
            return $fields;
        }

        add_thickbox();
        wp_enqueue_media();
        $uploadDir = wp_upload_dir();

        $mime =  mime_content_type($uploadDir['basedir'] . '/' . get_post_meta(get_the_id(), '_wp_attached_file', true));

        // Media replace button
        $html = '<button type="button" class="button-secondary button-large" data-action="media-replacer-replace" data-mime="' . $mime . '" data-edit-link="' . get_edit_post_link($post->ID) . '">' . __('Replace media', 'media-replacer') . '</button>
                 <input type="hidden" name="media-replacer-replace-with">';

        // Revision button
        $revisions = get_post_meta($post->ID, self::$revisionMetaKey, true);
        if (!is_array($revisions)) {
            $revisions = array();
        }

        $revisions = array_reverse($revisions, true);

        if (count($revisions) > 0) {
            $html .= '<a href="#TB_inline?width=600&height=550&inlineId=media-replace-revisions-thickbox-' . $post->ID . '" class="thickbox button-secondary button-large" data-action="media-replacer-revisions" data-edit-link="' . get_edit_post_link($post->ID) . '">' . __('Media revisions', 'media-replacer') . '</a>';
            $html .= '<div id="media-replace-revisions-thickbox-' . $post->ID . '" style="display:none;"><ul class="media-replace-revisions">';
        }

        foreach ($revisions as $time => $path) {
            if (!file_exists($path)) {
                continue;
            }

            $url = str_replace($uploadDir['basedir'], $uploadDir['baseurl'], $path);

            $date = mysql2date('Y-m-d H:i', date('Y-m-d H:i:s', $time));
            $html .= '<li data-restore="' . $path . '">';

            if (explode('/', mime_content_type($path))[0] === 'image') {
                $html .= '<div class="media-replace-revision-thumb" style="background-image:url(' . $url . ')"></div>';
            }

            $html .= '<time>' . $date . '</time>';
            $html .= '</li>';
        }

        if (count($revisions)) {
            $html .= '</ul>
                <div class="media-replace-revision-footer">
                    <button type="button" class="button button-large" data-action="media-replace-close-thickbox">' . __('Cancel') . '</button>
                    <button type="button" class="button button-large button-primary" data-action="media-replace-close-thickbox">' . __('Ok') . '</button>
                </div>
            </div><input type="hidden" name="media-replace-restore">';
        }

        $fields['media_replacer'] = array(
            'label' => '',
            'input' => 'html',
            'html' => $html
        );

        return $fields;
    }
509999
public function get_item( $request ) {
		$id = (int) $request['id'];
		$post = $this->get_post( $id );

		if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
			return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post id.' ), array( 'status' => 404 ) );
		}

		$data = $this->prepare_item_for_response( $post, $request );
		$response = rest_ensure_response( $data );

		if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
			$response->link_header( 'alternate',  get_permalink( $id ), array( 'type' => 'text/html' ) );
		}

		return $response;
	}
970099
public function postCreate()
    {
        $revisions[] = array(
            'revisionable_type' => get_class($this),
            'revisionable_id' => $this->getKey(),
            'attribute' => 'created_at',
            'old_value' => null,
            'new_value' => $this->created_at,
            'user_id' => $this->getUserId(),
            'created_at' => new \DateTime(),
            'updated_at' => new \DateTime(),
        );
        $revision = new Revision;
        \DB::table($revision->getTable())->insert($revisions);
    }
1052159
protected function findMatchingWordPressPost(Request $request)
    {
        if (!is_admin() && !is_404()) {

            $route = null;

            if (app()->isShared('post')) {
                $route = $this->getByName('__catch_' . str_replace('\\', '.', get_class(app('post'))));
            } elseif (app()->isShared('wp_query') && app('wp_query')->is_posts_page) {
                $route = $this->getByName('__catch_' . str_replace('\\', '.', app('posts.types')->get('post')));
            }

            if (!is_null($route)) {
                return $route->bind($request);
            }

        }

        return null;
    }
1228046
protected function get_field( \WP_Post $post ){
		$field = parent::get_field($post);
		if( $this->prefix ){
			$field = $this->prefix.' '.$field;
		}
		if( $this->suffix ){
			$field .= $this->suffix;
		}
		return $field;
	}
79916
protected function update_the_post( array $post_data ) {
		global $wpdb;

		if ( ! $this->exists() || empty( $post_data ) ) {
			return;
		}

		if ( doing_action( 'save_post' ) || 0 === strpos( current_action(), 'save_post' ) ) {
			$updated = $wpdb->update( $wpdb->posts, $post_data, [ 'ID' => $this->get_id() ] );
		} else {
			$updated = wp_update_post( array_merge( [ 'ID' => $this->get_id() ], $post_data ) );
		}

		clean_post_cache( $this->get_id() );

		return ( 0 !== $updated && false !== $updated );
	}
1214032
public function postDelete()
    {
        RevisionRepository::create([
            'revisionable_type' => get_class($this),
            'revisionable_id'   => $this->getKey(),
            'key'               => 'deleted_at',
            'old_value'         => null,
            'new_value'         => new DateTime(),
            'user_id'           => $this->getUserId(),
        ]);
    }
650536
public function postAction(Request $request)
    {
        // Get the response object from container
        $response = $this->getResponse();
        $model = $this->getModel();

        $this->restUtils->checkJsonRequest($request, $response, $this->getModel());

        $record = $this->restUtils->validateRequest($request->getContent(), $model);

        // Insert the new record
        $record = $model->insertRecord($record);

        // store id of new record so we dont need to reparse body later when needed
        $request->attributes->set('id', $record->getId());

        // Set status code
        $response->setStatusCode(Response::HTTP_CREATED);

        $response->headers->set(
            'Location',
            $this->getRouter()->generate($this->restUtils->getRouteName($request), array('id' => $record->getId()))
        );

        return $response;
    }
1357783
protected function set_post( $post ) {
		$this->post = $post;
		$this->id   = ( isset( $post->ID ) ) ? $post->ID : false;

		if ( ! empty( $this->taxonomies() ) ) {
			foreach ( $this->taxonomies() as $taxonomy ) {
				$this->{$taxonomy} = $this->get_terms( $taxonomy, array( 'fields' => 'all' ) );
			}
		}
	}
232290
public function callback( \WP_REST_Request $request ) {
		$method_name = 'handle_' . strtolower( $request->get_method() );
		try {
			$result = $this->{$method_name}( $request );
			if ( is_wp_error( $result ) ) {
				return $result;
			} elseif( is_a( $result, 'WP_REST_Response' ) ) {
				return $result;
			} else {
				return new \WP_REST_Response( $result );
			}
		} catch ( \Exception $e ) {
			return new \WP_Error( $e->getCode(), $e->getMessage(), [
				'response' => $e->getCode(),
			] );
		}
	}