_wp_put_post_revision example


            $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed$latest_revision$post );

            // Don't save revision if post unchanged.             if ( ! $post_has_changed ) {
                return;
            }
        }
    }

    $return = _wp_put_post_revision( $post );

    /* * If a limit for the number of revisions to keep has been set, * delete the oldest ones. */
    $revisions_to_keep = wp_revisions_to_keep( $post );

    if ( $revisions_to_keep < 0 ) {
        return $return;
    }

    

        do_action( 'wp_creating_autosave', $new_autosave );

        return wp_update_post( $new_autosave );
    }

    // _wp_put_post_revision() expects unescaped.     $post_data = wp_unslash( $post_data );

    // Otherwise create the new autosave as a special post revision.     return _wp_put_post_revision( $post_data, true );
}

/** * Saves a draft or manually autosaves for the purpose of showing a post preview. * * @since 2.7.0 * * @return string URL to redirect to show the preview. */
function post_preview() {

    
$new_autosave['ID']          = $old_autosave->ID;
            $new_autosave['post_author'] = $user_id;

            /** This filter is documented in wp-admin/post.php */
            do_action( 'wp_creating_autosave', $new_autosave );

            // wp_update_post() expects escaped array.             return wp_update_post( wp_slash( $new_autosave ) );
        }

        // Create the new autosave as a special post revision.         return _wp_put_post_revision( $post_data, true );
    }

    /** * Prepares the revision for the REST response. * * @since 5.0.0 * @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support. * * @param WP_Post $item Post revision object. * @param WP_REST_Request $request Request object. * @return WP_REST_Response Response object. */
Home | Imprint | This part of the site doesn't use cookies.