| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Template WordPress Administration API. 4 * 5 * A Big Mess. Also some neat functions that are nicely written. 6 * 7 * @package WordPress 8 * @subpackage Administration 9 */ 10 11 12 // 13 // Category Checklists 14 // 15 16 /** 17 * {@internal Missing Short Description}} 18 * 19 * @since 2.5.1 20 */ 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 24 25 function start_lvl(&$output, $depth, $args) { 26 $indent = str_repeat("\t", $depth); 27 $output .= "$indent<ul class='children'>\n"; 28 } 29 30 function end_lvl(&$output, $depth, $args) { 31 $indent = str_repeat("\t", $depth); 32 $output .= "$indent</ul>\n"; 33 } 34 35 function start_el(&$output, $category, $depth, $args) { 36 extract($args); 37 if ( empty($taxonomy) ) 38 $taxonomy = 'category'; 39 40 if ( $taxonomy == 'category' ) 41 $name = 'post_category'; 42 else 43 $name = 'tax_input['.$taxonomy.']'; 44 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>'; 47 } 48 49 function end_el(&$output, $category, $depth, $args) { 50 $output .= "</li>\n"; 51 } 52 } 53 54 /** 55 * {@internal Missing Short Description}} 56 * 57 * @since 2.5.1 58 * 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 63 */ 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, 66 array( 67 'taxonomy' => 'category', 68 'descendants_and_self' => $descendants_and_self, 69 'selected_cats' => $selected_cats, 70 'popular_cats' => $popular_cats, 71 'walker' => $walker, 72 'checked_ontop' => $checked_ontop 73 )); 74 } 75 76 /** 77 * Taxonomy independent version of wp_category_checklist 78 * 79 * @since 3.0.0 80 * 81 * @param int $post_id 82 * @param array $args 83 */ 84 function wp_terms_checklist($post_id = 0, $args = array()) { 85 $defaults = array( 86 'descendants_and_self' => 0, 87 'selected_cats' => false, 88 'popular_cats' => false, 89 'walker' => null, 90 'taxonomy' => 'category', 91 'checked_ontop' => true 92 ); 93 extract( wp_parse_args($args, $defaults), EXTR_SKIP ); 94 95 if ( empty($walker) || !is_a($walker, 'Walker') ) 96 $walker = new Walker_Category_Checklist; 97 98 $descendants_and_self = (int) $descendants_and_self; 99 100 $args = array('taxonomy' => $taxonomy); 101 102 $tax = get_taxonomy($taxonomy); 103 $args['disabled'] = !current_user_can($tax->cap->assign_terms); 104 105 if ( is_array( $selected_cats ) ) 106 $args['selected_cats'] = $selected_cats; 107 elseif ( $post_id ) 108 $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids'))); 109 else 110 $args['selected_cats'] = array(); 111 112 if ( is_array( $popular_cats ) ) 113 $args['popular_cats'] = $popular_cats; 114 else 115 $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); 116 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 ); 121 } else { 122 $categories = (array) get_terms($taxonomy, array('get' => 'all')); 123 } 124 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 ); 129 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] ); 134 } 135 } 136 137 // Put checked cats on top 138 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); 139 } 140 // Then the rest of them 141 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); 142 } 143 144 /** 145 * {@internal Missing Short Description}} 146 * 147 * @since 2.5.0 148 * 149 * @param unknown_type $taxonomy 150 * @param unknown_type $default 151 * @param unknown_type $number 152 * @param unknown_type $echo 153 * @return unknown 154 */ 155 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { 156 global $post_ID; 157 158 if ( $post_ID ) 159 $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids')); 160 else 161 $checked_terms = array(); 162 163 $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); 164 165 $tax = get_taxonomy($taxonomy); 166 if ( ! current_user_can($tax->cap->assign_terms) ) 167 $disabled = 'disabled="disabled"'; 168 else 169 $disabled = ''; 170 171 $popular_ids = array(); 172 foreach ( (array) $terms as $term ) { 173 $popular_ids[] = $term->term_id; 174 if ( !$echo ) // hack for AJAX use 175 continue; 176 $id = "popular-$taxonomy-$term->term_id"; 177 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; 178 ?> 179 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 ) ); ?> 184 </label> 185 </li> 186 187 <?php 188 } 189 return $popular_ids; 190 } 191 192 /** 193 * {@internal Missing Short Description}} 194 * 195 * @since 2.5.1 196 * 197 * @param unknown_type $link_id 198 */ 199 function wp_link_category_checklist( $link_id = 0 ) { 200 $default = 1; 201 202 if ( $link_id ) { 203 $checked_categories = wp_get_link_cats( $link_id ); 204 // No selected categories, strange 205 if ( ! count( $checked_categories ) ) 206 $checked_categories[] = $default; 207 } else { 208 $checked_categories[] = $default; 209 } 210 211 $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); 212 213 if ( empty( $categories ) ) 214 return; 215 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>"; 221 } 222 } 223 224 /** 225 * Get the column headers for a screen 226 * 227 * @since 2.7.0 228 * 229 * @param string|object $screen The screen you want the headers for 230 * @return array Containing the headers in the format id => UI String 231 */ 232 function get_column_headers( $screen ) { 233 if ( is_string( $screen ) ) 234 $screen = convert_to_screen( $screen ); 235 236 global $_wp_column_headers; 237 238 if ( !isset( $_wp_column_headers[ $screen->id ] ) ) { 239 $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() ); 240 } 241 242 return $_wp_column_headers[ $screen->id ]; 243 } 244 245 /** 246 * Get a list of hidden columns. 247 * 248 * @since 2.7.0 249 * 250 * @param string|object $screen The screen you want the hidden columns for 251 * @return array 252 */ 253 function get_hidden_columns( $screen ) { 254 if ( is_string( $screen ) ) 255 $screen = convert_to_screen( $screen ); 256 257 return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' ); 258 } 259 260 // adds hidden fields with the data for use in the inline editor for posts and pages 261 /** 262 * {@internal Missing Short Description}} 263 * 264 * @since 2.7.0 265 * 266 * @param unknown_type $post 267 */ 268 function get_inline_data($post) { 269 $post_type_object = get_post_type_object($post->post_type); 270 if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) ) 271 return; 272 273 $title = esc_textarea( trim( $post->post_title ) ); 274 275 echo ' 276 <div class="hidden" id="inline_' . $post->ID . '"> 277 <div class="post_title">' . $title . '</div> 278 <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div> 279 <div class="post_author">' . $post->post_author . '</div> 280 <div class="comment_status">' . esc_html( $post->comment_status ) . '</div> 281 <div class="ping_status">' . esc_html( $post->ping_status ) . '</div> 282 <div class="_status">' . esc_html( $post->post_status ) . '</div> 283 <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div> 284 <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div> 285 <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div> 286 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div> 287 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div> 288 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> 289 <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; 290 291 if ( $post_type_object->hierarchical ) 292 echo '<div class="post_parent">' . $post->post_parent . '</div>'; 293 294 if ( $post->post_type == 'page' ) 295 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; 296 297 if ( $post_type_object->hierarchical ) 298 echo '<div class="menu_order">' . $post->menu_order . '</div>'; 299 300 $taxonomy_names = get_object_taxonomies( $post->post_type ); 301 foreach ( $taxonomy_names as $taxonomy_name) { 302 $taxonomy = get_taxonomy( $taxonomy_name ); 303 304 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) 305 echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>'; 306 elseif ( $taxonomy->show_ui ) 307 echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>'; 308 } 309 310 if ( !$post_type_object->hierarchical ) 311 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; 312 313 echo '</div>'; 314 } 315 316 /** 317 * {@internal Missing Short Description}} 318 * 319 * @since 2.7.0 320 * 321 * @param unknown_type $position 322 * @param unknown_type $checkbox 323 * @param unknown_type $mode 324 */ 325 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) { 326 // allow plugin to replace the popup content 327 $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) ); 328 329 if ( ! empty($content) ) { 330 echo $content; 331 return; 332 } 333 334 if ( $mode == 'single' ) { 335 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table'); 336 } else { 337 $wp_list_table = _get_list_table('WP_Comments_List_Table'); 338 } 339 340 ?> 341 <form method="get" action=""> 342 <?php if ( $table_row ) : ?> 343 <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"> 344 <?php else : ?> 345 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;"> 346 <?php endif; ?> 347 <div id="replyhead" style="display:none;"><?php _e('Reply to Comment'); ?></div> 348 349 <div id="edithead" style="display:none;"> 350 <div class="inside"> 351 <label for="author"><?php _e('Name') ?></label> 352 <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" /> 353 </div> 354 355 <div class="inside"> 356 <label for="author-email"><?php _e('E-mail') ?></label> 357 <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" /> 358 </div> 359 360 <div class="inside"> 361 <label for="author-url"><?php _e('URL') ?></label> 362 <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" /> 363 </div> 364 <div style="clear:both;"></div> 365 </div> 366 367 <div id="replycontainer"><textarea rows="8" cols="40" name="replycontent" tabindex="104" id="replycontent"></textarea></div> 368 369 <p id="replysubmit" class="submit"> 370 <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a> 371 <a href="#comments-form" class="save button-primary alignright" tabindex="104"> 372 <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span> 373 <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a> 374 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 375 <span class="error" style="display:none;"></span> 376 <br class="clear" /> 377 </p> 378 379 <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" /> 380 <input type="hidden" name="action" id="action" value="" /> 381 <input type="hidden" name="comment_ID" id="comment_ID" value="" /> 382 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> 383 <input type="hidden" name="status" id="status" value="" /> 384 <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" /> 385 <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" /> 386 <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" /> 387 <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); ?> 388 <?php wp_comment_form_unfiltered_html_nonce(); ?> 389 <?php if ( $table_row ) : ?> 390 </td></tr></tbody></table> 391 <?php else : ?> 392 </div></div> 393 <?php endif; ?> 394 </form> 395 <?php 396 } 397 398 /** 399 * Output 'undo move to trash' text for comments 400 * 401 * @since 2.9.0 402 */ 403 function wp_comment_trashnotice() { 404 ?> 405 <div class="hidden" id="trash-undo-holder"> 406 <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> 407 </div> 408 <div class="hidden" id="spam-undo-holder"> 409 <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> 410 </div> 411 <?php 412 } 413 414 /** 415 * {@internal Missing Short Description}} 416 * 417 * @since 1.2.0 418 * 419 * @param unknown_type $meta 420 */ 421 function list_meta( $meta ) { 422 // Exit if no meta 423 if ( ! $meta ) { 424 echo ' 425 <table id="list-table" style="display: none;"> 426 <thead> 427 <tr> 428 <th class="left">' . __( 'Name' ) . '</th> 429 <th>' . __( 'Value' ) . '</th> 430 </tr> 431 </thead> 432 <tbody id="the-list" class="list:meta"> 433 <tr><td></td></tr> 434 </tbody> 435 </table>'; //TBODY needed for list-manipulation JS 436 return; 437 } 438 $count = 0; 439 ?> 440 <table id="list-table"> 441 <thead> 442 <tr> 443 <th class="left"><?php _e( 'Name' ) ?></th> 444 <th><?php _e( 'Value' ) ?></th> 445 </tr> 446 </thead> 447 <tbody id='the-list' class='list:meta'> 448 <?php 449 foreach ( $meta as $entry ) 450 echo _list_meta_row( $entry, $count ); 451 ?> 452 </tbody> 453 </table> 454 <?php 455 } 456 457 /** 458 * {@internal Missing Short Description}} 459 * 460 * @since 2.5.0 461 * 462 * @param unknown_type $entry 463 * @param unknown_type $count 464 * @return unknown 465 */ 466 function _list_meta_row( $entry, &$count ) { 467 static $update_nonce = false; 468 469 if ( is_protected_meta( $entry['meta_key'] ) ) 470 return; 471 472 if ( !$update_nonce ) 473 $update_nonce = wp_create_nonce( 'add-meta' ); 474 475 $r = ''; 476 ++ $count; 477 if ( $count % 2 ) 478 $style = 'alternate'; 479 else 480 $style = ''; 481 if ('_' == $entry['meta_key'] { 0 } ) 482 $style .= ' hidden'; 483 484 if ( is_serialized( $entry['meta_value'] ) ) { 485 if ( is_serialized_string( $entry['meta_value'] ) ) { 486 // this is a serialized string, so we should display it 487 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); 488 } else { 489 // this is a serialized array/object so we should NOT display it 490 --$count; 491 return; 492 } 493 } 494 495 $entry['meta_key'] = esc_attr($entry['meta_key']); 496 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea /> 497 $entry['meta_id'] = (int) $entry['meta_id']; 498 499 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); 500 501 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>"; 502 $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']}' />"; 503 504 $r .= "\n\t\t<div class='submit'>"; 505 $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' ) ); 506 $r .= "\n\t\t"; 507 $r .= get_submit_button( __( 'Update' ), "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta" , 'updatemeta', false, array( 'tabindex' => '6' ) ); 508 $r .= "</div>"; 509 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false ); 510 $r .= "</td>"; 511 512 $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>"; 513 return $r; 514 } 515 516 /** 517 * {@internal Missing Short Description}} 518 * 519 * @since 1.2.0 520 */ 521 function meta_form() { 522 global $wpdb; 523 $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); 524 $keys = $wpdb->get_col( " 525 SELECT meta_key 526 FROM $wpdb->postmeta 527 GROUP BY meta_key 528 HAVING meta_key NOT LIKE '\_%' 529 ORDER BY meta_key 530 LIMIT $limit" ); 531 if ( $keys ) 532 natcasesort($keys); 533 ?> 534 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p> 535 <table id="newmeta"> 536 <thead> 537 <tr> 538 <th class="left"><label for="metakeyselect"><?php _e( 'Name' ) ?></label></th> 539 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th> 540 </tr> 541 </thead> 542 543 <tbody> 544 <tr> 545 <td id="newmetaleft" class="left"> 546 <?php if ( $keys ) { ?> 547 <select id="metakeyselect" name="metakeyselect" tabindex="7"> 548 <option value="#NONE#"><?php _e( '— Select —' ); ?></option> 549 <?php 550 551 foreach ( $keys as $key ) { 552 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>"; 553 } 554 ?> 555 </select> 556 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" /> 557 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;"> 558 <span id="enternew"><?php _e('Enter new'); ?></span> 559 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a> 560 <?php } else { ?> 561 <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" /> 562 <?php } ?> 563 </td> 564 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td> 565 </tr> 566 567 <tr><td colspan="2" class="submit"> 568 <?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'addmetasub', 'tabindex' => '9' ) ); ?> 569 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?> 570 </td></tr> 571 </tbody> 572 </table> 573 <?php 574 575 } 576 577 /** 578 * {@internal Missing Short Description}} 579 * 580 * @since 0.71 581 * 582 * @param unknown_type $edit 583 * @param unknown_type $for_post 584 * @param unknown_type $tab_index 585 * @param unknown_type $multi 586 */ 587 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { 588 global $wp_locale, $post, $comment; 589 590 if ( $for_post ) 591 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); 592 593 $tab_index_attribute = ''; 594 if ( (int) $tab_index > 0 ) 595 $tab_index_attribute = " tabindex=\"$tab_index\""; 596 597 // 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 />'; 598 599 $time_adj = current_time('timestamp'); 600 $post_date = ($for_post) ? $post->post_date : $comment->comment_date; 601 $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); 602 $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); 603 $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); 604 $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); 605 $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); 606 $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj ); 607 608 $cur_jj = gmdate( 'd', $time_adj ); 609 $cur_mm = gmdate( 'm', $time_adj ); 610 $cur_aa = gmdate( 'Y', $time_adj ); 611 $cur_hh = gmdate( 'H', $time_adj ); 612 $cur_mn = gmdate( 'i', $time_adj ); 613 614 $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n"; 615 for ( $i = 1; $i < 13; $i = $i +1 ) { 616 $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"'; 617 if ( $i == $mm ) 618 $month .= ' selected="selected"'; 619 $month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n"; 620 } 621 $month .= '</select>'; 622 623 $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; 624 $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />'; 625 $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; 626 $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; 627 628 echo '<div class="timestamp-wrap">'; 629 /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */ 630 printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute); 631 632 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; 633 634 if ( $multi ) return; 635 636 echo "\n\n"; 637 foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) { 638 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n"; 639 $cur_timeunit = 'cur_' . $timeunit; 640 echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n"; 641 } 642 ?> 643 644 <p> 645 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a> 646 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a> 647 </p> 648 <?php 649 } 650 651 /** 652 * {@internal Missing Short Description}} 653 * 654 * @since 1.5.0 655 * 656 * @param unknown_type $default 657 */ 658 function page_template_dropdown( $default = '' ) { 659 $templates = get_page_templates(); 660 ksort( $templates ); 661 foreach (array_keys( $templates ) as $template ) 662 : if ( $default == $templates[$template] ) 663 $selected = " selected='selected'"; 664 else 665 $selected = ''; 666 echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>"; 667 endforeach; 668 } 669 670 /** 671 * {@internal Missing Short Description}} 672 * 673 * @since 1.5.0 674 * 675 * @param unknown_type $default 676 * @param unknown_type $parent 677 * @param unknown_type $level 678 * @return unknown 679 */ 680 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { 681 global $wpdb, $post_ID; 682 $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) ); 683 684 if ( $items ) { 685 foreach ( $items as $item ) { 686 // A page cannot be its own parent. 687 if (!empty ( $post_ID ) ) { 688 if ( $item->ID == $post_ID ) { 689 continue; 690 } 691 } 692 $pad = str_repeat( ' ', $level * 3 ); 693 if ( $item->ID == $default) 694 $current = ' selected="selected"'; 695 else 696 $current = ''; 697 698 echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>"; 699 parent_dropdown( $default, $item->ID, $level +1 ); 700 } 701 } else { 702 return false; 703 } 704 } 705 706 /** 707 * {@internal Missing Short Description}} 708 * 709 * @since 2.0.0 710 * 711 * @param unknown_type $id 712 * @return unknown 713 */ 714 function the_attachment_links( $id = false ) { 715 $id = (int) $id; 716 $post = & get_post( $id ); 717 718 if ( $post->post_type != 'attachment' ) 719 return false; 720 721 $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true ); 722 $attachment_data = wp_get_attachment_metadata( $id ); 723 $thumb = isset( $attachment_data['thumb'] ); 724 ?> 725 <form id="the-attachment-links"> 726 <table> 727 <col /> 728 <col class="widefat" /> 729 <tr> 730 <th scope="row"><?php _e( 'URL' ) ?></th> 731 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo esc_textarea( wp_get_attachment_url() ); ?></textarea></td> 732 </tr> 733 <?php if ( $icon ) : ?> 734 <tr> 735 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th> 736 <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> 737 </tr> 738 <tr> 739 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th> 740 <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> 741 </tr> 742 <?php else : ?> 743 <tr> 744 <th scope="row"><?php _e( 'Link to file' ) ?></th> 745 <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> 746 </tr> 747 <tr> 748 <th scope="row"><?php _e( 'Link to page' ) ?></th> 749 <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> 750 </tr> 751 <?php endif; ?> 752 </table> 753 </form> 754 <?php 755 } 756 757 758 /** 759 * Print out <option> html elements for role selectors 760 * 761 * @since 2.1.0 762 * 763 * @param string $selected slug for the role that should be already selected 764 */ 765 function wp_dropdown_roles( $selected = false ) { 766 $p = ''; 767 $r = ''; 768 769 $editable_roles = get_editable_roles(); 770 771 foreach ( $editable_roles as $role => $details ) { 772 $name = translate_user_role($details['name'] ); 773 if ( $selected == $role ) // preselect specified role 774 $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; 775 else 776 $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>"; 777 } 778 echo $p . $r; 779 } 780 781 /** 782 * {@internal Missing Short Description}} 783 * 784 * @since 2.3.0 785 * 786 * @param unknown_type $size 787 * @return unknown 788 */ 789 function wp_convert_hr_to_bytes( $size ) { 790 $size = strtolower($size); 791 $bytes = (int) $size; 792 if ( strpos($size, 'k') !== false ) 793 $bytes = intval($size) * 1024; 794 elseif ( strpos($size, 'm') !== false ) 795 $bytes = intval($size) * 1024 * 1024; 796 elseif ( strpos($size, 'g') !== false ) 797 $bytes = intval($size) * 1024 * 1024 * 1024; 798 return $bytes; 799 } 800 801 /** 802 * {@internal Missing Short Description}} 803 * 804 * @since 2.3.0 805 * 806 * @param unknown_type $bytes 807 * @return unknown 808 */ 809 function wp_convert_bytes_to_hr( $bytes ) { 810 $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' ); 811 $log = log( $bytes, 1024 ); 812 $power = (int) $log; 813 $size = pow(1024, $log - $power); 814 return $size . $units[$power]; 815 } 816 817 /** 818 * {@internal Missing Short Description}} 819 * 820 * @since 2.5.0 821 * 822 * @return unknown 823 */ 824 function wp_max_upload_size() { 825 $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); 826 $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); 827 $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes ); 828 return $bytes; 829 } 830 831 /** 832 * Outputs the form used by the importers to accept the data to be imported 833 * 834 * @since 2.0.0 835 * 836 * @param string $action The action attribute for the form. 837 */ 838 function wp_import_upload_form( $action ) { 839 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); 840 $size = wp_convert_bytes_to_hr( $bytes ); 841 $upload_dir = wp_upload_dir(); 842 if ( ! empty( $upload_dir['error'] ) ) : 843 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p> 844 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php 845 else : 846 ?> 847 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>"> 848 <p> 849 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>) 850 <input type="file" id="upload" name="import" size="25" /> 851 <input type="hidden" name="action" value="save" /> 852 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> 853 </p> 854 <?php submit_button( __('Upload file and import'), 'button' ); ?> 855 </form> 856 <?php 857 endif; 858 } 859 860 /** 861 * Add a meta box to an edit form. 862 * 863 * @since 2.5.0 864 * 865 * @param string $id String for use in the 'id' attribute of tags. 866 * @param string $title Title of the meta box. 867 * @param string $callback Function that fills the box with the desired content. The function should echo its output. 868 * @param string $page The type of edit page on which to show the box (post, page, link). 869 * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). 870 * @param string $priority The priority within the context where the boxes should show ('high', 'low'). 871 */ 872 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) { 873 global $wp_meta_boxes; 874 875 if ( !isset($wp_meta_boxes) ) 876 $wp_meta_boxes = array(); 877 if ( !isset($wp_meta_boxes[$page]) ) 878 $wp_meta_boxes[$page] = array(); 879 if ( !isset($wp_meta_boxes[$page][$context]) ) 880 $wp_meta_boxes[$page][$context] = array(); 881 882 foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) { 883 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) { 884 if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) ) 885 continue; 886 887 // If a core box was previously added or removed by a plugin, don't add. 888 if ( 'core' == $priority ) { 889 // If core box previously deleted, don't add 890 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) 891 return; 892 // If box was added with default priority, give it core priority to maintain sort order 893 if ( 'default' == $a_priority ) { 894 $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id]; 895 unset($wp_meta_boxes[$page][$a_context]['default'][$id]); 896 } 897 return; 898 } 899 // If no priority given and id already present, use existing priority 900 if ( empty($priority) ) { 901 $priority = $a_priority; 902 // else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority. 903 } elseif ( 'sorted' == $priority ) { 904 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; 905 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; 906 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args']; 907 } 908 // An id can be in only one priority and one context 909 if ( $priority != $a_priority || $context != $a_context ) 910 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); 911 } 912 } 913 914 if ( empty($priority) ) 915 $priority = 'low'; 916 917 if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) 918 $wp_meta_boxes[$page][$context][$priority] = array(); 919 920 $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args); 921 } 922 923 /** 924 * Meta-Box template function 925 * 926 * @since 2.5.0 927 * 928 * @param string $page page identifier, also known as screen identifier 929 * @param string $context box context 930 * @param mixed $object gets passed to the box callback function as first parameter 931 * @return int number of meta_boxes 932 */ 933 function do_meta_boxes($page, $context, $object) { 934 global $wp_meta_boxes; 935 static $already_sorted = false; 936 937 $hidden = get_hidden_meta_boxes($page); 938 939 printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context)); 940 941 $i = 0; 942 do { 943 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose 944 if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { 945 foreach ( $sorted as $box_context => $ids ) 946 foreach ( explode(',', $ids) as $id ) 947 if ( $id ) 948 add_meta_box( $id, null, null, $page, $box_context, 'sorted' ); 949 } 950 $already_sorted = true; 951 952 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) ) 953 break; 954 955 foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) { 956 if ( isset($wp_meta_boxes[$page][$context][$priority]) ) { 957 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { 958 if ( false == $box || ! $box['title'] ) 959 continue; 960 $i++; 961 $style = ''; 962 $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; 963 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n"; 964 if ( 'dashboard_browser_nag' != $box['id'] ) 965 echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>'; 966 echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n"; 967 echo '<div class="inside">' . "\n"; 968 call_user_func($box['callback'], $object, $box); 969 echo "</div>\n"; 970 echo "</div>\n"; 971 } 972 } 973 } 974 } while(0); 975 976 echo "</div>"; 977 978 return $i; 979 980 } 981 982 /** 983 * Remove a meta box from an edit form. 984 * 985 * @since 2.6.0 986 * 987 * @param string $id String for use in the 'id' attribute of tags. 988 * @param string $page The type of edit page on which to show the box (post, page, link). 989 * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). 990 */ 991 function remove_meta_box($id, $page, $context) { 992 global $wp_meta_boxes; 993 994 if ( !isset($wp_meta_boxes) ) 995 $wp_meta_boxes = array(); 996 if ( !isset($wp_meta_boxes[$page]) ) 997 $wp_meta_boxes[$page] = array(); 998 if ( !isset($wp_meta_boxes[$page][$context]) ) 999 $wp_meta_boxes[$page][$context] = array(); 1000 1001 foreach ( array('high', 'core', 'default', 'low') as $priority ) 1002 $wp_meta_boxes[$page][$context][$priority][$id] = false; 1003 } 1004 1005 /** 1006 * {@internal Missing Short Description}} 1007 * 1008 * @since 2.7.0 1009 * 1010 * @param unknown_type $screen 1011 */ 1012 function meta_box_prefs($screen) { 1013 global $wp_meta_boxes; 1014 1015 if ( is_string($screen) ) 1016 $screen = convert_to_screen($screen); 1017 1018 if ( empty($wp_meta_boxes[$screen->id]) ) 1019 return; 1020 1021 $hidden = get_hidden_meta_boxes($screen); 1022 1023 foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) { 1024 foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) { 1025 foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) { 1026 if ( false == $box || ! $box['title'] ) 1027 continue; 1028 // Submit box cannot be hidden 1029 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) 1030 continue; 1031 $box_id = $box['id']; 1032 echo '<label for="' . $box_id . '-hide">'; 1033 echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />'; 1034 echo "{$box['title']}</label>\n"; 1035 } 1036 } 1037 } 1038 } 1039 1040 /** 1041 * Get Hidden Meta Boxes 1042 * 1043 * @since 2.7.0 1044 * 1045 * @param string|object $screen Screen identifier 1046 * @return array Hidden Meta Boxes 1047 */ 1048 function get_hidden_meta_boxes( $screen ) { 1049 if ( is_string( $screen ) ) 1050 $screen = convert_to_screen( $screen ); 1051 1052 $hidden = get_user_option( "metaboxhidden_{$screen->id}" ); 1053 1054 // Hide slug boxes by default 1055 if ( !is_array( $hidden ) ) { 1056 if ( 'post' == $screen->base || 'page' == $screen->base ) 1057 $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv'); 1058 else 1059 $hidden = array( 'slugdiv' ); 1060 $hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen); 1061 } 1062 1063 return $hidden; 1064 } 1065 1066 /** 1067 * Add a new section to a settings page. 1068 * 1069 * Part of the Settings API. Use this to define new settings sections for an admin page. 1070 * Show settings sections in your admin page callback function with do_settings_sections(). 1071 * Add settings fields to your section with add_settings_field() 1072 * 1073 * The $callback argument should be the name of a function that echoes out any 1074 * content you want to show at the top of the settings section before the actual 1075 * fields. It can output nothing if you want. 1076 * 1077 * @since 2.7.0 1078 * 1079 * @global $wp_settings_sections Storage array of all settings sections added to admin pages 1080 * 1081 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. 1082 * @param string $title Formatted title of the section. Shown as the heading for the section. 1083 * @param string $callback Function that echos out any content at the top of the section (between heading and fields). 1084 * @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(); 1085 */ 1086 function add_settings_section($id, $title, $callback, $page) { 1087 global $wp_settings_sections; 1088 1089 if ( 'misc' == $page ) { 1090 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) ); 1091 $page = 'general'; 1092 } 1093 1094 if ( !isset($wp_settings_sections) ) 1095 $wp_settings_sections = array(); 1096 if ( !isset($wp_settings_sections[$page]) ) 1097 $wp_settings_sections[$page] = array(); 1098 if ( !isset($wp_settings_sections[$page][$id]) ) 1099 $wp_settings_sections[$page][$id] = array(); 1100 1101 $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); 1102 } 1103 1104 /** 1105 * Add a new field to a section of a settings page 1106 * 1107 * Part of the Settings API. Use this to define a settings field that will show 1108 * as part of a settings section inside a settings page. The fields are shown using 1109 * do_settings_fields() in do_settings-sections() 1110 * 1111 * The $callback argument should be the name of a function that echoes out the 1112 * html input tags for this setting field. Use get_option() to retrive existing 1113 * values to show. 1114 * 1115 * @since 2.7.0 1116 * 1117 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections 1118 * 1119 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. 1120 * @param string $title Formatted title of the field. Shown as the label for the field during output. 1121 * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output. 1122 * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...). 1123 * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...). 1124 * @param array $args Additional arguments 1125 */ 1126 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) { 1127 global $wp_settings_fields; 1128 1129 if ( 'misc' == $page ) { 1130 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) ); 1131 $page = 'general'; 1132 } 1133 1134 if ( !isset($wp_settings_fields) ) 1135 $wp_settings_fields = array(); 1136 if ( !isset($wp_settings_fields[$page]) ) 1137 $wp_settings_fields[$page] = array(); 1138 if ( !isset($wp_settings_fields[$page][$section]) ) 1139 $wp_settings_fields[$page][$section] = array(); 1140 1141 $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args); 1142 } 1143 1144 /** 1145 * Prints out all settings sections added to a particular settings page 1146 * 1147 * Part of the Settings API. Use this in a settings page callback function 1148 * to output all the sections and fields that were added to that $page with 1149 * add_settings_section() and add_settings_field() 1150 * 1151 * @global $wp_settings_sections Storage array of all settings sections added to admin pages 1152 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections 1153 * @since 2.7.0 1154 * 1155 * @param string $page The slug name of the page whos settings sections you want to output 1156 */ 1157 function do_settings_sections($page) { 1158 global $wp_settings_sections, $wp_settings_fields; 1159 1160 if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) ) 1161 return; 1162 1163 foreach ( (array) $wp_settings_sections[$page] as $section ) { 1164 echo "<h3>{$section['title']}</h3>\n"; 1165 call_user_func($section['callback'], $section); 1166 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) ) 1167 continue; 1168 echo '<table class="form-table">'; 1169 do_settings_fields($page, $section['id']); 1170 echo '</table>'; 1171 } 1172 } 1173 1174 /** 1175 * Print out the settings fields for a particular settings section 1176 * 1177 * Part of the Settings API. Use this in a settings page to output 1178 * a specific section. Should normally be called by do_settings_sections() 1179 * rather than directly. 1180 * 1181 * @global $wp_settings_fields Storage array of settings fields and their pages/sections 1182 * 1183 * @since 2.7.0 1184 * 1185 * @param string $page Slug title of the admin page who's settings fields you want to show. 1186 * @param section $section Slug title of the settings section who's fields you want to show. 1187 */ 1188 function do_settings_fields($page, $section) { 1189 global $wp_settings_fields; 1190 1191 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) ) 1192 return; 1193 1194 foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { 1195 echo '<tr valign="top">'; 1196 if ( !empty($field['args']['label_for']) ) 1197 echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>'; 1198 else 1199 echo '<th scope="row">' . $field['title'] . '</th>'; 1200 echo '<td>'; 1201 call_user_func($field['callback'], $field['args']); 1202 echo '</td>'; 1203 echo '</tr>'; 1204 } 1205 } 1206 1207 /** 1208 * Register a settings error to be displayed to the user 1209 * 1210 * Part of the Settings API. Use this to show messages to users about settings validation 1211 * problems, missing settings or anything else. 1212 * 1213 * Settings errors should be added inside the $sanitize_callback function defined in 1214 * register_setting() for a given setting to give feedback about the submission. 1215 * 1216 * By default messages will show immediately after the submission that generated the error. 1217 * Additional calls to settings_errors() can be used to show errors even when the settings 1218 * page is first accessed. 1219 * 1220 * @since 3.0.0 1221 * 1222 * @global array $wp_settings_errors Storage array of errors registered during this pageload 1223 * 1224 * @param string $setting Slug title of the setting to which this error applies 1225 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. 1226 * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>) 1227 * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'. 1228 */ 1229 function add_settings_error( $setting, $code, $message, $type = 'error' ) { 1230 global $wp_settings_errors; 1231 1232 if ( !isset($wp_settings_errors) ) 1233 $wp_settings_errors = array(); 1234 1235 $new_error = array( 1236 'setting' => $setting, 1237 'code' => $code, 1238 'message' => $message, 1239 'type' => $type 1240 ); 1241 $wp_settings_errors[] = $new_error; 1242 } 1243 1244 /** 1245 * Fetch settings errors registered by add_settings_error() 1246 * 1247 * Checks the $wp_settings_errors array for any errors declared during the current 1248 * pageload and returns them. 1249 * 1250 * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved 1251 * to the 'settings_errors' transient then those errors will be returned instead. This 1252 * is used to pass errors back across pageloads. 1253 * 1254 * Use the $sanitize argument to manually re-sanitize the option before returning errors. 1255 * This is useful if you have errors or notices you want to show even when the user 1256 * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook) 1257 * 1258 * @since 3.0.0 1259 * 1260 * @global array $wp_settings_errors Storage array of errors registered during this pageload 1261 * 1262 * @param string $setting Optional slug title of a specific setting who's errors you want. 1263 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. 1264 * @return array Array of settings errors 1265 */ 1266 function get_settings_errors( $setting = '', $sanitize = FALSE ) { 1267 global $wp_settings_errors; 1268 1269 // If $sanitize is true, manually re-run the sanitizisation for this option 1270 // This allows the $sanitize_callback from register_setting() to run, adding 1271 // any settings errors you want to show by default. 1272 if ( $sanitize ) 1273 sanitize_option( $setting, get_option($setting)); 1274 1275 // If settings were passed back from options.php then use them 1276 // Ignore transients if $sanitize is true, we dont' want the old values anyway 1277 if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) { 1278 $settings_errors = get_transient('settings_errors'); 1279 delete_transient('settings_errors'); 1280 // Otherwise check global in case validation has been run on this pageload 1281 } elseif ( count( $wp_settings_errors ) ) { 1282 $settings_errors = $wp_settings_errors; 1283 } else { 1284 return; 1285 } 1286 1287 // Filter the results to those of a specific setting if one was set 1288 if ( $setting ) { 1289 foreach ( (array) $settings_errors as $key => $details ) 1290 if ( $setting != $details['setting'] ) 1291 unset( $settings_errors[$key] ); 1292 } 1293 return $settings_errors; 1294 } 1295 1296 /** 1297 * Display settings errors registered by add_settings_error() 1298 * 1299 * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors(). 1300 * 1301 * This is called automatically after a settings page based on the Settings API is submitted. 1302 * Errors should be added during the validation callback function for a setting defined in register_setting() 1303 * 1304 * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization 1305 * on its current value. 1306 * 1307 * The $hide_on_update option will cause errors to only show when the settings page is first loaded. 1308 * if the user has already saved new values it will be hidden to avoid repeating messages already 1309 * shown in the default error reporting after submission. This is useful to show general errors like missing 1310 * settings when the user arrives at the settings page. 1311 * 1312 * @since 3.0.0 1313 * 1314 * @param string $setting Optional slug title of a specific setting who's errors you want. 1315 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. 1316 * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted. 1317 */ 1318 function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) { 1319 1320 if ($hide_on_update AND $_GET['settings-updated']) return; 1321 1322 $settings_errors = get_settings_errors( $setting, $sanitize ); 1323 1324 if ( !is_array($settings_errors) ) return; 1325 1326 $output = ''; 1327 foreach ( $settings_errors as $key => $details ) { 1328 $css_id = 'setting-error-' . $details['code']; 1329 $css_class = $details['type'] . ' settings-error'; 1330 $output .= "<div id='$css_id' class='$css_class'> \n"; 1331 $output .= "<p><strong>{$details['message']}</strong></p>"; 1332 $output .= "</div> \n"; 1333 } 1334 echo $output; 1335 } 1336 1337 /** 1338 * {@internal Missing Short Description}} 1339 * 1340 * @since 2.7.0 1341 * 1342 * @param unknown_type $found_action 1343 */ 1344 function find_posts_div($found_action = '') { 1345 ?> 1346 <div id="find-posts" class="find-box" style="display:none;"> 1347 <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div> 1348 <div class="find-box-inside"> 1349 <div class="find-box-search"> 1350 <?php if ( $found_action ) { ?> 1351 <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" /> 1352 <?php } ?> 1353 1354 <input type="hidden" name="affected" id="affected" value="" /> 1355 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?> 1356 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label> 1357 <input type="text" id="find-posts-input" name="ps" value="" /> 1358 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br /> 1359 1360 <?php 1361 $post_types = get_post_types( array('public' => true), 'objects' ); 1362 foreach ( $post_types as $post ) { 1363 if ( 'attachment' == $post->name ) 1364 continue; 1365 ?> 1366 <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'); ?> /> 1367 <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label> 1368 <?php 1369 } ?> 1370 </div> 1371 <div id="find-posts-response"></div> 1372 </div> 1373 <div class="find-box-buttons"> 1374 <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" /> 1375 <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?> 1376 </div> 1377 </div> 1378 <?php 1379 } 1380 1381 /** 1382 * Display the post password. 1383 * 1384 * The password is passed through {@link esc_attr()} to ensure that it 1385 * is safe for placing in an html attribute. 1386 * 1387 * @uses attr 1388 * @since 2.7.0 1389 */ 1390 function the_post_password() { 1391 global $post; 1392 if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password ); 1393 } 1394 1395 /** 1396 * {@internal Missing Short Description}} 1397 * 1398 * @since 2.7.0 1399 */ 1400 function favorite_actions( $screen = null ) { 1401 $default_action = false; 1402 1403 if ( is_string($screen) ) 1404 $screen = convert_to_screen($screen); 1405 1406 if ( $screen->is_user ) 1407 return; 1408 1409 if ( isset($screen->post_type) ) { 1410 $post_type_object = get_post_type_object($screen->post_type); 1411 if ( 'add' != $screen->action ) 1412 $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts)); 1413 else 1414 $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts)); 1415 } 1416 1417 if ( !$default_action ) { 1418 if ( $screen->is_network ) { 1419 $default_action = array('sites.php' => array( __('Sites'), 'manage_sites')); 1420 } else { 1421 switch ( $screen->id ) { 1422 case 'upload': 1423 $default_action = array('media-new.php' => array(__('New Media'), 'upload_files')); 1424 break; 1425 case 'media': 1426 $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files')); 1427 break; 1428 case 'link-manager': 1429 case 'link': 1430 if ( 'add' != $screen->action ) 1431 $default_action = array('link-add.php' => array(__('New Link'), 'manage_links')); 1432 else 1433 $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links')); 1434 break; 1435 case 'users': 1436 $default_action = array('user-new.php' => array(__('New User'), 'create_users')); 1437 break; 1438 case 'user': 1439 $default_action = array('users.php' => array(__('Edit Users'), 'edit_users')); 1440 break; 1441 case 'plugins': 1442 $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins')); 1443 break; 1444 case 'plugin-install': 1445 $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins')); 1446 break; 1447 case 'themes': 1448 $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes')); 1449 break; 1450 case 'theme-install': 1451 $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes')); 1452 break; 1453 default: 1454 $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts')); 1455 break; 1456 } 1457 } 1458 } 1459 1460 if ( !$screen->is_network ) { 1461 $actions = array( 1462 'post-new.php' => array(__('New Post'), 'edit_posts'), 1463 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'), 1464 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'), 1465 'media-new.php' => array(__('Upload'), 'upload_files'), 1466 'edit-comments.php' => array(__('Comments'), 'moderate_comments') 1467 ); 1468 } else { 1469 $actions = array( 1470 'sites.php' => array( __('Sites'), 'manage_sites'), 1471 'users.php' => array( __('Users'), 'manage_network_users') 1472 ); 1473 } 1474 1475 $default_key = array_keys($default_action); 1476 $default_key = $default_key[0]; 1477 if ( isset($actions[$default_key]) ) 1478 unset($actions[$default_key]); 1479 $actions = array_merge($default_action, $actions); 1480 $actions = apply_filters( 'favorite_actions', $actions, $screen ); 1481 1482 $allowed_actions = array(); 1483 foreach ( $actions as $action => $data ) { 1484 if ( current_user_can($data[1]) ) 1485 $allowed_actions[$action] = $data[0]; 1486 } 1487 1488 if ( empty($allowed_actions) ) 1489 return; 1490 1491 $first = array_keys($allowed_actions); 1492 $first = $first[0]; 1493 echo '<div id="favorite-actions">'; 1494 echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>'; 1495 echo '<div id="favorite-inside">'; 1496 1497 array_shift($allowed_actions); 1498 1499 foreach ( $allowed_actions as $action => $label) { 1500 echo "<div class='favorite-action'><a href='$action'>"; 1501 echo $label; 1502 echo "</a></div>\n"; 1503 } 1504 echo "</div></div>\n"; 1505 } 1506 1507 /** 1508 * Get the post title. 1509 * 1510 * The post title is fetched and if it is blank then a default string is 1511 * returned. 1512 * 1513 * @since 2.7.0 1514 * @param int $post_id The post id. If not supplied the global $post is used. 1515 * @return string The post title if set 1516 */ 1517 function _draft_or_post_title( $post_id = 0 ) { 1518 $title = get_the_title($post_id); 1519 if ( empty($title) ) 1520 $title = __('(no title)'); 1521 return $title; 1522 } 1523 1524 /** 1525 * Display the search query. 1526 * 1527 * A simple wrapper to display the "s" parameter in a GET URI. This function 1528 * should only be used when {@link the_search_query()} cannot. 1529 * 1530 * @uses attr 1531 * @since 2.7.0 1532 * 1533 */ 1534 function _admin_search_query() { 1535 echo isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : ''; 1536 } 1537 1538 /** 1539 * Generic Iframe header for use with Thickbox 1540 * 1541 * @since 2.7.0 1542 * @param string $title Title of the Iframe page. 1543 * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued). 1544 * 1545 */ 1546 function iframe_header( $title = '', $limit_styles = false ) { 1547 show_admin_bar( false ); 1548 global $hook_suffix, $current_screen, $current_user, $admin_body_class, $wp_locale; 1549 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); 1550 $admin_body_class .= ' iframe'; 1551 1552 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1553 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>> 1554 <head> 1555 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 1556 <title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title> 1557 <?php 1558 wp_enqueue_style( 'global' ); 1559 if ( ! $limit_styles ) 1560 wp_enqueue_style( 'wp-admin' ); 1561 wp_enqueue_style( 'colors' ); 1562 ?> 1563 <script type="text/javascript"> 1564 //<![CDATA[ 1565 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();}}}; 1566 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();} 1567 var userSettings = { 1568 'url': '<?php echo SITECOOKIEPATH; ?>', 1569 'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>', 1570 'time':'<?php echo time() ?>' 1571 }, 1572 ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', 1573 pagenow = '<?php echo $current_screen->id; ?>', 1574 typenow = '<?php if ( isset($current_screen->post_type) ) echo $current_screen->post_type; ?>', 1575 adminpage = '<?php echo $admin_body_class; ?>', 1576 thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>', 1577 decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>', 1578 isRtl = <?php echo (int) is_rtl(); ?>; 1579 //]]> 1580 </script> 1581 <?php 1582 do_action('admin_enqueue_scripts', $hook_suffix); 1583 do_action("admin_print_styles-$hook_suffix"); 1584 do_action('admin_print_styles'); 1585 do_action("admin_print_scripts-$hook_suffix"); 1586 do_action('admin_print_scripts'); 1587 do_action("admin_head-$hook_suffix"); 1588 do_action('admin_head'); 1589 ?> 1590 </head> 1591 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js <?php echo $admin_body_class; ?>"> 1592 <script type="text/javascript"> 1593 //<![CDATA[ 1594 (function(){ 1595 var c = document.body.className; 1596 c = c.replace(/no-js/, 'js'); 1597 document.body.className = c; 1598 })(); 1599 //]]> 1600 </script> 1601 <?php 1602 } 1603 1604 /** 1605 * Generic Iframe footer for use with Thickbox 1606 * 1607 * @since 2.7.0 1608 * 1609 */ 1610 function iframe_footer() { 1611 //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?> 1612 <div class="hidden"> 1613 <?php 1614 do_action('admin_footer', ''); 1615 do_action('admin_print_footer_scripts'); ?> 1616 </div> 1617 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script> 1618 </body> 1619 </html> 1620 <?php 1621 } 1622 1623 function _post_states($post) { 1624 $post_states = array(); 1625 if ( isset($_GET['post_status']) ) 1626 $post_status = $_GET['post_status']; 1627 else 1628 $post_status = ''; 1629 1630 if ( !empty($post->post_password) ) 1631 $post_states['protected'] = __('Password protected'); 1632 if ( 'private' == $post->post_status && 'private' != $post_status ) 1633 $post_states['private'] = __('Private'); 1634 if ( 'draft' == $post->post_status && 'draft' != $post_status ) 1635 $post_states['draft'] = __('Draft'); 1636 if ( 'pending' == $post->post_status && 'pending' != $post_status ) 1637 /* translators: post state */ 1638 $post_states['pending'] = _x('Pending', 'post state'); 1639 if ( is_sticky($post->ID) ) 1640 $post_states['sticky'] = __('Sticky'); 1641 1642 $post_states = apply_filters( 'display_post_states', $post_states ); 1643 1644 if ( ! empty($post_states) ) { 1645 $state_count = count($post_states); 1646 $i = 0; 1647 echo ' - '; 1648 foreach ( $post_states as $state ) { 1649 ++$i; 1650 ( $i == $state_count ) ? $sep = '' : $sep = ', '; 1651 echo "<span class='post-state'>$state$sep</span>"; 1652 } 1653 } 1654 1655 if ( get_post_format( $post->ID ) ) 1656 echo ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>'; 1657 } 1658 1659 function _media_states( $post ) { 1660 $media_states = array(); 1661 $stylesheet = get_option('stylesheet'); 1662 1663 if ( current_theme_supports( 'custom-header') ) { 1664 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true ); 1665 if ( ! empty( $meta_header ) && $meta_header == $stylesheet ) 1666 $media_states[] = __( 'Header Image' ); 1667 } 1668 1669 if ( current_theme_supports( 'custom-background') ) { 1670 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true ); 1671 if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) 1672 $media_states[] = __( 'Background Image' ); 1673 } 1674 1675 $media_states = apply_filters( 'display_media_states', $media_states ); 1676 1677 if ( ! empty( $media_states ) ) { 1678 $state_count = count( $media_states ); 1679 $i = 0; 1680 echo ' - '; 1681 foreach ( $media_states as $state ) { 1682 ++$i; 1683 ( $i == $state_count ) ? $sep = '' : $sep = ', '; 1684 echo "<span class='post-state'>$state$sep</span>"; 1685 } 1686 } 1687 } 1688 1689 /** 1690 * Convert a screen string to a screen object 1691 * 1692 * @since 3.0.0 1693 * 1694 * @param string $screen The name of the screen 1695 * @return object An object containing the safe screen name and id 1696 */ 1697 function convert_to_screen( $screen ) { 1698 $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen); 1699 1700 if ( is_network_admin() ) 1701 $screen .= '-network'; 1702 elseif ( is_user_admin() ) 1703 $screen .= '-user'; 1704 1705 $screen = (string) apply_filters( 'screen_meta_screen', $screen ); 1706 $screen = (object) array('id' => $screen, 'base' => $screen); 1707 return $screen; 1708 } 1709 1710 function screen_meta($screen) { 1711 global $wp_meta_boxes, $_wp_contextual_help, $wp_list_table, $wp_current_screen_options; 1712 1713 if ( is_string($screen) ) 1714 $screen = convert_to_screen($screen); 1715 1716 $columns = get_column_headers( $screen ); 1717 $hidden = get_hidden_columns( $screen ); 1718 1719 $meta_screens = array('index' => 'dashboard'); 1720 1721 if ( isset($meta_screens[$screen->id]) ) { 1722 $screen->id = $meta_screens[$screen->id]; 1723 $screen->base = $screen->id; 1724 } 1725 1726 $show_screen = false; 1727 if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) ) 1728 $show_screen = true; 1729 1730 $screen_options = screen_options($screen); 1731 if ( $screen_options ) 1732 $show_screen = true; 1733 1734 if ( !isset($_wp_contextual_help) ) 1735 $_wp_contextual_help = array(); 1736 1737 $settings = apply_filters('screen_settings', '', $screen); 1738 1739 switch ( $screen->id ) { 1740 case 'widgets': 1741 $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n"; 1742 $show_screen = true; 1743 break; 1744 } 1745 if ( ! empty( $settings ) ) 1746 $show_screen = true; 1747 1748 if ( !empty($wp_current_screen_options) ) 1749 $show_screen = true; 1750 1751 $show_screen = apply_filters('screen_options_show_screen', $show_screen, $screen); 1752 1753 ?> 1754 <div id="screen-meta"> 1755 <?php if ( $show_screen ) : ?> 1756 <div id="screen-options-wrap" class="hidden"> 1757 <form id="adv-settings" action="" method="post"> 1758 <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?> 1759 <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5> 1760 <div class="metabox-prefs"> 1761 <?php meta_box_prefs($screen); ?> 1762 <br class="clear" /> 1763 </div> 1764 <?php endif; 1765 if ( ! empty($columns) ) : ?> 1766 <h5><?php echo ( isset( $columns['_title'] ) ? $columns['_title'] : _x('Show on screen', 'Columns') ) ?></h5> 1767 <div class="metabox-prefs"> 1768 <?php 1769 $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname'); 1770 1771 foreach ( $columns as $column => $title ) { 1772 // Can't hide these for they are special 1773 if ( in_array( $column, $special ) ) 1774 continue; 1775 if ( empty( $title ) ) 1776 continue; 1777 1778 if ( 'comments' == $column ) 1779 $title = __( 'Comments' ); 1780 $id = "$column-hide"; 1781 echo '<label for="' . $id . '">'; 1782 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />'; 1783 echo "$title</label>\n"; 1784 } 1785 ?> 1786 <br class="clear" /> 1787 </div> 1788 <?php endif; 1789 echo screen_layout($screen); 1790 1791 if ( !empty( $screen_options ) ) { 1792 ?> 1793 <h5><?php _ex('Show on screen', 'Screen Options') ?></h5> 1794 <?php 1795 } 1796 1797 echo $screen_options; 1798 echo $settings; ?> 1799 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div> 1800 </form> 1801 </div> 1802 1803 <?php endif; // $show_screen 1804 1805 $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen); 1806 ?> 1807 <div id="contextual-help-wrap" class="hidden"> 1808 <?php 1809 $contextual_help = ''; 1810 if ( isset($_wp_contextual_help[$screen->id]) ) { 1811 $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n"; 1812 } else { 1813 $contextual_help .= '<div class="metabox-prefs">'; 1814 $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>'); 1815 $default_help .= '<br />'; 1816 $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>'); 1817 $contextual_help .= apply_filters('default_contextual_help', $default_help); 1818 $contextual_help .= "</div>\n"; 1819 } 1820 1821 echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen); 1822 ?> 1823 </div> 1824 1825 <div id="screen-meta-links"> 1826 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle"> 1827 <a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a> 1828 </div> 1829 <?php if ( $show_screen ) { ?> 1830 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle"> 1831 <a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a> 1832 </div> 1833 <?php } ?> 1834 </div> 1835 </div> 1836 <?php 1837 } 1838 1839 /** 1840 * Add contextual help text for a page 1841 * 1842 * @since 2.7.0 1843 * 1844 * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions. 1845 * @param string $help Arbitrary help text 1846 */ 1847 function add_contextual_help($screen, $help) { 1848 global $_wp_contextual_help; 1849 1850 if ( is_string($screen) ) 1851 $screen = convert_to_screen($screen); 1852 1853 if ( !isset($_wp_contextual_help) ) 1854 $_wp_contextual_help = array(); 1855 1856 $_wp_contextual_help[$screen->id] = $help; 1857 } 1858 1859 function screen_layout($screen) { 1860 global $screen_layout_columns, $wp_current_screen_options; 1861 1862 if ( is_string($screen) ) 1863 $screen = convert_to_screen($screen); 1864 1865 // Back compat for plugins using the filter instead of add_screen_option() 1866 $columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen); 1867 if ( !empty($columns) && isset($columns[$screen->id]) ) 1868 add_screen_option('layout_columns', array('max' => $columns[$screen->id]) ); 1869 1870 if ( !isset($wp_current_screen_options['layout_columns']) ) { 1871 $screen_layout_columns = 0; 1872 return ''; 1873 } 1874 1875 $screen_layout_columns = get_user_option("screen_layout_$screen->id"); 1876 $num = $wp_current_screen_options['layout_columns']['max']; 1877 1878 if ( ! $screen_layout_columns ) { 1879 if ( isset($wp_current_screen_options['layout_columns']['default']) ) 1880 $screen_layout_columns = $wp_current_screen_options['layout_columns']['default']; 1881 else 1882 $screen_layout_columns = 2; 1883 } 1884 1885 $i = 1; 1886 $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n"; 1887 while ( $i <= $num ) { 1888 $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n"; 1889 ++$i; 1890 } 1891 $return .= "</div>\n"; 1892 return $return; 1893 } 1894 1895 /** 1896 * Register and configure an admin screen option 1897 * 1898 * @since 3.1.0 1899 * 1900 * @param string $option An option name. 1901 * @param mixed $args Option dependent arguments 1902 * @return void 1903 */ 1904 function add_screen_option( $option, $args = array() ) { 1905 global $wp_current_screen_options; 1906 1907 if ( !isset($wp_current_screen_options) ) 1908 $wp_current_screen_options = array(); 1909 1910 $wp_current_screen_options[$option] = $args; 1911 } 1912 1913 function screen_options($screen) { 1914 global $wp_current_screen_options; 1915 1916 if ( is_string($screen) ) 1917 $screen = convert_to_screen($screen); 1918 1919 if ( !isset($wp_current_screen_options['per_page']) ) 1920 return ''; 1921 1922 $per_page_label = $wp_current_screen_options['per_page']['label']; 1923 1924 if ( empty($wp_current_screen_options['per_page']['option']) ) { 1925 $option = str_replace( '-', '_', "{$screen->id}_per_page" ); 1926 } else { 1927 $option = $wp_current_screen_options['per_page']['option']; 1928 } 1929 1930 $per_page = (int) get_user_option( $option ); 1931 if ( empty( $per_page ) || $per_page < 1 ) { 1932 if ( isset($wp_current_screen_options['per_page']['default']) ) 1933 $per_page = $wp_current_screen_options['per_page']['default']; 1934 else 1935 $per_page = 20; 1936 } 1937 1938 if ( 'edit_comments_per_page' == $option ) 1939 $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' ); 1940 elseif ( 'categories_per_page' == $option ) 1941 $per_page = apply_filters( 'edit_categories_per_page', $per_page ); 1942 else 1943 $per_page = apply_filters( $option, $per_page ); 1944 1945 // Back compat 1946 if ( isset( $screen->post_type ) ) 1947 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $screen->post_type ); 1948 1949 $return = "<div class='screen-options'>\n"; 1950 if ( !empty($per_page_label) ) 1951 $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n"; 1952 $return .= get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); 1953 $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />"; 1954 $return .= "</div>\n"; 1955 return $return; 1956 } 1957 1958 function screen_icon( $screen = '' ) { 1959 echo get_screen_icon( $screen ); 1960 } 1961 1962 function get_screen_icon( $screen = '' ) { 1963 global $current_screen, $typenow; 1964 1965 if ( empty($screen) ) 1966 $screen = $current_screen; 1967 elseif ( is_string($screen) ) 1968 $name = $screen; 1969 1970 $class = 'icon32'; 1971 1972 if ( empty($name) ) { 1973 if ( !empty($screen->parent_base) ) 1974 $name = $screen->parent_base; 1975 else 1976 $name = $screen->base; 1977 1978 if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type ) 1979 $name = 'edit-pages'; 1980 1981 $post_type = ''; 1982 if ( isset( $screen->post_type ) ) 1983 $post_type = $screen->post_type; 1984 elseif ( $current_screen == $screen ) 1985 $post_type = $typenow; 1986 if ( $post_type ) 1987 $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type ); 1988 } 1989 1990 return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>'; 1991 } 1992 1993 /** 1994 * Test support for compressing JavaScript from PHP 1995 * 1996 * Outputs JavaScript that tests if compression from PHP works as expected 1997 * and sets an option with the result. Has no effect when the current user 1998 * is not an administrator. To run the test again the option 'can_compress_scripts' 1999 * has to be deleted. 2000 * 2001 * @since 2.8.0 2002 */ 2003 function compression_test() { 2004 ?> 2005 <script type="text/javascript"> 2006 /* <![CDATA[ */ 2007 var testCompression = { 2008 get : function(test) { 2009 var x; 2010 if ( window.XMLHttpRequest ) { 2011 x = new XMLHttpRequest(); 2012 } else { 2013 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};} 2014 } 2015 2016 if (x) { 2017 x.onreadystatechange = function() { 2018 var r, h; 2019 if ( x.readyState == 4 ) { 2020 r = x.responseText.substr(0, 18); 2021 h = x.getResponseHeader('Content-Encoding'); 2022 testCompression.check(r, h, test); 2023 } 2024 } 2025 2026 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true); 2027 x.send(''); 2028 } 2029 }, 2030 2031 check : function(r, h, test) { 2032 if ( ! r && ! test ) 2033 this.get(1); 2034 2035 if ( 1 == test ) { 2036 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) ) 2037 this.get('no'); 2038 else 2039 this.get(2); 2040 2041 return; 2042 } 2043 2044 if ( 2 == test ) { 2045 if ( '"wpCompressionTest' == r ) 2046 this.get('yes'); 2047 else 2048 this.get('no'); 2049 } 2050 } 2051 }; 2052 testCompression.check(); 2053 /* ]]> */ 2054 </script> 2055 <?php 2056 } 2057 2058 /** 2059 * Get the current screen object 2060 * 2061 * @since 3.1.0 2062 * 2063 * @return object Current screen object 2064 */ 2065 function get_current_screen() { 2066 global $current_screen; 2067 2068 if ( !isset($current_screen) ) 2069 return null; 2070 2071 return $current_screen; 2072 } 2073 2074 /** 2075 * Set the current screen object 2076 * 2077 * @since 3.0.0 2078 * 2079 * @uses $current_screen 2080 * 2081 * @param string $id Screen id, optional. 2082 */ 2083 function set_current_screen( $id = '' ) { 2084 global $current_screen, $hook_suffix, $typenow, $taxnow; 2085 2086 $action = ''; 2087 2088 if ( empty($id) ) { 2089 $current_screen = $hook_suffix; 2090 $current_screen = str_replace('.php', '', $current_screen); 2091 if ( preg_match('/-add|-new$/', $current_screen) ) 2092 $action = 'add'; 2093 $current_screen = str_replace('-new', '', $current_screen); 2094 $current_screen = str_replace('-add', '', $current_screen); 2095 $current_screen = array('id' => $current_screen, 'base' => $current_screen); 2096 } else { 2097 $id = sanitize_key($id); 2098 if ( false !== strpos($id, '-') ) { 2099 list( $id, $typenow ) = explode('-', $id, 2); 2100 if ( taxonomy_exists( $typenow ) ) { 2101 $id = 'edit-tags'; 2102 $taxnow = $typenow; 2103 $typenow = ''; 2104 } 2105 } 2106 $current_screen = array('id' => $id, 'base' => $id); 2107 } 2108 2109 $current_screen = (object) $current_screen; 2110 2111 $current_screen->action = $action; 2112 2113 // Map index to dashboard 2114 if ( 'index' == $current_screen->base ) 2115 $current_screen->base = 'dashboard'; 2116 if ( 'index' == $current_screen->id ) 2117 $current_screen->id = 'dashboard'; 2118 2119 if ( 'edit' == $current_screen->id ) { 2120 if ( empty($typenow) ) 2121 $typenow = 'post'; 2122 $current_screen->id .= '-' . $typenow; 2123 $current_screen->post_type = $typenow; 2124 } elseif ( 'post' == $current_screen->id ) { 2125 if ( empty($typenow) ) 2126 $typenow = 'post'; 2127 $current_screen->id = $typenow; 2128 $current_screen->post_type = $typenow; 2129 } elseif ( 'edit-tags' == $current_screen->id ) { 2130 if ( empty($taxnow) ) 2131 $taxnow = 'post_tag'; 2132 $current_screen->id = 'edit-' . $taxnow; 2133 $current_screen->taxonomy = $taxnow; 2134 } 2135 2136 $current_screen->is_network = is_network_admin(); 2137 $current_screen->is_user = is_user_admin(); 2138 2139 if ( $current_screen->is_network ) { 2140 $current_screen->base .= '-network'; 2141 $current_screen->id .= '-network'; 2142 } elseif ( $current_screen->is_user ) { 2143 $current_screen->base .= '-user'; 2144 $current_screen->id .= '-user'; 2145 } 2146 2147 $current_screen = apply_filters('current_screen', $current_screen); 2148 } 2149 2150 /** 2151 * Echos a submit button, with provided text and appropriate class 2152 * 2153 * @since 3.1.0 2154 * 2155 * @param string $text The text of the button (defaults to 'Save Changes') 2156 * @param string $type The type of button. One of: primary, secondary, delete 2157 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute 2158 * is given in $other_attributes below, $name will be used as the button's id. 2159 * @param bool $wrap True if the output button should be wrapped in a paragraph tag, 2160 * false otherwise. Defaults to true 2161 * @param array|string $other_attributes Other attributes that should be output with the button, 2162 * mapping attributes to their values, such as array( 'tabindex' => '1' ). 2163 * These attributes will be ouput as attribute="value", such as tabindex="1". 2164 * Defaults to no other attributes. Other attributes can also be provided as a 2165 * string such as 'tabindex="1"', though the array format is typically cleaner. 2166 */ 2167 function submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) { 2168 echo get_submit_button( $text, $type, $name, $wrap, $other_attributes ); 2169 } 2170 2171 /** 2172 * Returns a submit button, with provided text and appropriate class 2173 * 2174 * @since 3.1.0 2175 * 2176 * @param string $text The text of the button (defaults to 'Save Changes') 2177 * @param string $type The type of button. One of: primary, secondary, delete 2178 * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute 2179 * is given in $other_attributes below, $name will be used as the button's id. 2180 * @param bool $wrap True if the output button should be wrapped in a paragraph tag, 2181 * false otherwise. Defaults to true 2182 * @param array|string $other_attributes Other attributes that should be output with the button, 2183 * mapping attributes to their values, such as array( 'tabindex' => '1' ). 2184 * These attributes will be ouput as attribute="value", such as tabindex="1". 2185 * Defaults to no other attributes. Other attributes can also be provided as a 2186 * string such as 'tabindex="1"', though the array format is typically cleaner. 2187 */ 2188 function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) { 2189 switch ( $type ) : 2190 case 'primary' : 2191 case 'secondary' : 2192 $class = 'button-' . $type; 2193 break; 2194 case 'delete' : 2195 $class = 'button-secondary delete'; 2196 break; 2197 default : 2198 $class = $type; // Custom cases can just pass in the classes they want to be used 2199 endswitch; 2200 $text = ( NULL == $text ) ? __( 'Save Changes' ) : $text; 2201 2202 // Default the id attribute to $name unless an id was specifically provided in $other_attributes 2203 $id = $name; 2204 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) { 2205 $id = $other_attributes['id']; 2206 unset( $other_attributes['id'] ); 2207 } 2208 2209 $attributes = ''; 2210 if ( is_array( $other_attributes ) ) { 2211 foreach ( $other_attributes as $attribute => $value ) { 2212 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important 2213 } 2214 } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string 2215 $attributes = $other_attributes; 2216 } 2217 2218 $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ); 2219 $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; 2220 2221 if ( $wrap ) { 2222 $button = '<p class="submit">' . $button . '</p>'; 2223 } 2224 2225 return $button; 2226 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |