3 * Template WordPress Administration API.
5 * A Big Mess. Also some neat functions that are nicely written.
8 * @subpackage Administration
13 // Category Checklists
17 * {@internal Missing Short Description}}
21 class Walker_Category_Checklist extends Walker {
22 var $tree_type = 'category';
23 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
25 function start_lvl(&$output, $depth, $args) {
26 $indent = str_repeat("\t", $depth);
27 $output .= "$indent<ul class='children'>\n";
30 function end_lvl(&$output, $depth, $args) {
31 $indent = str_repeat("\t", $depth);
32 $output .= "$indent</ul>\n";
35 function start_el(&$output, $category, $depth, $args) {
37 if ( empty($taxonomy) )
38 $taxonomy = 'category';
40 if ( $taxonomy == 'category' )
41 $name = 'post_category';
43 $name = 'tax_input['.$taxonomy.']';
45 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
46 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
49 function end_el(&$output, $category, $depth, $args) {
55 * {@internal Missing Short Description}}
59 * @param unknown_type $post_id
60 * @param unknown_type $descendants_and_self
61 * @param unknown_type $selected_cats
62 * @param unknown_type $popular_cats
64 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
65 wp_terms_checklist($post_id,
67 'taxonomy' => 'category',
68 'descendants_and_self' => $descendants_and_self,
69 'selected_cats' => $selected_cats,
70 'popular_cats' => $popular_cats,
72 'checked_ontop' => $checked_ontop
77 * Taxonomy independent version of wp_category_checklist
84 function wp_terms_checklist($post_id = 0, $args = array()) {
86 'descendants_and_self' => 0,
87 'selected_cats' => false,
88 'popular_cats' => false,
90 'taxonomy' => 'category',
91 'checked_ontop' => true
93 extract( wp_parse_args($args, $defaults), EXTR_SKIP );
95 if ( empty($walker) || !is_a($walker, 'Walker') )
96 $walker = new Walker_Category_Checklist;
98 $descendants_and_self = (int) $descendants_and_self;
100 $args = array('taxonomy' => $taxonomy);
102 $tax = get_taxonomy($taxonomy);
103 $args['disabled'] = !current_user_can($tax->cap->assign_terms);
105 if ( is_array( $selected_cats ) )
106 $args['selected_cats'] = $selected_cats;
108 $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
110 $args['selected_cats'] = array();
112 if ( is_array( $popular_cats ) )
113 $args['popular_cats'] = $popular_cats;
115 $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
117 if ( $descendants_and_self ) {
118 $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
119 $self = get_term( $descendants_and_self, $taxonomy );
120 array_unshift( $categories, $self );
122 $categories = (array) get_terms($taxonomy, array('get' => 'all'));
125 if ( $checked_ontop ) {
126 // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
127 $checked_categories = array();
128 $keys = array_keys( $categories );
130 foreach( $keys as $k ) {
131 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
132 $checked_categories[] = $categories[$k];
133 unset( $categories[$k] );
137 // Put checked cats on top
138 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
140 // Then the rest of them
141 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
145 * {@internal Missing Short Description}}
149 * @param unknown_type $taxonomy
150 * @param unknown_type $default
151 * @param unknown_type $number
152 * @param unknown_type $echo
155 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
159 $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids'));
161 $checked_terms = array();
163 $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
165 $tax = get_taxonomy($taxonomy);
166 if ( ! current_user_can($tax->cap->assign_terms) )
167 $disabled = 'disabled="disabled"';
171 $popular_ids = array();
172 foreach ( (array) $terms as $term ) {
173 $popular_ids[] = $term->term_id;
174 if ( !$echo ) // hack for AJAX use
176 $id = "popular-$taxonomy-$term->term_id";
177 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
180 <li id="<?php echo $id; ?>" class="popular-category">
181 <label class="selectit">
182 <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/>
183 <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?>
193 * {@internal Missing Short Description}}
197 * @param unknown_type $link_id
199 function wp_link_category_checklist( $link_id = 0 ) {
203 $checked_categories = wp_get_link_cats( $link_id );
204 // No selected categories, strange
205 if ( ! count( $checked_categories ) )
206 $checked_categories[] = $default;
208 $checked_categories[] = $default;
211 $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
213 if ( empty( $categories ) )
216 foreach ( $categories as $category ) {
217 $cat_id = $category->term_id;
218 $name = esc_html( apply_filters( 'the_category', $category->name ) );
219 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
220 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
224 // adds hidden fields with the data for use in the inline editor for posts and pages
226 * {@internal Missing Short Description}}
230 * @param unknown_type $post
232 function get_inline_data($post) {
233 $post_type_object = get_post_type_object($post->post_type);
234 if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) )
237 $title = esc_textarea( trim( $post->post_title ) );
240 <div class="hidden" id="inline_' . $post->ID . '">
241 <div class="post_title">' . $title . '</div>
242 <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div>
243 <div class="post_author">' . $post->post_author . '</div>
244 <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
245 <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
246 <div class="_status">' . esc_html( $post->post_status ) . '</div>
247 <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
248 <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
249 <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
250 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
251 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
252 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
253 <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
255 if ( $post_type_object->hierarchical )
256 echo '<div class="post_parent">' . $post->post_parent . '</div>';
258 if ( $post->post_type == 'page' )
259 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
261 if ( $post_type_object->hierarchical )
262 echo '<div class="menu_order">' . $post->menu_order . '</div>';
264 $taxonomy_names = get_object_taxonomies( $post->post_type );
265 foreach ( $taxonomy_names as $taxonomy_name) {
266 $taxonomy = get_taxonomy( $taxonomy_name );
268 if ( $taxonomy->hierarchical && $taxonomy->show_ui )
269 echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
270 elseif ( $taxonomy->show_ui )
271 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
274 if ( !$post_type_object->hierarchical )
275 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
277 if ( post_type_supports( $post->post_type, 'post-formats' ) )
278 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
284 * {@internal Missing Short Description}}
288 * @param unknown_type $position
289 * @param unknown_type $checkbox
290 * @param unknown_type $mode
292 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
293 // allow plugin to replace the popup content
294 $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
296 if ( ! empty($content) ) {
301 if ( $mode == 'single' ) {
302 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
304 $wp_list_table = _get_list_table('WP_Comments_List_Table');
308 <form method="get" action="">
309 <?php if ( $table_row ) : ?>
310 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
312 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
314 <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
316 <div id="edithead" style="display:none;">
318 <label for="author"><?php _e('Name') ?></label>
319 <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
323 <label for="author-email"><?php _e('E-mail') ?></label>
324 <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
328 <label for="author-url"><?php _e('URL') ?></label>
329 <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
331 <div style="clear:both;"></div>
334 <div id="replycontainer">
336 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' );
337 wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
341 <p id="replysubmit" class="submit">
342 <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
343 <a href="#comments-form" class="save button-primary alignright" tabindex="104">
344 <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
345 <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
346 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
347 <span class="error" style="display:none;"></span>
351 <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
352 <input type="hidden" name="action" id="action" value="" />
353 <input type="hidden" name="comment_ID" id="comment_ID" value="" />
354 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
355 <input type="hidden" name="status" id="status" value="" />
356 <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
357 <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
358 <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
360 wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
361 if ( current_user_can( 'unfiltered_html' ) )
362 wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
364 <?php if ( $table_row ) : ?>
365 </td></tr></tbody></table>
374 * Output 'undo move to trash' text for comments
378 function wp_comment_trashnotice() {
380 <div class="hidden" id="trash-undo-holder">
381 <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
383 <div class="hidden" id="spam-undo-holder">
384 <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
390 * {@internal Missing Short Description}}
394 * @param unknown_type $meta
396 function list_meta( $meta ) {
400 <table id="list-table" style="display: none;">
403 <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
404 <th>' . __( 'Value' ) . '</th>
407 <tbody id="the-list" class="list:meta">
410 </table>'; //TBODY needed for list-manipulation JS
415 <table id="list-table">
418 <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
419 <th><?php _e( 'Value' ) ?></th>
422 <tbody id='the-list' class='list:meta'>
424 foreach ( $meta as $entry )
425 echo _list_meta_row( $entry, $count );
433 * {@internal Missing Short Description}}
437 * @param unknown_type $entry
438 * @param unknown_type $count
441 function _list_meta_row( $entry, &$count ) {
442 static $update_nonce = false;
444 if ( is_protected_meta( $entry['meta_key'], 'post' ) )
447 if ( !$update_nonce )
448 $update_nonce = wp_create_nonce( 'add-meta' );
453 $style = 'alternate';
457 if ( is_serialized( $entry['meta_value'] ) ) {
458 if ( is_serialized_string( $entry['meta_value'] ) ) {
459 // this is a serialized string, so we should display it
460 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
462 // this is a serialized array/object so we should NOT display it
468 $entry['meta_key'] = esc_attr($entry['meta_key']);
469 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
470 $entry['meta_id'] = (int) $entry['meta_id'];
472 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
474 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
475 $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta[{$entry['meta_id']}][key]'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' />";
477 $r .= "\n\t\t<div class='submit'>";
478 $r .= get_submit_button( __( 'Delete' ), "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta", "deletemeta[{$entry['meta_id']}]", false, array( 'tabindex' => '6' ) );
480 $r .= get_submit_button( __( 'Update' ), "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta" , 'updatemeta', false, array( 'tabindex' => '6' ) );
482 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
485 $r .= "\n\t\t<td><label class='screen-reader-text' for='meta[{$entry['meta_id']}][value]'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
490 * {@internal Missing Short Description}}
494 function meta_form() {
496 $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
497 $keys = $wpdb->get_col( "
501 HAVING meta_key NOT LIKE '\_%'
507 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
511 <th class="left"><label for="metakeyselect"><?php _ex( 'Name', 'meta name' ) ?></label></th>
512 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
518 <td id="newmetaleft" class="left">
519 <?php if ( $keys ) { ?>
520 <select id="metakeyselect" name="metakeyselect" tabindex="7">
521 <option value="#NONE#"><?php _e( '— Select —' ); ?></option>
524 foreach ( $keys as $key ) {
525 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
529 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
530 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
531 <span id="enternew"><?php _e('Enter new'); ?></span>
532 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
534 <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
537 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
540 <tr><td colspan="2" class="submit">
541 <?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'addmetasub', 'tabindex' => '9' ) ); ?>
542 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
551 * {@internal Missing Short Description}}
555 * @param unknown_type $edit
556 * @param unknown_type $for_post
557 * @param unknown_type $tab_index
558 * @param unknown_type $multi
560 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
561 global $wp_locale, $post, $comment;
564 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
566 $tab_index_attribute = '';
567 if ( (int) $tab_index > 0 )
568 $tab_index_attribute = " tabindex=\"$tab_index\"";
570 // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
572 $time_adj = current_time('timestamp');
573 $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
574 $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
575 $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
576 $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
577 $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
578 $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
579 $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
581 $cur_jj = gmdate( 'd', $time_adj );
582 $cur_mm = gmdate( 'm', $time_adj );
583 $cur_aa = gmdate( 'Y', $time_adj );
584 $cur_hh = gmdate( 'H', $time_adj );
585 $cur_mn = gmdate( 'i', $time_adj );
587 $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
588 for ( $i = 1; $i < 13; $i = $i +1 ) {
589 $monthnum = zeroise($i, 2);
590 $month .= "\t\t\t" . '<option value="' . $monthnum . '"';
592 $month .= ' selected="selected"';
593 $month .= '>' . $monthnum . '-' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
595 $month .= '</select>';
597 $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
598 $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
599 $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
600 $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
602 echo '<div class="timestamp-wrap">';
603 /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
604 printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
606 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
608 if ( $multi ) return;
611 foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
612 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
613 $cur_timeunit = 'cur_' . $timeunit;
614 echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
619 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
620 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
626 * {@internal Missing Short Description}}
630 * @param unknown_type $default
632 function page_template_dropdown( $default = '' ) {
633 $templates = get_page_templates();
635 foreach (array_keys( $templates ) as $template )
636 : if ( $default == $templates[$template] )
637 $selected = " selected='selected'";
640 echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
645 * {@internal Missing Short Description}}
649 * @param unknown_type $default
650 * @param unknown_type $parent
651 * @param unknown_type $level
654 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
655 global $wpdb, $post_ID;
656 $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
659 foreach ( $items as $item ) {
660 // A page cannot be its own parent.
661 if (!empty ( $post_ID ) ) {
662 if ( $item->ID == $post_ID ) {
666 $pad = str_repeat( ' ', $level * 3 );
667 if ( $item->ID == $default)
668 $current = ' selected="selected"';
672 echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
673 parent_dropdown( $default, $item->ID, $level +1 );
681 * {@internal Missing Short Description}}
685 * @param unknown_type $id
688 function the_attachment_links( $id = false ) {
690 $post = & get_post( $id );
692 if ( $post->post_type != 'attachment' )
695 $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
696 $attachment_data = wp_get_attachment_metadata( $id );
697 $thumb = isset( $attachment_data['thumb'] );
699 <form id="the-attachment-links">
702 <col class="widefat" />
704 <th scope="row"><?php _e( 'URL' ) ?></th>
705 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo esc_textarea( wp_get_attachment_url() ); ?></textarea></td>
707 <?php if ( $icon ) : ?>
709 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
710 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
713 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
714 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
718 <th scope="row"><?php _e( 'Link to file' ) ?></th>
719 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td>
722 <th scope="row"><?php _e( 'Link to page' ) ?></th>
723 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
733 * Print out <option> html elements for role selectors
737 * @param string $selected slug for the role that should be already selected
739 function wp_dropdown_roles( $selected = false ) {
743 $editable_roles = get_editable_roles();
745 foreach ( $editable_roles as $role => $details ) {
746 $name = translate_user_role($details['name'] );
747 if ( $selected == $role ) // preselect specified role
748 $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
750 $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
756 * {@internal Missing Short Description}}
760 * @param unknown_type $size
763 function wp_convert_hr_to_bytes( $size ) {
764 $size = strtolower($size);
765 $bytes = (int) $size;
766 if ( strpos($size, 'k') !== false )
767 $bytes = intval($size) * 1024;
768 elseif ( strpos($size, 'm') !== false )
769 $bytes = intval($size) * 1024 * 1024;
770 elseif ( strpos($size, 'g') !== false )
771 $bytes = intval($size) * 1024 * 1024 * 1024;
776 * {@internal Missing Short Description}}
780 * @param unknown_type $bytes
783 function wp_convert_bytes_to_hr( $bytes ) {
784 $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
785 $log = log( $bytes, 1024 );
787 $size = pow(1024, $log - $power);
788 return $size . $units[$power];
792 * {@internal Missing Short Description}}
798 function wp_max_upload_size() {
799 $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
800 $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
801 $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
806 * Outputs the form used by the importers to accept the data to be imported
810 * @param string $action The action attribute for the form.
812 function wp_import_upload_form( $action ) {
813 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
814 $size = wp_convert_bytes_to_hr( $bytes );
815 $upload_dir = wp_upload_dir();
816 if ( ! empty( $upload_dir['error'] ) ) :
817 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
818 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
821 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
823 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
824 <input type="file" id="upload" name="import" size="25" />
825 <input type="hidden" name="action" value="save" />
826 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
828 <?php submit_button( __('Upload file and import'), 'button' ); ?>
835 * Add a meta box to an edit form.
839 * @param string $id String for use in the 'id' attribute of tags.
840 * @param string $title Title of the meta box.
841 * @param string $callback Function that fills the box with the desired content. The function should echo its output.
842 * @param string|object $screen Optional. The screen on which to show the box (post, page, link). Defaults to current screen.
843 * @param string $context Optional. The context within the page where the boxes should show ('normal', 'advanced').
844 * @param string $priority Optional. The priority within the context where the boxes should show ('high', 'low').
846 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
847 global $wp_meta_boxes;
849 if ( empty( $screen ) )
850 $screen = get_current_screen();
851 elseif ( is_string( $screen ) )
852 $screen = convert_to_screen( $screen );
856 if ( !isset($wp_meta_boxes) )
857 $wp_meta_boxes = array();
858 if ( !isset($wp_meta_boxes[$page]) )
859 $wp_meta_boxes[$page] = array();
860 if ( !isset($wp_meta_boxes[$page][$context]) )
861 $wp_meta_boxes[$page][$context] = array();
863 foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
864 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
865 if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
868 // If a core box was previously added or removed by a plugin, don't add.
869 if ( 'core' == $priority ) {
870 // If core box previously deleted, don't add
871 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
873 // If box was added with default priority, give it core priority to maintain sort order
874 if ( 'default' == $a_priority ) {
875 $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
876 unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
880 // If no priority given and id already present, use existing priority
881 if ( empty($priority) ) {
882 $priority = $a_priority;
883 // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority.
884 } elseif ( 'sorted' == $priority ) {
885 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
886 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
887 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
889 // An id can be in only one priority and one context
890 if ( $priority != $a_priority || $context != $a_context )
891 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
895 if ( empty($priority) )
898 if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
899 $wp_meta_boxes[$page][$context][$priority] = array();
901 $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
905 * Meta-Box template function
909 * @param string|object $screen Screen identifier
910 * @param string $context box context
911 * @param mixed $object gets passed to the box callback function as first parameter
912 * @return int number of meta_boxes
914 function do_meta_boxes( $screen, $context, $object ) {
915 global $wp_meta_boxes;
916 static $already_sorted = false;
918 if ( empty( $screen ) )
919 $screen = get_current_screen();
920 elseif ( is_string( $screen ) )
921 $screen = convert_to_screen( $screen );
925 $hidden = get_hidden_meta_boxes( $screen );
927 printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
931 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
932 if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
933 foreach ( $sorted as $box_context => $ids ) {
934 foreach ( explode(',', $ids ) as $id ) {
935 if ( $id && 'dashboard_browser_nag' !== $id )
936 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
940 $already_sorted = true;
942 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
945 foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
946 if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
947 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
948 if ( false == $box || ! $box['title'] )
952 $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
953 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
954 if ( 'dashboard_browser_nag' != $box['id'] )
955 echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
956 echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
957 echo '<div class="inside">' . "\n";
958 call_user_func($box['callback'], $object, $box);
973 * Remove a meta box from an edit form.
977 * @param string $id String for use in the 'id' attribute of tags.
978 * @param string|object $screen The screen on which to show the box (post, page, link).
979 * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
981 function remove_meta_box($id, $screen, $context) {
982 global $wp_meta_boxes;
984 if ( empty( $screen ) )
985 $screen = get_current_screen();
986 elseif ( is_string( $screen ) )
987 $screen = convert_to_screen( $screen );
991 if ( !isset($wp_meta_boxes) )
992 $wp_meta_boxes = array();
993 if ( !isset($wp_meta_boxes[$page]) )
994 $wp_meta_boxes[$page] = array();
995 if ( !isset($wp_meta_boxes[$page][$context]) )
996 $wp_meta_boxes[$page][$context] = array();
998 foreach ( array('high', 'core', 'default', 'low') as $priority )
999 $wp_meta_boxes[$page][$context][$priority][$id] = false;
1003 * Add a new section to a settings page.
1005 * Part of the Settings API. Use this to define new settings sections for an admin page.
1006 * Show settings sections in your admin page callback function with do_settings_sections().
1007 * Add settings fields to your section with add_settings_field()
1009 * The $callback argument should be the name of a function that echoes out any
1010 * content you want to show at the top of the settings section before the actual
1011 * fields. It can output nothing if you want.
1015 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1017 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
1018 * @param string $title Formatted title of the section. Shown as the heading for the section.
1019 * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
1020 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
1022 function add_settings_section($id, $title, $callback, $page) {
1023 global $wp_settings_sections;
1025 if ( 'misc' == $page ) {
1026 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1030 if ( !isset($wp_settings_sections) )
1031 $wp_settings_sections = array();
1032 if ( !isset($wp_settings_sections[$page]) )
1033 $wp_settings_sections[$page] = array();
1034 if ( !isset($wp_settings_sections[$page][$id]) )
1035 $wp_settings_sections[$page][$id] = array();
1037 $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1041 * Add a new field to a section of a settings page
1043 * Part of the Settings API. Use this to define a settings field that will show
1044 * as part of a settings section inside a settings page. The fields are shown using
1045 * do_settings_fields() in do_settings-sections()
1047 * The $callback argument should be the name of a function that echoes out the
1048 * html input tags for this setting field. Use get_option() to retrieve existing
1053 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1055 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
1056 * @param string $title Formatted title of the field. Shown as the label for the field during output.
1057 * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
1058 * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
1059 * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
1060 * @param array $args Additional arguments
1062 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1063 global $wp_settings_fields;
1065 if ( 'misc' == $page ) {
1066 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1070 if ( !isset($wp_settings_fields) )
1071 $wp_settings_fields = array();
1072 if ( !isset($wp_settings_fields[$page]) )
1073 $wp_settings_fields[$page] = array();
1074 if ( !isset($wp_settings_fields[$page][$section]) )
1075 $wp_settings_fields[$page][$section] = array();
1077 $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1081 * Prints out all settings sections added to a particular settings page
1083 * Part of the Settings API. Use this in a settings page callback function
1084 * to output all the sections and fields that were added to that $page with
1085 * add_settings_section() and add_settings_field()
1087 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1088 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1091 * @param string $page The slug name of the page whos settings sections you want to output
1093 function do_settings_sections($page) {
1094 global $wp_settings_sections, $wp_settings_fields;
1096 if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
1099 foreach ( (array) $wp_settings_sections[$page] as $section ) {
1100 if ( $section['title'] )
1101 echo "<h3>{$section['title']}</h3>\n";
1102 call_user_func($section['callback'], $section);
1103 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
1105 echo '<table class="form-table">';
1106 do_settings_fields($page, $section['id']);
1112 * Print out the settings fields for a particular settings section
1114 * Part of the Settings API. Use this in a settings page to output
1115 * a specific section. Should normally be called by do_settings_sections()
1116 * rather than directly.
1118 * @global $wp_settings_fields Storage array of settings fields and their pages/sections
1122 * @param string $page Slug title of the admin page who's settings fields you want to show.
1123 * @param section $section Slug title of the settings section who's fields you want to show.
1125 function do_settings_fields($page, $section) {
1126 global $wp_settings_fields;
1128 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
1131 foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1132 echo '<tr valign="top">';
1133 if ( !empty($field['args']['label_for']) )
1134 echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
1136 echo '<th scope="row">' . $field['title'] . '</th>';
1138 call_user_func($field['callback'], $field['args']);
1145 * Register a settings error to be displayed to the user
1147 * Part of the Settings API. Use this to show messages to users about settings validation
1148 * problems, missing settings or anything else.
1150 * Settings errors should be added inside the $sanitize_callback function defined in
1151 * register_setting() for a given setting to give feedback about the submission.
1153 * By default messages will show immediately after the submission that generated the error.
1154 * Additional calls to settings_errors() can be used to show errors even when the settings
1155 * page is first accessed.
1159 * @global array $wp_settings_errors Storage array of errors registered during this pageload
1161 * @param string $setting Slug title of the setting to which this error applies
1162 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1163 * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
1164 * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
1166 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1167 global $wp_settings_errors;
1169 if ( !isset($wp_settings_errors) )
1170 $wp_settings_errors = array();
1173 'setting' => $setting,
1175 'message' => $message,
1178 $wp_settings_errors[] = $new_error;
1182 * Fetch settings errors registered by add_settings_error()
1184 * Checks the $wp_settings_errors array for any errors declared during the current
1185 * pageload and returns them.
1187 * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1188 * to the 'settings_errors' transient then those errors will be returned instead. This
1189 * is used to pass errors back across pageloads.
1191 * Use the $sanitize argument to manually re-sanitize the option before returning errors.
1192 * This is useful if you have errors or notices you want to show even when the user
1193 * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
1197 * @global array $wp_settings_errors Storage array of errors registered during this pageload
1199 * @param string $setting Optional slug title of a specific setting who's errors you want.
1200 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1201 * @return array Array of settings errors
1203 function get_settings_errors( $setting = '', $sanitize = FALSE ) {
1204 global $wp_settings_errors;
1206 // If $sanitize is true, manually re-run the sanitizisation for this option
1207 // This allows the $sanitize_callback from register_setting() to run, adding
1208 // any settings errors you want to show by default.
1210 sanitize_option( $setting, get_option($setting));
1212 // If settings were passed back from options.php then use them
1213 // Ignore transients if $sanitize is true, we don't want the old values anyway
1214 if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) {
1215 $settings_errors = get_transient('settings_errors');
1216 delete_transient('settings_errors');
1217 // Otherwise check global in case validation has been run on this pageload
1218 } elseif ( count( $wp_settings_errors ) ) {
1219 $settings_errors = $wp_settings_errors;
1224 // Filter the results to those of a specific setting if one was set
1226 foreach ( (array) $settings_errors as $key => $details )
1227 if ( $setting != $details['setting'] )
1228 unset( $settings_errors[$key] );
1230 return $settings_errors;
1234 * Display settings errors registered by add_settings_error()
1236 * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
1238 * This is called automatically after a settings page based on the Settings API is submitted.
1239 * Errors should be added during the validation callback function for a setting defined in register_setting()
1241 * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
1242 * on its current value.
1244 * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
1245 * if the user has already saved new values it will be hidden to avoid repeating messages already
1246 * shown in the default error reporting after submission. This is useful to show general errors like missing
1247 * settings when the user arrives at the settings page.
1251 * @param string $setting Optional slug title of a specific setting who's errors you want.
1252 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1253 * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
1255 function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
1257 if ($hide_on_update AND $_GET['settings-updated']) return;
1259 $settings_errors = get_settings_errors( $setting, $sanitize );
1261 if ( !is_array($settings_errors) ) return;
1264 foreach ( $settings_errors as $key => $details ) {
1265 $css_id = 'setting-error-' . $details['code'];
1266 $css_class = $details['type'] . ' settings-error';
1267 $output .= "<div id='$css_id' class='$css_class'> \n";
1268 $output .= "<p><strong>{$details['message']}</strong></p>";
1269 $output .= "</div> \n";
1275 * {@internal Missing Short Description}}
1279 * @param unknown_type $found_action
1281 function find_posts_div($found_action = '') {
1283 <div id="find-posts" class="find-box" style="display:none;">
1284 <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
1285 <div class="find-box-inside">
1286 <div class="find-box-search">
1287 <?php if ( $found_action ) { ?>
1288 <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
1291 <input type="hidden" name="affected" id="affected" value="" />
1292 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1293 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1294 <input type="text" id="find-posts-input" name="ps" value="" />
1295 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
1298 $post_types = get_post_types( array('public' => true), 'objects' );
1299 foreach ( $post_types as $post ) {
1300 if ( 'attachment' == $post->name )
1303 <input type="radio" name="find-posts-what" id="find-posts-<?php echo esc_attr($post->name); ?>" value="<?php echo esc_attr($post->name); ?>" <?php checked($post->name, 'post'); ?> />
1304 <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
1308 <div id="find-posts-response"></div>
1310 <div class="find-box-buttons">
1311 <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
1312 <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1319 * Display the post password.
1321 * The password is passed through {@link esc_attr()} to ensure that it
1322 * is safe for placing in an html attribute.
1327 function the_post_password() {
1329 if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
1333 * Get the post title.
1335 * The post title is fetched and if it is blank then a default string is
1339 * @param int $post_id The post id. If not supplied the global $post is used.
1340 * @return string The post title if set
1342 function _draft_or_post_title( $post_id = 0 ) {
1343 $title = get_the_title($post_id);
1344 if ( empty($title) )
1345 $title = __('(no title)');
1350 * Display the search query.
1352 * A simple wrapper to display the "s" parameter in a GET URI. This function
1353 * should only be used when {@link the_search_query()} cannot.
1359 function _admin_search_query() {
1360 echo isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
1364 * Generic Iframe header for use with Thickbox
1367 * @param string $title Title of the Iframe page.
1368 * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
1371 function iframe_header( $title = '', $limit_styles = false ) {
1372 show_admin_bar( false );
1373 global $hook_suffix, $current_user, $admin_body_class, $wp_locale;
1374 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
1376 $current_screen = get_current_screen();
1378 _wp_admin_html_begin();
1380 <title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title>
1382 wp_enqueue_style( 'colors' );
1384 <script type="text/javascript">
1386 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
1387 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1388 var userSettings = {
1389 'url': '<?php echo SITECOOKIEPATH; ?>',
1390 'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>',
1391 'time':'<?php echo time() ?>'
1393 ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
1394 pagenow = '<?php echo $current_screen->id; ?>',
1395 typenow = '<?php echo $current_screen->post_type; ?>',
1396 adminpage = '<?php echo $admin_body_class; ?>',
1397 thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1398 decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1399 isRtl = <?php echo (int) is_rtl(); ?>;
1403 do_action('admin_enqueue_scripts', $hook_suffix);
1404 do_action("admin_print_styles-$hook_suffix");
1405 do_action('admin_print_styles');
1406 do_action("admin_print_scripts-$hook_suffix");
1407 do_action('admin_print_scripts');
1408 do_action("admin_head-$hook_suffix");
1409 do_action('admin_head');
1412 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin no-js iframe <?php echo apply_filters( 'admin_body_class', '' ) . ' ' . $admin_body_class; ?>">
1413 <script type="text/javascript">
1416 var c = document.body.className;
1417 c = c.replace(/no-js/, 'js');
1418 document.body.className = c;
1426 * Generic Iframe footer for use with Thickbox
1431 function iframe_footer() {
1432 //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
1433 <div class="hidden">
1435 do_action('admin_footer', '');
1436 do_action('admin_print_footer_scripts'); ?>
1438 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1444 function _post_states($post) {
1445 $post_states = array();
1446 if ( isset( $_REQUEST['post_status'] ) )
1447 $post_status = $_REQUEST['post_status'];
1451 if ( !empty($post->post_password) )
1452 $post_states['protected'] = __('Password protected');
1453 if ( 'private' == $post->post_status && 'private' != $post_status )
1454 $post_states['private'] = __('Private');
1455 if ( 'draft' == $post->post_status && 'draft' != $post_status )
1456 $post_states['draft'] = __('Draft');
1457 if ( 'pending' == $post->post_status && 'pending' != $post_status )
1458 /* translators: post state */
1459 $post_states['pending'] = _x('Pending', 'post state');
1460 if ( is_sticky($post->ID) )
1461 $post_states['sticky'] = __('Sticky');
1463 $post_states = apply_filters( 'display_post_states', $post_states );
1465 if ( ! empty($post_states) ) {
1466 $state_count = count($post_states);
1469 foreach ( $post_states as $state ) {
1471 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1472 echo "<span class='post-state'>$state$sep</span>";
1476 if ( get_post_format( $post->ID ) )
1477 echo ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>';
1480 function _media_states( $post ) {
1481 $media_states = array();
1482 $stylesheet = get_option('stylesheet');
1484 if ( current_theme_supports( 'custom-header') ) {
1485 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
1486 if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
1487 $media_states[] = __( 'Header Image' );
1490 if ( current_theme_supports( 'custom-background') ) {
1491 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
1492 if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
1493 $media_states[] = __( 'Background Image' );
1496 $media_states = apply_filters( 'display_media_states', $media_states );
1498 if ( ! empty( $media_states ) ) {
1499 $state_count = count( $media_states );
1502 foreach ( $media_states as $state ) {
1504 ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1505 echo "<span class='post-state'>$state$sep</span>";
1511 * Test support for compressing JavaScript from PHP
1513 * Outputs JavaScript that tests if compression from PHP works as expected
1514 * and sets an option with the result. Has no effect when the current user
1515 * is not an administrator. To run the test again the option 'can_compress_scripts'
1516 * has to be deleted.
1520 function compression_test() {
1522 <script type="text/javascript">
1524 var testCompression = {
1525 get : function(test) {
1527 if ( window.XMLHttpRequest ) {
1528 x = new XMLHttpRequest();
1530 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1534 x.onreadystatechange = function() {
1536 if ( x.readyState == 4 ) {
1537 r = x.responseText.substr(0, 18);
1538 h = x.getResponseHeader('Content-Encoding');
1539 testCompression.check(r, h, test);
1543 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1548 check : function(r, h, test) {
1549 if ( ! r && ! test )
1553 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1562 if ( '"wpCompressionTest' == r )
1569 testCompression.check();
1576 * Echos a submit button, with provided text and appropriate class
1580 * @param string $text The text of the button (defaults to 'Save Changes')
1581 * @param string $type The type of button. One of: primary, secondary, delete
1582 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1583 * is given in $other_attributes below, $name will be used as the button's id.
1584 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1585 * false otherwise. Defaults to true
1586 * @param array|string $other_attributes Other attributes that should be output with the button,
1587 * mapping attributes to their values, such as array( 'tabindex' => '1' ).
1588 * These attributes will be output as attribute="value", such as tabindex="1".
1589 * Defaults to no other attributes. Other attributes can also be provided as a
1590 * string such as 'tabindex="1"', though the array format is typically cleaner.
1592 function submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
1593 echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
1597 * Returns a submit button, with provided text and appropriate class
1601 * @param string $text The text of the button (defaults to 'Save Changes')
1602 * @param string $type The type of button. One of: primary, secondary, delete
1603 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1604 * is given in $other_attributes below, $name will be used as the button's id.
1605 * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1606 * false otherwise. Defaults to true
1607 * @param array|string $other_attributes Other attributes that should be output with the button,
1608 * mapping attributes to their values, such as array( 'tabindex' => '1' ).
1609 * These attributes will be output as attribute="value", such as tabindex="1".
1610 * Defaults to no other attributes. Other attributes can also be provided as a
1611 * string such as 'tabindex="1"', though the array format is typically cleaner.
1613 function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
1617 $class = 'button-' . $type;
1620 $class = 'button-secondary delete';
1623 $class = $type; // Custom cases can just pass in the classes they want to be used
1625 $text = ( NULL == $text ) ? __( 'Save Changes' ) : $text;
1627 // Default the id attribute to $name unless an id was specifically provided in $other_attributes
1629 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1630 $id = $other_attributes['id'];
1631 unset( $other_attributes['id'] );
1635 if ( is_array( $other_attributes ) ) {
1636 foreach ( $other_attributes as $attribute => $value ) {
1637 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1639 } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
1640 $attributes = $other_attributes;
1643 $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
1644 $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1647 $button = '<p class="submit">' . $button . '</p>';
1653 function _wp_admin_html_begin() {
1657 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
1659 <!--[if !(IE 8) ]><!-->
1660 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
1663 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1667 final class WP_Internal_Pointers {
1669 * Initializes the new feature pointers.
1673 * All pointers can be disabled using the following:
1674 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1676 * Individual pointers (e.g. wp330_toolbar) can be disabled using the following:
1677 * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp330_toolbar' ) );
1679 public static function enqueue_scripts( $hook_suffix ) {
1681 * Register feature pointers
1682 * Format: array( hook_suffix => pointer_id )
1685 $registered_pointers = array(
1686 'index.php' => 'wp330_toolbar',
1687 'post-new.php' => 'wp330_media_uploader',
1688 'post.php' => 'wp330_media_uploader',
1689 'themes.php' => 'wp330_saving_widgets',
1692 // Check if screen related pointer is registered
1693 if ( empty( $registered_pointers[ $hook_suffix ] ) )
1696 $pointer = $registered_pointers[ $hook_suffix ];
1698 $caps_required = array(
1699 'wp330_media_uploader' => array( 'upload_files' ),
1700 'wp330_saving_widgets' => array( 'edit_theme_options', 'switch_themes' ),
1703 if ( isset( $caps_required[ $pointer ] ) ) {
1704 foreach ( $caps_required[ $pointer ] as $cap ) {
1705 if ( ! current_user_can( $cap ) )
1710 // Get dismissed pointers
1711 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1713 // Pointer has been dismissed
1714 if ( in_array( $pointer, $dismissed ) )
1717 // Bind pointer print function
1718 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
1720 // Add pointers script and style to queue
1721 wp_enqueue_style( 'wp-pointer' );
1722 wp_enqueue_script( 'wp-pointer' );
1726 * Print the pointer javascript data.
1730 * @param string $pointer_id The pointer ID.
1731 * @param string $selector The HTML elements, on which the pointer should be attached.
1732 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.dev.js).
1734 private static function print_js( $pointer_id, $selector, $args ) {
1735 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
1739 <script type="text/javascript">
1741 jQuery(document).ready( function($) {
1742 var options = <?php echo json_encode( $args ); ?>;
1747 options = $.extend( options, {
1750 pointer: '<?php echo $pointer_id; ?>',
1751 action: 'dismiss-wp-pointer'
1756 $('<?php echo $selector; ?>').pointer( options ).pointer('open');
1763 public static function pointer_wp330_toolbar() {
1764 $content = '<h3>' . esc_js( __( 'New Feature: Toolbar' ) ). '</h3>';
1765 $content .= '<p>' . esc_js( __( 'We’ve combined the admin bar and the old Dashboard header into one persistent toolbar. Hover over the toolbar items to see what’s new.' ) ) . '</p>';
1767 if ( is_multisite() && is_super_admin() )
1768 $content .= '<p>' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '</p>';
1770 WP_Internal_Pointers::print_js( 'wp330_toolbar', '#wpadminbar', array(
1771 'content' => $content,
1772 'position' => array( 'edge' => 'top', 'align' => 'center' ),
1777 * Print 'Updated Media Uploader' for 3.3.0.
1781 public static function pointer_wp330_media_uploader() {
1782 $content = '<h3>' . esc_js( __( 'Updated Media Uploader' ) ) . '</h3>';
1783 $content .= '<p>' . esc_js( __( 'The single media icon now launches the uploader for all file types, and the new drag and drop interface makes uploading a breeze.' ) ) . '</p>';
1785 WP_Internal_Pointers::print_js( 'wp330_media_uploader', '#content-add_media', array(
1786 'content' => $content,
1787 'position' => array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ),
1792 * Print 'New Feature: Saving Widgets' for 3.3.0.
1796 public static function pointer_wp330_saving_widgets() {
1797 $content = '<h3>' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '</h3>';
1798 $content .= '<p>' . esc_js( __( 'If you change your mind and revert to your previous theme, we’ll put the widgets back the way you had them.' ) ) . '</p>';
1800 WP_Internal_Pointers::print_js( 'wp330_saving_widgets', '#message2', array(
1801 'content' => $content,
1802 'position' => array( 'edge' => 'top', 'align' => is_rtl() ? 'right' : 'left' ),
1807 * Prevents new users from seeing existing 'new feature' pointers.
1811 public static function dismiss_pointers_for_new_users( $user_id ) {
1812 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp330_toolbar,wp330_media_uploader,wp330_saving_widgets' );
1816 add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1817 add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
1820 * Convert a screen string to a screen object
1824 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
1825 * @return WP_Screen Screen object.
1827 function convert_to_screen( $hook_name ) {
1828 if ( ! class_exists( 'WP_Screen' ) ) {
1829 _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3' );
1830 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
1833 return WP_Screen::get( $hook_name );