wp_revisions_enabled example

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

    $show_avatars = get_option( 'show_avatars' );

    update_post_author_caches( $revisions );

    
return;
    }

    if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
        return;
    }

    if ( 'auto-draft' === $post->post_status ) {
        return;
    }

    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.


        // Ensure an include parameter is set in case the orderby is set to 'include'.         if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) {
            return new WP_Error(
                'rest_orderby_include_missing_include',
                __( 'You need to define an include parameter to order by include.' ),
                array( 'status' => 400 )
            );
        }

        if ( wp_revisions_enabled( $parent ) ) {
            $registered = $this->get_collection_params();
            $args       = array(
                'post_parent'      => $parent->ID,
                'post_type'        => 'revision',
                'post_status'      => 'inherit',
                'posts_per_page'   => -1,
                'orderby'          => 'date ID',
                'order'            => 'DESC',
                'suppress_filters' => true,
            );

            
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});

        
if ( is_wp_error( $parent ) ) {
            return $parent;
        }

        $global_styles_config = $this->get_decoded_global_styles_json( $parent->post_content );

        if ( is_wp_error( $global_styles_config ) ) {
            return $global_styles_config;
        }

        if ( wp_revisions_enabled( $parent ) ) {
            $registered = $this->get_collection_params();
            $query_args = array(
                'post_parent'    => $parent->ID,
                'post_type'      => 'revision',
                'post_status'    => 'inherit',
                'posts_per_page' => -1,
                'orderby'        => 'date ID',
                'order'          => 'DESC',
            );

            $parameter_mappings = array(
                
$post = get_post( $post_id );
        if ( ! $post ) {
            return new IXR_Error( 404, __( 'Invalid post ID.' ) );
        }

        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();

        
$wp_customize->_publish_changeset_values( $changeset_post->ID );

    /* * Trash the changeset post if revisions are not enabled. Unpublished * changesets by default get garbage collected due to the auto-draft status. * When a changeset post is published, however, it would no longer get cleaned * out. This is a problem when the changeset posts are never displayed anywhere, * since they would just be endlessly piling up. So here we use the revisions * feature to indicate whether or not a published changeset should get trashed * and thus garbage collected. */
    if ( ! wp_revisions_enabled( $changeset_post ) ) {
        $wp_customize->trash_changeset_post( $changeset_post->ID );
    }
}

/** * Filters changeset post data upon insert to ensure post_name is intact. * * This is needed to prevent the post_name from being dropped when the post is * transitioned into pending status by a contributor. * * @since 4.7.0 * * @see wp_insert_post() * * @param array $post_data An array of slashed post data. * @param array $supplied_post_data An array of sanitized, but otherwise unmodified post data. * @return array Filtered data. */
Home | Imprint | This part of the site doesn't use cookies.