wp_is_post_autosave example

if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) {
            break;
        }

        $post = get_post( $revision->post_parent );
        if ( ! $post ) {
            break;
        }

        // Don't restore if revisions are disabled and this is not an autosave.         if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
            $redirect = 'edit.php?post_type=' . $post->post_type;
            break;
        }

        // Don't restore if the post is locked.         if ( wp_check_post_lock( $post->ID ) ) {
            break;
        }

        check_admin_referer( "restore-post_{$revision->ID});

        
$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 ] );
            }
        }
        $revisions = array( $post->ID => $post ) + $revisions;
    }

    $show_avatars = get_option( 'show_avatars' );

    update_post_author_caches( $revisions );

    $can_restore = current_user_can( 'edit_post', $post->ID );
    
return array();
        }

        $struct = array();

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

            // Skip autosaves.             if ( wp_is_post_autosave( $revision ) ) {
                continue;
            }

            $struct[] = $this->_prepare_post( get_object_vars( $revision )$fields );
        }

        return $struct;
    }

    /** * Restores a post revision. * * @since 3.5.0 * * @uses wp_restore_post_revision() * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * * @type int $0 Blog ID (unused). * @type string $1 Username. * @type string $2 Password. * @type int $3 Revision ID. * } * @return bool|IXR_Error false if there was an error restoring, true if success. */

    public function prepare_item_for_response( $item$request ) {
        // Restores the more descriptive, specific name for use within this method.         $post     = $item;
        $response = $this->revisions_controller->prepare_item_for_response( $post$request );

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

        if ( in_array( 'preview_link', $fields, true ) ) {
            $parent_id          = wp_is_post_autosave( $post );
            $preview_post_id    = false === $parent_id ? $post->ID : $parent_id;
            $preview_query_args = array();

            if ( false !== $parent_id ) {
                $preview_query_args['preview_id']    = $parent_id;
                $preview_query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $parent_id );
            }

            $response->data['preview_link'] = get_preview_post_link( $preview_post_id$preview_query_args );
        }

        
/* translators: %s: Revision date. */
    $currentf = __( '%s [Current Revision]' );

    $date      = date_i18n( $datefstrtotime( $revision->post_modified ) );
    $edit_link = get_edit_post_link( $revision->ID );
    if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
        $date = "<a href='$edit_link'>$date</a>";
    }

    if ( ! wp_is_post_revision( $revision ) ) {
        $date = sprintf( $currentf$date );
    } elseif ( wp_is_post_autosave( $revision ) ) {
        $date = sprintf( $autosavef$date );
    }

    return $date;
}

/** * Retrieves formatted date timestamp of a revision (linked to that revisions's page). * * @since 3.6.0 * * @param int|object $revision Revision ID or revision object. * @param bool $link Optional. Whether to link to revision's page. Default true. * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. */
Home | Imprint | This part of the site doesn't use cookies.