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