wp_delete_post_revision example

        $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid$post->post_type );
        $children       = $wpdb->get_results( $children_query );
        if ( $children ) {
            $wpdb->update( $wpdb->posts, $parent_data$parent_where + array( 'post_type' => $post->post_type ) );
        }
    }

    // Do raw query. wp_get_post_revisions() is filtered.     $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.     foreach ( $revision_ids as $revision_id ) {
        wp_delete_post_revision( $revision_id );
    }

    // Point all attachments to this post up one level.     $wpdb->update( $wpdb->posts, $parent_data$parent_where + array( 'post_type' => 'attachment' ) );

    wp_defer_comment_counting( true );

    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) );
    foreach ( $comment_ids as $comment_id ) {
        wp_delete_comment( $comment_id, true );
    }

    
if ( normalize_whitespace( $autosave->$autosave_field ) !== normalize_whitespace( $post->$autosave_field ) ) {
            $notice = sprintf(
                /* translators: %s: URL to view the autosave. */
                __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>' ),
                get_edit_post_link( $autosave->ID )
            );
            break;
        }
    }
    // If this autosave isn't different from the current post, begone.     if ( ! $notice ) {
        wp_delete_post_revision( $autosave->ID );
    }
    unset( $autosave_field$_autosave_field );
}

$post_type_object = get_post_type_object( $post_type );

// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action). require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';

register_and_do_post_meta_boxes( $post );

// Add additional back-compat patterns registered by `current_screen` et al. $editor_settings['__experimentalAdditionalBlockPatterns']          = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
$editor_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );

$autosave = wp_get_post_autosave( $post->ID );
if ( $autosave ) {
    if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
        $editor_settings['autosave'] = array(
            'editLink' => get_edit_post_link( $autosave->ID ),
        );
    } else {
        wp_delete_post_revision( $autosave->ID );
    }
}

if ( ! empty( $post_type_object->template ) ) {
    $editor_settings['template']     = $post_type_object->template;
    $editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
}

// If there's no template set on a new post, use the post format, instead. if ( $is_new_post && ! isset( $editor_settings['template'] ) && 'post' === $post->post_type ) {
    $post_format = get_post_format( $post );
    
if ( $delete < 1 ) {
        return $return;
    }

    $revisions = array_slice( $revisions, 0, $delete );

    for ( $i = 0; isset( $revisions[ $i ] )$i++ ) {
        if ( str_contains( $revisions[ $i ]->post_name, 'autosave' ) ) {
            continue;
        }

        wp_delete_post_revision( $revisions[ $i ]->ID );
    }

    return $return;
}

/** * Retrieves the autosaved data of the specified post. * * Returns a post object with the information that was autosaved for the specified post. * If the optional $user_id is passed, returns the autosave for that user, otherwise * returns the latest autosave. * * @since 2.6.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $post_id The post ID. * @param int $user_id Optional. The post author ID. Default 0. * @return WP_Post|false The autosaved data or false on failure or when no autosave exists. */
// If the new autosave has the same content as the post, delete the autosave.         $autosave_is_different = false;
        foreach ( array_intersect( array_keys( $new_autosave )array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
            if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
                $autosave_is_different = true;
                break;
            }
        }

        if ( ! $autosave_is_different ) {
            wp_delete_post_revision( $old_autosave->ID );
            return 0;
        }

        /** * Fires before an autosave is stored. * * @since 4.1.0 * * @param array $new_autosave Post array - the autosave that is about to be saved. */
        do_action( 'wp_creating_autosave', $new_autosave );

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