WordPress.org

Make WordPress Core

Changeset 7930


Ignore:
Timestamp:
05/14/2008 08:22:01 AM (10 years ago)
Author:
ryan
Message:

Add default edit post meta boxes via API. see #6964

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r7919 r7930  
    226226<?php echo $form_prevstatus ?>
    227227
    228 <div id="tagsdiv" class="postbox <?php echo postbox_classes('tagsdiv', 'post'); ?>">
    229 <h3><?php _e('Tags'); ?></h3>
    230 <div class="inside">
    231 <p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post_ID ); ?>" /></p>
     228<?php
     229function post_tags_meta_box($post) {
     230?>
     231<p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
    232232<div id="tagchecklist"></div>
    233 </div>
    234 </div>
    235 
    236 <div id="categorydiv" class="postbox <?php echo postbox_classes('categorydiv', 'post'); ?>">
    237 <h3><?php _e('Categories') ?></h3>
    238 <div class="inside">
    239 
     233<?php
     234}
     235add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'normal', 'core');
     236
     237function post_categories_meta_box($post) {
     238?>
    240239<div id="category-adder" class="wp-hidden-children">
    241240    <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
     
    262261<div id="categories-all" class="ui-tabs-panel">
    263262    <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    264         <?php wp_category_checklist($post_ID) ?>
     263        <?php wp_category_checklist($post->ID) ?>
    265264    </ul>
    266265</div>
    267 
    268 </div>
    269 </div>
     266<?php
     267}
     268add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'normal', 'core');
     269?>
    270270
    271271<?php do_meta_boxes('post', 'normal', $post); ?>
     
    275275<h2><?php _e('Advanced Options'); ?></h2>
    276276
    277 <div id="postexcerpt" class="postbox <?php echo postbox_classes('postexcerpt', 'post'); ?>">
    278 <h3><?php _e('Excerpt') ?></h3>
    279 <div class="inside"><label class="hidden" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt ?></textarea>
     277<?php
     278function post_excerpt_meta_box($post) {
     279?>
     280<label class="hidden" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt"><?php echo $post->post_excerpt ?></textarea>
    280281<p><?php _e('Excerpts are optional hand-crafted summaries of your content. You can <a href="http://codex.wordpress.org/Template_Tags/the_excerpt" target="_blank">use them in your template</a>'); ?></p>
    281 </div>
    282 </div>
    283 
    284 <div id="trackbacksdiv" class="postbox <?php echo postbox_classes('trackbacksdiv', 'post'); ?>">
    285 <h3><?php _e('Trackbacks') ?></h3>
    286 <div class="inside">
     282<?php
     283}
     284add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'advanced', 'core');
     285
     286function post_trackback_meta_box($post) {
     287?>
    287288<p><label for="trackback"><?php _e('Send trackbacks to:'); ?></label> <?php echo $form_trackback; ?><br /> (<?php _e('Separate multiple URLs with spaces'); ?>)</p>
    288289<p><?php _e('Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. If you link other WordPress blogs they&#8217;ll be notified automatically using <a href="http://codex.wordpress.org/Introduction_to_Blogging#Managing_Comments" target="_blank">pingbacks</a>, no other action necessary.'); ?></p>
     
    290291if ( ! empty($pings) )
    291292    echo $pings;
    292 ?>
    293 </div>
    294 </div>
    295 
    296 <div id="postcustom" class="postbox <?php echo postbox_classes('postcustom', 'post'); ?>">
    297 <h3><?php _e('Custom Fields') ?></h3>
    298 <div class="inside">
     293}
     294add_meta_box('trackbacksdiv', __('Trackbacks'), 'post_trackback_meta_box', 'post', 'advanced', 'core');
     295
     296function post_custom_meta_box($post) {
     297?>
    299298<div id="postcustomstuff">
    300299<table cellpadding="3">
    301300<?php
    302 $metadata = has_meta($post_ID);
     301$metadata = has_meta($post->ID);
    303302list_meta($metadata);
    304303?>
     
    311310</div>
    312311<p><?php _e('Custom fields can be used to add extra metadata to a post that you can <a href="http://codex.wordpress.org/Using_Custom_Fields" target="_blank">use in your theme</a>.'); ?></p>
    313 </div>
    314 </div>
    315 
    316 <?php do_action('dbx_post_advanced'); ?>
    317 
    318 <div id="commentstatusdiv" class="postbox <?php echo postbox_classes('commentstatusdiv', 'post'); ?>">
    319 <h3><?php _e('Comments &amp; Pings') ?></h3>
    320 <div class="inside">
     312<?php
     313}
     314add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', 'advanced', 'core');
     315
     316do_action('dbx_post_advanced');
     317
     318function post_comment_status_meta_box($post) {
     319?>
    321320<input name="advanced_view" type="hidden" value="1" />
    322321<p><label for="comment_status" class="selectit">
     
    325324<p><label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked($post->ping_status, 'open'); ?> /> <?php _e('Allow Pings') ?></label></p>
    326325<p><?php _e('These settings apply to this post only. &#8220;Pings&#8221; are <a href="http://codex.wordpress.org/Introduction_to_Blogging#Managing_Comments" target="_blank">trackbacks and pingbacks</a>.'); ?></p>
    327 </div>
    328 </div>
    329 
    330 <div id="passworddiv" class="postbox <?php echo postbox_classes('passworddiv', 'post'); ?>">
    331 <h3><?php _e('Password Protect This Post') ?></h3>
    332 <div class="inside">
     326<?php
     327}
     328add_meta_box('commentstatusdiv', __('Comments &amp; Pings'), 'post_comment_status_meta_box', 'post', 'advanced', 'core');
     329
     330function post_password_meta_box($post) {
     331?>
    333332<p><label class="hidden" for="post_password"><?php _e('Password Protect This Post') ?></label><input name="post_password" type="text" size="25" id="post_password" value="<?php echo attribute_escape( $post->post_password ); ?>" /></p>
    334333<p><?php _e('Setting a password will require people who visit your blog to enter the above password to view this post and its comments.'); ?></p>
    335 </div>
    336 </div>
    337 
    338 <div id="slugdiv" class="postbox <?php echo postbox_classes('slugdiv', 'post'); ?>">
    339 <h3><?php _e('Post Slug') ?></h3>
    340 <div class="inside">
     334<?php
     335}
     336add_meta_box('passworddiv', __('Password Protect This Post'), 'post_password_meta_box', 'post', 'advanced', 'core');
     337
     338function post_slug_meta_box($post) {
     339?>
    341340<label class="hidden" for="post_name"><?php _e('Post Slug') ?></label><input name="post_name" type="text" size="13" id="post_name" value="<?php echo attribute_escape( $post->post_name ); ?>" />
    342 </div>
    343 </div>
    344 
    345 <?php
     341<?php
     342}
     343add_meta_box('slugdiv', __('Post Slug'), 'post_slug_meta_box', 'post', 'advanced', 'core');
     344
    346345$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
    347346if ( $post->post_author && !in_array($post->post_author, $authors) )
    348347    $authors[] = $post->post_author;
    349348if ( $authors && count( $authors ) > 1 ) :
    350 ?>
    351 <div id="authordiv" class="postbox <?php echo postbox_classes('authordiv', 'post'); ?>">
    352 <h3><?php _e('Post Author'); ?></h3>
    353 <div class="inside">
     349function post_author_meta_box($post) {
     350?>
    354351<label class="hidden" for="post_author_override"><?php _e('Post Author'); ?></label><?php wp_dropdown_users( array('include' => $authors, 'name' => 'post_author_override', 'selected' => empty($post_ID) ? $user_ID : $post->post_author) ); ?>
    355 </div>
    356 </div>
    357 <?php endif; ?>
    358 
    359 <?php if ( isset($post_ID) && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) : ?>
    360 <div id="revisionsdiv" class="postbox <?php echo postbox_classes('revisionsdiv', 'post'); ?>">
    361 <h3><?php _e('Post Revisions'); ?></h3>
    362 <div class="inside">
    363 <?php wp_list_post_revisions(); ?>
    364 </div>
    365 </div>
    366 <?php endif; ?>
    367 
    368 <?php do_meta_boxes('post', 'advanced', $post); ?>
    369 
    370 <?php do_action('dbx_post_sidebar'); ?>
     352<?php
     353}
     354add_meta_box('authordiv', __('Post Author'), 'post_author_meta_box', 'post', 'advanced', 'core');
     355endif;
     356
     357if ( isset($post_ID) && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) :
     358function post_revisions_meta_box($post) {
     359    wp_list_post_revisions();
     360}
     361add_meta_box('revisionsdiv', __('Post Revisions'), 'post_revisions_meta_box', 'post', 'advanced', 'core');
     362endif;
     363
     364do_meta_boxes('post', 'advanced', $post);
     365
     366do_action('dbx_post_sidebar');
     367?>
    371368</div>
    372369</div>
  • trunk/wp-admin/includes/template.php

    r7911 r7930  
    10421042 * @param string $page The type of edit page on which to show the box (post, page, link)
    10431043 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
     1044 * @param string $priority The priority within the context where the boxes should show ('high', 'low')
    10441045 */
    1045 function add_meta_box($id, $title, $callback, $page, $context = 'advanced') {
     1046function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') {
    10461047    global $wp_meta_boxes;
    10471048
     1049   
    10481050    if  ( !isset($wp_meta_boxes) )
    10491051        $wp_meta_boxes = array();
     
    10531055        $wp_meta_boxes[$page][$context] = array();
    10541056
    1055     $wp_meta_boxes[$page][$context][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     1057    foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
     1058        if ( !isset($wp_meta_boxes[$page][$context][$a_priority][$id]) )
     1059            continue;
     1060        // If a core box was previously added or removed by a plugin, don't add.
     1061        if ( 'core' == $priority ) {
     1062            // If core box previously deleted, don't add
     1063            if ( false === $wp_meta_boxes[$page][$context][$a_priority][$id] )
     1064                return;
     1065            // If box was added with default priority, give it core priority to maintain sort order
     1066            if ( 'default' == $a_priority ) {
     1067                $wp_meta_boxes[$page][$context]['core'][$id] = $wp_meta_boxes[$page][$context]['default'][$id];
     1068                unset($wp_meta_boxes[$page][$context]['default'][$id]);
     1069            }
     1070            return;
     1071        }
     1072        // If no priority given and id already present, use existing priority
     1073        if ( empty($priority) )
     1074            $priority = $a_priority;
     1075        // An id can be in only one priority
     1076        if ( $priority != $a_priority )
     1077            unset($wp_meta_boxes[$page][$context][$a_priority][$id]);
     1078    }
     1079
     1080    if ( empty($priority) )
     1081        $priority = low;
     1082
     1083    if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
     1084        $wp_meta_boxes[$page][$context][$priority] = array();
     1085
     1086    $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
    10561087}
    10571088
     
    10591090    global $wp_meta_boxes;
    10601091
     1092    do_action('do_meta_boxes', $page, $context, $object);
     1093
    10611094    if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
    10621095        return;
    10631096
    1064     foreach ( (array) $wp_meta_boxes[$page][$context] as $box ) {
    1065         echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
    1066         echo "<h3>{$box['title']}</h3>\n";
    1067         echo '<div class="inside">' . "\n";
    1068         call_user_func($box['callback'], $object, $box);
    1069         echo "</div>\n";
    1070         echo "</div>\n";
    1071     }
     1097    foreach ( array('high', 'core', 'default', 'low') as $priority ) {
     1098        foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
     1099            if ( false === $box )
     1100                continue;
     1101            echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
     1102            echo "<h3>{$box['title']}</h3>\n";
     1103            echo '<div class="inside">' . "\n";
     1104            call_user_func($box['callback'], $object, $box);
     1105            echo "</div>\n";
     1106            echo "</div>\n";
     1107        }
     1108    }
     1109}
     1110
     1111/**
     1112 * remove_meta_box() - Remove a meta box from an edit form
     1113 *
     1114 * @since 2.6
     1115 *
     1116 * @param string $id String for use in the 'id' attribute of tags.
     1117 * @param string $page The type of edit page on which to show the box (post, page, link)
     1118 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
     1119 */
     1120function remove_meta_box($id, $page, $context) {
     1121    global $wp_meta_boxes;
     1122
     1123    if  ( !isset($wp_meta_boxes) )
     1124        $wp_meta_boxes = array();
     1125    if ( !isset($wp_meta_boxes[$page]) )
     1126        $wp_meta_boxes[$page] = array();
     1127    if ( !isset($wp_meta_boxes[$page][$context]) )
     1128        $wp_meta_boxes[$page][$context] = array();
     1129
     1130    foreach ( array('high', 'core', 'default', 'low') as $priority )
     1131        $wp_meta_boxes[$page][$context][$priority][$id] = false;
    10721132}
    10731133
Note: See TracChangeset for help on using the changeset viewer.