[ Index ] |
PHP Cross Reference of WordPress |
[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 /** Walker_Category_Checklist class */ 12 require_once ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php'; 13 14 /** WP_Internal_Pointers class */ 15 require_once ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php'; 16 17 // 18 // Category Checklists. 19 // 20 21 /** 22 * Output an unordered list of checkbox input elements labeled with category names. 23 * 24 * @since 2.5.1 25 * 26 * @see wp_terms_checklist() 27 * 28 * @param int $post_id Optional. Post to generate a categories checklist for. Default 0. 29 * $selected_cats must not be an array. Default 0. 30 * @param int $descendants_and_self Optional. ID of the category to output along with its descendants. 31 * Default 0. 32 * @param int[]|false $selected_cats Optional. Array of category IDs to mark as checked. Default false. 33 * @param int[]|false $popular_cats Optional. Array of category IDs to receive the "popular-category" class. 34 * Default false. 35 * @param Walker $walker Optional. Walker object to use to build the output. 36 * Default is a Walker_Category_Checklist instance. 37 * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to 38 * the top of the list. Default true. 39 */ 40 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { 41 wp_terms_checklist( 42 $post_id, 43 array( 44 'taxonomy' => 'category', 45 'descendants_and_self' => $descendants_and_self, 46 'selected_cats' => $selected_cats, 47 'popular_cats' => $popular_cats, 48 'walker' => $walker, 49 'checked_ontop' => $checked_ontop, 50 ) 51 ); 52 } 53 54 /** 55 * Output an unordered list of checkbox input elements labelled with term names. 56 * 57 * Taxonomy-independent version of wp_category_checklist(). 58 * 59 * @since 3.0.0 60 * @since 4.4.0 Introduced the `$echo` argument. 61 * 62 * @param int $post_id Optional. Post ID. Default 0. 63 * @param array|string $args { 64 * Optional. Array or string of arguments for generating a terms checklist. Default empty array. 65 * 66 * @type int $descendants_and_self ID of the category to output along with its descendants. 67 * Default 0. 68 * @type int[] $selected_cats Array of category IDs to mark as checked. Default false. 69 * @type int[] $popular_cats Array of category IDs to receive the "popular-category" class. 70 * Default false. 71 * @type Walker $walker Walker object to use to build the output. 72 * Default is a Walker_Category_Checklist instance. 73 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. 74 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to 75 * the top of the list. Default true. 76 * @type bool $echo Whether to echo the generated markup. False to return the markup instead 77 * of echoing it. Default true. 78 * } 79 * @return string HTML list of input elements. 80 */ 81 function wp_terms_checklist( $post_id = 0, $args = array() ) { 82 $defaults = array( 83 'descendants_and_self' => 0, 84 'selected_cats' => false, 85 'popular_cats' => false, 86 'walker' => null, 87 'taxonomy' => 'category', 88 'checked_ontop' => true, 89 'echo' => true, 90 ); 91 92 /** 93 * Filters the taxonomy terms checklist arguments. 94 * 95 * @since 3.4.0 96 * 97 * @see wp_terms_checklist() 98 * 99 * @param array $args An array of arguments. 100 * @param int $post_id The post ID. 101 */ 102 $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); 103 104 $parsed_args = wp_parse_args( $params, $defaults ); 105 106 if ( empty( $parsed_args['walker'] ) || ! ( $parsed_args['walker'] instanceof Walker ) ) { 107 $walker = new Walker_Category_Checklist; 108 } else { 109 $walker = $parsed_args['walker']; 110 } 111 112 $taxonomy = $parsed_args['taxonomy']; 113 $descendants_and_self = (int) $parsed_args['descendants_and_self']; 114 115 $args = array( 'taxonomy' => $taxonomy ); 116 117 $tax = get_taxonomy( $taxonomy ); 118 $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); 119 120 $args['list_only'] = ! empty( $parsed_args['list_only'] ); 121 122 if ( is_array( $parsed_args['selected_cats'] ) ) { 123 $args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] ); 124 } elseif ( $post_id ) { 125 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); 126 } else { 127 $args['selected_cats'] = array(); 128 } 129 130 if ( is_array( $parsed_args['popular_cats'] ) ) { 131 $args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] ); 132 } else { 133 $args['popular_cats'] = get_terms( 134 array( 135 'taxonomy' => $taxonomy, 136 'fields' => 'ids', 137 'orderby' => 'count', 138 'order' => 'DESC', 139 'number' => 10, 140 'hierarchical' => false, 141 ) 142 ); 143 } 144 145 if ( $descendants_and_self ) { 146 $categories = (array) get_terms( 147 array( 148 'taxonomy' => $taxonomy, 149 'child_of' => $descendants_and_self, 150 'hierarchical' => 0, 151 'hide_empty' => 0, 152 ) 153 ); 154 $self = get_term( $descendants_and_self, $taxonomy ); 155 array_unshift( $categories, $self ); 156 } else { 157 $categories = (array) get_terms( 158 array( 159 'taxonomy' => $taxonomy, 160 'get' => 'all', 161 ) 162 ); 163 } 164 165 $output = ''; 166 167 if ( $parsed_args['checked_ontop'] ) { 168 // Post-process $categories rather than adding an exclude to the get_terms() query 169 // to keep the query the same across all posts (for any query cache). 170 $checked_categories = array(); 171 $keys = array_keys( $categories ); 172 173 foreach ( $keys as $k ) { 174 if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) { 175 $checked_categories[] = $categories[ $k ]; 176 unset( $categories[ $k ] ); 177 } 178 } 179 180 // Put checked categories on top. 181 $output .= $walker->walk( $checked_categories, 0, $args ); 182 } 183 // Then the rest of them. 184 $output .= $walker->walk( $categories, 0, $args ); 185 186 if ( $parsed_args['echo'] ) { 187 echo $output; 188 } 189 190 return $output; 191 } 192 193 /** 194 * Retrieve a list of the most popular terms from the specified taxonomy. 195 * 196 * If the $echo argument is true then the elements for a list of checkbox 197 * `<input>` elements labelled with the names of the selected terms is output. 198 * If the $post_ID global isn't empty then the terms associated with that 199 * post will be marked as checked. 200 * 201 * @since 2.5.0 202 * 203 * @param string $taxonomy Taxonomy to retrieve terms from. 204 * @param int $default Not used. 205 * @param int $number Number of terms to retrieve. Defaults to 10. 206 * @param bool $echo Optionally output the list as well. Defaults to true. 207 * @return int[] Array of popular term IDs. 208 */ 209 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { 210 $post = get_post(); 211 212 if ( $post && $post->ID ) { 213 $checked_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); 214 } else { 215 $checked_terms = array(); 216 } 217 218 $terms = get_terms( 219 array( 220 'taxonomy' => $taxonomy, 221 'orderby' => 'count', 222 'order' => 'DESC', 223 'number' => $number, 224 'hierarchical' => false, 225 ) 226 ); 227 228 $tax = get_taxonomy( $taxonomy ); 229 230 $popular_ids = array(); 231 232 foreach ( (array) $terms as $term ) { 233 $popular_ids[] = $term->term_id; 234 if ( ! $echo ) { // Hack for Ajax use. 235 continue; 236 } 237 $id = "popular-$taxonomy-$term->term_id"; 238 $checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : ''; 239 ?> 240 241 <li id="<?php echo $id; ?>" class="popular-category"> 242 <label class="selectit"> 243 <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> /> 244 <?php 245 /** This filter is documented in wp-includes/category-template.php */ 246 echo esc_html( apply_filters( 'the_category', $term->name, '', '' ) ); 247 ?> 248 </label> 249 </li> 250 251 <?php 252 } 253 return $popular_ids; 254 } 255 256 /** 257 * Outputs a link category checklist element. 258 * 259 * @since 2.5.1 260 * 261 * @param int $link_id 262 */ 263 function wp_link_category_checklist( $link_id = 0 ) { 264 $default = 1; 265 266 $checked_categories = array(); 267 268 if ( $link_id ) { 269 $checked_categories = wp_get_link_cats( $link_id ); 270 // No selected categories, strange. 271 if ( ! count( $checked_categories ) ) { 272 $checked_categories[] = $default; 273 } 274 } else { 275 $checked_categories[] = $default; 276 } 277 278 $categories = get_terms( 279 array( 280 'taxonomy' => 'link_category', 281 'orderby' => 'name', 282 'hide_empty' => 0, 283 ) 284 ); 285 286 if ( empty( $categories ) ) { 287 return; 288 } 289 290 foreach ( $categories as $category ) { 291 $cat_id = $category->term_id; 292 293 /** This filter is documented in wp-includes/category-template.php */ 294 $name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) ); 295 $checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : ''; 296 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>'; 297 } 298 } 299 300 /** 301 * Adds hidden fields with the data for use in the inline editor for posts and pages. 302 * 303 * @since 2.7.0 304 * 305 * @param WP_Post $post Post object. 306 */ 307 function get_inline_data( $post ) { 308 $post_type_object = get_post_type_object( $post->post_type ); 309 if ( ! current_user_can( 'edit_post', $post->ID ) ) { 310 return; 311 } 312 313 $title = esc_textarea( trim( $post->post_title ) ); 314 315 echo ' 316 <div class="hidden" id="inline_' . $post->ID . '"> 317 <div class="post_title">' . $title . '</div>' . 318 /** This filter is documented in wp-admin/edit-tag-form.php */ 319 '<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name, $post ) . '</div> 320 <div class="post_author">' . $post->post_author . '</div> 321 <div class="comment_status">' . esc_html( $post->comment_status ) . '</div> 322 <div class="ping_status">' . esc_html( $post->ping_status ) . '</div> 323 <div class="_status">' . esc_html( $post->post_status ) . '</div> 324 <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div> 325 <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div> 326 <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div> 327 <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div> 328 <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div> 329 <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> 330 <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; 331 332 if ( $post_type_object->hierarchical ) { 333 echo '<div class="post_parent">' . $post->post_parent . '</div>'; 334 } 335 336 echo '<div class="page_template">' . ( $post->page_template ? esc_html( $post->page_template ) : 'default' ) . '</div>'; 337 338 if ( post_type_supports( $post->post_type, 'page-attributes' ) ) { 339 echo '<div class="menu_order">' . $post->menu_order . '</div>'; 340 } 341 342 $taxonomy_names = get_object_taxonomies( $post->post_type ); 343 344 foreach ( $taxonomy_names as $taxonomy_name ) { 345 $taxonomy = get_taxonomy( $taxonomy_name ); 346 347 if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { 348 349 $terms = get_object_term_cache( $post->ID, $taxonomy_name ); 350 if ( false === $terms ) { 351 $terms = wp_get_object_terms( $post->ID, $taxonomy_name ); 352 wp_cache_add( $post->ID, wp_list_pluck( $terms, 'term_id' ), $taxonomy_name . '_relationships' ); 353 } 354 $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' ); 355 356 echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>'; 357 358 } elseif ( $taxonomy->show_ui ) { 359 360 $terms_to_edit = get_terms_to_edit( $post->ID, $taxonomy_name ); 361 if ( ! is_string( $terms_to_edit ) ) { 362 $terms_to_edit = ''; 363 } 364 365 echo '<div class="tags_input" id="' . $taxonomy_name . '_' . $post->ID . '">' 366 . esc_html( str_replace( ',', ', ', $terms_to_edit ) ) . '</div>'; 367 368 } 369 } 370 371 if ( ! $post_type_object->hierarchical ) { 372 echo '<div class="sticky">' . ( is_sticky( $post->ID ) ? 'sticky' : '' ) . '</div>'; 373 } 374 375 if ( post_type_supports( $post->post_type, 'post-formats' ) ) { 376 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>'; 377 } 378 379 /** 380 * Fires after outputting the fields for the inline editor for posts and pages. 381 * 382 * @since 4.9.8 383 * 384 * @param WP_Post $post The current post object. 385 * @param WP_Post_Type $post_type_object The current post's post type object. 386 */ 387 do_action( 'add_inline_data', $post, $post_type_object ); 388 389 echo '</div>'; 390 } 391 392 /** 393 * Outputs the in-line comment reply-to form in the Comments list table. 394 * 395 * @since 2.7.0 396 * 397 * @global WP_List_Table $wp_list_table 398 * 399 * @param int $position 400 * @param bool $checkbox 401 * @param string $mode 402 * @param bool $table_row 403 */ 404 function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) { 405 global $wp_list_table; 406 /** 407 * Filters the in-line comment reply-to form output in the Comments 408 * list table. 409 * 410 * Returning a non-empty value here will short-circuit display 411 * of the in-line comment-reply form in the Comments list table, 412 * echoing the returned value instead. 413 * 414 * @since 2.7.0 415 * 416 * @see wp_comment_reply() 417 * 418 * @param string $content The reply-to form content. 419 * @param array $args An array of default args. 420 */ 421 $content = apply_filters( 422 'wp_comment_reply', 423 '', 424 array( 425 'position' => $position, 426 'checkbox' => $checkbox, 427 'mode' => $mode, 428 ) 429 ); 430 431 if ( ! empty( $content ) ) { 432 echo $content; 433 return; 434 } 435 436 if ( ! $wp_list_table ) { 437 if ( 'single' === $mode ) { 438 $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); 439 } else { 440 $wp_list_table = _get_list_table( 'WP_Comments_List_Table' ); 441 } 442 } 443 444 ?> 445 <form method="get"> 446 <?php if ( $table_row ) : ?> 447 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" class="inline-edit-row" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange"> 448 <?php else : ?> 449 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;"> 450 <?php endif; ?> 451 <fieldset class="comment-reply"> 452 <legend> 453 <span class="hidden" id="editlegend"><?php _e( 'Edit Comment' ); ?></span> 454 <span class="hidden" id="replyhead"><?php _e( 'Reply to Comment' ); ?></span> 455 <span class="hidden" id="addhead"><?php _e( 'Add new Comment' ); ?></span> 456 </legend> 457 458 <div id="replycontainer"> 459 <label for="replycontent" class="screen-reader-text"><?php _e( 'Comment' ); ?></label> 460 <?php 461 $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); 462 wp_editor( 463 '', 464 'replycontent', 465 array( 466 'media_buttons' => false, 467 'tinymce' => false, 468 'quicktags' => $quicktags_settings, 469 ) 470 ); 471 ?> 472 </div> 473 474 <div id="edithead" style="display:none;"> 475 <div class="inside"> 476 <label for="author-name"><?php _e( 'Name' ); ?></label> 477 <input type="text" name="newcomment_author" size="50" value="" id="author-name" /> 478 </div> 479 480 <div class="inside"> 481 <label for="author-email"><?php _e( 'Email' ); ?></label> 482 <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" /> 483 </div> 484 485 <div class="inside"> 486 <label for="author-url"><?php _e( 'URL' ); ?></label> 487 <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" /> 488 </div> 489 </div> 490 491 <div id="replysubmit" class="submit"> 492 <p class="reply-submit-buttons"> 493 <button type="button" class="save button button-primary"> 494 <span id="addbtn" style="display: none;"><?php _e( 'Add Comment' ); ?></span> 495 <span id="savebtn" style="display: none;"><?php _e( 'Update Comment' ); ?></span> 496 <span id="replybtn" style="display: none;"><?php _e( 'Submit Reply' ); ?></span> 497 </button> 498 <button type="button" class="cancel button"><?php _e( 'Cancel' ); ?></button> 499 <span class="waiting spinner"></span> 500 </p> 501 <div class="notice notice-error notice-alt inline hidden"> 502 <p class="error"></p> 503 </div> 504 </div> 505 506 <input type="hidden" name="action" id="action" value="" /> 507 <input type="hidden" name="comment_ID" id="comment_ID" value="" /> 508 <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> 509 <input type="hidden" name="status" id="status" value="" /> 510 <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" /> 511 <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" /> 512 <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr( $mode ); ?>" /> 513 <?php 514 wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); 515 if ( current_user_can( 'unfiltered_html' ) ) { 516 wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false ); 517 } 518 ?> 519 </fieldset> 520 <?php if ( $table_row ) : ?> 521 </td></tr></tbody></table> 522 <?php else : ?> 523 </div></div> 524 <?php endif; ?> 525 </form> 526 <?php 527 } 528 529 /** 530 * Output 'undo move to Trash' text for comments 531 * 532 * @since 2.9.0 533 */ 534 function wp_comment_trashnotice() { 535 ?> 536 <div class="hidden" id="trash-undo-holder"> 537 <div class="trash-undo-inside"> 538 <?php 539 /* translators: %s: Comment author, filled by Ajax. */ 540 printf( __( 'Comment by %s moved to the Trash.' ), '<strong></strong>' ); 541 ?> 542 <span class="undo untrash"><a href="#"><?php _e( 'Undo' ); ?></a></span> 543 </div> 544 </div> 545 <div class="hidden" id="spam-undo-holder"> 546 <div class="spam-undo-inside"> 547 <?php 548 /* translators: %s: Comment author, filled by Ajax. */ 549 printf( __( 'Comment by %s marked as spam.' ), '<strong></strong>' ); 550 ?> 551 <span class="undo unspam"><a href="#"><?php _e( 'Undo' ); ?></a></span> 552 </div> 553 </div> 554 <?php 555 } 556 557 /** 558 * Outputs a post's public meta data in the Custom Fields meta box. 559 * 560 * @since 1.2.0 561 * 562 * @param array $meta 563 */ 564 function list_meta( $meta ) { 565 // Exit if no meta. 566 if ( ! $meta ) { 567 echo ' 568 <table id="list-table" style="display: none;"> 569 <thead> 570 <tr> 571 <th class="left">' . _x( 'Name', 'meta name' ) . '</th> 572 <th>' . __( 'Value' ) . '</th> 573 </tr> 574 </thead> 575 <tbody id="the-list" data-wp-lists="list:meta"> 576 <tr><td></td></tr> 577 </tbody> 578 </table>'; // TBODY needed for list-manipulation JS. 579 return; 580 } 581 $count = 0; 582 ?> 583 <table id="list-table"> 584 <thead> 585 <tr> 586 <th class="left"><?php _ex( 'Name', 'meta name' ); ?></th> 587 <th><?php _e( 'Value' ); ?></th> 588 </tr> 589 </thead> 590 <tbody id='the-list' data-wp-lists='list:meta'> 591 <?php 592 foreach ( $meta as $entry ) { 593 echo _list_meta_row( $entry, $count ); 594 } 595 ?> 596 </tbody> 597 </table> 598 <?php 599 } 600 601 /** 602 * Outputs a single row of public meta data in the Custom Fields meta box. 603 * 604 * @since 2.5.0 605 * 606 * @param array $entry 607 * @param int $count 608 * @return string 609 */ 610 function _list_meta_row( $entry, &$count ) { 611 static $update_nonce = ''; 612 613 if ( is_protected_meta( $entry['meta_key'], 'post' ) ) { 614 return ''; 615 } 616 617 if ( ! $update_nonce ) { 618 $update_nonce = wp_create_nonce( 'add-meta' ); 619 } 620 621 $r = ''; 622 ++ $count; 623 624 if ( is_serialized( $entry['meta_value'] ) ) { 625 if ( is_serialized_string( $entry['meta_value'] ) ) { 626 // This is a serialized string, so we should display it. 627 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); 628 } else { 629 // This is a serialized array/object so we should NOT display it. 630 --$count; 631 return ''; 632 } 633 } 634 635 $entry['meta_key'] = esc_attr( $entry['meta_key'] ); 636 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // Using a <textarea />. 637 $entry['meta_id'] = (int) $entry['meta_id']; 638 639 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); 640 641 $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>"; 642 $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' type='text' size='20' value='{$entry['meta_key']}' />"; 643 644 $r .= "\n\t\t<div class='submit'>"; 645 $r .= get_submit_button( __( 'Delete' ), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ) ); 646 $r .= "\n\t\t"; 647 $r .= get_submit_button( __( 'Update' ), 'updatemeta small', "meta-{$entry['meta_id']}-submit", false, array( 'data-wp-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce" ) ); 648 $r .= '</div>'; 649 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false ); 650 $r .= '</td>'; 651 652 $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' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>"; 653 return $r; 654 } 655 656 /** 657 * Prints the form in the Custom Fields meta box. 658 * 659 * @since 1.2.0 660 * 661 * @global wpdb $wpdb WordPress database abstraction object. 662 * 663 * @param WP_Post $post Optional. The post being edited. 664 */ 665 function meta_form( $post = null ) { 666 global $wpdb; 667 $post = get_post( $post ); 668 669 /** 670 * Filters values for the meta key dropdown in the Custom Fields meta box. 671 * 672 * Returning a non-null value will effectively short-circuit and avoid a 673 * potentially expensive query against postmeta. 674 * 675 * @since 4.4.0 676 * 677 * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null. 678 * @param WP_Post $post The current post object. 679 */ 680 $keys = apply_filters( 'postmeta_form_keys', null, $post ); 681 682 if ( null === $keys ) { 683 /** 684 * Filters the number of custom fields to retrieve for the drop-down 685 * in the Custom Fields meta box. 686 * 687 * @since 2.1.0 688 * 689 * @param int $limit Number of custom fields to retrieve. Default 30. 690 */ 691 $limit = apply_filters( 'postmeta_form_limit', 30 ); 692 693 $keys = $wpdb->get_col( 694 $wpdb->prepare( 695 "SELECT DISTINCT meta_key 696 FROM $wpdb->postmeta 697 WHERE meta_key NOT BETWEEN '_' AND '_z' 698 HAVING meta_key NOT LIKE %s 699 ORDER BY meta_key 700 LIMIT %d", 701 $wpdb->esc_like( '_' ) . '%', 702 $limit 703 ) 704 ); 705 } 706 707 if ( $keys ) { 708 natcasesort( $keys ); 709 $meta_key_input_id = 'metakeyselect'; 710 } else { 711 $meta_key_input_id = 'metakeyinput'; 712 } 713 ?> 714 <p><strong><?php _e( 'Add New Custom Field:' ); ?></strong></p> 715 <table id="newmeta"> 716 <thead> 717 <tr> 718 <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ); ?></label></th> 719 <th><label for="metavalue"><?php _e( 'Value' ); ?></label></th> 720 </tr> 721 </thead> 722 723 <tbody> 724 <tr> 725 <td id="newmetaleft" class="left"> 726 <?php if ( $keys ) { ?> 727 <select id="metakeyselect" name="metakeyselect"> 728 <option value="#NONE#"><?php _e( '— Select —' ); ?></option> 729 <?php 730 foreach ( $keys as $key ) { 731 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) { 732 continue; 733 } 734 echo "\n<option value='" . esc_attr( $key ) . "'>" . esc_html( $key ) . '</option>'; 735 } 736 ?> 737 </select> 738 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" /> 739 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;"> 740 <span id="enternew"><?php _e( 'Enter new' ); ?></span> 741 <span id="cancelnew" class="hidden"><?php _e( 'Cancel' ); ?></span></a> 742 <?php } else { ?> 743 <input type="text" id="metakeyinput" name="metakeyinput" value="" /> 744 <?php } ?> 745 </td> 746 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td> 747 </tr> 748 749 <tr><td colspan="2"> 750 <div class="submit"> 751 <?php 752 submit_button( 753 __( 'Add Custom Field' ), 754 '', 755 'addmeta', 756 false, 757 array( 758 'id' => 'newmeta-submit', 759 'data-wp-lists' => 'add:the-list:newmeta', 760 ) 761 ); 762 ?> 763 </div> 764 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?> 765 </td></tr> 766 </tbody> 767 </table> 768 <?php 769 770 } 771 772 /** 773 * Print out HTML form date elements for editing post or comment publish date. 774 * 775 * @since 0.71 776 * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`. 777 * 778 * @global WP_Locale $wp_locale WordPress date and time locale object. 779 * 780 * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date. 781 * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. 782 * @param int $tab_index The tabindex attribute to add. Default 0. 783 * @param int|bool $multi Optional. Whether the additional fields and buttons should be added. 784 * Default 0|false. 785 */ 786 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { 787 global $wp_locale; 788 $post = get_post(); 789 790 if ( $for_post ) { 791 $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ), true ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) ); 792 } 793 794 $tab_index_attribute = ''; 795 if ( (int) $tab_index > 0 ) { 796 $tab_index_attribute = " tabindex=\"$tab_index\""; 797 } 798 799 // @todo Remove this? 800 // 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 />'; 801 802 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date; 803 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' ); 804 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' ); 805 $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' ); 806 $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' ); 807 $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' ); 808 $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' ); 809 810 $cur_jj = current_time( 'd' ); 811 $cur_mm = current_time( 'm' ); 812 $cur_aa = current_time( 'Y' ); 813 $cur_hh = current_time( 'H' ); 814 $cur_mn = current_time( 'i' ); 815 816 $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select class="form-required" ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; 817 for ( $i = 1; $i < 13; $i = $i + 1 ) { 818 $monthnum = zeroise( $i, 2 ); 819 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); 820 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>'; 821 /* translators: 1: Month number (01, 02, etc.), 2: Month abbreviation. */ 822 $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; 823 } 824 $month .= '</select></label>'; 825 826 $day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>'; 827 $year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>'; 828 $hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>'; 829 $minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>'; 830 831 echo '<div class="timestamp-wrap">'; 832 /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */ 833 printf( __( '%1$s %2$s, %3$s at %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); 834 835 echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; 836 837 if ( $multi ) { 838 return; 839 } 840 841 echo "\n\n"; 842 843 $map = array( 844 'mm' => array( $mm, $cur_mm ), 845 'jj' => array( $jj, $cur_jj ), 846 'aa' => array( $aa, $cur_aa ), 847 'hh' => array( $hh, $cur_hh ), 848 'mn' => array( $mn, $cur_mn ), 849 ); 850 851 foreach ( $map as $timeunit => $value ) { 852 list( $unit, $curr ) = $value; 853 854 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n"; 855 $cur_timeunit = 'cur_' . $timeunit; 856 echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n"; 857 } 858 ?> 859 860 <p> 861 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e( 'OK' ); ?></a> 862 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e( 'Cancel' ); ?></a> 863 </p> 864 <?php 865 } 866 867 /** 868 * Print out option HTML elements for the page templates drop-down. 869 * 870 * @since 1.5.0 871 * @since 4.7.0 Added the `$post_type` parameter. 872 * 873 * @param string $default Optional. The template file name. Default empty. 874 * @param string $post_type Optional. Post type to get templates for. Default 'post'. 875 */ 876 function page_template_dropdown( $default = '', $post_type = 'page' ) { 877 $templates = get_page_templates( null, $post_type ); 878 879 ksort( $templates ); 880 881 foreach ( array_keys( $templates ) as $template ) { 882 $selected = selected( $default, $templates[ $template ], false ); 883 echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>'; 884 } 885 } 886 887 /** 888 * Print out option HTML elements for the page parents drop-down. 889 * 890 * @since 1.5.0 891 * @since 4.4.0 `$post` argument was added. 892 * 893 * @global wpdb $wpdb WordPress database abstraction object. 894 * 895 * @param int $default Optional. The default page ID to be pre-selected. Default 0. 896 * @param int $parent Optional. The parent page ID. Default 0. 897 * @param int $level Optional. Page depth level. Default 0. 898 * @param int|WP_Post $post Post ID or WP_Post object. 899 * @return void|false Void on success, false if the page has no children. 900 */ 901 function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) { 902 global $wpdb; 903 904 $post = get_post( $post ); 905 $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 ) ); 906 907 if ( $items ) { 908 foreach ( $items as $item ) { 909 // A page cannot be its own parent. 910 if ( $post && $post->ID && (int) $item->ID === $post->ID ) { 911 continue; 912 } 913 914 $pad = str_repeat( ' ', $level * 3 ); 915 $selected = selected( $default, $item->ID, false ); 916 917 echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html( $item->post_title ) . '</option>'; 918 parent_dropdown( $default, $item->ID, $level + 1 ); 919 } 920 } else { 921 return false; 922 } 923 } 924 925 /** 926 * Print out option HTML elements for role selectors. 927 * 928 * @since 2.1.0 929 * 930 * @param string $selected Slug for the role that should be already selected. 931 */ 932 function wp_dropdown_roles( $selected = '' ) { 933 $r = ''; 934 935 $editable_roles = array_reverse( get_editable_roles() ); 936 937 foreach ( $editable_roles as $role => $details ) { 938 $name = translate_user_role( $details['name'] ); 939 // Preselect specified role. 940 if ( $selected === $role ) { 941 $r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>"; 942 } else { 943 $r .= "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>"; 944 } 945 } 946 947 echo $r; 948 } 949 950 /** 951 * Outputs the form used by the importers to accept the data to be imported 952 * 953 * @since 2.0.0 954 * 955 * @param string $action The action attribute for the form. 956 */ 957 function wp_import_upload_form( $action ) { 958 959 /** 960 * Filters the maximum allowed upload size for import files. 961 * 962 * @since 2.3.0 963 * 964 * @see wp_max_upload_size() 965 * 966 * @param int $max_upload_size Allowed upload size. Default 1 MB. 967 */ 968 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); 969 $size = size_format( $bytes ); 970 $upload_dir = wp_upload_dir(); 971 if ( ! empty( $upload_dir['error'] ) ) : 972 ?> 973 <div class="error"><p><?php _e( 'Before you can upload your import file, you will need to fix the following error:' ); ?></p> 974 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div> 975 <?php 976 else : 977 ?> 978 <form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>"> 979 <p> 980 <?php 981 printf( 982 '<label for="upload">%s</label> (%s)', 983 __( 'Choose a file from your computer:' ), 984 /* translators: %s: Maximum allowed file size. */ 985 sprintf( __( 'Maximum size: %s' ), $size ) 986 ); 987 ?> 988 <input type="file" id="upload" name="import" size="25" /> 989 <input type="hidden" name="action" value="save" /> 990 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> 991 </p> 992 <?php submit_button( __( 'Upload file and import' ), 'primary' ); ?> 993 </form> 994 <?php 995 endif; 996 } 997 998 /** 999 * Adds a meta box to one or more screens. 1000 * 1001 * @since 2.5.0 1002 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. 1003 * 1004 * @global array $wp_meta_boxes 1005 * 1006 * @param string $id Meta box ID (used in the 'id' attribute for the meta box). 1007 * @param string $title Title of the meta box. 1008 * @param callable $callback Function that fills the box with the desired content. 1009 * The function should echo its output. 1010 * @param string|array|WP_Screen $screen Optional. The screen or screens on which to show the box 1011 * (such as a post type, 'link', or 'comment'). Accepts a single 1012 * screen ID, WP_Screen object, or array of screen IDs. Default 1013 * is the current screen. If you have used add_menu_page() or 1014 * add_submenu_page() to create a new screen (and hence screen_id), 1015 * make sure your menu slug conforms to the limits of sanitize_key() 1016 * otherwise the 'screen' menu may not correctly render on your page. 1017 * @param string $context Optional. The context within the screen where the box 1018 * should display. Available contexts vary from screen to 1019 * screen. Post edit screen contexts include 'normal', 'side', 1020 * and 'advanced'. Comments screen contexts include 'normal' 1021 * and 'side'. Menus meta boxes (accordion sections) all use 1022 * the 'side' context. Global default is 'advanced'. 1023 * @param string $priority Optional. The priority within the context where the box should show. 1024 * Accepts 'high', 'core', 'default', or 'low'. Default 'default'. 1025 * @param array $callback_args Optional. Data that should be set as the $args property 1026 * of the box array (which is the second parameter passed 1027 * to your callback). Default null. 1028 */ 1029 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { 1030 global $wp_meta_boxes; 1031 1032 if ( empty( $screen ) ) { 1033 $screen = get_current_screen(); 1034 } elseif ( is_string( $screen ) ) { 1035 $screen = convert_to_screen( $screen ); 1036 } elseif ( is_array( $screen ) ) { 1037 foreach ( $screen as $single_screen ) { 1038 add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args ); 1039 } 1040 } 1041 1042 if ( ! isset( $screen->id ) ) { 1043 return; 1044 } 1045 1046 $page = $screen->id; 1047 1048 if ( ! isset( $wp_meta_boxes ) ) { 1049 $wp_meta_boxes = array(); 1050 } 1051 if ( ! isset( $wp_meta_boxes[ $page ] ) ) { 1052 $wp_meta_boxes[ $page ] = array(); 1053 } 1054 if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 1055 $wp_meta_boxes[ $page ][ $context ] = array(); 1056 } 1057 1058 foreach ( array_keys( $wp_meta_boxes[ $page ] ) as $a_context ) { 1059 foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) { 1060 if ( ! isset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) ) { 1061 continue; 1062 } 1063 1064 // If a core box was previously removed, don't add. 1065 if ( ( 'core' === $priority || 'sorted' === $priority ) 1066 && false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] 1067 ) { 1068 return; 1069 } 1070 1071 // If a core box was previously added by a plugin, don't add. 1072 if ( 'core' === $priority ) { 1073 /* 1074 * If the box was added with default priority, give it core priority 1075 * to maintain sort order. 1076 */ 1077 if ( 'default' === $a_priority ) { 1078 $wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ]; 1079 unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] ); 1080 } 1081 return; 1082 } 1083 1084 // If no priority given and ID already present, use existing priority. 1085 if ( empty( $priority ) ) { 1086 $priority = $a_priority; 1087 /* 1088 * Else, if we're adding to the sorted priority, we don't know the title 1089 * or callback. Grab them from the previously added context/priority. 1090 */ 1091 } elseif ( 'sorted' === $priority ) { 1092 $title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title']; 1093 $callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback']; 1094 $callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args']; 1095 } 1096 1097 // An ID can be in only one priority and one context. 1098 if ( $priority !== $a_priority || $context !== $a_context ) { 1099 unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ); 1100 } 1101 } 1102 } 1103 1104 if ( empty( $priority ) ) { 1105 $priority = 'low'; 1106 } 1107 1108 if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { 1109 $wp_meta_boxes[ $page ][ $context ][ $priority ] = array(); 1110 } 1111 1112 $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = array( 1113 'id' => $id, 1114 'title' => $title, 1115 'callback' => $callback, 1116 'args' => $callback_args, 1117 ); 1118 } 1119 1120 1121 /** 1122 * Function that renders a "fake" meta box with an information message, 1123 * shown on the block editor, when an incompatible meta box is found. 1124 * 1125 * @since 5.0.0 1126 * 1127 * @param mixed $object The data object being rendered on this screen. 1128 * @param array $box { 1129 * Custom formats meta box arguments. 1130 * 1131 * @type string $id Meta box 'id' attribute. 1132 * @type string $title Meta box title. 1133 * @type callable $old_callback The original callback for this meta box. 1134 * @type array $args Extra meta box arguments. 1135 * } 1136 */ 1137 function do_block_editor_incompatible_meta_box( $object, $box ) { 1138 $plugin = _get_plugin_from_callback( $box['old_callback'] ); 1139 $plugins = get_plugins(); 1140 echo '<p>'; 1141 if ( $plugin ) { 1142 /* translators: %s: The name of the plugin that generated this meta box. */ 1143 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); 1144 } else { 1145 _e( "This meta box isn't compatible with the block editor." ); 1146 } 1147 echo '</p>'; 1148 1149 if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) { 1150 if ( current_user_can( 'install_plugins' ) ) { 1151 echo '<p>'; 1152 printf( 1153 /* translators: %s: A link to install the Classic Editor plugin. */ 1154 __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), 1155 esc_url( wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ) ) 1156 ); 1157 echo '</p>'; 1158 } 1159 } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) { 1160 if ( current_user_can( 'activate_plugins' ) ) { 1161 $activate_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ), 'activate-plugin_classic-editor/classic-editor.php' ); 1162 echo '<p>'; 1163 /* translators: %s: A link to activate the Classic Editor plugin. */ 1164 printf( __( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $activate_url ) ); 1165 echo '</p>'; 1166 } 1167 } elseif ( $object instanceof WP_Post ) { 1168 $edit_url = add_query_arg( 1169 array( 1170 'classic-editor' => '', 1171 'classic-editor__forget' => '', 1172 ), 1173 get_edit_post_link( $object ) 1174 ); 1175 echo '<p>'; 1176 /* translators: %s: A link to use the Classic Editor plugin. */ 1177 printf( __( 'Please open the <a href="%s">classic editor</a> to use this meta box.' ), esc_url( $edit_url ) ); 1178 echo '</p>'; 1179 } 1180 } 1181 1182 /** 1183 * Internal helper function to find the plugin from a meta box callback. 1184 * 1185 * @since 5.0.0 1186 * 1187 * @access private 1188 * 1189 * @param callable $callback The callback function to check. 1190 * @return array|null The plugin that the callback belongs to, or null if it doesn't belong to a plugin. 1191 */ 1192 function _get_plugin_from_callback( $callback ) { 1193 try { 1194 if ( is_array( $callback ) ) { 1195 $reflection = new ReflectionMethod( $callback[0], $callback[1] ); 1196 } elseif ( is_string( $callback ) && false !== strpos( $callback, '::' ) ) { 1197 $reflection = new ReflectionMethod( $callback ); 1198 } else { 1199 $reflection = new ReflectionFunction( $callback ); 1200 } 1201 } catch ( ReflectionException $exception ) { 1202 // We could not properly reflect on the callable, so we abort here. 1203 return null; 1204 } 1205 1206 // Don't show an error if it's an internal PHP function. 1207 if ( ! $reflection->isInternal() ) { 1208 1209 // Only show errors if the meta box was registered by a plugin. 1210 $filename = wp_normalize_path( $reflection->getFileName() ); 1211 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); 1212 1213 if ( strpos( $filename, $plugin_dir ) === 0 ) { 1214 $filename = str_replace( $plugin_dir, '', $filename ); 1215 $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); 1216 1217 $plugins = get_plugins(); 1218 1219 foreach ( $plugins as $name => $plugin ) { 1220 if ( strpos( $name, $filename ) === 0 ) { 1221 return $plugin; 1222 } 1223 } 1224 } 1225 } 1226 1227 return null; 1228 } 1229 1230 /** 1231 * Meta-Box template function. 1232 * 1233 * @since 2.5.0 1234 * 1235 * @global array $wp_meta_boxes 1236 * 1237 * @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or 1238 * add_submenu_page() to create a new screen (and hence screen_id) 1239 * make sure your menu slug conforms to the limits of sanitize_key() 1240 * otherwise the 'screen' menu may not correctly render on your page. 1241 * @param string $context The screen context for which to display meta boxes. 1242 * @param mixed $object Gets passed to the meta box callback function as the first parameter. 1243 * Often this is the object that's the focus of the current screen, for 1244 * example a `WP_Post` or `WP_Comment` object. 1245 * @return int Number of meta_boxes. 1246 */ 1247 function do_meta_boxes( $screen, $context, $object ) { 1248 global $wp_meta_boxes; 1249 static $already_sorted = false; 1250 1251 if ( empty( $screen ) ) { 1252 $screen = get_current_screen(); 1253 } elseif ( is_string( $screen ) ) { 1254 $screen = convert_to_screen( $screen ); 1255 } 1256 1257 $page = $screen->id; 1258 1259 $hidden = get_hidden_meta_boxes( $screen ); 1260 1261 printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) ); 1262 1263 // Grab the ones the user has manually sorted. 1264 // Pull them out of their previous context/priority and into the one the user chose. 1265 $sorted = get_user_option( "meta-box-order_$page" ); 1266 1267 if ( ! $already_sorted && $sorted ) { 1268 foreach ( $sorted as $box_context => $ids ) { 1269 foreach ( explode( ',', $ids ) as $id ) { 1270 if ( $id && 'dashboard_browser_nag' !== $id ) { 1271 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); 1272 } 1273 } 1274 } 1275 } 1276 1277 $already_sorted = true; 1278 1279 $i = 0; 1280 1281 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 1282 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { 1283 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { 1284 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { 1285 if ( false === $box || ! $box['title'] ) { 1286 continue; 1287 } 1288 1289 $block_compatible = true; 1290 if ( is_array( $box['args'] ) ) { 1291 // If a meta box is just here for back compat, don't show it in the block editor. 1292 if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) { 1293 continue; 1294 } 1295 1296 if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) { 1297 $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box']; 1298 unset( $box['args']['__block_editor_compatible_meta_box'] ); 1299 } 1300 1301 // If the meta box is declared as incompatible with the block editor, override the callback function. 1302 if ( ! $block_compatible && $screen->is_block_editor() ) { 1303 $box['old_callback'] = $box['callback']; 1304 $box['callback'] = 'do_block_editor_incompatible_meta_box'; 1305 } 1306 1307 if ( isset( $box['args']['__back_compat_meta_box'] ) ) { 1308 $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box']; 1309 unset( $box['args']['__back_compat_meta_box'] ); 1310 } 1311 } 1312 1313 $i++; 1314 // get_hidden_meta_boxes() doesn't apply in the block editor. 1315 $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : ''; 1316 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n"; 1317 1318 echo '<div class="postbox-header">'; 1319 echo '<h2 class="hndle">'; 1320 if ( 'dashboard_php_nag' === $box['id'] ) { 1321 echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>'; 1322 echo '<span class="screen-reader-text">' . __( 'Warning:' ) . ' </span>'; 1323 } 1324 echo $box['title']; 1325 echo "</h2>\n"; 1326 1327 if ( 'dashboard_browser_nag' !== $box['id'] ) { 1328 $widget_title = $box['title']; 1329 1330 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { 1331 $widget_title = $box['args']['__widget_basename']; 1332 // Do not pass this parameter to the user callback function. 1333 unset( $box['args']['__widget_basename'] ); 1334 } 1335 1336 echo '<div class="handle-actions hide-if-no-js">'; 1337 1338 echo '<button type="button" class="handle-order-higher" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-higher-description">'; 1339 echo '<span class="screen-reader-text">' . __( 'Move up' ) . '</span>'; 1340 echo '<span class="order-higher-indicator" aria-hidden="true"></span>'; 1341 echo '</button>'; 1342 echo '<span class="hidden" id="' . $box['id'] . '-handle-order-higher-description">' . sprintf( 1343 /* translators: %s: Meta box title. */ 1344 __( 'Move %s box up' ), 1345 $widget_title 1346 ) . '</span>'; 1347 1348 echo '<button type="button" class="handle-order-lower" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-lower-description">'; 1349 echo '<span class="screen-reader-text">' . __( 'Move down' ) . '</span>'; 1350 echo '<span class="order-lower-indicator" aria-hidden="true"></span>'; 1351 echo '</button>'; 1352 echo '<span class="hidden" id="' . $box['id'] . '-handle-order-lower-description">' . sprintf( 1353 /* translators: %s: Meta box title. */ 1354 __( 'Move %s box down' ), 1355 $widget_title 1356 ) . '</span>'; 1357 1358 echo '<button type="button" class="handlediv" aria-expanded="true">'; 1359 echo '<span class="screen-reader-text">' . sprintf( 1360 /* translators: %s: Meta box title. */ 1361 __( 'Toggle panel: %s' ), 1362 $widget_title 1363 ) . '</span>'; 1364 echo '<span class="toggle-indicator" aria-hidden="true"></span>'; 1365 echo '</button>'; 1366 1367 echo '</div>'; 1368 } 1369 echo '</div>'; 1370 1371 echo '<div class="inside">' . "\n"; 1372 1373 if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) { 1374 $plugin = _get_plugin_from_callback( $box['callback'] ); 1375 if ( $plugin ) { 1376 ?> 1377 <div class="error inline"> 1378 <p> 1379 <?php 1380 /* translators: %s: The name of the plugin that generated this meta box. */ 1381 printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" ); 1382 ?> 1383 </p> 1384 </div> 1385 <?php 1386 } 1387 } 1388 1389 call_user_func( $box['callback'], $object, $box ); 1390 echo "</div>\n"; 1391 echo "</div>\n"; 1392 } 1393 } 1394 } 1395 } 1396 1397 echo '</div>'; 1398 1399 return $i; 1400 1401 } 1402 1403 /** 1404 * Removes a meta box from one or more screens. 1405 * 1406 * @since 2.6.0 1407 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. 1408 * 1409 * @global array $wp_meta_boxes 1410 * 1411 * @param string $id Meta box ID (used in the 'id' attribute for the meta box). 1412 * @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a 1413 * post type, 'link', or 'comment'). Accepts a single screen ID, 1414 * WP_Screen object, or array of screen IDs. 1415 * @param string $context The context within the screen where the box is set to display. 1416 * Contexts vary from screen to screen. Post edit screen contexts 1417 * include 'normal', 'side', and 'advanced'. Comments screen contexts 1418 * include 'normal' and 'side'. Menus meta boxes (accordion sections) 1419 * all use the 'side' context. 1420 */ 1421 function remove_meta_box( $id, $screen, $context ) { 1422 global $wp_meta_boxes; 1423 1424 if ( empty( $screen ) ) { 1425 $screen = get_current_screen(); 1426 } elseif ( is_string( $screen ) ) { 1427 $screen = convert_to_screen( $screen ); 1428 } elseif ( is_array( $screen ) ) { 1429 foreach ( $screen as $single_screen ) { 1430 remove_meta_box( $id, $single_screen, $context ); 1431 } 1432 } 1433 1434 if ( ! isset( $screen->id ) ) { 1435 return; 1436 } 1437 1438 $page = $screen->id; 1439 1440 if ( ! isset( $wp_meta_boxes ) ) { 1441 $wp_meta_boxes = array(); 1442 } 1443 if ( ! isset( $wp_meta_boxes[ $page ] ) ) { 1444 $wp_meta_boxes[ $page ] = array(); 1445 } 1446 if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 1447 $wp_meta_boxes[ $page ][ $context ] = array(); 1448 } 1449 1450 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { 1451 $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false; 1452 } 1453 } 1454 1455 /** 1456 * Meta Box Accordion Template Function. 1457 * 1458 * Largely made up of abstracted code from do_meta_boxes(), this 1459 * function serves to build meta boxes as list items for display as 1460 * a collapsible accordion. 1461 * 1462 * @since 3.6.0 1463 * 1464 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. 1465 * 1466 * @param string|object $screen The screen identifier. 1467 * @param string $context The screen context for which to display accordion sections. 1468 * @param mixed $object Gets passed to the section callback function as the first parameter. 1469 * @return int Number of meta boxes as accordion sections. 1470 */ 1471 function do_accordion_sections( $screen, $context, $object ) { 1472 global $wp_meta_boxes; 1473 1474 wp_enqueue_script( 'accordion' ); 1475 1476 if ( empty( $screen ) ) { 1477 $screen = get_current_screen(); 1478 } elseif ( is_string( $screen ) ) { 1479 $screen = convert_to_screen( $screen ); 1480 } 1481 1482 $page = $screen->id; 1483 1484 $hidden = get_hidden_meta_boxes( $screen ); 1485 ?> 1486 <div id="side-sortables" class="accordion-container"> 1487 <ul class="outer-border"> 1488 <?php 1489 $i = 0; 1490 $first_open = false; 1491 1492 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 1493 foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { 1494 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { 1495 foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { 1496 if ( false === $box || ! $box['title'] ) { 1497 continue; 1498 } 1499 1500 $i++; 1501 $hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : ''; 1502 1503 $open_class = ''; 1504 if ( ! $first_open && empty( $hidden_class ) ) { 1505 $first_open = true; 1506 $open_class = 'open'; 1507 } 1508 ?> 1509 <li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"> 1510 <h3 class="accordion-section-title hndle" tabindex="0"> 1511 <?php echo esc_html( $box['title'] ); ?> 1512 <span class="screen-reader-text"><?php _e( 'Press return or enter to open this section' ); ?></span> 1513 </h3> 1514 <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>"> 1515 <div class="inside"> 1516 <?php call_user_func( $box['callback'], $object, $box ); ?> 1517 </div><!-- .inside --> 1518 </div><!-- .accordion-section-content --> 1519 </li><!-- .accordion-section --> 1520 <?php 1521 } 1522 } 1523 } 1524 } 1525 ?> 1526 </ul><!-- .outer-border --> 1527 </div><!-- .accordion-container --> 1528 <?php 1529 return $i; 1530 } 1531 1532 /** 1533 * Add a new section to a settings page. 1534 * 1535 * Part of the Settings API. Use this to define new settings sections for an admin page. 1536 * Show settings sections in your admin page callback function with do_settings_sections(). 1537 * Add settings fields to your section with add_settings_field(). 1538 * 1539 * The $callback argument should be the name of a function that echoes out any 1540 * content you want to show at the top of the settings section before the actual 1541 * fields. It can output nothing if you want. 1542 * 1543 * @since 2.7.0 1544 * 1545 * @global array $wp_settings_sections Storage array of all settings sections added to admin pages. 1546 * 1547 * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. 1548 * @param string $title Formatted title of the section. Shown as the heading for the section. 1549 * @param callable $callback Function that echos out any content at the top of the section (between heading and fields). 1550 * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 1551 * 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using 1552 * add_options_page(); 1553 */ 1554 function add_settings_section( $id, $title, $callback, $page ) { 1555 global $wp_settings_sections; 1556 1557 if ( 'misc' === $page ) { 1558 _deprecated_argument( 1559 __FUNCTION__, 1560 '3.0.0', 1561 sprintf( 1562 /* translators: %s: misc */ 1563 __( 'The "%s" options group has been removed. Use another settings group.' ), 1564 'misc' 1565 ) 1566 ); 1567 $page = 'general'; 1568 } 1569 1570 if ( 'privacy' === $page ) { 1571 _deprecated_argument( 1572 __FUNCTION__, 1573 '3.5.0', 1574 sprintf( 1575 /* translators: %s: privacy */ 1576 __( 'The "%s" options group has been removed. Use another settings group.' ), 1577 'privacy' 1578 ) 1579 ); 1580 $page = 'reading'; 1581 } 1582 1583 $wp_settings_sections[ $page ][ $id ] = array( 1584 'id' => $id, 1585 'title' => $title, 1586 'callback' => $callback, 1587 ); 1588 } 1589 1590 /** 1591 * Add a new field to a section of a settings page. 1592 * 1593 * Part of the Settings API. Use this to define a settings field that will show 1594 * as part of a settings section inside a settings page. The fields are shown using 1595 * do_settings_fields() in do_settings-sections() 1596 * 1597 * The $callback argument should be the name of a function that echoes out the 1598 * HTML input tags for this setting field. Use get_option() to retrieve existing 1599 * values to show. 1600 * 1601 * @since 2.7.0 1602 * @since 4.2.0 The `$class` argument was added. 1603 * 1604 * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections. 1605 * 1606 * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. 1607 * @param string $title Formatted title of the field. Shown as the label for the field 1608 * during output. 1609 * @param callable $callback Function that fills the field with the desired form inputs. The 1610 * function should echo its output. 1611 * @param string $page The slug-name of the settings page on which to show the section 1612 * (general, reading, writing, ...). 1613 * @param string $section Optional. The slug-name of the section of the settings page 1614 * in which to show the box. Default 'default'. 1615 * @param array $args { 1616 * Optional. Extra arguments used when outputting the field. 1617 * 1618 * @type string $label_for When supplied, the setting title will be wrapped 1619 * in a `<label>` element, its `for` attribute populated 1620 * with this value. 1621 * @type string $class CSS Class to be added to the `<tr>` element when the 1622 * field is output. 1623 * } 1624 */ 1625 function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) { 1626 global $wp_settings_fields; 1627 1628 if ( 'misc' === $page ) { 1629 _deprecated_argument( 1630 __FUNCTION__, 1631 '3.0.0', 1632 sprintf( 1633 /* translators: %s: misc */ 1634 __( 'The "%s" options group has been removed. Use another settings group.' ), 1635 'misc' 1636 ) 1637 ); 1638 $page = 'general'; 1639 } 1640 1641 if ( 'privacy' === $page ) { 1642 _deprecated_argument( 1643 __FUNCTION__, 1644 '3.5.0', 1645 sprintf( 1646 /* translators: %s: privacy */ 1647 __( 'The "%s" options group has been removed. Use another settings group.' ), 1648 'privacy' 1649 ) 1650 ); 1651 $page = 'reading'; 1652 } 1653 1654 $wp_settings_fields[ $page ][ $section ][ $id ] = array( 1655 'id' => $id, 1656 'title' => $title, 1657 'callback' => $callback, 1658 'args' => $args, 1659 ); 1660 } 1661 1662 /** 1663 * Prints out all settings sections added to a particular settings page 1664 * 1665 * Part of the Settings API. Use this in a settings page callback function 1666 * to output all the sections and fields that were added to that $page with 1667 * add_settings_section() and add_settings_field() 1668 * 1669 * @global array $wp_settings_sections Storage array of all settings sections added to admin pages. 1670 * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections. 1671 * @since 2.7.0 1672 * 1673 * @param string $page The slug name of the page whose settings sections you want to output. 1674 */ 1675 function do_settings_sections( $page ) { 1676 global $wp_settings_sections, $wp_settings_fields; 1677 1678 if ( ! isset( $wp_settings_sections[ $page ] ) ) { 1679 return; 1680 } 1681 1682 foreach ( (array) $wp_settings_sections[ $page ] as $section ) { 1683 if ( $section['title'] ) { 1684 echo "<h2>{$section['title']}</h2>\n"; 1685 } 1686 1687 if ( $section['callback'] ) { 1688 call_user_func( $section['callback'], $section ); 1689 } 1690 1691 if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) { 1692 continue; 1693 } 1694 echo '<table class="form-table" role="presentation">'; 1695 do_settings_fields( $page, $section['id'] ); 1696 echo '</table>'; 1697 } 1698 } 1699 1700 /** 1701 * Print out the settings fields for a particular settings section. 1702 * 1703 * Part of the Settings API. Use this in a settings page to output 1704 * a specific section. Should normally be called by do_settings_sections() 1705 * rather than directly. 1706 * 1707 * @global array $wp_settings_fields Storage array of settings fields and their pages/sections. 1708 * 1709 * @since 2.7.0 1710 * 1711 * @param string $page Slug title of the admin page whose settings fields you want to show. 1712 * @param string $section Slug title of the settings section whose fields you want to show. 1713 */ 1714 function do_settings_fields( $page, $section ) { 1715 global $wp_settings_fields; 1716 1717 if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) { 1718 return; 1719 } 1720 1721 foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) { 1722 $class = ''; 1723 1724 if ( ! empty( $field['args']['class'] ) ) { 1725 $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; 1726 } 1727 1728 echo "<tr{$class}>"; 1729 1730 if ( ! empty( $field['args']['label_for'] ) ) { 1731 echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>'; 1732 } else { 1733 echo '<th scope="row">' . $field['title'] . '</th>'; 1734 } 1735 1736 echo '<td>'; 1737 call_user_func( $field['callback'], $field['args'] ); 1738 echo '</td>'; 1739 echo '</tr>'; 1740 } 1741 } 1742 1743 /** 1744 * Register a settings error to be displayed to the user. 1745 * 1746 * Part of the Settings API. Use this to show messages to users about settings validation 1747 * problems, missing settings or anything else. 1748 * 1749 * Settings errors should be added inside the $sanitize_callback function defined in 1750 * register_setting() for a given setting to give feedback about the submission. 1751 * 1752 * By default messages will show immediately after the submission that generated the error. 1753 * Additional calls to settings_errors() can be used to show errors even when the settings 1754 * page is first accessed. 1755 * 1756 * @since 3.0.0 1757 * @since 5.3.0 Added `warning` and `info` as possible values for `$type`. 1758 * 1759 * @global array $wp_settings_errors Storage array of errors registered during this pageload 1760 * 1761 * @param string $setting Slug title of the setting to which this error applies. 1762 * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. 1763 * @param string $message The formatted message text to display to the user (will be shown inside styled 1764 * `<div>` and `<p>` tags). 1765 * @param string $type Optional. Message type, controls HTML class. Possible values include 'error', 1766 * 'success', 'warning', 'info'. Default 'error'. 1767 */ 1768 function add_settings_error( $setting, $code, $message, $type = 'error' ) { 1769 global $wp_settings_errors; 1770 1771 $wp_settings_errors[] = array( 1772 'setting' => $setting, 1773 'code' => $code, 1774 'message' => $message, 1775 'type' => $type, 1776 ); 1777 } 1778 1779 /** 1780 * Fetch settings errors registered by add_settings_error(). 1781 * 1782 * Checks the $wp_settings_errors array for any errors declared during the current 1783 * pageload and returns them. 1784 * 1785 * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved 1786 * to the 'settings_errors' transient then those errors will be returned instead. This 1787 * is used to pass errors back across pageloads. 1788 * 1789 * Use the $sanitize argument to manually re-sanitize the option before returning errors. 1790 * This is useful if you have errors or notices you want to show even when the user 1791 * hasn't submitted data (i.e. when they first load an options page, or in the {@see 'admin_notices'} 1792 * action hook). 1793 * 1794 * @since 3.0.0 1795 * 1796 * @global array $wp_settings_errors Storage array of errors registered during this pageload 1797 * 1798 * @param string $setting Optional. Slug title of a specific setting whose errors you want. 1799 * @param bool $sanitize Optional. Whether to re-sanitize the setting value before returning errors. 1800 * @return array { 1801 * Array of settings errors. 1802 * 1803 * @type string $setting Slug title of the setting to which this error applies. 1804 * @type string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. 1805 * @type string $message The formatted message text to display to the user (will be shown inside styled 1806 * `<div>` and `<p>` tags). 1807 * @type string $type Optional. Message type, controls HTML class. Possible values include 'error', 1808 * 'success', 'warning', 'info'. Default 'error'. 1809 * } 1810 */ 1811 function get_settings_errors( $setting = '', $sanitize = false ) { 1812 global $wp_settings_errors; 1813 1814 /* 1815 * If $sanitize is true, manually re-run the sanitization for this option 1816 * This allows the $sanitize_callback from register_setting() to run, adding 1817 * any settings errors you want to show by default. 1818 */ 1819 if ( $sanitize ) { 1820 sanitize_option( $setting, get_option( $setting ) ); 1821 } 1822 1823 // If settings were passed back from options.php then use them. 1824 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { 1825 $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); 1826 delete_transient( 'settings_errors' ); 1827 } 1828 1829 // Check global in case errors have been added on this pageload. 1830 if ( empty( $wp_settings_errors ) ) { 1831 return array(); 1832 } 1833 1834 // Filter the results to those of a specific setting if one was set. 1835 if ( $setting ) { 1836 $setting_errors = array(); 1837 1838 foreach ( (array) $wp_settings_errors as $key => $details ) { 1839 if ( $setting === $details['setting'] ) { 1840 $setting_errors[] = $wp_settings_errors[ $key ]; 1841 } 1842 } 1843 1844 return $setting_errors; 1845 } 1846 1847 return $wp_settings_errors; 1848 } 1849 1850 /** 1851 * Display settings errors registered by add_settings_error(). 1852 * 1853 * Part of the Settings API. Outputs a div for each error retrieved by 1854 * get_settings_errors(). 1855 * 1856 * This is called automatically after a settings page based on the 1857 * Settings API is submitted. Errors should be added during the validation 1858 * callback function for a setting defined in register_setting(). 1859 * 1860 * The $sanitize option is passed into get_settings_errors() and will 1861 * re-run the setting sanitization 1862 * on its current value. 1863 * 1864 * The $hide_on_update option will cause errors to only show when the settings 1865 * page is first loaded. if the user has already saved new values it will be 1866 * hidden to avoid repeating messages already shown in the default error 1867 * reporting after submission. This is useful to show general errors like 1868 * missing settings when the user arrives at the settings page. 1869 * 1870 * @since 3.0.0 1871 * @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to 1872 * `notice-error` and `notice-success`. 1873 * 1874 * @param string $setting Optional slug title of a specific setting whose errors you want. 1875 * @param bool $sanitize Whether to re-sanitize the setting value before returning errors. 1876 * @param bool $hide_on_update If set to true errors will not be shown if the settings page has 1877 * already been submitted. 1878 */ 1879 function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) { 1880 1881 if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) { 1882 return; 1883 } 1884 1885 $settings_errors = get_settings_errors( $setting, $sanitize ); 1886 1887 if ( empty( $settings_errors ) ) { 1888 return; 1889 } 1890 1891 $output = ''; 1892 1893 foreach ( $settings_errors as $key => $details ) { 1894 if ( 'updated' === $details['type'] ) { 1895 $details['type'] = 'success'; 1896 } 1897 1898 if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) { 1899 $details['type'] = 'notice-' . $details['type']; 1900 } 1901 1902 $css_id = sprintf( 1903 'setting-error-%s', 1904 esc_attr( $details['code'] ) 1905 ); 1906 $css_class = sprintf( 1907 'notice %s settings-error is-dismissible', 1908 esc_attr( $details['type'] ) 1909 ); 1910 1911 $output .= "<div id='$css_id' class='$css_class'> \n"; 1912 $output .= "<p><strong>{$details['message']}</strong></p>"; 1913 $output .= "</div> \n"; 1914 } 1915 1916 echo $output; 1917 } 1918 1919 /** 1920 * Outputs the modal window used for attaching media to posts or pages in the media-listing screen. 1921 * 1922 * @since 2.7.0 1923 * 1924 * @param string $found_action 1925 */ 1926 function find_posts_div( $found_action = '' ) { 1927 ?> 1928 <div id="find-posts" class="find-box" style="display: none;"> 1929 <div id="find-posts-head" class="find-box-head"> 1930 <?php _e( 'Attach to existing content' ); ?> 1931 <button type="button" id="find-posts-close"><span class="screen-reader-text"><?php _e( 'Close media attachment panel' ); ?></span></button> 1932 </div> 1933 <div class="find-box-inside"> 1934 <div class="find-box-search"> 1935 <?php if ( $found_action ) { ?> 1936 <input type="hidden" name="found_action" value="<?php echo esc_attr( $found_action ); ?>" /> 1937 <?php } ?> 1938 <input type="hidden" name="affected" id="affected" value="" /> 1939 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?> 1940 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label> 1941 <input type="text" id="find-posts-input" name="ps" value="" /> 1942 <span class="spinner"></span> 1943 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /> 1944 <div class="clear"></div> 1945 </div> 1946 <div id="find-posts-response"></div> 1947 </div> 1948 <div class="find-box-buttons"> 1949 <?php submit_button( __( 'Select' ), 'primary alignright', 'find-posts-submit', false ); ?> 1950 <div class="clear"></div> 1951 </div> 1952 </div> 1953 <?php 1954 } 1955 1956 /** 1957 * Displays the post password. 1958 * 1959 * The password is passed through esc_attr() to ensure that it is safe for placing in an HTML attribute. 1960 * 1961 * @since 2.7.0 1962 */ 1963 function the_post_password() { 1964 $post = get_post(); 1965 if ( isset( $post->post_password ) ) { 1966 echo esc_attr( $post->post_password ); 1967 } 1968 } 1969 1970 /** 1971 * Get the post title. 1972 * 1973 * The post title is fetched and if it is blank then a default string is 1974 * returned. 1975 * 1976 * @since 2.7.0 1977 * 1978 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 1979 * @return string The post title if set. 1980 */ 1981 function _draft_or_post_title( $post = 0 ) { 1982 $title = get_the_title( $post ); 1983 if ( empty( $title ) ) { 1984 $title = __( '(no title)' ); 1985 } 1986 return esc_html( $title ); 1987 } 1988 1989 /** 1990 * Displays the search query. 1991 * 1992 * A simple wrapper to display the "s" parameter in a `GET` URI. This function 1993 * should only be used when the_search_query() cannot. 1994 * 1995 * @since 2.7.0 1996 */ 1997 function _admin_search_query() { 1998 echo isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; 1999 } 2000 2001 /** 2002 * Generic Iframe header for use with Thickbox 2003 * 2004 * @since 2.7.0 2005 * 2006 * @global string $hook_suffix 2007 * @global string $admin_body_class 2008 * @global WP_Locale $wp_locale WordPress date and time locale object. 2009 * 2010 * @param string $title Optional. Title of the Iframe page. Default empty. 2011 * @param bool $deprecated Not used. 2012 */ 2013 function iframe_header( $title = '', $deprecated = false ) { 2014 show_admin_bar( false ); 2015 global $hook_suffix, $admin_body_class, $wp_locale; 2016 $admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix ); 2017 2018 $current_screen = get_current_screen(); 2019 2020 header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); 2021 _wp_admin_html_begin(); 2022 ?> 2023 <title><?php bloginfo( 'name' ); ?> › <?php echo $title; ?> — <?php _e( 'WordPress' ); ?></title> 2024 <?php 2025 wp_enqueue_style( 'colors' ); 2026 ?> 2027 <script type="text/javascript"> 2028 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();}}}; 2029 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();} 2030 var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', 2031 pagenow = '<?php echo esc_js( $current_screen->id ); ?>', 2032 typenow = '<?php echo esc_js( $current_screen->post_type ); ?>', 2033 adminpage = '<?php echo esc_js( $admin_body_class ); ?>', 2034 thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>', 2035 decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>', 2036 isRtl = <?php echo (int) is_rtl(); ?>; 2037 </script> 2038 <?php 2039 /** This action is documented in wp-admin/admin-header.php */ 2040 do_action( 'admin_enqueue_scripts', $hook_suffix ); 2041 2042 /** This action is documented in wp-admin/admin-header.php */ 2043 do_action( "admin_print_styles-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 2044 2045 /** This action is documented in wp-admin/admin-header.php */ 2046 do_action( 'admin_print_styles' ); 2047 2048 /** This action is documented in wp-admin/admin-header.php */ 2049 do_action( "admin_print_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 2050 2051 /** This action is documented in wp-admin/admin-header.php */ 2052 do_action( 'admin_print_scripts' ); 2053 2054 /** This action is documented in wp-admin/admin-header.php */ 2055 do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 2056 2057 /** This action is documented in wp-admin/admin-header.php */ 2058 do_action( 'admin_head' ); 2059 2060 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) ); 2061 2062 if ( is_rtl() ) { 2063 $admin_body_class .= ' rtl'; 2064 } 2065 2066 ?> 2067 </head> 2068 <?php 2069 /** 2070 * @global string $body_id 2071 */ 2072 $admin_body_id = isset( $GLOBALS['body_id'] ) ? 'id="' . $GLOBALS['body_id'] . '" ' : ''; 2073 2074 /** This filter is documented in wp-admin/admin-header.php */ 2075 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 2076 $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class ); 2077 ?> 2078 <body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>"> 2079 <script type="text/javascript"> 2080 (function(){ 2081 var c = document.body.className; 2082 c = c.replace(/no-js/, 'js'); 2083 document.body.className = c; 2084 })(); 2085 </script> 2086 <?php 2087 } 2088 2089 /** 2090 * Generic Iframe footer for use with Thickbox 2091 * 2092 * @since 2.7.0 2093 */ 2094 function iframe_footer() { 2095 /* 2096 * We're going to hide any footer output on iFrame pages, 2097 * but run the hooks anyway since they output JavaScript 2098 * or other needed content. 2099 */ 2100 2101 /** 2102 * @global string $hook_suffix 2103 */ 2104 global $hook_suffix; 2105 ?> 2106 <div class="hidden"> 2107 <?php 2108 /** This action is documented in wp-admin/admin-footer.php */ 2109 do_action( 'admin_footer', $hook_suffix ); 2110 2111 /** This action is documented in wp-admin/admin-footer.php */ 2112 do_action( "admin_print_footer_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 2113 2114 /** This action is documented in wp-admin/admin-footer.php */ 2115 do_action( 'admin_print_footer_scripts' ); 2116 ?> 2117 </div> 2118 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script> 2119 </body> 2120 </html> 2121 <?php 2122 } 2123 2124 /** 2125 * Function to echo or return the post states as HTML. 2126 * 2127 * @since 2.7.0 2128 * @since 5.3.0 Added the `$echo` parameter and a return value. 2129 * 2130 * @see get_post_states() 2131 * 2132 * @param WP_Post $post The post to retrieve states for. 2133 * @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true. 2134 * @return string Post states string. 2135 */ 2136 function _post_states( $post, $echo = true ) { 2137 $post_states = get_post_states( $post ); 2138 $post_states_string = ''; 2139 2140 if ( ! empty( $post_states ) ) { 2141 $state_count = count( $post_states ); 2142 $i = 0; 2143 2144 $post_states_string .= ' — '; 2145 2146 foreach ( $post_states as $state ) { 2147 $sep = ( ++$i === $state_count ) ? '' : ', '; 2148 2149 $post_states_string .= "<span class='post-state'>$state$sep</span>"; 2150 } 2151 } 2152 2153 if ( $echo ) { 2154 echo $post_states_string; 2155 } 2156 2157 return $post_states_string; 2158 } 2159 2160 /** 2161 * Retrieves an array of post states from a post. 2162 * 2163 * @since 5.3.0 2164 * 2165 * @param WP_Post $post The post to retrieve states for. 2166 * @return string[] Array of post state labels keyed by their state. 2167 */ 2168 function get_post_states( $post ) { 2169 $post_states = array(); 2170 2171 if ( isset( $_REQUEST['post_status'] ) ) { 2172 $post_status = $_REQUEST['post_status']; 2173 } else { 2174 $post_status = ''; 2175 } 2176 2177 if ( ! empty( $post->post_password ) ) { 2178 $post_states['protected'] = _x( 'Password protected', 'post status' ); 2179 } 2180 2181 if ( 'private' === $post->post_status && 'private' !== $post_status ) { 2182 $post_states['private'] = _x( 'Private', 'post status' ); 2183 } 2184 2185 if ( 'draft' === $post->post_status ) { 2186 if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { 2187 $post_states[] = __( 'Customization Draft' ); 2188 } elseif ( 'draft' !== $post_status ) { 2189 $post_states['draft'] = _x( 'Draft', 'post status' ); 2190 } 2191 } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) { 2192 $post_states[] = _x( 'Customization Draft', 'post status' ); 2193 } 2194 2195 if ( 'pending' === $post->post_status && 'pending' !== $post_status ) { 2196 $post_states['pending'] = _x( 'Pending', 'post status' ); 2197 } 2198 2199 if ( is_sticky( $post->ID ) ) { 2200 $post_states['sticky'] = _x( 'Sticky', 'post status' ); 2201 } 2202 2203 if ( 'future' === $post->post_status ) { 2204 $post_states['scheduled'] = _x( 'Scheduled', 'post status' ); 2205 } 2206 2207 if ( 'page' === get_option( 'show_on_front' ) ) { 2208 if ( (int) get_option( 'page_on_front' ) === $post->ID ) { 2209 $post_states['page_on_front'] = _x( 'Front Page', 'page label' ); 2210 } 2211 2212 if ( (int) get_option( 'page_for_posts' ) === $post->ID ) { 2213 $post_states['page_for_posts'] = _x( 'Posts Page', 'page label' ); 2214 } 2215 } 2216 2217 if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) { 2218 $post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' ); 2219 } 2220 2221 /** 2222 * Filters the default post display states used in the posts list table. 2223 * 2224 * @since 2.8.0 2225 * @since 3.6.0 Added the `$post` parameter. 2226 * @since 5.5.0 Also applied in the Customizer context. If any admin functions 2227 * are used within the filter, their existence should be checked 2228 * with `function_exists()` before being used. 2229 * 2230 * @param string[] $post_states An array of post display states. 2231 * @param WP_Post $post The current post object. 2232 */ 2233 return apply_filters( 'display_post_states', $post_states, $post ); 2234 } 2235 2236 /** 2237 * Outputs the attachment media states as HTML. 2238 * 2239 * @since 3.2.0 2240 * @since 5.6.0 Added the `$echo` parameter and a return value. 2241 * 2242 * @param WP_Post $post The attachment post to retrieve states for. 2243 * @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true. 2244 * @return string Media states string. 2245 */ 2246 function _media_states( $post, $echo = true ) { 2247 $media_states = get_media_states( $post ); 2248 $media_states_string = ''; 2249 2250 if ( ! empty( $media_states ) ) { 2251 $state_count = count( $media_states ); 2252 $i = 0; 2253 2254 $media_states_string .= ' — '; 2255 2256 foreach ( $media_states as $state ) { 2257 $sep = ( ++$i === $state_count ) ? '' : ', '; 2258 2259 $media_states_string .= "<span class='post-state'>$state$sep</span>"; 2260 } 2261 } 2262 2263 if ( $echo ) { 2264 echo $media_states_string; 2265 } 2266 2267 return $media_states_string; 2268 } 2269 2270 /** 2271 * Retrieves an array of media states from an attachment. 2272 * 2273 * @since 5.6.0 2274 * 2275 * @param WP_Post $post The attachment to retrieve states for. 2276 * @return string[] Array of media state labels keyed by their state. 2277 */ 2278 function get_media_states( $post ) { 2279 static $header_images; 2280 2281 $media_states = array(); 2282 $stylesheet = get_option( 'stylesheet' ); 2283 2284 if ( current_theme_supports( 'custom-header' ) ) { 2285 $meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true ); 2286 2287 if ( is_random_header_image() ) { 2288 if ( ! isset( $header_images ) ) { 2289 $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' ); 2290 } 2291 2292 if ( $meta_header === $stylesheet && in_array( $post->ID, $header_images, true ) ) { 2293 $media_states[] = __( 'Header Image' ); 2294 } 2295 } else { 2296 $header_image = get_header_image(); 2297 2298 // Display "Header Image" if the image was ever used as a header image. 2299 if ( ! empty( $meta_header ) && $meta_header === $stylesheet && wp_get_attachment_url( $post->ID ) !== $header_image ) { 2300 $media_states[] = __( 'Header Image' ); 2301 } 2302 2303 // Display "Current Header Image" if the image is currently the header image. 2304 if ( $header_image && wp_get_attachment_url( $post->ID ) === $header_image ) { 2305 $media_states[] = __( 'Current Header Image' ); 2306 } 2307 } 2308 2309 if ( get_theme_support( 'custom-header', 'video' ) && has_header_video() ) { 2310 $mods = get_theme_mods(); 2311 if ( isset( $mods['header_video'] ) && $post->ID === $mods['header_video'] ) { 2312 $media_states[] = __( 'Current Header Video' ); 2313 } 2314 } 2315 } 2316 2317 if ( current_theme_supports( 'custom-background' ) ) { 2318 $meta_background = get_post_meta( $post->ID, '_wp_attachment_is_custom_background', true ); 2319 2320 if ( ! empty( $meta_background ) && $meta_background === $stylesheet ) { 2321 $media_states[] = __( 'Background Image' ); 2322 2323 $background_image = get_background_image(); 2324 if ( $background_image && wp_get_attachment_url( $post->ID ) === $background_image ) { 2325 $media_states[] = __( 'Current Background Image' ); 2326 } 2327 } 2328 } 2329 2330 if ( (int) get_option( 'site_icon' ) === $post->ID ) { 2331 $media_states[] = __( 'Site Icon' ); 2332 } 2333 2334 if ( (int) get_theme_mod( 'custom_logo' ) === $post->ID ) { 2335 $media_states[] = __( 'Logo' ); 2336 } 2337 2338 /** 2339 * Filters the default media display states for items in the Media list table. 2340 * 2341 * @since 3.2.0 2342 * @since 4.8.0 Added the `$post` parameter. 2343 * 2344 * @param string[] $media_states An array of media states. Default 'Header Image', 2345 * 'Background Image', 'Site Icon', 'Logo'. 2346 * @param WP_Post $post The current attachment object. 2347 */ 2348 return apply_filters( 'display_media_states', $media_states, $post ); 2349 } 2350 2351 /** 2352 * Test support for compressing JavaScript from PHP 2353 * 2354 * Outputs JavaScript that tests if compression from PHP works as expected 2355 * and sets an option with the result. Has no effect when the current user 2356 * is not an administrator. To run the test again the option 'can_compress_scripts' 2357 * has to be deleted. 2358 * 2359 * @since 2.8.0 2360 */ 2361 function compression_test() { 2362 ?> 2363 <script type="text/javascript"> 2364 var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ) ); ?>; 2365 var testCompression = { 2366 get : function(test) { 2367 var x; 2368 if ( window.XMLHttpRequest ) { 2369 x = new XMLHttpRequest(); 2370 } else { 2371 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};} 2372 } 2373 2374 if (x) { 2375 x.onreadystatechange = function() { 2376 var r, h; 2377 if ( x.readyState == 4 ) { 2378 r = x.responseText.substr(0, 18); 2379 h = x.getResponseHeader('Content-Encoding'); 2380 testCompression.check(r, h, test); 2381 } 2382 }; 2383 2384 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&_ajax_nonce='+compressionNonce+'&'+(new Date()).getTime(), true); 2385 x.send(''); 2386 } 2387 }, 2388 2389 check : function(r, h, test) { 2390 if ( ! r && ! test ) 2391 this.get(1); 2392 2393 if ( 1 == test ) { 2394 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) ) 2395 this.get('no'); 2396 else 2397 this.get(2); 2398 2399 return; 2400 } 2401 2402 if ( 2 == test ) { 2403 if ( '"wpCompressionTest' === r ) 2404 this.get('yes'); 2405 else 2406 this.get('no'); 2407 } 2408 } 2409 }; 2410 testCompression.check(); 2411 </script> 2412 <?php 2413 } 2414 2415 /** 2416 * Echoes a submit button, with provided text and appropriate class(es). 2417 * 2418 * @since 3.1.0 2419 * 2420 * @see get_submit_button() 2421 * 2422 * @param string $text The text of the button (defaults to 'Save Changes') 2423 * @param string $type Optional. The type and CSS class(es) of the button. Core values 2424 * include 'primary', 'small', and 'large'. Default 'primary'. 2425 * @param string $name The HTML name of the submit button. Defaults to "submit". If no 2426 * id attribute is given in $other_attributes below, $name will be 2427 * used as the button's id. 2428 * @param bool $wrap True if the output button should be wrapped in a paragraph tag, 2429 * false otherwise. Defaults to true. 2430 * @param array|string $other_attributes Other attributes that should be output with the button, mapping 2431 * attributes to their values, such as setting tabindex to 1, etc. 2432 * These key/value attribute pairs will be output as attribute="value", 2433 * where attribute is the key. Other attributes can also be provided 2434 * as a string such as 'tabindex="1"', though the array format is 2435 * preferred. Default null. 2436 */ 2437 function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) { 2438 echo get_submit_button( $text, $type, $name, $wrap, $other_attributes ); 2439 } 2440 2441 /** 2442 * Returns a submit button, with provided text and appropriate class 2443 * 2444 * @since 3.1.0 2445 * 2446 * @param string $text Optional. The text of the button. Default 'Save Changes'. 2447 * @param string $type Optional. The type and CSS class(es) of the button. Core values 2448 * include 'primary', 'small', and 'large'. Default 'primary large'. 2449 * @param string $name Optional. The HTML name of the submit button. Defaults to "submit". 2450 * If no id attribute is given in $other_attributes below, `$name` will 2451 * be used as the button's id. Default 'submit'. 2452 * @param bool $wrap Optional. True if the output button should be wrapped in a paragraph 2453 * tag, false otherwise. Default true. 2454 * @param array|string $other_attributes Optional. Other attributes that should be output with the button, 2455 * mapping attributes to their values, such as `array( 'tabindex' => '1' )`. 2456 * These attributes will be output as `attribute="value"`, such as 2457 * `tabindex="1"`. Other attributes can also be provided as a string such 2458 * as `tabindex="1"`, though the array format is typically cleaner. 2459 * Default empty. 2460 * @return string Submit button HTML. 2461 */ 2462 function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) { 2463 if ( ! is_array( $type ) ) { 2464 $type = explode( ' ', $type ); 2465 } 2466 2467 $button_shorthand = array( 'primary', 'small', 'large' ); 2468 $classes = array( 'button' ); 2469 2470 foreach ( $type as $t ) { 2471 if ( 'secondary' === $t || 'button-secondary' === $t ) { 2472 continue; 2473 } 2474 2475 $classes[] = in_array( $t, $button_shorthand, true ) ? 'button-' . $t : $t; 2476 } 2477 2478 // Remove empty items, remove duplicate items, and finally build a string. 2479 $class = implode( ' ', array_unique( array_filter( $classes ) ) ); 2480 2481 $text = $text ? $text : __( 'Save Changes' ); 2482 2483 // Default the id attribute to $name unless an id was specifically provided in $other_attributes. 2484 $id = $name; 2485 if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) { 2486 $id = $other_attributes['id']; 2487 unset( $other_attributes['id'] ); 2488 } 2489 2490 $attributes = ''; 2491 if ( is_array( $other_attributes ) ) { 2492 foreach ( $other_attributes as $attribute => $value ) { 2493 $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important. 2494 } 2495 } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string. 2496 $attributes = $other_attributes; 2497 } 2498 2499 // Don't output empty name and id attributes. 2500 $name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : ''; 2501 $id_attr = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 2502 2503 $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr( $class ); 2504 $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; 2505 2506 if ( $wrap ) { 2507 $button = '<p class="submit">' . $button . '</p>'; 2508 } 2509 2510 return $button; 2511 } 2512 2513 /** 2514 * @global bool $is_IE 2515 */ 2516 function _wp_admin_html_begin() { 2517 global $is_IE; 2518 2519 $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : ''; 2520 2521 if ( $is_IE ) { 2522 header( 'X-UA-Compatible: IE=edge' ); 2523 } 2524 2525 ?> 2526 <!DOCTYPE html> 2527 <html class="<?php echo $admin_html_class; ?>" 2528 <?php 2529 /** 2530 * Fires inside the HTML tag in the admin header. 2531 * 2532 * @since 2.2.0 2533 */ 2534 do_action( 'admin_xml_ns' ); 2535 2536 language_attributes(); 2537 ?> 2538 > 2539 <head> 2540 <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?>" /> 2541 <?php 2542 } 2543 2544 /** 2545 * Convert a screen string to a screen object 2546 * 2547 * @since 3.0.0 2548 * 2549 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. 2550 * @return WP_Screen Screen object. 2551 */ 2552 function convert_to_screen( $hook_name ) { 2553 if ( ! class_exists( 'WP_Screen' ) ) { 2554 _doing_it_wrong( 2555 'convert_to_screen(), add_meta_box()', 2556 sprintf( 2557 /* translators: 1: wp-admin/includes/template.php, 2: add_meta_box(), 3: add_meta_boxes */ 2558 __( 'Likely direct inclusion of %1$s in order to use %2$s. This is very wrong. Hook the %2$s call into the %3$s action instead.' ), 2559 '<code>wp-admin/includes/template.php</code>', 2560 '<code>add_meta_box()</code>', 2561 '<code>add_meta_boxes</code>' 2562 ), 2563 '3.3.0' 2564 ); 2565 return (object) array( 2566 'id' => '_invalid', 2567 'base' => '_are_belong_to_us', 2568 ); 2569 } 2570 2571 return WP_Screen::get( $hook_name ); 2572 } 2573 2574 /** 2575 * Output the HTML for restoring the post data from DOM storage 2576 * 2577 * @since 3.6.0 2578 * @access private 2579 */ 2580 function _local_storage_notice() { 2581 ?> 2582 <div id="local-storage-notice" class="hidden notice is-dismissible"> 2583 <p class="local-restore"> 2584 <?php _e( 'The backup of this post in your browser is different from the version below.' ); ?> 2585 <button type="button" class="button restore-backup"><?php _e( 'Restore the backup' ); ?></button> 2586 </p> 2587 <p class="help"> 2588 <?php _e( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' ); ?> 2589 </p> 2590 </div> 2591 <?php 2592 } 2593 2594 /** 2595 * Output a HTML element with a star rating for a given rating. 2596 * 2597 * Outputs a HTML element with the star rating exposed on a 0..5 scale in 2598 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the 2599 * number of ratings may also be displayed by passing the $number parameter. 2600 * 2601 * @since 3.8.0 2602 * @since 4.4.0 Introduced the `echo` parameter. 2603 * 2604 * @param array $args { 2605 * Optional. Array of star ratings arguments. 2606 * 2607 * @type int|float $rating The rating to display, expressed in either a 0.5 rating increment, 2608 * or percentage. Default 0. 2609 * @type string $type Format that the $rating is in. Valid values are 'rating' (default), 2610 * or, 'percent'. Default 'rating'. 2611 * @type int $number The number of ratings that makes up this rating. Default 0. 2612 * @type bool $echo Whether to echo the generated markup. False to return the markup instead 2613 * of echoing it. Default true. 2614 * } 2615 * @return string Star rating HTML. 2616 */ 2617 function wp_star_rating( $args = array() ) { 2618 $defaults = array( 2619 'rating' => 0, 2620 'type' => 'rating', 2621 'number' => 0, 2622 'echo' => true, 2623 ); 2624 $parsed_args = wp_parse_args( $args, $defaults ); 2625 2626 // Non-English decimal places when the $rating is coming from a string. 2627 $rating = (float) str_replace( ',', '.', $parsed_args['rating'] ); 2628 2629 // Convert percentage to star rating, 0..5 in .5 increments. 2630 if ( 'percent' === $parsed_args['type'] ) { 2631 $rating = round( $rating / 10, 0 ) / 2; 2632 } 2633 2634 // Calculate the number of each type of star needed. 2635 $full_stars = floor( $rating ); 2636 $half_stars = ceil( $rating - $full_stars ); 2637 $empty_stars = 5 - $full_stars - $half_stars; 2638 2639 if ( $parsed_args['number'] ) { 2640 /* translators: 1: The rating, 2: The number of ratings. */ 2641 $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number'] ); 2642 $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $parsed_args['number'] ) ); 2643 } else { 2644 /* translators: %s: The rating. */ 2645 $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); 2646 } 2647 2648 $output = '<div class="star-rating">'; 2649 $output .= '<span class="screen-reader-text">' . $title . '</span>'; 2650 $output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars ); 2651 $output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars ); 2652 $output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars ); 2653 $output .= '</div>'; 2654 2655 if ( $parsed_args['echo'] ) { 2656 echo $output; 2657 } 2658 2659 return $output; 2660 } 2661 2662 /** 2663 * Output a notice when editing the page for posts (internal use only). 2664 * 2665 * @ignore 2666 * @since 4.2.0 2667 */ 2668 function _wp_posts_page_notice() { 2669 echo '<div class="notice notice-warning inline"><p>' . __( 'You are currently editing the page that shows your latest posts.' ) . '</p></div>'; 2670 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 19 01:00:03 2021 | Cross-referenced by PHPXref 0.7.1 |