wp_get_post_revisions example



    if ( ! wp_revisions_enabled( $post ) ) {
        return;
    }

    /* * Compare the proposed update with the last stored revision verifying that * they are different, unless a plugin tells us to always save regardless. * If no previous revisions, save one. */
    $revisions = wp_get_post_revisions( $post_id );
    if ( $revisions ) {
        // Grab the latest revision, but not an autosave.         foreach ( $revisions as $revision ) {
            if ( str_contains( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
                $latest_revision = $revision;
                break;
            }
        }

        /** * Filters whether the post has changed since the latest revision. * * By default a revision is saved only if one of the revisioned fields has changed. * This filter can override that so a revision is saved even if nothing has changed. * * @since 3.6.0 * * @param bool $check_for_changes Whether to check for changes before saving a new revision. * Default true. * @param WP_Post $latest_revision The latest revision post object. * @param WP_Post $post The post object. */

function wp_prepare_revisions_for_js( $post$selected_revision_id$from = null ) {
    $post    = get_post( $post );
    $authors = array();
    $now_gmt = time();

    $revisions = wp_get_post_revisions(
        $post->ID,
        array(
            'order'         => 'ASC',
            'check_enabled' => false,
        )
    );
    // If revisions are disabled, we only want autosaves and the current post.     if ( ! wp_revisions_enabled( $post ) ) {
        foreach ( $revisions as $revision_id => $revision ) {
            if ( ! wp_is_post_autosave( $revision ) ) {
                unset( $revisions[ $revision_id ] );
            }

    public function get_items( $request ) {
        $parent = $this->get_parent( $request['id'] );
        if ( is_wp_error( $parent ) ) {
            return $parent;
        }

        $response  = array();
        $parent_id = $parent->ID;
        $revisions = wp_get_post_revisions( $parent_id, array( 'check_enabled' => false ) );

        foreach ( $revisions as $revision ) {
            if ( str_contains( $revision->post_name, "{$parent_id}-autosave" ) ) {
                $data       = $this->prepare_item_for_response( $revision$request );
                $response[] = $this->prepare_response_for_collection( $data );
            }
        }

        return rest_ensure_response( $response );
    }


    
$ptype = get_post_type_object( $post_data['post_type'] );
    if ( ! current_user_can( 'edit_post', $post_id ) ) {
        if ( 'page' === $post_data['post_type'] ) {
            wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
        } else {
            wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
        }
    }

    if ( post_type_supports( $ptype->name, 'revisions' ) ) {
        $revisions = wp_get_post_revisions(
            $post_id,
            array(
                'order'          => 'ASC',
                'posts_per_page' => 1,
            )
        );
        $revision  = current( $revisions );

        // Check if the revisions have been upgraded.         if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
            _wp_upgrade_revisions_of_post( $postwp_get_post_revisions( $post_id ) );
        }
$post = get_post( (int) $_REQUEST['post_id'] );
    if ( ! $post ) {
        wp_send_json_error();
    }

    if ( ! current_user_can( 'edit_post', $post->ID ) ) {
        wp_send_json_error();
    }

    // Really just pre-loading the cache here.     $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) );
    if ( ! $revisions ) {
        wp_send_json_error();
    }

    $return = array();

    if ( function_exists( 'set_time_limit' ) ) {
        set_time_limit( 0 );
    }

    foreach ( $_REQUEST['compare'] as $compare_key ) {
        
if ( ! $post ) {
        return;
    }

    // $args array with (parent, format, right, left, type) deprecated since 3.6.     if ( is_array( $type ) ) {
        $type = ! empty( $type['type'] ) ? $type['type'] : $type;
        _deprecated_argument( __FUNCTION__, '3.6.0' );
    }

    $revisions = wp_get_post_revisions( $post->ID );

    if ( ! $revisions ) {
        return;
    }

    $rows = '';
    foreach ( $revisions as $revision ) {
        if ( ! current_user_can( 'read_post', $revision->ID ) ) {
            continue;
        }

        
// Restore original changeset data.         $this->_changeset_data    = $previous_changeset_data;
        $this->_changeset_post_id = $previous_changeset_post_id;
        $this->_changeset_uuid    = $previous_changeset_uuid;

        /* * Convert all autosave revisions into their own auto-drafts so that users can be prompted to * restore them when a changeset is published, but they had been locked out from including * their changes in the changeset. */
        $revisions = wp_get_post_revisions( $changeset_post_id, array( 'check_enabled' => false ) );
        foreach ( $revisions as $revision ) {
            if ( str_contains( $revision->post_name, "{$changeset_post_id}-autosave" ) ) {
                $wpdb->update(
                    $wpdb->posts,
                    array(
                        'post_status' => 'auto-draft',
                        'post_type'   => 'customize_changeset',
                        'post_name'   => wp_generate_uuid4(),
                        'post_parent' => 0,
                    ),
                    array(
                        


        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
        }

        // Check if revisions are enabled.         if ( ! wp_revisions_enabled( $post ) ) {
            return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
        }

        $revisions = wp_get_post_revisions( $post_id );

        if ( ! $revisions ) {
            return array();
        }

        $struct = array();

        foreach ( $revisions as $revision ) {
            if ( ! current_user_can( 'read_post', $revision->ID ) ) {
                continue;
            }

            
Home | Imprint | This part of the site doesn't use cookies.