Make WordPress Core

Ticket #9674: 9674.14.diff

File 9674.14.diff, 19.1 KB (added by ryan, 16 years ago)

Merge edit-page-form.php into edit-form-advanced.php

  • wp-admin/edit-page-form.php

     
    1 <?php
    2 /**
    3  * Edit page form for inclusion in the administration panels.
    4  *
    5  * @package WordPress
    6  * @subpackage Administration
    7  */
    8 
    9 // don't load directly
    10 if ( !defined('ABSPATH') )
    11         die('-1');
    12 
    13 /**
    14  * Post ID global.
    15  * @name $post_ID
    16  * @var int
    17  */
    18 if ( ! isset( $post_ID ) )
    19         $post_ID = 0;
    20 if ( ! isset( $temp_ID ) )
    21         $temp_ID = 0;
    22 
    23 $message = false;
    24 if ( isset($_GET['message']) ) {
    25         $_GET['message'] = absint( $_GET['message'] );
    26 
    27         switch ( $_GET['message'] ) {
    28                 case 1:
    29                         $message = sprintf( __('Page updated. <a href="%s">View page</a>'), get_permalink($post_ID) );
    30                         break;
    31                 case 2:
    32                         $message = __('Custom field updated.');
    33                         break;
    34                 case 3:
    35                         $message = __('Custom field deleted.');
    36                         break;
    37                 case 4:
    38                         $message = sprintf( __('Page published. <a href="%s">View page</a>'), get_permalink($post_ID) );
    39                         break;
    40                 case 5:
    41                         if ( isset($_GET['revision']) )
    42                                 $message = sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) );
    43                         break;
    44                 case 6:
    45                         $message = sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
    46                         break;
    47                 case 7:
    48                         // translators: Publish box date formt, see http://php.net/date - Same as in meta-boxes.php
    49                         $message = sprintf( __('Page scheduled for: <b>%1$s</b>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID) );
    50                         break;
    51                 case 8:
    52                         $message = sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
    53                         break;
    54         }
    55 }
    56 
    57 $notice = false;
    58 if ( 0 == $post_ID) {
    59         $form_action = 'post';
    60         $nonce_action = 'add-page';
    61         $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
    62         $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='$temp_ID' />";
    63 } else {
    64         $post_ID = (int) $post_ID;
    65         $form_action = 'editpost';
    66         $nonce_action = 'update-page_' . $post_ID;
    67         $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='$post_ID' />";
    68         $autosave = wp_get_post_autosave( $post_ID );
    69         if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) )
    70                 $notice = sprintf( __( 'There is an autosave of this page that is more recent than the version below.  <a href="%s">View the autosave</a>.' ), get_edit_post_link( $autosave->ID ) );
    71 }
    72 
    73 $temp_ID = (int) $temp_ID;
    74 $user_ID = (int) $user_ID;
    75 
    76 require_once('includes/meta-boxes.php');
    77 
    78 $post_type = 'page';
    79 
    80 add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 'page', 'side', 'core');
    81 
    82 // all tag-style page taxonomies
    83 foreach ( get_object_taxonomies('page') as $tax_name ) {
    84         if ( !is_taxonomy_hierarchical($tax_name) ) {
    85                 $taxonomy = get_taxonomy($tax_name);
    86                 $label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
    87 
    88                 add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core');
    89         }
    90 }
    91 
    92 if ( post_type_supports($post_type, 'page-attributes') )
    93         add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');
    94 if ( post_type_supports($post_type, 'custom-fields') )
    95         add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
    96 if ( post_type_supports($post_type, 'comments') )
    97         add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
    98 add_meta_box('slugdiv', __('Page Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
    99 if ( current_theme_supports( 'post-thumbnails', 'page' ) && post_type_supports($post_type, 'post-thumbnails') )
    100         add_meta_box('postimagediv', __('Page Image'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
    101 
    102 $authors = get_editable_user_ids( $current_user->id, true, 'page' ); // TODO: ROLE SYSTEM
    103 if ( $post->post_author && !in_array($post->post_author, $authors) )
    104         $authors[] = $post->post_author;
    105 if ( $authors && count( $authors ) > 1 )
    106         add_meta_box('pageauthordiv', __('Page Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
    107 
    108 if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
    109         add_meta_box('revisionsdiv', __('Page Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
    110 
    111 do_action('do_meta_boxes', $post_type, 'normal', $post);
    112 do_action('do_meta_boxes', $post_type, 'advanced', $post);
    113 do_action('do_meta_boxes', $post_type, 'side', $post);
    114 
    115 require_once('admin-header.php');
    116 ?>
    117 
    118 <div class="wrap">
    119 <?php screen_icon(); ?>
    120 <h2><?php echo esc_html( $title ); ?></h2>
    121 
    122 <form name="post" action="page.php" method="post" id="post">
    123 <?php if ( $notice ) : ?>
    124 <div id="notice" class="error"><p><?php echo $notice ?></p></div>
    125 <?php endif; ?>
    126 <?php if ( $message ) : ?>
    127 <div id="message" class="updated"><p><?php echo $message; ?></p></div>
    128 <?php endif; ?>
    129 
    130 <?php wp_nonce_field($nonce_action); ?>
    131 
    132 <input type="hidden" id="user-id" name="user_ID" value="<?php echo $user_ID ?>" />
    133 <input type="hidden" id="hiddenaction" name="action" value='<?php echo esc_attr($form_action) ?>' />
    134 <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr($form_action) ?>" />
    135 <input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
    136 <?php echo $form_extra ?>
    137 <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr($post->post_type) ?>" />
    138 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr($post->post_status) ?>" />
    139 <input name="referredby" type="hidden" id="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" />
    140 <?php if ( 'draft' != $post->post_status ) wp_original_referer_field(true, 'previous'); ?>
    141 
    142 <div id="poststuff" class="metabox-holder<?php echo 2 == $screen_layout_columns ? ' has-right-sidebar' : ''; ?>">
    143 
    144 <div id="side-info-column" class="inner-sidebar">
    145 <?php
    146 do_action('submitpage_box');
    147 $side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?>
    148 </div>
    149 
    150 <div id="post-body">
    151 <div id="post-body-content">
    152 <div id="titlediv">
    153 <div id="titlewrap">
    154         <label class="screen-reader-text" for="title"><?php _e('Title') ?></label>
    155         <input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( htmlspecialchars( $post->post_title ) ); ?>" id="title" autocomplete="off" />
    156 </div>
    157 <div class="inside">
    158 <?php $sample_permalink_html = get_sample_permalink_html($post->ID); ?>
    159         <div id="edit-slug-box">
    160 <?php if ( ! empty($post->ID) && ! empty($sample_permalink_html) ) :
    161         echo $sample_permalink_html;
    162 endif; ?>
    163         </div>
    164 </div>
    165 </div>
    166 
    167 <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
    168 
    169 <?php the_editor($post->post_content); ?>
    170 <table id="post-status-info" cellspacing="0"><tbody><tr>
    171         <td id="wp-word-count"></td>
    172         <td class="autosave-info">
    173         <span id="autosave">&nbsp;</span>
    174 
    175 <?php
    176         if ($post_ID) {
    177                 if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
    178                         $last_user = get_userdata($last_id);
    179                         printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
    180                 } else {
    181                         printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
    182                 }
    183         }
    184 ?>
    185         </td>
    186 </tr></tbody></table>
    187 
    188 <?php
    189 wp_nonce_field( 'autosave', 'autosavenonce', false );
    190 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
    191 wp_nonce_field( 'getpermalink', 'getpermalinknonce', false );
    192 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
    193 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
    194 </div>
    195 
    196 <?php
    197 do_meta_boxes($post_type, 'normal', $post);
    198 do_action('edit_page_form');
    199 do_meta_boxes($post_type, 'advanced', $post);
    200 ?>
    201 
    202 </div>
    203 </div>
    204 </div>
    205 
    206 </form>
    207 </div>
    208 
    209 <script type="text/javascript">
    210 try{document.post.title.focus();}catch(e){}
    211 </script>
  • wp-admin/edit-form-advanced.php

     
    1616 * @var int
    1717 */
    1818$post_ID = isset($post_ID) ? (int) $post_ID : 0;
    19 
     19$temp_ID = isset($temp_ID) ? (int) $temp_ID : 0;
     20$user_ID = isset($user_ID) ? (int) $user_ID : 0;
    2021$action = isset($action) ? $action : '';
    2122
     23$messages = array();
     24$messages['post'] = array(
     25        '',
     26        sprintf( __('Post updated. <a href="%s">View post</a>'), get_permalink($post_ID) ),
     27        __('Custom field updated.'),
     28        __('Custom field deleted.'),
     29        __('Post updated.'),
     30        isset($_GET['revision']) ? sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
     31        sprintf( __('Post published. <a href="%s">View post</a>'), get_permalink($post_ID) ),
     32        __('Post saved.'),
     33        sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ),
     34        // translators: Publish box date format, see http://php.net/date - Same as in meta-boxes.php
     35        sprintf( __('Post scheduled for: <b>%1$s</b>. <a target="_blank" href="%2$s">Preview post</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID) ),
     36        sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) )
     37);
     38$messages['page'] = array(
     39        '',
     40        sprintf( __('Page updated. <a href="%s">View page</a>'), get_permalink($post_ID) ),
     41        __('Custom field updated.'),
     42        __('Custom field deleted.'),
     43        sprintf( __('Page published. <a href="%s">View page</a>'), get_permalink($post_ID) ),
     44        isset($_GET['revision']) ? sprintf( __('Page restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
     45        sprintf( __('Page submitted. <a target="_blank" href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ),
     46        // translators: Publish box date format, see http://php.net/date - Same as in meta-boxes.php
     47        sprintf( __('Page scheduled for: <b>%1$s</b>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID) ),
     48        sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) )
     49);
     50
    2251$message = false;
    2352if ( isset($_GET['message']) ) {
    2453        $_GET['message'] = absint( $_GET['message'] );
    25 
    26         switch ( $_GET['message'] ) {
    27                 case 1:
    28                         $message = sprintf( __('Post updated. <a href="%s">View post</a>'), get_permalink($post_ID) );
    29                         break;
    30                 case 2:
    31                         $message = __('Custom field updated.');
    32                         break;
    33                 case 3:
    34                         $message = __('Custom field deleted.');
    35                         break;
    36                 case 4:
    37                         $message = __('Post updated.');
    38                         break;
    39                 case 5:
    40                         if ( isset($_GET['revision']) )
    41                                 $message = sprintf( __('Post restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) );
    42                         break;
    43                 case 6:
    44                         $message = sprintf( __('Post published. <a href="%s">View post</a>'), get_permalink($post_ID) );
    45                         break;
    46                 case 7:
    47                         $message = __('Post saved.');
    48                         break;
    49                 case 8:
    50                         $message = sprintf( __('Post submitted. <a target="_blank" href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
    51                         break;
    52                 case 9:
    53                         // translators: Publish box date formt, see http://php.net/date - Same as in meta-boxes.php
    54                         $message = sprintf( __('Post scheduled for: <b>%1$s</b>. <a target="_blank" href="%2$s">Preview post</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), get_permalink($post_ID) );
    55                         break;
    56                 case 10:
    57                         $message = sprintf( __('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), add_query_arg( 'preview', 'true', get_permalink($post_ID) ) );
    58                         break;
    59         }
     54        if ( isset($messages[$post_type][$_GET['message']]) )
     55                $message = $messages[$post_type][$_GET['message']];
     56        elseif ( !isset($messages[$post_type]) && isset($messages['post'][$_GET['message']]) )
     57                $message = $messages['post'][$_GET['message']];
    6058}
    6159
    6260$notice = false;
    6361if ( 0 == $post_ID ) {
    6462        $form_action = 'post';
     63        $nonce_action = 'add-' . $post_type;
    6564        $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
    6665        $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='" . esc_attr($temp_ID) . "' />";
    6766        $autosave = false;
    6867} else {
    6968        $form_action = 'editpost';
     69        $nonce_action = 'update-' . $post_type . '_' . $post_ID;
    7070        $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />";
    7171        $autosave = wp_get_post_autosave( $post_ID );
    7272
     
    8282        }
    8383}
    8484
     85$post_type_object = get_post_type_object($post_type);
     86$post_type_cap = $post_type_object->capability_type;
     87$form_post = 'post.php';
     88if ( 'page' == $post_type )
     89        $form_post = 'page.php';
     90
    8591// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
    8692require_once('includes/meta-boxes.php');
    8793
    8894add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $post_type, 'side', 'core');
    8995
    90 // all tag-style post taxonomies
     96// all tag-style taxonomies
    9197foreach ( get_object_taxonomies($post_type) as $tax_name ) {
    9298        if ( !is_taxonomy_hierarchical($tax_name) ) {
    9399                $taxonomy = get_taxonomy($tax_name);
     
    99105
    100106if ( is_object_in_taxonomy($post_type, 'category') )
    101107        add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
     108
     109if ( post_type_supports($post_type, 'page-attributes') )
     110        add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');
     111
    102112if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports($post_type, 'post-thumbnails') )
    103113        add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
     114
    104115if ( post_type_supports($post_type, 'excerpts') )
    105116        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
     117
    106118if ( post_type_supports($post_type, 'trackbacks') )
    107119        add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
     120
    108121if ( post_type_supports($post_type, 'custom-fields') )
    109122        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
     123
    110124do_action('dbx_post_advanced');
    111125if ( post_type_supports($post_type, 'comments') )
    112126        add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
     
    115129        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
    116130
    117131if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) )
    118         add_meta_box('slugdiv', __('Post Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
     132        add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
    119133
    120134$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
    121135if ( $post->post_author && !in_array($post->post_author, $authors) )
    122136        $authors[] = $post->post_author;
    123137if ( $authors && count( $authors ) > 1 )
    124         add_meta_box('authordiv', __('Post Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
     138        add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
    125139
    126140if ( 0 < $post_ID && wp_get_post_revisions( $post_ID ) )
    127         add_meta_box('revisionsdiv', __('Post Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
     141        add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', $post_type, 'normal', 'core');
    128142
    129143do_action('do_meta_boxes', $post_type, 'normal', $post);
    130144do_action('do_meta_boxes', $post_type, 'advanced', $post);
    131145do_action('do_meta_boxes', $post_type, 'side', $post);
    132146
    133147require_once('admin-header.php');
    134 
    135148?>
    136149
    137150<div class="wrap">
     
    143156<?php if ( $message ) : ?>
    144157<div id="message" class="updated"><p><?php echo $message; ?></p></div>
    145158<?php endif; ?>
    146 <form name="post" action="post.php" method="post" id="post">
    147 <?php
    148 
    149 if ( 0 == $post_ID)
    150         wp_nonce_field('add-post');
    151 else
    152         wp_nonce_field('update-post_' .  $post_ID);
    153 
    154 ?>
    155 
     159<form name="post" action="<?php echo $form_post; ?>" method="post" id="post">
     160<?php wp_nonce_field($nonce_action); ?>
    156161<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
    157162<input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr($form_action) ?>" />
    158163<input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr($form_action) ?>" />
     
    169174<div id="poststuff" class="metabox-holder<?php echo 2 == $screen_layout_columns ? ' has-right-sidebar' : ''; ?>">
    170175<div id="side-info-column" class="inner-sidebar">
    171176
    172 <?php do_action('submitpost_box'); ?>
    173 
    174 <?php $side_meta_boxes = do_meta_boxes($post_type, 'side', $post); ?>
     177<?php
     178('page' == $post_type) ? do_action('submitpage_box') : do_action('submitpost_box');
     179$side_meta_boxes = do_meta_boxes($post_type, 'side', $post);
     180?>
    175181</div>
    176182
    177183<div id="post-body">
     
    184190<div class="inside">
    185191<?php
    186192$sample_permalink_html = get_sample_permalink_html($post->ID);
    187 if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) ) { ?>
     193if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_' . $post_type_cap . 's' ) ) ) { ?>
    188194        <div id="edit-slug-box">
    189195<?php
    190196        if ( ! empty($post->ID) && ! empty($sample_permalink_html) ) :
     
    230236
    231237do_meta_boxes($post_type, 'normal', $post);
    232238
    233 do_action('edit_form_advanced');
     239( 'page' == $post_type ) ? do_action('edit_page_form') : do_action('edit_form_advanced');
    234240
    235241do_meta_boxes($post_type, 'advanced', $post);
    236242
  • wp-admin/page-new.php

     
    88
    99/** WordPress Administration Bootstrap */
    1010require_once('admin.php');
     11
     12$post_type = 'page';
     13
    1114$title = __('Add New Page');
    1215$parent_file = 'edit-pages.php';
    1316$editing = true;
     
    2326        $action = 'post';
    2427        $post = get_default_page_to_edit();
    2528
    26         include('edit-page-form.php');
     29        include('edit-form-advanced.php');
    2730}
    2831
    2932include('admin-footer.php');
  • wp-admin/page.php

     
    122122                wp_enqueue_script('autosave');
    123123        }
    124124
    125         include('edit-page-form.php');
     125        $post_type = $post->post_type;
     126        include('edit-form-advanced.php');
    126127        break;
    127128
    128129case 'editattachment':