Ticket #23314: 23314.2.diff
File 23314.2.diff, 16.8 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
30 30 'rewrite' => false, 31 31 'query_var' => false, 32 32 'delete_with_user' => true, 33 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', ' post-formats' ),33 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'advanced-revisions', 'post-formats' ), 34 34 ) ); 35 35 36 36 register_post_type( 'page', array( … … 47 47 'rewrite' => false, 48 48 'query_var' => false, 49 49 'delete_with_user' => true, 50 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),50 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions', 'advanced-revisions' ), 51 51 ) ); 52 52 53 53 register_post_type( 'attachment', array( … … 79 79 'labels' => array( 80 80 'name' => __( 'Revisions' ), 81 81 'singular_name' => __( 'Revision' ), 82 'edit_item' => __( 'Edit Revision' ), 82 83 ), 83 84 'public' => false, 84 85 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ … … 5241 5242 return $post; 5242 5243 5243 5244 $preview = wp_get_post_autosave($post->ID); 5245 $autosave_id = ( $preview ) ? $preview->ID : 0; 5244 5246 5247 $preview_id = (int) $_GET['preview_id']; 5248 if ( $autosave_id != $preview_id && current_user_can( 'read_post', $preview_id ) ) { 5249 $revision = get_post( $preview_id ); 5250 if ( 'revision' == $revision->post_type && $revision->post_parent == $post->ID ) { 5251 $preview = $revision; 5252 } 5253 } 5254 5245 5255 if ( ! is_object($preview) ) 5246 5256 return $post; 5247 5257 -
wp-admin/includes/post.php
160 160 $post_data['post_type'] = $post->post_type; 161 161 $post_data['post_mime_type'] = $post->post_mime_type; 162 162 163 $parent = null; 164 $is_advanced_revision = false; 165 if ( 'revision' == $post->post_type ) { 166 $parent = get_post( $post->post_parent ); 167 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 168 $is_advanced_revision = true; 169 } 170 163 171 $ptype = get_post_type_object($post_data['post_type']); 164 172 if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) { 165 173 if ( 'page' == $post_data['post_type'] ) … … 243 251 244 252 update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); 245 253 246 wp_update_post( $post_data ); 254 if ( ! empty( $_POST['save-version'] ) && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { 255 unset( $post_data['post_ID'], $post_data['ID'] ); 256 $post_data['post_type'] = 'revision'; 257 $post_data['post_parent'] = $post_ID; 258 $post_data['post_status'] = 'draft'; 259 } 247 260 261 if ( ! empty( $_POST['publish'] ) && $is_advanced_revision ) { 262 if ( ! current_user_can( 'edit_post', $parent->ID ) ) 263 wp_die( __( 'You are not allowed to edit this post.' ) ); 264 265 unset( $post_data['post_parent'] ); 266 $post_data['post_type'] = $parent->post_type; 267 $post_data['post_status'] = $parent->post_status; 268 $post_data['ID'] = $parent->ID; 269 $post_data['post_ID'] = $parent->ID; 270 271 // Discard the revision 272 wp_delete_post( $post->ID, true ); 273 } 274 275 $post_ID = ( ! empty( $post_data['ID'] ) ) ? wp_update_post( $post_data ) : wp_insert_post( $post_data ); 276 248 277 // Now that we have an ID we can fix any attachment anchor hrefs 249 278 _fix_attachment_links( $post_ID ); 250 279 … … 1279 1308 $_POST['ID'] = $post_ID; 1280 1309 $post = get_post($post_ID); 1281 1310 1311 $parent = null; 1312 $is_advanced_revision = null; 1313 if ( 'revision' == $post->post_type ) { 1314 $parent = get_post( $post->post_parent ); 1315 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 1316 $is_advanced_revision = true; 1317 } 1318 1282 1319 if ( 'page' == $post->post_type ) { 1283 1320 if ( !current_user_can('edit_page', $post_ID) ) 1284 1321 wp_die(__('You are not allowed to edit this page.')); … … 1287 1324 wp_die(__('You are not allowed to edit this post.')); 1288 1325 } 1289 1326 1327 if ( $is_advanced_revision ) { 1328 $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); 1329 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), get_permalink( $parent->ID ) ); 1330 return $url; 1331 } 1332 1290 1333 if ( 'draft' == $post->post_status ) { 1291 1334 $id = edit_post(); 1292 1335 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. -
wp-admin/includes/meta-boxes.php
15 15 $post_type = $post->post_type; 16 16 $post_type_object = get_post_type_object($post_type); 17 17 $can_publish = current_user_can($post_type_object->cap->publish_posts); 18 19 $parent = null; 20 $is_advanced_revision = false; 21 if ( 'revision' == $post->post_type && $post->post_parent ) { 22 $parent = get_post( $post->post_parent ); 23 $is_advanced_revision = post_type_supports( $parent->post_type, 'advanced-revisions' ); 24 } 18 25 ?> 19 26 <div class="submitbox" id="submitpost"> 20 27 … … 27 34 28 35 <div id="minor-publishing-actions"> 29 36 <div id="save-action"> 30 <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> 37 <?php if ( $is_advanced_revision ) { ?> 38 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Changes' ); ?>" class="button" /> 39 <?php } elseif ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> 31 40 <input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button" /> 32 41 <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> 33 42 <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" /> 43 <?php } elseif ( 'publish' == $post->post_status && post_type_supports( $post->post_type, 'advanced-revisions' ) ) { ?> 44 <input type="submit" name="save-version" id="save-post" value="<?php esc_attr_e( 'Save a Version' ); ?>" class="button" /> 34 45 <?php } ?> 35 46 <span class="spinner"></span> 36 47 </div> 37 <?php if ( $post_type_object->public ) : ?>48 <?php if ( $post_type_object->public || $is_advanced_revision ) : ?> 38 49 <div id="preview-action"> 39 50 <?php 40 51 if ( 'publish' == $post->post_status ) { … … 43 54 } else { 44 55 $preview_link = set_url_scheme( get_permalink( $post->ID ) ); 45 56 $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) ); 46 $preview_button = __( 'Preview' );57 $preview_button = ( $is_advanced_revision ) ? __( 'Preview Changes' ) : __( 'Preview' ); 47 58 } 48 59 ?> 49 60 <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview" id="post-preview"><?php echo $preview_button; ?></a> … … 54 65 </div><!-- #minor-publishing-actions --> 55 66 56 67 <div id="misc-publishing-actions"> 68 <?php if ( $is_advanced_revision ) : ?> 69 <?php else: ?> 57 70 58 71 <div class="misc-pub-section"><label for="post_status"><?php _e('Status:') ?></label> 59 72 <span id="post-status-display"> … … 181 194 <?php endif; ?> 182 195 183 196 <?php do_action('post_submitbox_misc_actions'); ?> 184 </div> 197 <?php endif; // $is_advanced_revision ?> 198 </div><!-- #misc-publishing-actions --> 185 199 <div class="clear"></div> 186 200 </div> 187 201 … … 194 208 $delete_text = __('Delete Permanently'); 195 209 else 196 210 $delete_text = __('Move to Trash'); 211 212 $delete_link = get_delete_post_link( $post->ID ); 213 if ( $is_advanced_revision ) { 214 $delete_text = __( 'Discard Changes' ); 215 $delete_link = add_query_arg( 'post', $post->ID, get_delete_post_link( $post->post_parent, '', true ) ); 216 $delete_link = wp_nonce_url( $delete_link, "delete-post_{$post->ID}" ); 217 } 197 218 ?> 198 <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php219 <a class="submitdelete deletion" href="<?php echo esc_url( $delete_link ); ?>"><?php echo esc_html( $delete_text ); ?></a><?php 199 220 } ?> 200 221 </div> 201 222 … … 208 229 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" /> 209 230 <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 210 231 <?php else : ?> 232 <?php $publish_label = ( $is_advanced_revision ) ? __( 'Publish Changes' ) : __( 'Publish' ); ?> 233 <?php if ( $is_advanced_revision ) : ?> 234 <input name="publish_revision" type="hidden" value="1" /> 235 <?php endif; ?> 211 236 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> 212 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>237 <?php submit_button( $publish_label, 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 213 238 <?php endif; 214 239 else : ?> 215 240 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" /> -
wp-admin/post.php
31 31 if ( $post ) { 32 32 $post_type = $post->post_type; 33 33 $post_type_object = get_post_type_object( $post_type ); 34 35 if ( post_type_supports( $post_type, 'advanced-revisions' ) ) { 36 $revisions = get_posts( array( 37 'post_parent' => $post->ID, 38 'post_type' => 'revision', 39 'post_status' => array( 'draft' ), 40 ) ); 41 42 if ( ! empty( $revisions ) && is_array( $revisions ) ) { 43 $revision = $revisions[0]; 44 if ( current_user_can( 'edit_post', $revision->ID ) ) 45 redirect_post( $revision->ID ); 46 } 47 } 34 48 } 35 49 36 50 /** … … 39 53 * @param int $post_id Optional. Post ID. 40 54 */ 41 55 function redirect_post($post_id = '') { 42 if ( isset($_POST['save']) || isset($_POST['publish']) ) { 56 $post = get_post( $post_id ); 57 58 $parent = null; 59 $is_advanced_revision = false; 60 if ( 'revision' == $post->post_type ) { 61 $parent = get_post( $post->post_parent ); 62 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 63 $is_advanced_revision = true; 64 } 65 66 if ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) && ! $is_advanced_revision ) { 43 67 $status = get_post_status( $post_id ); 44 68 45 69 if ( isset( $_POST['publish'] ) ) { … … 57 81 $message = 'draft' == $status ? 10 : 1; 58 82 } 59 83 84 if ( ! empty( $_POST['publish_revision'] ) ) 85 $message = 13; 86 60 87 $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); 61 88 } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { 62 89 $location = add_query_arg( 'message', 2, wp_get_referer() ); … … 68 95 $location = $location[0] . '#postcustom'; 69 96 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { 70 97 $location = "post.php?action=edit&post=$post_id&message=7"; 98 } elseif ( $is_advanced_revision ) { 99 $location = add_query_arg( 'post', $post->ID, get_edit_post_link( $parent->ID, 'url' ) ); 100 101 if ( ! empty( $_POST['save-version'] ) ) 102 $message = 11; 103 elseif ( ! empty( $_POST['save'] ) ) 104 $message = 12; 105 106 if ( $message ) 107 $location = add_query_arg( 'message', $message, $location ); 71 108 } else { 72 109 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); 73 110 } … … 253 290 wp_die( __('Error in deleting.') ); 254 291 } 255 292 293 if ( 'revision' == $post->post_type ) { 294 $parent = get_post( $post->post_parent ); 295 $sendback = get_edit_post_link( $post->post_parent, 'url' ); 296 $sendback = add_query_arg( 'message', 14, $sendback ); 297 } 298 256 299 wp_redirect( add_query_arg('deleted', 1, $sendback) ); 257 300 exit(); 258 301 break; -
wp-admin/edit-form-advanced.php
24 24 $user_ID = isset($user_ID) ? (int) $user_ID : 0; 25 25 $action = isset($action) ? $action : ''; 26 26 27 if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail') ) { 27 $parent = null; 28 $is_advanced_revision = false; 29 if ( 'revision' == $post->post_type ) { 30 $parent = get_post( $post->post_parent ); 31 if ( post_type_supports( $parent->post_type, 'advanced-revisions' ) ) 32 $is_advanced_revision = true; 33 } 34 35 if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'thumbnail' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) { 28 36 add_thickbox(); 29 37 wp_enqueue_media( array( 'post' => $post_ID ) ); 30 38 } … … 45 53 // translators: Publish box date format, see http://php.net/date 46 54 date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 47 55 10 => sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 56 11 => __( 'A new version of this post has been created, but not published.' ), 57 12 => __( 'Your changes have been saved, but not published.' ), 58 13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View post</a>' ), esc_url( get_permalink( $post_ID ) ) ), 59 14 => __( 'Your changes have been discarded.' ), 48 60 ); 49 61 $messages['page'] = array( 50 62 0 => '', // Unused. Messages start at index 1. … … 58 70 8 => sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 59 71 9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 60 72 10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 73 11 => __( 'A new version of this page has been created, but not published.' ), 74 12 => __( 'Your changes have been saved, but not published.' ), 75 13 => sprintf( __( 'Your changes have been saved and published. <a href="%s">View page</a>' ), esc_url( get_permalink( $post_ID ) ) ), 76 14 => __( 'Your changes have been discarded.' ), 61 77 ); 62 78 $messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated.' ) ); // Hack, for now. 63 79 … … 135 151 if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) ) 136 152 add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); 137 153 138 if ( post_type_supports($post_type, 'excerpt') )154 if ( post_type_supports($post_type, 'excerpt') || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'excerpt' ) ) ) 139 155 add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); 140 156 141 157 if ( post_type_supports($post_type, 'trackbacks') ) … … 151 167 if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') ) 152 168 add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core'); 153 169 154 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )170 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) && ! $is_advanced_revision ) 155 171 add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core'); 156 172 157 if ( post_type_supports($post_type, 'author') ) {173 if ( post_type_supports($post_type, 'author') && ! $is_advanced_revision ) { 158 174 if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) 159 175 add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core'); 160 176 } … … 323 339 324 340 <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> 325 341 <div id="post-body-content"> 326 <?php if ( post_type_supports( $post_type, 'title') ) { ?>342 <?php if ( post_type_supports( $post_type, 'title' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'title' ) ) ) { ?> 327 343 <div id="titlediv"> 328 344 <div id="titlewrap"> 329 345 <label class="screen-reader-text" id="title-prompt-text" for="title"><?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?></label> … … 356 372 357 373 do_action( 'edit_form_after_title' ); 358 374 359 if ( post_type_supports( $post_type, 'editor') ) {375 if ( post_type_supports( $post_type, 'editor' ) || ( $is_advanced_revision && post_type_supports( $parent->post_type, 'editor' ) ) ) { 360 376 ?> 361 377 <div id="postdivrich" class="postarea"> 362 378