Make WordPress Core


Ignore:
Timestamp:
05/29/2008 10:21:36 PM (17 years ago)
Author:
ryan
Message:

Post revisions API cleanup from mdawaffe. see #6775

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r7995 r8011  
    957957    // Do raw query.  wp_get_post_revisions() is filtered
    958958    $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    959     // Use wp_delete_post (via wp_delete_revision) again.  Ensures any meta/misplaced data gets cleaned up.
     959    // Use wp_delete_post (via wp_delete_post_revision) again.  Ensures any meta/misplaced data gets cleaned up.
    960960    foreach ( $revision_ids as $revision_id )
    961         wp_delete_revision( $revision_id );
     961        wp_delete_post_revision( $revision_id );
    962962
    963963    // Point all attachments to this post up one level
     
    29522952
    29532953/**
    2954  * _wp_revision_fields() - determines which fields of posts are to be saved in revisions
     2954 * _wp_post_revision_fields() - determines which fields of posts are to be saved in revisions
    29552955 *
    29562956 * Does two things. If passed a post *array*, it will return a post array ready to be
     
    29662966 * @return array post array ready to be inserted as a post revision or array of fields that can be versioned
    29672967 */
    2968 function _wp_revision_fields( $post = null, $autosave = false ) {
     2968function _wp_post_revision_fields( $post = null, $autosave = false ) {
    29692969    static $fields = false;
    29702970
     
    29792979
    29802980        // Runs only once
    2981         $fields = apply_filters( '_wp_revision_fields', $fields );
     2981        $fields = apply_filters( '_wp_post_revision_fields', $fields );
    29822982
    29832983        // WP uses these internally either in versioning or elsewhere - they cannot be versioned
     
    30043004
    30053005/**
    3006  * wp_save_revision() - Saves an already existing post as a post revision.  Typically used immediately prior to post updates.
     3006 * wp_save_post_revision() - Saves an already existing post as a post revision.  Typically used immediately prior to post updates.
    30073007 *
    30083008 * @package WordPress
     
    30103010 * @since 2.6
    30113011 *
    3012  * @uses _wp_put_revision()
     3012 * @uses _wp_put_post_revision()
    30133013 *
    30143014 * @param int $post_id The ID of the post to save as a revision
    30153015 * @return mixed null or 0 if error, new revision ID if success
    30163016 */
    3017 function wp_save_revision( $post_id ) {
    3018     // We do autosaves manually with wp_create_autosave()
     3017function wp_save_post_revision( $post_id ) {
     3018    // We do autosaves manually with wp_create_post_autosave()
    30193019    if ( @constant( 'DOING_AUTOSAVE' ) )
    30203020        return;
     
    30303030        return;
    30313031
    3032     $return = _wp_put_revision( $post );
     3032    $return = _wp_put_post_revision( $post );
    30333033
    30343034    // WP_POST_REVISIONS = true (default), -1
     
    30503050        if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) )
    30513051            continue;
    3052         wp_delete_revision( $revisions[$i]->ID );
     3052        wp_delete_post_revision( $revisions[$i]->ID );
    30533053    }
    30543054
     
    30573057
    30583058/**
    3059  * wp_get_autosave() - returns the autosaved data of the specified post.
     3059 * wp_get_post_autosave() - returns the autosaved data of the specified post.
    30603060 *
    30613061 * Returns a post object containing the information that was autosaved for the specified post.
     
    30683068 * @return object|bool the autosaved data or false on failure or when no autosave exists
    30693069 */
    3070 function wp_get_autosave( $post_id ) {
     3070function wp_get_post_autosave( $post_id ) {
    30713071    global $wpdb;
    30723072    if ( !$post = get_post( $post_id ) )
     
    30833083    $autosave_query = new WP_Query;
    30843084
    3085     add_action( 'parse_query', '_wp_get_autosave_hack' );
     3085    add_action( 'parse_query', '_wp_get_post_autosave_hack' );
    30863086    $autosave = $autosave_query->query( $q );
    3087     remove_action( 'parse_query', '_wp_get_autosave_hack' );
     3087    remove_action( 'parse_query', '_wp_get_post_autosave_hack' );
    30883088
    30893089    if ( $autosave && is_array($autosave) && is_object($autosave[0]) )
     
    30943094
    30953095// Internally used to hack WP_Query into submission
    3096 function _wp_get_autosave_hack( $query ) {
     3096function _wp_get_post_autosave_hack( $query ) {
    30973097    $query->is_single = false;
    30983098}
    30993099
    3100 /**
    3101  * _wp_put_revision() - Inserts post data into the posts table as a post revision
     3100
     3101/**
     3102 * wp_is_post_revision() - Determines if the specified post is a revision.
     3103 *
     3104 * @package WordPress
     3105 * @subpackage Post Revisions
     3106 * @since 2.6
     3107 *
     3108 * @param int|object $post post ID or post object
     3109 * @return bool|int false if not a revision, ID of revision's parent otherwise
     3110 */
     3111function wp_is_post_revision( $post ) {
     3112    if ( !$post = wp_get_post_revision( $post ) )
     3113        return false;
     3114    return (int) $post->post_parent;
     3115}
     3116
     3117/**
     3118 * wp_is_post_autosave() - Determines if the specified post is an autosave.
     3119 *
     3120 * @package WordPress
     3121 * @subpackage Post Revisions
     3122 * @since 2.6
     3123 *
     3124 * @param int|object $post post ID or post object
     3125 * @return bool|int false if not a revision, ID of autosave's parent otherwise
     3126 */
     3127function wp_is_post_autosave( $post ) {
     3128    if ( !$post = wp_get_post_revision( $post ) )
     3129        return false;
     3130    if ( "{$post->post_parent}-autosave" !== $post->post_name )
     3131        return false;
     3132    return (int) $post->post_parent;
     3133}
     3134
     3135/**
     3136 * _wp_put_post_revision() - Inserts post data into the posts table as a post revision
    31023137 *
    31033138 * @package WordPress
     
    31113146 * @return mixed null or 0 if error, new revision ID if success
    31123147 */
    3113 function _wp_put_revision( $post = null, $autosave = false ) {
     3148function _wp_put_post_revision( $post = null, $autosave = false ) {
    31143149    if ( is_object($post) )
    31153150        $post = get_object_vars( $post );
     
    31223157        return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
    31233158
    3124     $post = _wp_revision_fields( $post, $autosave );
     3159    $post = _wp_post_revision_fields( $post, $autosave );
    31253160
    31263161    $revision_id = wp_insert_post( $post );
     
    31293164
    31303165    if ( $revision_id )
    3131         do_action( '_wp_put_revision', $revision_id );
     3166        do_action( '_wp_put_post_revision', $revision_id );
    31323167    return $revision_id;
    31333168}
    31343169
    31353170/**
    3136  * wp_get_revision() - Gets a post revision
     3171 * wp_get_post_revision() - Gets a post revision
    31373172 *
    31383173 * @package WordPress
     
    31473182 * @return mixed null if error or post object if success
    31483183 */
    3149 function &wp_get_revision(&$post, $output = OBJECT, $filter = 'raw') {
     3184function &wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
    31503185    $null = null;
    31513186    if ( !$revision = get_post( $post, OBJECT, $filter ) )
     
    31683203
    31693204/**
    3170  * wp_restore_revision() - Restores a post to the specified revision
     3205 * wp_restore_post_revision() - Restores a post to the specified revision
    31713206 *
    31723207 * Can restore a past using all fields of the post revision, or only selected fields.
     
    31763211 * @since 2.6
    31773212 *
    3178  * @uses wp_get_revision()
     3213 * @uses wp_get_post_revision()
    31793214 * @uses wp_update_post()
    31803215 *
     
    31833218 * @return mixed null if error, false if no fields to restore, (int) post ID if success
    31843219 */
    3185 function wp_restore_revision( $revision_id, $fields = null ) {
    3186     if ( !$revision = wp_get_revision( $revision_id, ARRAY_A ) )
     3220function wp_restore_post_revision( $revision_id, $fields = null ) {
     3221    if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
    31873222        return $revision;
    31883223
    31893224    if ( !is_array( $fields ) )
    3190         $fields = array_keys( _wp_revision_fields() );
     3225        $fields = array_keys( _wp_post_revision_fields() );
    31913226
    31923227    $update = array();
     
    32043239
    32053240    if ( $post_id )
    3206         do_action( 'wp_restore_revision', $post_id, $revision['ID'] );
     3241        do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
    32073242
    32083243    return $post_id;
     
    32103245
    32113246/**
    3212  * wp_delete_revision() - Deletes a revision.
     3247 * wp_delete_post_revision() - Deletes a revision.
    32133248 *
    32143249 * Deletes the row from the posts table corresponding to the specified revision
     
    32183253 * @since 2.6
    32193254 *
    3220  * @uses wp_get_revision()
     3255 * @uses wp_get_post_revision()
    32213256 * @uses wp_delete_post()
    32223257 *
     
    32253260 * @return mixed null if error, false if no fields to restore, (int) post ID if success
    32263261 */
    3227 function wp_delete_revision( $revision_id ) {
    3228     if ( !$revision = wp_get_revision( $revision_id ) )
     3262function wp_delete_post_revision( $revision_id ) {
     3263    if ( !$revision = wp_get_post_revision( $revision_id ) )
    32293264        return $revision;
    32303265
     
    32343269
    32353270    if ( $delete )
    3236         do_action( 'wp_delete_revision', $revision->ID, $revision );
     3271        do_action( 'wp_delete_post_revision', $revision->ID, $revision );
    32373272
    32383273    return $delete;
Note: See TracChangeset for help on using the changeset viewer.