WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/30/2008 11:33:02 PM (12 years ago)
Author:
mdawaffe
Message:

First pass at draggable meta boxes. Meta boxes must now be defined before the first call to do_meta_boxes(). Meta boxes can be dragged from any set of meta boxes to any set of meta boxes on the same page, including the sidebar. Some funkiness with Opera. Untested in IE

File:
1 edited

Legend:

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

    r8124 r8219  
    3434<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
    3535<?php endif; ?>
     36
     37<?php
     38
     39// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
     40
     41function post_tags_meta_box($post) {
     42?>
     43<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>
     44<div id="tagchecklist"></div>
     45<?php
     46}
     47add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'normal', 'core');
     48
     49function post_categories_meta_box($post) {
     50?>
     51<div id="category-adder" class="wp-hidden-children">
     52    <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
     53    <p id="category-add" class="wp-hidden-child">
     54        <label class="hidden" for="newcat"><?php _e( 'Add New Category' ); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" aria-required="true"/>
     55        <label class="hidden" for="newcat_parent"><?php _e('Parent category'); ?>:</label><?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
     56        <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" />
     57        <?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
     58        <span id="category-ajax-response"></span>
     59    </p>
     60</div>
     61
     62<ul id="category-tabs">
     63    <li class="ui-tabs-selected"><a href="#categories-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
     64    <li class="wp-no-js-hidden"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
     65</ul>
     66
     67<div id="categories-pop" class="ui-tabs-panel" style="display: none;">
     68    <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
     69        <?php $popular_ids = wp_popular_terms_checklist('category'); ?>
     70    </ul>
     71</div>
     72
     73<div id="categories-all" class="ui-tabs-panel">
     74    <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
     75        <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
     76    </ul>
     77</div>
     78<?php
     79}
     80add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'normal', 'core');
     81
     82function post_excerpt_meta_box($post) {
     83?>
     84<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>
     85<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>
     86<?php
     87}
     88add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'advanced', 'core');
     89
     90function post_trackback_meta_box($post) {
     91    $form_trackback = '<input type="text" name="trackback_url" style="width: 415px" id="trackback" tabindex="7" value="'. attribute_escape( str_replace("\n", ' ', $post->to_ping) ) .'" />';
     92    if ('' != $post->pinged) {
     93        $pings = '<p>'. __('Already pinged:') . '</p><ul>';
     94        $already_pinged = explode("\n", trim($post->pinged));
     95        foreach ($already_pinged as $pinged_url) {
     96            $pings .= "\n\t<li>" . wp_specialchars($pinged_url) . "</li>";
     97        }
     98        $pings .= '</ul>';
     99    }
     100
     101?>
     102<p><label for="trackback"><?php _e('Send trackbacks to:'); ?></label> <?php echo $form_trackback; ?><br /> (<?php _e('Separate multiple URLs with spaces'); ?>)</p>
     103<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>
     104<?php
     105if ( ! empty($pings) )
     106    echo $pings;
     107}
     108add_meta_box('trackbacksdiv', __('Trackbacks'), 'post_trackback_meta_box', 'post', 'advanced', 'core');
     109
     110function post_custom_meta_box($post) {
     111?>
     112<div id="postcustomstuff">
     113<table cellpadding="3">
     114<?php
     115$metadata = has_meta($post->ID);
     116list_meta($metadata);
     117?>
     118
     119</table>
     120<?php
     121    meta_form();
     122?>
     123<div id="ajax-response"></div>
     124</div>
     125<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>
     126<?php
     127}
     128add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', 'advanced', 'core');
     129
     130do_action('dbx_post_advanced');
     131
     132function post_comment_status_meta_box($post) {
     133?>
     134<input name="advanced_view" type="hidden" value="1" />
     135<p><label for="comment_status" class="selectit">
     136<input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($post->comment_status, 'open'); ?> />
     137<?php _e('Allow Comments') ?></label></p>
     138<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>
     139<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>
     140<?php
     141}
     142add_meta_box('commentstatusdiv', __('Comments &amp; Pings'), 'post_comment_status_meta_box', 'post', 'advanced', 'core');
     143
     144function post_password_meta_box($post) {
     145?>
     146<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>
     147<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>
     148<?php
     149}
     150add_meta_box('passworddiv', __('Password Protect This Post'), 'post_password_meta_box', 'post', 'advanced', 'core');
     151
     152function post_slug_meta_box($post) {
     153?>
     154<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 ); ?>" />
     155<?php
     156}
     157add_meta_box('slugdiv', __('Post Slug'), 'post_slug_meta_box', 'post', 'advanced', 'core');
     158
     159$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
     160if ( $post->post_author && !in_array($post->post_author, $authors) )
     161    $authors[] = $post->post_author;
     162if ( $authors && count( $authors ) > 1 ) :
     163function post_author_meta_box($post) {
     164    global $current_user, $user_ID;
     165    $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
     166    if ( $post->post_author && !in_array($post->post_author, $authors) )
     167        $authors[] = $post->post_author;
     168?>
     169<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) ); ?>
     170<?php
     171}
     172add_meta_box('authordiv', __('Post Author'), 'post_author_meta_box', 'post', 'advanced', 'core');
     173endif;
     174
     175if ( isset($post_ID) && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) :
     176function post_revisions_meta_box($post) {
     177    wp_list_post_revisions();
     178}
     179add_meta_box('revisionsdiv', __('Post Revisions'), 'post_revisions_meta_box', 'post', 'advanced', 'core');
     180endif;
     181
     182?>
    36183
    37184<form name="post" action="post.php" method="post" id="post">
     
    81228
    82229<div id="poststuff">
     230
     231<div id="side-info-column">
    83232
    84233<div class="submitbox" id="submitpost">
     
    173322</p>
    174323
     324</div>
     325
    175326<div class="side-info">
    176327<h5><?php _e('Related') ?></h5>
     
    193344
    194345<?php do_action('submitpost_box'); ?>
     346
     347<?php do_meta_boxes('post', 'side', $post); ?>
     348
    195349</div>
    196350
     
    218372<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
    219373<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
     374<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
    220375</div>
    221376
     
    223378<?php echo $form_prevstatus ?>
    224379
    225 <?php
    226 function post_tags_meta_box($post) {
    227 ?>
    228 <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>
    229 <div id="tagchecklist"></div>
    230 <?php
    231 }
    232 add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'normal', 'core');
    233 
    234 function post_categories_meta_box($post) {
    235 ?>
    236 <div id="category-adder" class="wp-hidden-children">
    237     <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
    238     <p id="category-add" class="wp-hidden-child">
    239         <label class="hidden" for="newcat"><?php _e( 'Add New Category' ); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" aria-required="true"/>
    240         <label class="hidden" for="newcat_parent"><?php _e('Parent category'); ?>:</label><?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
    241         <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" />
    242         <?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
    243         <span id="category-ajax-response"></span>
    244     </p>
    245 </div>
    246 
    247 <ul id="category-tabs">
    248     <li class="ui-tabs-selected"><a href="#categories-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
    249     <li class="wp-no-js-hidden"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
    250 </ul>
    251 
    252 <div id="categories-pop" class="ui-tabs-panel" style="display: none;">
    253     <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
    254         <?php $popular_ids = wp_popular_terms_checklist('category'); ?>
    255     </ul>
    256 </div>
    257 
    258 <div id="categories-all" class="ui-tabs-panel">
    259     <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    260         <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
    261     </ul>
    262 </div>
    263 <?php
    264 }
    265 add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'normal', 'core');
    266 ?>
    267 
    268380<?php do_meta_boxes('post', 'normal', $post); ?>
    269381
     
    273385
    274386<?php
    275 function post_excerpt_meta_box($post) {
    276 ?>
    277 <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>
    278 <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>
    279 <?php
    280 }
    281 add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'advanced', 'core');
    282 
    283 function post_trackback_meta_box($post) {
    284     $form_trackback = '<input type="text" name="trackback_url" style="width: 415px" id="trackback" tabindex="7" value="'. attribute_escape( str_replace("\n", ' ', $post->to_ping) ) .'" />';
    285     if ('' != $post->pinged) {
    286         $pings = '<p>'. __('Already pinged:') . '</p><ul>';
    287         $already_pinged = explode("\n", trim($post->pinged));
    288         foreach ($already_pinged as $pinged_url) {
    289             $pings .= "\n\t<li>" . wp_specialchars($pinged_url) . "</li>";
    290         }
    291         $pings .= '</ul>';
    292     }
    293 
    294 ?>
    295 <p><label for="trackback"><?php _e('Send trackbacks to:'); ?></label> <?php echo $form_trackback; ?><br /> (<?php _e('Separate multiple URLs with spaces'); ?>)</p>
    296 <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>
    297 <?php
    298 if ( ! empty($pings) )
    299     echo $pings;
    300 }
    301 add_meta_box('trackbacksdiv', __('Trackbacks'), 'post_trackback_meta_box', 'post', 'advanced', 'core');
    302 
    303 function post_custom_meta_box($post) {
    304 ?>
    305 <div id="postcustomstuff">
    306 <table cellpadding="3">
    307 <?php
    308 $metadata = has_meta($post->ID);
    309 list_meta($metadata);
    310 ?>
    311 
    312 </table>
    313 <?php
    314     meta_form();
    315 ?>
    316 <div id="ajax-response"></div>
    317 </div>
    318 <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>
    319 <?php
    320 }
    321 add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', 'post', 'advanced', 'core');
    322 
    323 do_action('dbx_post_advanced');
    324 
    325 function post_comment_status_meta_box($post) {
    326 ?>
    327 <input name="advanced_view" type="hidden" value="1" />
    328 <p><label for="comment_status" class="selectit">
    329 <input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($post->comment_status, 'open'); ?> />
    330 <?php _e('Allow Comments') ?></label></p>
    331 <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>
    332 <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>
    333 <?php
    334 }
    335 add_meta_box('commentstatusdiv', __('Comments &amp; Pings'), 'post_comment_status_meta_box', 'post', 'advanced', 'core');
    336 
    337 function post_password_meta_box($post) {
    338 ?>
    339 <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>
    340 <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>
    341 <?php
    342 }
    343 add_meta_box('passworddiv', __('Password Protect This Post'), 'post_password_meta_box', 'post', 'advanced', 'core');
    344 
    345 function post_slug_meta_box($post) {
    346 ?>
    347 <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 ); ?>" />
    348 <?php
    349 }
    350 add_meta_box('slugdiv', __('Post Slug'), 'post_slug_meta_box', 'post', 'advanced', 'core');
    351 
    352 $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
    353 if ( $post->post_author && !in_array($post->post_author, $authors) )
    354     $authors[] = $post->post_author;
    355 if ( $authors && count( $authors ) > 1 ) :
    356 function post_author_meta_box($post) {
    357     global $current_user, $user_ID;
    358     $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
    359     if ( $post->post_author && !in_array($post->post_author, $authors) )
    360         $authors[] = $post->post_author;
    361 ?>
    362 <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) ); ?>
    363 <?php
    364 }
    365 add_meta_box('authordiv', __('Post Author'), 'post_author_meta_box', 'post', 'advanced', 'core');
    366 endif;
    367 
    368 if ( isset($post_ID) && 0 < $post_ID && wp_get_post_revisions( $post_ID ) ) :
    369 function post_revisions_meta_box($post) {
    370     wp_list_post_revisions();
    371 }
    372 add_meta_box('revisionsdiv', __('Post Revisions'), 'post_revisions_meta_box', 'post', 'advanced', 'core');
    373 endif;
    374387
    375388do_meta_boxes('post', 'advanced', $post);
    376389
    377390do_action('dbx_post_sidebar');
     391
    378392?>
    379393</div>
Note: See TracChangeset for help on using the changeset viewer.