Changeset 7907 for trunk/wp-includes/post.php
- Timestamp:
- 05/08/2008 05:25:07 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r7900 r7907 89 89 90 90 $children = get_posts( $r ); 91 92 91 if ( !$children ) 93 92 return false; … … 2958 2957 * _wp_revision_fields() - determines which fields of posts are to be saved in revisions 2959 2958 * 2960 * Does two things. If passed a post n*array*, it will return a post array ready to be2959 * Does two things. If passed a post *array*, it will return a post array ready to be 2961 2960 * insterted into the posts table as a post revision. 2962 * Otherwise, returns an array whose keys are the post fields to be saved post revisions.2961 * Otherwise, returns an array whose keys are the post fields to be saved for post revisions. 2963 2962 * 2964 2963 * @package WordPress … … 2967 2966 * 2968 2967 * @param array $post optional a post array to be processed for insertion as a post revision 2968 * @param bool $autosave optional Is the revision an autosave? 2969 2969 * @return array post array ready to be inserted as a post revision or array of fields that can be versioned 2970 2970 */ 2971 function _wp_revision_fields( $post = null ) {2971 function _wp_revision_fields( $post = null, $autosave = false ) { 2972 2972 static $fields = false; 2973 2973 … … 2981 2981 ); 2982 2982 2983 // Runs only once 2984 $fields = apply_filters( '_wp_revision_fields', $fields ); 2985 2983 2986 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 2984 2987 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count' ) as $protect ) … … 2996 2999 $return['post_status'] = 'inherit'; 2997 3000 $return['post_type'] = 'revision'; 2998 $return['post_name'] = "$post[ID]-revision";3001 $return['post_name'] = $autosave ? "$post[ID]-autosave" : "$post[ID]-revision"; 2999 3002 $return['post_date'] = $post['post_modified']; 3000 3003 $return['post_date_gmt'] = $post['post_modified_gmt']; … … 3016 3019 */ 3017 3020 function wp_save_revision( $post_id ) { 3018 // TODO: rework autosave to use special type of post revision3021 // We do autosaves manually with wp_create_autosave() 3019 3022 if ( @constant( 'DOING_AUTOSAVE' ) ) 3020 3023 return; … … 3023 3026 return; 3024 3027 3025 // TODO: open this up for pages also 3026 if ( 'post' != $post->post_type ) 3028 if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) ) 3027 3029 return; 3028 3030 … … 3031 3033 3032 3034 /** 3033 * _wp_put_revision() - Inserts post data into the posts table as a post revision 3035 * wp_get_autosave() - returns the autosaved data of the specified post. 3036 * 3037 * Returns a post object containing the information that was autosaved for the specified post. 3034 3038 * 3035 3039 * @package WordPress … … 3037 3041 * @since 2.6 3038 3042 * 3043 * @param int $post_id The post ID 3044 * @return object|bool the autosaved data or false on failure or when no autosave exists 3045 */ 3046 function wp_get_autosave( $post_id ) { 3047 global $wpdb; 3048 if ( !$post = get_post( $post_id ) ) 3049 return false; 3050 3051 $q = array( 3052 'name' => "{$post->ID}-autosave", 3053 'post_parent' => $post->ID, 3054 'post_type' => 'revision', 3055 'post_status' => 'inherit' 3056 ); 3057 3058 // Use WP_Query so that the result gets cached 3059 $autosave_query = new WP_Query; 3060 3061 add_action( 'parse_query', '_wp_get_autosave_hack' ); 3062 $autosave = $autosave_query->query( $q ); 3063 remove_action( 'parse_query', '_wp_get_autosave_hack' ); 3064 3065 if ( $autosave && is_array($autosave) && is_object($autosave[0]) ) 3066 return $autosave[0]; 3067 3068 return false; 3069 } 3070 3071 // Internally used to hack WP_Query into submission 3072 function _wp_get_autosave_hack( $query ) { 3073 $query->is_single = false; 3074 } 3075 3076 /** 3077 * _wp_put_revision() - Inserts post data into the posts table as a post revision 3078 * 3079 * @package WordPress 3080 * @subpackage Post Revisions 3081 * @since 2.6 3082 * 3039 3083 * @uses wp_insert_post() 3040 3084 * 3041 3085 * @param int|object|array $post post ID, post object OR post array 3086 * @param bool $autosave optional Is the revision an autosave? 3042 3087 * @return mixed null or 0 if error, new revision ID if success 3043 3088 */ 3044 function _wp_put_revision( $post = null ) {3089 function _wp_put_revision( $post = null, $autosave = false ) { 3045 3090 if ( is_object($post) ) 3046 3091 $post = get_object_vars( $post ); 3047 3092 elseif ( !is_array($post) ) 3048 3093 $post = get_post($post, ARRAY_A); 3049 3050 3094 if ( !$post || empty($post['ID']) ) 3051 3095 return; … … 3054 3098 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 3055 3099 3056 $post = _wp_revision_fields( $post ); 3057 3058 if ( $revision_id = wp_insert_post( $post ) ) 3100 $post = _wp_revision_fields( $post, $autosave ); 3101 3102 $revision_id = wp_insert_post( $post ); 3103 if ( is_wp_error($revision_id) ) 3104 return $revision_id; 3105 3106 if ( $revision_id ) 3059 3107 do_action( '_wp_put_revision', $revision_id ); 3060 3061 3108 return $revision_id; 3062 3109 } … … 3128 3175 $update['ID'] = $revision['post_parent']; 3129 3176 3130 if ( $post_id = wp_update_post( $update ) ) 3177 $post_id = wp_update_post( $update ); 3178 if ( is_wp_error( $post_id ) ) 3179 return $post_id; 3180 3181 if ( $post_id ) 3131 3182 do_action( 'wp_restore_revision', $post_id, $revision['ID'] ); 3132 3183 … … 3154 3205 return $revision; 3155 3206 3156 if ( $delete = wp_delete_post( $revision->ID ) ) 3207 $delete = wp_delete_post( $revision->ID ); 3208 if ( is_wp_error( $delete ) ) 3209 return $delete; 3210 3211 if ( $delete ) 3157 3212 do_action( 'wp_delete_revision', $revision->ID, $revision ); 3158 3213 … … 3175 3230 if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) 3176 3231 return array(); 3177 3178 if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision' ) ) ) 3232 if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ) ) 3179 3233 return array(); 3180 3234 return $revisions; 3181 3235 } 3182 3183 ?>
Note: See TracChangeset
for help on using the changeset viewer.