/wp-admin/includes/template.php

  1. <?php 
  2. /** 
  3. * Template WordPress Administration API. 
  4. * 
  5. * A Big Mess. Also some neat functions that are nicely written. 
  6. * 
  7. * @package WordPress 
  8. * @subpackage Administration 
  9. */ 
  10.  
  11. /** Walker_Category_Checklist class */ 
  12. require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' ); 
  13.  
  14. /** WP_Internal_Pointers class */ 
  15. require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ); 
  16.  
  17. // 
  18. // Category Checklists 
  19. // 
  20.   
  21. /** 
  22. * Output an unordered list of checkbox input elements labeled with category names. 
  23. * 
  24. * @since 2.5.1 
  25. * 
  26. * @see wp_terms_checklist() 
  27. * 
  28. * @param int $post_id Optional. Post to generate a categories checklist for. Default 0. 
  29. * $selected_cats must not be an array. Default 0. 
  30. * @param int $descendants_and_self Optional. ID of the category to output along with its descendants. 
  31. * Default 0. 
  32. * @param array $selected_cats Optional. List of categories to mark as checked. Default false. 
  33. * @param array $popular_cats Optional. List of categories to receive the "popular-category" class. 
  34. * Default false. 
  35. * @param object $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( $post_id, array( 
  42. 'taxonomy' => 'category',  
  43. 'descendants_and_self' => $descendants_and_self,  
  44. 'selected_cats' => $selected_cats,  
  45. 'popular_cats' => $popular_cats,  
  46. 'walker' => $walker,  
  47. 'checked_ontop' => $checked_ontop 
  48. ) ); 
  49.  
  50. /** 
  51. * Output an unordered list of checkbox input elements labelled with term names. 
  52. * 
  53. * Taxonomy-independent version of wp_category_checklist(). 
  54. * 
  55. * @since 3.0.0 
  56. * @since 4.4.0 Introduced the `$echo` argument. 
  57. * 
  58. * @param int $post_id Optional. Post ID. Default 0. 
  59. * @param array|string $args { 
  60. * Optional. Array or string of arguments for generating a terms checklist. Default empty array. 
  61. * 
  62. * @type int $descendants_and_self ID of the category to output along with its descendants. 
  63. * Default 0. 
  64. * @type array $selected_cats List of categories to mark as checked. Default false. 
  65. * @type array $popular_cats List of categories to receive the "popular-category" class. 
  66. * Default false. 
  67. * @type object $walker Walker object to use to build the output. 
  68. * Default is a Walker_Category_Checklist instance. 
  69. * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. 
  70. * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to 
  71. * the top of the list. Default true. 
  72. * @type bool $echo Whether to echo the generated markup. False to return the markup instead 
  73. * of echoing it. Default true. 
  74. * } 
  75. */ 
  76. function wp_terms_checklist( $post_id = 0, $args = array() ) { 
  77. $defaults = array( 
  78. 'descendants_and_self' => 0,  
  79. 'selected_cats' => false,  
  80. 'popular_cats' => false,  
  81. 'walker' => null,  
  82. 'taxonomy' => 'category',  
  83. 'checked_ontop' => true,  
  84. 'echo' => true,  
  85. ); 
  86.  
  87. /** 
  88. * Filters the taxonomy terms checklist arguments. 
  89. * 
  90. * @since 3.4.0 
  91. * 
  92. * @see wp_terms_checklist() 
  93. * 
  94. * @param array $args An array of arguments. 
  95. * @param int $post_id The post ID. 
  96. */ 
  97. $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); 
  98.  
  99. $r = wp_parse_args( $params, $defaults ); 
  100.  
  101. if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) { 
  102. $walker = new Walker_Category_Checklist; 
  103. } else { 
  104. $walker = $r['walker']; 
  105.  
  106. $taxonomy = $r['taxonomy']; 
  107. $descendants_and_self = (int) $r['descendants_and_self']; 
  108.  
  109. $args = array( 'taxonomy' => $taxonomy ); 
  110.  
  111. $tax = get_taxonomy( $taxonomy ); 
  112. $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); 
  113.  
  114. $args['list_only'] = ! empty( $r['list_only'] ); 
  115.  
  116. if ( is_array( $r['selected_cats'] ) ) { 
  117. $args['selected_cats'] = $r['selected_cats']; 
  118. } elseif ( $post_id ) { 
  119. $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); 
  120. } else { 
  121. $args['selected_cats'] = array(); 
  122. if ( is_array( $r['popular_cats'] ) ) { 
  123. $args['popular_cats'] = $r['popular_cats']; 
  124. } else { 
  125. $args['popular_cats'] = get_terms( $taxonomy, array( 
  126. 'fields' => 'ids',  
  127. 'orderby' => 'count',  
  128. 'order' => 'DESC',  
  129. 'number' => 10,  
  130. 'hierarchical' => false 
  131. ) ); 
  132. if ( $descendants_and_self ) { 
  133. $categories = (array) get_terms( $taxonomy, array( 
  134. 'child_of' => $descendants_and_self,  
  135. 'hierarchical' => 0,  
  136. 'hide_empty' => 0 
  137. ) ); 
  138. $self = get_term( $descendants_and_self, $taxonomy ); 
  139. array_unshift( $categories, $self ); 
  140. } else { 
  141. $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); 
  142.  
  143. $output = ''; 
  144.  
  145. if ( $r['checked_ontop'] ) { 
  146. // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) 
  147. $checked_categories = array(); 
  148. $keys = array_keys( $categories ); 
  149.  
  150. foreach ( $keys as $k ) { 
  151. if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { 
  152. $checked_categories[] = $categories[$k]; 
  153. unset( $categories[$k] ); 
  154.  
  155. // Put checked cats on top 
  156. $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); 
  157. // Then the rest of them 
  158. $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); 
  159.  
  160. if ( $r['echo'] ) { 
  161. echo $output; 
  162.  
  163. return $output; 
  164.  
  165. /** 
  166. * Retrieve a list of the most popular terms from the specified taxonomy. 
  167. * 
  168. * If the $echo argument is true then the elements for a list of checkbox 
  169. * `<input>` elements labelled with the names of the selected terms is output. 
  170. * If the $post_ID global isn't empty then the terms associated with that 
  171. * post will be marked as checked. 
  172. * 
  173. * @since 2.5.0 
  174. * 
  175. * @param string $taxonomy Taxonomy to retrieve terms from. 
  176. * @param int $default Not used. 
  177. * @param int $number Number of terms to retrieve. Defaults to 10. 
  178. * @param bool $echo Optionally output the list as well. Defaults to true. 
  179. * @return array List of popular term IDs. 
  180. */ 
  181. function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { 
  182. $post = get_post(); 
  183.  
  184. if ( $post && $post->ID ) 
  185. $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids')); 
  186. else 
  187. $checked_terms = array(); 
  188.  
  189. $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); 
  190.  
  191. $tax = get_taxonomy($taxonomy); 
  192.  
  193. $popular_ids = array(); 
  194. foreach ( (array) $terms as $term ) { 
  195. $popular_ids[] = $term->term_id; 
  196. if ( !$echo ) // Hack for Ajax use. 
  197. continue; 
  198. $id = "popular-$taxonomy-$term->term_id"; 
  199. $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; 
  200. ?> 
  201.  
  202. <li id="<?php echo $id; ?>" class="popular-category"> 
  203. <label class="selectit"> 
  204. <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 ) ); ?> /> 
  205. <?php 
  206. /** This filter is documented in wp-includes/category-template.php */ 
  207. echo esc_html( apply_filters( 'the_category', $term->name ) ); 
  208. ?> 
  209. </label> 
  210. </li> 
  211.  
  212. <?php 
  213. return $popular_ids; 
  214.  
  215. /** 
  216. * Outputs a link category checklist element. 
  217. * 
  218. * @since 2.5.1 
  219. * 
  220. * @param int $link_id 
  221. */ 
  222. function wp_link_category_checklist( $link_id = 0 ) { 
  223. $default = 1; 
  224.  
  225. $checked_categories = array(); 
  226.  
  227. if ( $link_id ) { 
  228. $checked_categories = wp_get_link_cats( $link_id ); 
  229. // No selected categories, strange 
  230. if ( ! count( $checked_categories ) ) { 
  231. $checked_categories[] = $default; 
  232. } else { 
  233. $checked_categories[] = $default; 
  234.  
  235. $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); 
  236.  
  237. if ( empty( $categories ) ) 
  238. return; 
  239.  
  240. foreach ( $categories as $category ) { 
  241. $cat_id = $category->term_id; 
  242.  
  243. /** This filter is documented in wp-includes/category-template.php */ 
  244. $name = esc_html( apply_filters( 'the_category', $category->name ) ); 
  245. $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; 
  246. 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>"; 
  247.  
  248. /** 
  249. * Adds hidden fields with the data for use in the inline editor for posts and pages. 
  250. * 
  251. * @since 2.7.0 
  252. * 
  253. * @param WP_Post $post Post object. 
  254. */ 
  255. function get_inline_data($post) { 
  256. $post_type_object = get_post_type_object($post->post_type); 
  257. if ( ! current_user_can( 'edit_post', $post->ID ) ) 
  258. return; 
  259.  
  260. $title = esc_textarea( trim( $post->post_title ) ); 
  261.  
  262. /** This filter is documented in wp-admin/edit-tag-form.php */ 
  263. echo ' 
  264. <div class="hidden" id="inline_' . $post->ID . '"> 
  265. <div class="post_title">' . $title . '</div>' . 
  266. /** This filter is documented in wp-admin/edit-tag-form.php */ 
  267. '<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name, $post ) . '</div> 
  268. <div class="post_author">' . $post->post_author . '</div> 
  269. <div class="comment_status">' . esc_html( $post->comment_status ) . '</div> 
  270. <div class="ping_status">' . esc_html( $post->ping_status ) . '</div> 
  271. <div class="_status">' . esc_html( $post->post_status ) . '</div> 
  272. <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div> 
  273. <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div> 
  274. <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div> 
  275. <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div> 
  276. <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div> 
  277. <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> 
  278. <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; 
  279.  
  280. if ( $post_type_object->hierarchical ) 
  281. echo '<div class="post_parent">' . $post->post_parent . '</div>'; 
  282.  
  283. if ( $post->post_type == 'page' ) 
  284. echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; 
  285.  
  286. if ( post_type_supports( $post->post_type, 'page-attributes' ) ) 
  287. echo '<div class="menu_order">' . $post->menu_order . '</div>'; 
  288.  
  289. $taxonomy_names = get_object_taxonomies( $post->post_type ); 
  290. foreach ( $taxonomy_names as $taxonomy_name) { 
  291. $taxonomy = get_taxonomy( $taxonomy_name ); 
  292.  
  293. if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { 
  294.  
  295. $terms = get_object_term_cache( $post->ID, $taxonomy_name ); 
  296. if ( false === $terms ) { 
  297. $terms = wp_get_object_terms( $post->ID, $taxonomy_name ); 
  298. wp_cache_add( $post->ID, wp_list_pluck( $terms, 'term_id' ), $taxonomy_name . '_relationships' ); 
  299. $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' ); 
  300.  
  301. echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ', ', $term_ids ) . '</div>'; 
  302.  
  303. } elseif ( $taxonomy->show_ui ) { 
  304.  
  305. $terms_to_edit = get_terms_to_edit( $post->ID, $taxonomy_name ); 
  306. if ( ! is_string( $terms_to_edit ) ) { 
  307. $terms_to_edit = ''; 
  308.  
  309. echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' 
  310. . esc_html( str_replace( ', ', ', ', $terms_to_edit ) ) . '</div>'; 
  311.  
  312.  
  313. if ( !$post_type_object->hierarchical ) 
  314. echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; 
  315.  
  316. if ( post_type_supports( $post->post_type, 'post-formats' ) ) 
  317. echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>'; 
  318.  
  319. echo '</div>'; 
  320.  
  321. /** 
  322. * Outputs the in-line comment reply-to form in the Comments list table. 
  323. * 
  324. * @since 2.7.0 
  325. * 
  326. * @global WP_List_Table $wp_list_table 
  327. * 
  328. * @param int $position 
  329. * @param bool $checkbox 
  330. * @param string $mode 
  331. * @param bool $table_row 
  332. */ 
  333. function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) { 
  334. global $wp_list_table; 
  335. /** 
  336. * Filters the in-line comment reply-to form output in the Comments 
  337. * list table. 
  338. * 
  339. * Returning a non-empty value here will short-circuit display 
  340. * of the in-line comment-reply form in the Comments list table,  
  341. * echoing the returned value instead. 
  342. * 
  343. * @since 2.7.0 
  344. * 
  345. * @see wp_comment_reply() 
  346. * 
  347. * @param string $content The reply-to form content. 
  348. * @param array $args An array of default args. 
  349. */ 
  350. $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) ); 
  351.  
  352. if ( ! empty($content) ) { 
  353. echo $content; 
  354. return; 
  355.  
  356. if ( ! $wp_list_table ) { 
  357. if ( $mode == 'single' ) { 
  358. $wp_list_table = _get_list_table('WP_Post_Comments_List_Table'); 
  359. } else { 
  360. $wp_list_table = _get_list_table('WP_Comments_List_Table'); 
  361.  
  362. ?> 
  363. <form method="get"> 
  364. <?php if ( $table_row ) : ?> 
  365. <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"> 
  366. <?php else : ?> 
  367. <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;"> 
  368. <?php endif; ?> 
  369. <fieldset class="comment-reply"> 
  370. <legend> 
  371. <span class="hidden" id="editlegend"><?php _e( 'Edit Comment' ); ?></span> 
  372. <span class="hidden" id="replyhead"><?php _e( 'Reply to Comment' ); ?></span> 
  373. <span class="hidden" id="addhead"><?php _e( 'Add new Comment' ); ?></span> 
  374. </legend> 
  375.  
  376. <div id="replycontainer"> 
  377. <label for="replycontent" class="screen-reader-text"><?php _e( 'Comment' ); ?></label> 
  378. <?php 
  379. $quicktags_settings = array( 'buttons' => 'strong, em, link, block, del, ins, img, ul, ol, li, code, close' ); 
  380. wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) ); 
  381. ?> 
  382. </div> 
  383.  
  384. <div id="edithead" style="display:none;"> 
  385. <div class="inside"> 
  386. <label for="author-name"><?php _e( 'Name' ) ?></label> 
  387. <input type="text" name="newcomment_author" size="50" value="" id="author-name" /> 
  388. </div> 
  389.  
  390. <div class="inside"> 
  391. <label for="author-email"><?php _e('Email') ?></label> 
  392. <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" /> 
  393. </div> 
  394.  
  395. <div class="inside"> 
  396. <label for="author-url"><?php _e('URL') ?></label> 
  397. <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" /> 
  398. </div> 
  399. </div> 
  400.  
  401. <p id="replysubmit" class="submit"> 
  402. <a href="#comments-form" class="save button-primary alignright"> 
  403. <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span> 
  404. <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span> 
  405. <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a> 
  406. <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a> 
  407. <span class="waiting spinner"></span> 
  408. <span class="error" style="display:none;"></span> 
  409. </p> 
  410.  
  411. <input type="hidden" name="action" id="action" value="" /> 
  412. <input type="hidden" name="comment_ID" id="comment_ID" value="" /> 
  413. <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> 
  414. <input type="hidden" name="status" id="status" value="" /> 
  415. <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" /> 
  416. <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" /> 
  417. <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" /> 
  418. <?php 
  419. wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); 
  420. if ( current_user_can( 'unfiltered_html' ) ) 
  421. wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false ); 
  422. ?> 
  423. </fieldset> 
  424. <?php if ( $table_row ) : ?> 
  425. </td></tr></tbody></table> 
  426. <?php else : ?> 
  427. </div></div> 
  428. <?php endif; ?> 
  429. </form> 
  430. <?php 
  431.  
  432. /** 
  433. * Output 'undo move to trash' text for comments 
  434. * 
  435. * @since 2.9.0 
  436. */ 
  437. function wp_comment_trashnotice() { 
  438. ?> 
  439. <div class="hidden" id="trash-undo-holder"> 
  440. <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div> 
  441. </div> 
  442. <div class="hidden" id="spam-undo-holder"> 
  443. <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div> 
  444. </div> 
  445. <?php 
  446.  
  447. /** 
  448. * Outputs a post's public meta data in the Custom Fields meta box. 
  449. * 
  450. * @since 1.2.0 
  451. * 
  452. * @param array $meta 
  453. */ 
  454. function list_meta( $meta ) { 
  455. // Exit if no meta 
  456. if ( ! $meta ) { 
  457. echo ' 
  458. <table id="list-table" style="display: none;"> 
  459. <thead> 
  460. <tr> 
  461. <th class="left">' . _x( 'Name', 'meta name' ) . '</th> 
  462. <th>' . __( 'Value' ) . '</th> 
  463. </tr> 
  464. </thead> 
  465. <tbody id="the-list" data-wp-lists="list:meta"> 
  466. <tr><td></td></tr> 
  467. </tbody> 
  468. </table>'; //TBODY needed for list-manipulation JS 
  469. return; 
  470. $count = 0; 
  471. ?> 
  472. <table id="list-table"> 
  473. <thead> 
  474. <tr> 
  475. <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th> 
  476. <th><?php _e( 'Value' ) ?></th> 
  477. </tr> 
  478. </thead> 
  479. <tbody id='the-list' data-wp-lists='list:meta'> 
  480. <?php 
  481. foreach ( $meta as $entry ) 
  482. echo _list_meta_row( $entry, $count ); 
  483. ?> 
  484. </tbody> 
  485. </table> 
  486. <?php 
  487.  
  488. /** 
  489. * Outputs a single row of public meta data in the Custom Fields meta box. 
  490. * 
  491. * @since 2.5.0 
  492. * 
  493. * @staticvar string $update_nonce 
  494. * 
  495. * @param array $entry 
  496. * @param int $count 
  497. * @return string 
  498. */ 
  499. function _list_meta_row( $entry, &$count ) { 
  500. static $update_nonce = ''; 
  501.  
  502. if ( is_protected_meta( $entry['meta_key'], 'post' ) ) 
  503. return ''; 
  504.  
  505. if ( ! $update_nonce ) 
  506. $update_nonce = wp_create_nonce( 'add-meta' ); 
  507.  
  508. $r = ''; 
  509. ++ $count; 
  510.  
  511. if ( is_serialized( $entry['meta_value'] ) ) { 
  512. if ( is_serialized_string( $entry['meta_value'] ) ) { 
  513. // This is a serialized string, so we should display it. 
  514. $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); 
  515. } else { 
  516. // This is a serialized array/object so we should NOT display it. 
  517. --$count; 
  518. return ''; 
  519.  
  520. $entry['meta_key'] = esc_attr($entry['meta_key']); 
  521. $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea /> 
  522. $entry['meta_id'] = (int) $entry['meta_id']; 
  523.  
  524. $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); 
  525.  
  526. $r .= "\n\t<tr id='meta-{$entry['meta_id']}'>"; 
  527. $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta-{$entry['meta_id']}-key'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta-{$entry['meta_id']}-key' type='text' size='20' value='{$entry['meta_key']}' />"; 
  528.  
  529. $r .= "\n\t\t<div class='submit'>"; 
  530. $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" ) ); 
  531. $r .= "\n\t\t"; 
  532. $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" ) ); 
  533. $r .= "</div>"; 
  534. $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false ); 
  535. $r .= "</td>"; 
  536.  
  537. $r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>"; 
  538. return $r; 
  539.  
  540. /** 
  541. * Prints the form in the Custom Fields meta box. 
  542. * 
  543. * @since 1.2.0 
  544. * 
  545. * @global wpdb $wpdb WordPress database abstraction object. 
  546. * 
  547. * @param WP_Post $post Optional. The post being edited. 
  548. */ 
  549. function meta_form( $post = null ) { 
  550. global $wpdb; 
  551. $post = get_post( $post ); 
  552.  
  553. /** 
  554. * Filters values for the meta key dropdown in the Custom Fields meta box. 
  555. * 
  556. * Returning a non-null value will effectively short-circuit and avoid a 
  557. * potentially expensive query against postmeta. 
  558. * 
  559. * @since 4.4.0 
  560. * 
  561. * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null. 
  562. * @param WP_Post $post The current post object. 
  563. */ 
  564. $keys = apply_filters( 'postmeta_form_keys', null, $post ); 
  565.  
  566. if ( null === $keys ) { 
  567. /** 
  568. * Filters the number of custom fields to retrieve for the drop-down 
  569. * in the Custom Fields meta box. 
  570. * 
  571. * @since 2.1.0 
  572. * 
  573. * @param int $limit Number of custom fields to retrieve. Default 30. 
  574. */ 
  575. $limit = apply_filters( 'postmeta_form_limit', 30 ); 
  576. $sql = "SELECT DISTINCT meta_key 
  577. FROM $wpdb->postmeta 
  578. WHERE meta_key NOT BETWEEN '_' AND '_z' 
  579. HAVING meta_key NOT LIKE %s 
  580. ORDER BY meta_key 
  581. LIMIT %d"; 
  582. $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); 
  583.  
  584. if ( $keys ) { 
  585. natcasesort( $keys ); 
  586. $meta_key_input_id = 'metakeyselect'; 
  587. } else { 
  588. $meta_key_input_id = 'metakeyinput'; 
  589. ?> 
  590. <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p> 
  591. <table id="newmeta"> 
  592. <thead> 
  593. <tr> 
  594. <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th> 
  595. <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th> 
  596. </tr> 
  597. </thead> 
  598.  
  599. <tbody> 
  600. <tr> 
  601. <td id="newmetaleft" class="left"> 
  602. <?php if ( $keys ) { ?> 
  603. <select id="metakeyselect" name="metakeyselect"> 
  604. <option value="#NONE#"><?php _e( '— Select —' ); ?></option> 
  605. <?php 
  606.  
  607. foreach ( $keys as $key ) { 
  608. if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) 
  609. continue; 
  610. echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>"; 
  611. ?> 
  612. </select> 
  613. <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" /> 
  614. <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;"> 
  615. <span id="enternew"><?php _e('Enter new'); ?></span> 
  616. <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a> 
  617. <?php } else { ?> 
  618. <input type="text" id="metakeyinput" name="metakeyinput" value="" /> 
  619. <?php } ?> 
  620. </td> 
  621. <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td> 
  622. </tr> 
  623.  
  624. <tr><td colspan="2"> 
  625. <div class="submit"> 
  626. <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?> 
  627. </div> 
  628. <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?> 
  629. </td></tr> 
  630. </tbody> 
  631. </table> 
  632. <?php 
  633.  
  634.  
  635. /** 
  636. * Print out HTML form date elements for editing post or comment publish date. 
  637. * 
  638. * @since 0.71 
  639. * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`. 
  640. * 
  641. * @global WP_Locale $wp_locale 
  642. * 
  643. * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date. 
  644. * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. 
  645. * @param int $tab_index The tabindex attribute to add. Default 0. 
  646. * @param int|bool $multi Optional. Whether the additional fields and buttons should be added. 
  647. * Default 0|false. 
  648. */ 
  649. function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { 
  650. global $wp_locale; 
  651. $post = get_post(); 
  652.  
  653. if ( $for_post ) 
  654. $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); 
  655.  
  656. $tab_index_attribute = ''; 
  657. if ( (int) $tab_index > 0 ) 
  658. $tab_index_attribute = " tabindex=\"$tab_index\""; 
  659.  
  660. // todo: Remove this? 
  661. // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; 
  662.  
  663. $time_adj = current_time('timestamp'); 
  664. $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date; 
  665. $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); 
  666. $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); 
  667. $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); 
  668. $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); 
  669. $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); 
  670. $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj ); 
  671.  
  672. $cur_jj = gmdate( 'd', $time_adj ); 
  673. $cur_mm = gmdate( 'm', $time_adj ); 
  674. $cur_aa = gmdate( 'Y', $time_adj ); 
  675. $cur_hh = gmdate( 'H', $time_adj ); 
  676. $cur_mn = gmdate( 'i', $time_adj ); 
  677.  
  678. $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; 
  679. for ( $i = 1; $i < 13; $i = $i +1 ) { 
  680. $monthnum = zeroise($i, 2); 
  681. $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); 
  682. $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>'; 
  683. /** translators: 1: month number (01, 02, etc.), 2: month abbreviation */ 
  684. $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; 
  685. $month .= '</select></label>'; 
  686.  
  687. $day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  688. $year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  689. $hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  690. $minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  691.  
  692. echo '<div class="timestamp-wrap">'; 
  693. /** translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ 
  694. printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); 
  695.  
  696. echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; 
  697.  
  698. if ( $multi ) return; 
  699.  
  700. echo "\n\n"; 
  701. $map = array( 
  702. 'mm' => array( $mm, $cur_mm ),  
  703. 'jj' => array( $jj, $cur_jj ),  
  704. 'aa' => array( $aa, $cur_aa ),  
  705. 'hh' => array( $hh, $cur_hh ),  
  706. 'mn' => array( $mn, $cur_mn ),  
  707. ); 
  708. foreach ( $map as $timeunit => $value ) { 
  709. list( $unit, $curr ) = $value; 
  710.  
  711. echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n"; 
  712. $cur_timeunit = 'cur_' . $timeunit; 
  713. echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n"; 
  714. ?> 
  715.  
  716. <p> 
  717. <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a> 
  718. <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> 
  719. </p> 
  720. <?php 
  721.  
  722. /** 
  723. * Print out option HTML elements for the page templates drop-down. 
  724. * 
  725. * @since 1.5.0 
  726. * 
  727. * @param string $default Optional. The template file name. Default empty. 
  728. */ 
  729. function page_template_dropdown( $default = '' ) { 
  730. $templates = get_page_templates( get_post() ); 
  731. ksort( $templates ); 
  732. foreach ( array_keys( $templates ) as $template ) { 
  733. $selected = selected( $default, $templates[ $template ], false ); 
  734. echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>"; 
  735.  
  736. /** 
  737. * Print out option HTML elements for the page parents drop-down. 
  738. * 
  739. * @since 1.5.0 
  740. * @since 4.4.0 `$post` argument was added. 
  741. * 
  742. * @global wpdb $wpdb WordPress database abstraction object. 
  743. * 
  744. * @param int $default Optional. The default page ID to be pre-selected. Default 0. 
  745. * @param int $parent Optional. The parent page ID. Default 0. 
  746. * @param int $level Optional. Page depth level. Default 0. 
  747. * @param int|WP_Post $post Post ID or WP_Post object. 
  748. * 
  749. * @return null|false Boolean False if page has no children, otherwise print out html elements 
  750. */ 
  751. function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) { 
  752. global $wpdb; 
  753. $post = get_post( $post ); 
  754. $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) ); 
  755.  
  756. if ( $items ) { 
  757. foreach ( $items as $item ) { 
  758. // A page cannot be its own parent. 
  759. if ( $post && $post->ID && $item->ID == $post->ID ) 
  760. continue; 
  761.  
  762. $pad = str_repeat( ' ', $level * 3 ); 
  763. $selected = selected( $default, $item->ID, false ); 
  764.  
  765. echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>"; 
  766. parent_dropdown( $default, $item->ID, $level +1 ); 
  767. } else { 
  768. return false; 
  769.  
  770. /** 
  771. * Print out option html elements for role selectors. 
  772. * 
  773. * @since 2.1.0 
  774. * 
  775. * @param string $selected Slug for the role that should be already selected. 
  776. */ 
  777. function wp_dropdown_roles( $selected = '' ) { 
  778. $p = ''; 
  779. $r = ''; 
  780.  
  781. $editable_roles = array_reverse( get_editable_roles() ); 
  782.  
  783. foreach ( $editable_roles as $role => $details ) { 
  784. $name = translate_user_role($details['name'] ); 
  785. if ( $selected == $role ) // preselect specified role 
  786. $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; 
  787. else 
  788. $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>"; 
  789. echo $p . $r; 
  790.  
  791. /** 
  792. * Outputs the form used by the importers to accept the data to be imported 
  793. * 
  794. * @since 2.0.0 
  795. * 
  796. * @param string $action The action attribute for the form. 
  797. */ 
  798. function wp_import_upload_form( $action ) { 
  799.  
  800. /** 
  801. * Filters the maximum allowed upload size for import files. 
  802. * 
  803. * @since 2.3.0 
  804. * 
  805. * @see wp_max_upload_size() 
  806. * 
  807. * @param int $max_upload_size Allowed upload size. Default 1 MB. 
  808. */ 
  809. $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); 
  810. $size = size_format( $bytes ); 
  811. $upload_dir = wp_upload_dir(); 
  812. if ( ! empty( $upload_dir['error'] ) ) : 
  813. ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p> 
  814. <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php 
  815. else : 
  816. ?> 
  817. <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' ) ); ?>"> 
  818. <p> 
  819. <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>) 
  820. <input type="file" id="upload" name="import" size="25" /> 
  821. <input type="hidden" name="action" value="save" /> 
  822. <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> 
  823. </p> 
  824. <?php submit_button( __('Upload file and import'), 'primary' ); ?> 
  825. </form> 
  826. <?php 
  827. endif; 
  828.  
  829. /** 
  830. * Adds a meta box to one or more screens. 
  831. * 
  832. * @since 2.5.0 
  833. * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. 
  834. * 
  835. * @global array $wp_meta_boxes 
  836. * 
  837. * @param string $id Meta box ID (used in the 'id' attribute for the meta box). 
  838. * @param string $title Title of the meta box. 
  839. * @param callable $callback Function that fills the box with the desired content. 
  840. * The function should echo its output. 
  841. * @param string|array|WP_Screen $screen Optional. The screen or screens on which to show the box 
  842. * (such as a post type, 'link', or 'comment'). Accepts a single 
  843. * screen ID, WP_Screen object, or array of screen IDs. Default 
  844. * is the current screen. 
  845. * @param string $context Optional. The context within the screen where the boxes 
  846. * should display. Available contexts vary from screen to 
  847. * screen. Post edit screen contexts include 'normal', 'side',  
  848. * and 'advanced'. Comments screen contexts include 'normal' 
  849. * and 'side'. Menus meta boxes (accordion sections) all use 
  850. * the 'side' context. Global default is 'advanced'. 
  851. * @param string $priority Optional. The priority within the context where the boxes 
  852. * should show ('high', 'low'). Default 'default'. 
  853. * @param array $callback_args Optional. Data that should be set as the $args property 
  854. * of the box array (which is the second parameter passed 
  855. * to your callback). Default null. 
  856. */ 
  857. function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { 
  858. global $wp_meta_boxes; 
  859.  
  860. if ( empty( $screen ) ) { 
  861. $screen = get_current_screen(); 
  862. } elseif ( is_string( $screen ) ) { 
  863. $screen = convert_to_screen( $screen ); 
  864. } elseif ( is_array( $screen ) ) { 
  865. foreach ( $screen as $single_screen ) { 
  866. add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args ); 
  867.  
  868. if ( ! isset( $screen->id ) ) { 
  869. return; 
  870.  
  871. $page = $screen->id; 
  872.  
  873. if ( !isset($wp_meta_boxes) ) 
  874. $wp_meta_boxes = array(); 
  875. if ( !isset($wp_meta_boxes[$page]) ) 
  876. $wp_meta_boxes[$page] = array(); 
  877. if ( !isset($wp_meta_boxes[$page][$context]) ) 
  878. $wp_meta_boxes[$page][$context] = array(); 
  879.  
  880. foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) { 
  881. foreach ( array('high', 'core', 'default', 'low') as $a_priority ) { 
  882. if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) ) 
  883. continue; 
  884.  
  885. // If a core box was previously added or removed by a plugin, don't add. 
  886. if ( 'core' == $priority ) { 
  887. // If core box previously deleted, don't add 
  888. if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) 
  889. return; 
  890.  
  891. /** 
  892. * If box was added with default priority, give it core priority to 
  893. * maintain sort order. 
  894. */ 
  895. if ( 'default' == $a_priority ) { 
  896. $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id]; 
  897. unset($wp_meta_boxes[$page][$a_context]['default'][$id]); 
  898. return; 
  899. // If no priority given and id already present, use existing priority. 
  900. if ( empty($priority) ) { 
  901. $priority = $a_priority; 
  902. /** 
  903. * Else, if we're adding to the sorted priority, we don't know the title 
  904. * or callback. Grab them from the previously added context/priority. 
  905. */ 
  906. } elseif ( 'sorted' == $priority ) { 
  907. $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; 
  908. $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; 
  909. $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args']; 
  910. // An id can be in only one priority and one context. 
  911. if ( $priority != $a_priority || $context != $a_context ) 
  912. unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); 
  913.  
  914. if ( empty($priority) ) 
  915. $priority = 'low'; 
  916.  
  917. if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) 
  918. $wp_meta_boxes[$page][$context][$priority] = array(); 
  919.  
  920. $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args); 
  921.  
  922. /** 
  923. * Meta-Box template function 
  924. * 
  925. * @since 2.5.0 
  926. * 
  927. * @global array $wp_meta_boxes 
  928. * 
  929. * @staticvar bool $already_sorted 
  930. * @param string|WP_Screen $screen Screen identifier 
  931. * @param string $context box context 
  932. * @param mixed $object gets passed to the box callback function as first parameter 
  933. * @return int number of meta_boxes 
  934. */ 
  935. function do_meta_boxes( $screen, $context, $object ) { 
  936. global $wp_meta_boxes; 
  937. static $already_sorted = false; 
  938.  
  939. if ( empty( $screen ) ) 
  940. $screen = get_current_screen(); 
  941. elseif ( is_string( $screen ) ) 
  942. $screen = convert_to_screen( $screen ); 
  943.  
  944. $page = $screen->id; 
  945.  
  946. $hidden = get_hidden_meta_boxes( $screen ); 
  947.  
  948. printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context)); 
  949.  
  950. // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose 
  951. if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { 
  952. foreach ( $sorted as $box_context => $ids ) { 
  953. foreach ( explode( ', ', $ids ) as $id ) { 
  954. if ( $id && 'dashboard_browser_nag' !== $id ) { 
  955. add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); 
  956.  
  957. $already_sorted = true; 
  958.  
  959. $i = 0; 
  960.  
  961. if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 
  962. foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { 
  963. if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) { 
  964. foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { 
  965. if ( false == $box || ! $box['title'] ) 
  966. continue; 
  967. $i++; 
  968. $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; 
  969. echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n"; 
  970. if ( 'dashboard_browser_nag' != $box['id'] ) { 
  971. $widget_title = $box[ 'title' ]; 
  972.  
  973. if ( is_array( $box[ 'args' ] ) && isset( $box[ 'args' ][ '__widget_basename' ] ) ) { 
  974. $widget_title = $box[ 'args' ][ '__widget_basename' ]; 
  975. // Do not pass this parameter to the user callback function. 
  976. unset( $box[ 'args' ][ '__widget_basename' ] ); 
  977.  
  978. echo '<button type="button" class="handlediv button-link" aria-expanded="true">'; 
  979. echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>'; 
  980. echo '<span class="toggle-indicator" aria-hidden="true"></span>'; 
  981. echo '</button>'; 
  982. echo "<h2 class='hndle'><span>{$box['title']}</span></h2>\n"; 
  983. echo '<div class="inside">' . "\n"; 
  984. call_user_func($box['callback'], $object, $box); 
  985. echo "</div>\n"; 
  986. echo "</div>\n"; 
  987.  
  988. echo "</div>"; 
  989.  
  990. return $i; 
  991.  
  992.  
  993. /** 
  994. * Removes a meta box from one or more screens. 
  995. * 
  996. * @since 2.6.0 
  997. * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. 
  998. * 
  999. * @global array $wp_meta_boxes 
  1000. * 
  1001. * @param string $id Meta box ID (used in the 'id' attribute for the meta box). 
  1002. * @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a 
  1003. * post type, 'link', or 'comment'). Accepts a single screen ID,  
  1004. * WP_Screen object, or array of screen IDs. 
  1005. * @param string $context The context within the screen where the box is set to display. 
  1006. * Contexts vary from screen to screen. Post edit screen contexts 
  1007. * include 'normal', 'side', and 'advanced'. Comments screen contexts 
  1008. * include 'normal' and 'side'. Menus meta boxes (accordion sections) 
  1009. * all use the 'side' context. 
  1010. */ 
  1011. function remove_meta_box( $id, $screen, $context ) { 
  1012. global $wp_meta_boxes; 
  1013.  
  1014. if ( empty( $screen ) ) { 
  1015. $screen = get_current_screen(); 
  1016. } elseif ( is_string( $screen ) ) { 
  1017. $screen = convert_to_screen( $screen ); 
  1018. } elseif ( is_array( $screen ) ) { 
  1019. foreach ( $screen as $single_screen ) { 
  1020. remove_meta_box( $id, $single_screen, $context ); 
  1021.  
  1022. if ( ! isset( $screen->id ) ) { 
  1023. return; 
  1024.  
  1025. $page = $screen->id; 
  1026.  
  1027. if ( !isset($wp_meta_boxes) ) 
  1028. $wp_meta_boxes = array(); 
  1029. if ( !isset($wp_meta_boxes[$page]) ) 
  1030. $wp_meta_boxes[$page] = array(); 
  1031. if ( !isset($wp_meta_boxes[$page][$context]) ) 
  1032. $wp_meta_boxes[$page][$context] = array(); 
  1033.  
  1034. foreach ( array('high', 'core', 'default', 'low') as $priority ) 
  1035. $wp_meta_boxes[$page][$context][$priority][$id] = false; 
  1036.  
  1037. /** 
  1038. * Meta Box Accordion Template Function 
  1039. * 
  1040. * Largely made up of abstracted code from do_meta_boxes(), this 
  1041. * function serves to build meta boxes as list items for display as 
  1042. * a collapsible accordion. 
  1043. * 
  1044. * @since 3.6.0 
  1045. * 
  1046. * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. 
  1047. * 
  1048. * @param string|object $screen The screen identifier. 
  1049. * @param string $context The meta box context. 
  1050. * @param mixed $object gets passed to the section callback function as first parameter. 
  1051. * @return int number of meta boxes as accordion sections. 
  1052. */ 
  1053. function do_accordion_sections( $screen, $context, $object ) { 
  1054. global $wp_meta_boxes; 
  1055.  
  1056. wp_enqueue_script( 'accordion' ); 
  1057.  
  1058. if ( empty( $screen ) ) 
  1059. $screen = get_current_screen(); 
  1060. elseif ( is_string( $screen ) ) 
  1061. $screen = convert_to_screen( $screen ); 
  1062.  
  1063. $page = $screen->id; 
  1064.  
  1065. $hidden = get_hidden_meta_boxes( $screen ); 
  1066. ?> 
  1067. <div id="side-sortables" class="accordion-container"> 
  1068. <ul class="outer-border"> 
  1069. <?php 
  1070. $i = 0; 
  1071. $first_open = false; 
  1072.  
  1073. if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { 
  1074. foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { 
  1075. if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { 
  1076. foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { 
  1077. if ( false == $box || ! $box['title'] ) 
  1078. continue; 
  1079. $i++; 
  1080. $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : ''; 
  1081.  
  1082. $open_class = ''; 
  1083. if ( ! $first_open && empty( $hidden_class ) ) { 
  1084. $first_open = true; 
  1085. $open_class = 'open'; 
  1086. ?> 
  1087. <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'] ); ?>"> 
  1088. <h3 class="accordion-section-title hndle" tabindex="0"> 
  1089. <?php echo esc_html( $box['title'] ); ?> 
  1090. <span class="screen-reader-text"><?php _e( 'Press return or enter to open this section' ); ?></span> 
  1091. </h3> 
  1092. <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>"> 
  1093. <div class="inside"> 
  1094. <?php call_user_func( $box['callback'], $object, $box ); ?> 
  1095. </div><!-- .inside --> 
  1096. </div><!-- .accordion-section-content --> 
  1097. </li><!-- .accordion-section --> 
  1098. <?php 
  1099. ?> 
  1100. </ul><!-- .outer-border --> 
  1101. </div><!-- .accordion-container --> 
  1102. <?php 
  1103. return $i; 
  1104.  
  1105. /** 
  1106. * Add a new section to a settings page. 
  1107. * 
  1108. * Part of the Settings API. Use this to define new settings sections for an admin page. 
  1109. * Show settings sections in your admin page callback function with do_settings_sections(). 
  1110. * Add settings fields to your section with add_settings_field() 
  1111. * 
  1112. * The $callback argument should be the name of a function that echoes out any 
  1113. * content you want to show at the top of the settings section before the actual 
  1114. * fields. It can output nothing if you want. 
  1115. * 
  1116. * @since 2.7.0 
  1117. * 
  1118. * @global $wp_settings_sections Storage array of all settings sections added to admin pages 
  1119. * 
  1120. * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. 
  1121. * @param string $title Formatted title of the section. Shown as the heading for the section. 
  1122. * @param callable $callback Function that echos out any content at the top of the section (between heading and fields). 
  1123. * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 
  1124. * 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using 
  1125. * add_options_page(); 
  1126. */ 
  1127. function add_settings_section($id, $title, $callback, $page) { 
  1128. global $wp_settings_sections; 
  1129.  
  1130. if ( 'misc' == $page ) { 
  1131. _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); 
  1132. $page = 'general'; 
  1133.  
  1134. if ( 'privacy' == $page ) { 
  1135. _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); 
  1136. $page = 'reading'; 
  1137.  
  1138. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); 
  1139.  
  1140. /** 
  1141. * Add a new field to a section of a settings page 
  1142. * 
  1143. * Part of the Settings API. Use this to define a settings field that will show 
  1144. * as part of a settings section inside a settings page. The fields are shown using 
  1145. * do_settings_fields() in do_settings-sections() 
  1146. * 
  1147. * The $callback argument should be the name of a function that echoes out the 
  1148. * html input tags for this setting field. Use get_option() to retrieve existing 
  1149. * values to show. 
  1150. * 
  1151. * @since 2.7.0 
  1152. * @since 4.2.0 The `$class` argument was added. 
  1153. * 
  1154. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections 
  1155. * 
  1156. * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. 
  1157. * @param string $title Formatted title of the field. Shown as the label for the field 
  1158. * during output. 
  1159. * @param callable $callback Function that fills the field with the desired form inputs. The 
  1160. * function should echo its output. 
  1161. * @param string $page The slug-name of the settings page on which to show the section 
  1162. * (general, reading, writing, ...). 
  1163. * @param string $section Optional. The slug-name of the section of the settings page 
  1164. * in which to show the box. Default 'default'. 
  1165. * @param array $args { 
  1166. * Optional. Extra arguments used when outputting the field. 
  1167. * 
  1168. * @type string $label_for When supplied, the setting title will be wrapped 
  1169. * in a `<label>` element, its `for` attribute populated 
  1170. * with this value. 
  1171. * @type string $class CSS Class to be added to the `<tr>` element when the 
  1172. * field is output. 
  1173. * } 
  1174. */ 
  1175. function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) { 
  1176. global $wp_settings_fields; 
  1177.  
  1178. if ( 'misc' == $page ) { 
  1179. _deprecated_argument( __FUNCTION__, '3.0.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) ); 
  1180. $page = 'general'; 
  1181.  
  1182. if ( 'privacy' == $page ) { 
  1183. _deprecated_argument( __FUNCTION__, '3.5.0', __( 'The privacy options group has been removed. Use another settings group.' ) ); 
  1184. $page = 'reading'; 
  1185.  
  1186. $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args); 
  1187.  
  1188. /** 
  1189. * Prints out all settings sections added to a particular settings page 
  1190. * 
  1191. * Part of the Settings API. Use this in a settings page callback function 
  1192. * to output all the sections and fields that were added to that $page with 
  1193. * add_settings_section() and add_settings_field() 
  1194. * 
  1195. * @global $wp_settings_sections Storage array of all settings sections added to admin pages 
  1196. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections 
  1197. * @since 2.7.0 
  1198. * 
  1199. * @param string $page The slug name of the page whose settings sections you want to output 
  1200. */ 
  1201. function do_settings_sections( $page ) { 
  1202. global $wp_settings_sections, $wp_settings_fields; 
  1203.  
  1204. if ( ! isset( $wp_settings_sections[$page] ) ) 
  1205. return; 
  1206.  
  1207. foreach ( (array) $wp_settings_sections[$page] as $section ) { 
  1208. if ( $section['title'] ) 
  1209. echo "<h2>{$section['title']}</h2>\n"; 
  1210.  
  1211. if ( $section['callback'] ) 
  1212. call_user_func( $section['callback'], $section ); 
  1213.  
  1214. if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) ) 
  1215. continue; 
  1216. echo '<table class="form-table">'; 
  1217. do_settings_fields( $page, $section['id'] ); 
  1218. echo '</table>'; 
  1219.  
  1220. /** 
  1221. * Print out the settings fields for a particular settings section 
  1222. * 
  1223. * Part of the Settings API. Use this in a settings page to output 
  1224. * a specific section. Should normally be called by do_settings_sections() 
  1225. * rather than directly. 
  1226. * 
  1227. * @global $wp_settings_fields Storage array of settings fields and their pages/sections 
  1228. * 
  1229. * @since 2.7.0 
  1230. * 
  1231. * @param string $page Slug title of the admin page who's settings fields you want to show. 
  1232. * @param string $section Slug title of the settings section who's fields you want to show. 
  1233. */ 
  1234. function do_settings_fields($page, $section) { 
  1235. global $wp_settings_fields; 
  1236.  
  1237. if ( ! isset( $wp_settings_fields[$page][$section] ) ) 
  1238. return; 
  1239.  
  1240. foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { 
  1241. $class = ''; 
  1242.  
  1243. if ( ! empty( $field['args']['class'] ) ) { 
  1244. $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; 
  1245.  
  1246. echo "<tr{$class}>"; 
  1247.  
  1248. if ( ! empty( $field['args']['label_for'] ) ) { 
  1249. echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>'; 
  1250. } else { 
  1251. echo '<th scope="row">' . $field['title'] . '</th>'; 
  1252.  
  1253. echo '<td>'; 
  1254. call_user_func($field['callback'], $field['args']); 
  1255. echo '</td>'; 
  1256. echo '</tr>'; 
  1257.  
  1258. /** 
  1259. * Register a settings error to be displayed to the user 
  1260. * 
  1261. * Part of the Settings API. Use this to show messages to users about settings validation 
  1262. * problems, missing settings or anything else. 
  1263. * 
  1264. * Settings errors should be added inside the $sanitize_callback function defined in 
  1265. * register_setting() for a given setting to give feedback about the submission. 
  1266. * 
  1267. * By default messages will show immediately after the submission that generated the error. 
  1268. * Additional calls to settings_errors() can be used to show errors even when the settings 
  1269. * page is first accessed. 
  1270. * 
  1271. * @since 3.0.0 
  1272. * 
  1273. * @global array $wp_settings_errors Storage array of errors registered during this pageload 
  1274. * 
  1275. * @param string $setting Slug title of the setting to which this error applies 
  1276. * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. 
  1277. * @param string $message The formatted message text to display to the user (will be shown inside styled 
  1278. * `<div>` and `<p>` tags). 
  1279. * @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'. 
  1280. * Default 'error'. 
  1281. */ 
  1282. function add_settings_error( $setting, $code, $message, $type = 'error' ) { 
  1283. global $wp_settings_errors; 
  1284.  
  1285. $wp_settings_errors[] = array( 
  1286. 'setting' => $setting,  
  1287. 'code' => $code,  
  1288. 'message' => $message,  
  1289. 'type' => $type 
  1290. ); 
  1291.  
  1292. /** 
  1293. * Fetch settings errors registered by add_settings_error() 
  1294. * 
  1295. * Checks the $wp_settings_errors array for any errors declared during the current 
  1296. * pageload and returns them. 
  1297. * 
  1298. * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved 
  1299. * to the 'settings_errors' transient then those errors will be returned instead. This 
  1300. * is used to pass errors back across pageloads. 
  1301. * 
  1302. * Use the $sanitize argument to manually re-sanitize the option before returning errors. 
  1303. * This is useful if you have errors or notices you want to show even when the user 
  1304. * hasn't submitted data (i.e. when they first load an options page, or in the {@see 'admin_notices'} 
  1305. * action hook). 
  1306. * 
  1307. * @since 3.0.0 
  1308. * 
  1309. * @global array $wp_settings_errors Storage array of errors registered during this pageload 
  1310. * 
  1311. * @param string $setting Optional slug title of a specific setting who's errors you want. 
  1312. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. 
  1313. * @return array Array of settings errors 
  1314. */ 
  1315. function get_settings_errors( $setting = '', $sanitize = false ) { 
  1316. global $wp_settings_errors; 
  1317.  
  1318. /** 
  1319. * If $sanitize is true, manually re-run the sanitization for this option 
  1320. * This allows the $sanitize_callback from register_setting() to run, adding 
  1321. * any settings errors you want to show by default. 
  1322. */ 
  1323. if ( $sanitize ) 
  1324. sanitize_option( $setting, get_option( $setting ) ); 
  1325.  
  1326. // If settings were passed back from options.php then use them. 
  1327. if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { 
  1328. $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); 
  1329. delete_transient( 'settings_errors' ); 
  1330.  
  1331. // Check global in case errors have been added on this pageload. 
  1332. if ( ! count( $wp_settings_errors ) ) 
  1333. return array(); 
  1334.  
  1335. // Filter the results to those of a specific setting if one was set. 
  1336. if ( $setting ) { 
  1337. $setting_errors = array(); 
  1338. foreach ( (array) $wp_settings_errors as $key => $details ) { 
  1339. if ( $setting == $details['setting'] ) 
  1340. $setting_errors[] = $wp_settings_errors[$key]; 
  1341. return $setting_errors; 
  1342.  
  1343. return $wp_settings_errors; 
  1344.  
  1345. /** 
  1346. * Display settings errors registered by add_settings_error(). 
  1347. * 
  1348. * Part of the Settings API. Outputs a div for each error retrieved by 
  1349. * get_settings_errors(). 
  1350. * 
  1351. * This is called automatically after a settings page based on the 
  1352. * Settings API is submitted. Errors should be added during the validation 
  1353. * callback function for a setting defined in register_setting(). 
  1354. * 
  1355. * The $sanitize option is passed into get_settings_errors() and will 
  1356. * re-run the setting sanitization 
  1357. * on its current value. 
  1358. * 
  1359. * The $hide_on_update option will cause errors to only show when the settings 
  1360. * page is first loaded. if the user has already saved new values it will be 
  1361. * hidden to avoid repeating messages already shown in the default error 
  1362. * reporting after submission. This is useful to show general errors like 
  1363. * missing settings when the user arrives at the settings page. 
  1364. * 
  1365. * @since 3.0.0 
  1366. * 
  1367. * @param string $setting Optional slug title of a specific setting who's errors you want. 
  1368. * @param bool $sanitize Whether to re-sanitize the setting value before returning errors. 
  1369. * @param bool $hide_on_update If set to true errors will not be shown if the settings page has 
  1370. * already been submitted. 
  1371. */ 
  1372. function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) { 
  1373.  
  1374. if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) 
  1375. return; 
  1376.  
  1377. $settings_errors = get_settings_errors( $setting, $sanitize ); 
  1378.  
  1379. if ( empty( $settings_errors ) ) 
  1380. return; 
  1381.  
  1382. $output = ''; 
  1383. foreach ( $settings_errors as $key => $details ) { 
  1384. $css_id = 'setting-error-' . $details['code']; 
  1385. $css_class = $details['type'] . ' settings-error notice is-dismissible'; 
  1386. $output .= "<div id='$css_id' class='$css_class'> \n"; 
  1387. $output .= "<p><strong>{$details['message']}</strong></p>"; 
  1388. $output .= "</div> \n"; 
  1389. echo $output; 
  1390.  
  1391. /** 
  1392. * Outputs the modal window used for attaching media to posts or pages in the media-listing screen. 
  1393. * 
  1394. * @since 2.7.0 
  1395. * 
  1396. * @param string $found_action 
  1397. */ 
  1398. function find_posts_div($found_action = '') { 
  1399. ?> 
  1400. <div id="find-posts" class="find-box" style="display: none;"> 
  1401. <div id="find-posts-head" class="find-box-head"> 
  1402. <?php _e( 'Attach to existing content' ); ?> 
  1403. <button type="button" id="find-posts-close"><span class="screen-reader-text"><?php _e( 'Close media attachment panel' ); ?></button> 
  1404. </div> 
  1405. <div class="find-box-inside"> 
  1406. <div class="find-box-search"> 
  1407. <?php if ( $found_action ) { ?> 
  1408. <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" /> 
  1409. <?php } ?> 
  1410. <input type="hidden" name="affected" id="affected" value="" /> 
  1411. <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?> 
  1412. <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label> 
  1413. <input type="text" id="find-posts-input" name="ps" value="" /> 
  1414. <span class="spinner"></span> 
  1415. <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /> 
  1416. <div class="clear"></div> 
  1417. </div> 
  1418. <div id="find-posts-response"></div> 
  1419. </div> 
  1420. <div class="find-box-buttons"> 
  1421. <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?> 
  1422. <div class="clear"></div> 
  1423. </div> 
  1424. </div> 
  1425. <?php 
  1426.  
  1427. /** 
  1428. * Displays the post password. 
  1429. * 
  1430. * The password is passed through esc_attr() to ensure that it is safe for placing in an html attribute. 
  1431. * 
  1432. * @since 2.7.0 
  1433. */ 
  1434. function the_post_password() { 
  1435. $post = get_post(); 
  1436. if ( isset( $post->post_password ) ) 
  1437. echo esc_attr( $post->post_password ); 
  1438.  
  1439. /** 
  1440. * Get the post title. 
  1441. * 
  1442. * The post title is fetched and if it is blank then a default string is 
  1443. * returned. 
  1444. * 
  1445. * @since 2.7.0 
  1446. * 
  1447. * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 
  1448. * @return string The post title if set. 
  1449. */ 
  1450. function _draft_or_post_title( $post = 0 ) { 
  1451. $title = get_the_title( $post ); 
  1452. if ( empty( $title ) ) 
  1453. $title = __( '(no title)' ); 
  1454. return esc_html( $title ); 
  1455.  
  1456. /** 
  1457. * Displays the search query. 
  1458. * 
  1459. * A simple wrapper to display the "s" parameter in a `GET` URI. This function 
  1460. * should only be used when the_search_query() cannot. 
  1461. * 
  1462. * @since 2.7.0 
  1463. */ 
  1464. function _admin_search_query() { 
  1465. echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; 
  1466.  
  1467. /** 
  1468. * Generic Iframe header for use with Thickbox 
  1469. * 
  1470. * @since 2.7.0 
  1471. * 
  1472. * @global string $hook_suffix 
  1473. * @global string $admin_body_class 
  1474. * @global WP_Locale $wp_locale 
  1475. * 
  1476. * @param string $title Optional. Title of the Iframe page. Default empty. 
  1477. * @param bool $deprecated Not used. 
  1478. */ 
  1479. function iframe_header( $title = '', $deprecated = false ) { 
  1480. show_admin_bar( false ); 
  1481. global $hook_suffix, $admin_body_class, $wp_locale; 
  1482. $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); 
  1483.  
  1484. $current_screen = get_current_screen(); 
  1485.  
  1486. @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); 
  1487. _wp_admin_html_begin(); 
  1488. ?> 
  1489. <title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title> 
  1490. <?php 
  1491. wp_enqueue_style( 'colors' ); 
  1492. ?> 
  1493. <script type="text/javascript"> 
  1494. addLoadEvent = function(func) {if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function') {wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function() {oldonload();func();}}}; 
  1495. function tb_close() {var win=window.dialogArguments||opener||parent||top;win.tb_remove();} 
  1496. var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',  
  1497. pagenow = '<?php echo $current_screen->id; ?>',  
  1498. typenow = '<?php echo $current_screen->post_type; ?>',  
  1499. adminpage = '<?php echo $admin_body_class; ?>',  
  1500. thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',  
  1501. decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',  
  1502. isRtl = <?php echo (int) is_rtl(); ?>; 
  1503. </script> 
  1504. <?php 
  1505. /** This action is documented in wp-admin/admin-header.php */ 
  1506. do_action( 'admin_enqueue_scripts', $hook_suffix ); 
  1507.  
  1508. /** This action is documented in wp-admin/admin-header.php */ 
  1509. do_action( "admin_print_styles-$hook_suffix" ); 
  1510.  
  1511. /** This action is documented in wp-admin/admin-header.php */ 
  1512. do_action( 'admin_print_styles' ); 
  1513.  
  1514. /** This action is documented in wp-admin/admin-header.php */ 
  1515. do_action( "admin_print_scripts-$hook_suffix" ); 
  1516.  
  1517. /** This action is documented in wp-admin/admin-header.php */ 
  1518. do_action( 'admin_print_scripts' ); 
  1519.  
  1520. /** This action is documented in wp-admin/admin-header.php */ 
  1521. do_action( "admin_head-$hook_suffix" ); 
  1522.  
  1523. /** This action is documented in wp-admin/admin-header.php */ 
  1524. do_action( 'admin_head' ); 
  1525.  
  1526. $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 
  1527.  
  1528. if ( is_rtl() ) 
  1529. $admin_body_class .= ' rtl'; 
  1530.  
  1531. ?> 
  1532. </head> 
  1533. <?php 
  1534. /** This filter is documented in wp-admin/admin-header.php */ 
  1535. $admin_body_classes = apply_filters( 'admin_body_class', '' ); 
  1536. ?> 
  1537. <body<?php 
  1538. /** 
  1539. * @global string $body_id 
  1540. */ 
  1541. if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes . ' ' . $admin_body_class; ?>"> 
  1542. <script type="text/javascript"> 
  1543. (function() { 
  1544. var c = document.body.className; 
  1545. c = c.replace(/no-js/, 'js'); 
  1546. document.body.className = c; 
  1547. })(); 
  1548. </script> 
  1549. <?php 
  1550.  
  1551. /** 
  1552. * Generic Iframe footer for use with Thickbox 
  1553. * 
  1554. * @since 2.7.0 
  1555. */ 
  1556. function iframe_footer() { 
  1557. /** 
  1558. * We're going to hide any footer output on iFrame pages,  
  1559. * but run the hooks anyway since they output JavaScript 
  1560. * or other needed content. 
  1561. */ 
  1562.  
  1563. /** 
  1564. * @global string $hook_suffix 
  1565. */ 
  1566. global $hook_suffix; 
  1567. ?> 
  1568. <div class="hidden"> 
  1569. <?php 
  1570. /** This action is documented in wp-admin/admin-footer.php */ 
  1571. do_action( 'admin_footer', $hook_suffix ); 
  1572.  
  1573. /** This action is documented in wp-admin/admin-footer.php */ 
  1574. do_action( "admin_print_footer_scripts-$hook_suffix" ); 
  1575.  
  1576. /** This action is documented in wp-admin/admin-footer.php */ 
  1577. do_action( 'admin_print_footer_scripts' ); 
  1578. ?> 
  1579. </div> 
  1580. <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script> 
  1581. </body> 
  1582. </html> 
  1583. <?php 
  1584.  
  1585. /** 
  1586. * 
  1587. * @param WP_Post $post 
  1588. */ 
  1589. function _post_states($post) { 
  1590. $post_states = array(); 
  1591. if ( isset( $_REQUEST['post_status'] ) ) 
  1592. $post_status = $_REQUEST['post_status']; 
  1593. else 
  1594. $post_status = ''; 
  1595.  
  1596. if ( !empty($post->post_password) ) 
  1597. $post_states['protected'] = __('Password protected'); 
  1598. if ( 'private' == $post->post_status && 'private' != $post_status ) 
  1599. $post_states['private'] = __('Private'); 
  1600. if ( 'draft' == $post->post_status && 'draft' != $post_status ) 
  1601. $post_states['draft'] = __('Draft'); 
  1602. if ( 'pending' == $post->post_status && 'pending' != $post_status ) 
  1603. $post_states['pending'] = _x('Pending', 'post status'); 
  1604. if ( is_sticky($post->ID) ) 
  1605. $post_states['sticky'] = __('Sticky'); 
  1606.  
  1607. if ( 'future' === $post->post_status ) { 
  1608. $post_states['scheduled'] = __( 'Scheduled' ); 
  1609.  
  1610. if ( 'page' === get_option( 'show_on_front' ) ) { 
  1611. if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) { 
  1612. $post_states['page_on_front'] = __( 'Front Page' ); 
  1613.  
  1614. if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) { 
  1615. $post_states['page_for_posts'] = __( 'Posts Page' ); 
  1616.  
  1617. /** 
  1618. * Filters the default post display states used in the posts list table. 
  1619. * 
  1620. * @since 2.8.0 
  1621. * 
  1622. * @param array $post_states An array of post display states. 
  1623. * @param WP_Post $post The current post object. 
  1624. */ 
  1625. $post_states = apply_filters( 'display_post_states', $post_states, $post ); 
  1626.  
  1627. if ( ! empty($post_states) ) { 
  1628. $state_count = count($post_states); 
  1629. $i = 0; 
  1630. echo ' — '; 
  1631. foreach ( $post_states as $state ) { 
  1632. ++$i; 
  1633. ( $i == $state_count ) ? $sep = '' : $sep = ', '; 
  1634. echo "<span class='post-state'>$state$sep</span>"; 
  1635.  
  1636.  
  1637. /** 
  1638. * 
  1639. * @param WP_Post $post 
  1640. */ 
  1641. function _media_states( $post ) { 
  1642. $media_states = array(); 
  1643. $stylesheet = get_option('stylesheet'); 
  1644.  
  1645. if ( current_theme_supports( 'custom-header') ) { 
  1646. $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true ); 
  1647. if ( ! empty( $meta_header ) && $meta_header == $stylesheet ) 
  1648. $media_states[] = __( 'Header Image' ); 
  1649.  
  1650. if ( current_theme_supports( 'custom-background') ) { 
  1651. $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true ); 
  1652. if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) 
  1653. $media_states[] = __( 'Background Image' ); 
  1654.  
  1655. if ( $post->ID == get_option( 'site_icon' ) ) { 
  1656. $media_states[] = __( 'Site Icon' ); 
  1657.  
  1658. if ( $post->ID == get_theme_mod( 'site_logo' ) ) { 
  1659. $media_states[] = __( 'Logo' ); 
  1660.  
  1661. /** 
  1662. * Filters the default media display states for items in the Media list table. 
  1663. * 
  1664. * @since 3.2.0 
  1665. * 
  1666. * @param array $media_states An array of media states. Default 'Header Image',  
  1667. * 'Background Image', 'Site Icon', 'Logo'. 
  1668. */ 
  1669. $media_states = apply_filters( 'display_media_states', $media_states ); 
  1670.  
  1671. if ( ! empty( $media_states ) ) { 
  1672. $state_count = count( $media_states ); 
  1673. $i = 0; 
  1674. echo ' — '; 
  1675. foreach ( $media_states as $state ) { 
  1676. ++$i; 
  1677. ( $i == $state_count ) ? $sep = '' : $sep = ', '; 
  1678. echo "<span class='post-state'>$state$sep</span>"; 
  1679.  
  1680. /** 
  1681. * Test support for compressing JavaScript from PHP 
  1682. * 
  1683. * Outputs JavaScript that tests if compression from PHP works as expected 
  1684. * and sets an option with the result. Has no effect when the current user 
  1685. * is not an administrator. To run the test again the option 'can_compress_scripts' 
  1686. * has to be deleted. 
  1687. * 
  1688. * @since 2.8.0 
  1689. */ 
  1690. function compression_test() { 
  1691. ?> 
  1692. <script type="text/javascript"> 
  1693. var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ) ); ?>; 
  1694. var testCompression = { 
  1695. get : function(test) { 
  1696. var x; 
  1697. if ( window.XMLHttpRequest ) { 
  1698. x = new XMLHttpRequest(); 
  1699. } else { 
  1700. try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e) {try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e) {};} 
  1701.  
  1702. if (x) { 
  1703. x.onreadystatechange = function() { 
  1704. var r, h; 
  1705. if ( x.readyState == 4 ) { 
  1706. r = x.responseText.substr(0, 18); 
  1707. h = x.getResponseHeader('Content-Encoding'); 
  1708. testCompression.check(r, h, test); 
  1709. }; 
  1710.  
  1711. x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&_ajax_nonce='+compressionNonce+'&'+(new Date()).getTime(), true); 
  1712. x.send(''); 
  1713. },  
  1714.  
  1715. check : function(r, h, test) { 
  1716. if ( ! r && ! test ) 
  1717. this.get(1); 
  1718.  
  1719. if ( 1 == test ) { 
  1720. if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) ) 
  1721. this.get('no'); 
  1722. else 
  1723. this.get(2); 
  1724.  
  1725. return; 
  1726.  
  1727. if ( 2 == test ) { 
  1728. if ( '"wpCompressionTest' == r ) 
  1729. this.get('yes'); 
  1730. else 
  1731. this.get('no'); 
  1732. }; 
  1733. testCompression.check(); 
  1734. </script> 
  1735. <?php 
  1736.  
  1737. /** 
  1738. * Echoes a submit button, with provided text and appropriate class(es). 
  1739. * 
  1740. * @since 3.1.0 
  1741. * 
  1742. * @see get_submit_button() 
  1743. * 
  1744. * @param string $text The text of the button (defaults to 'Save Changes') 
  1745. * @param string $type Optional. The type and CSS class(es) of the button. Core values 
  1746. * include 'primary', 'secondary', 'delete'. Default 'primary' 
  1747. * @param string $name The HTML name of the submit button. Defaults to "submit". If no 
  1748. * id attribute is given in $other_attributes below, $name will be 
  1749. * used as the button's id. 
  1750. * @param bool $wrap True if the output button should be wrapped in a paragraph tag,  
  1751. * false otherwise. Defaults to true 
  1752. * @param array|string $other_attributes Other attributes that should be output with the button, mapping 
  1753. * attributes to their values, such as setting tabindex to 1, etc. 
  1754. * These key/value attribute pairs will be output as attribute="value",  
  1755. * where attribute is the key. Other attributes can also be provided 
  1756. * as a string such as 'tabindex="1"', though the array format is 
  1757. * preferred. Default null. 
  1758. */ 
  1759. function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) { 
  1760. echo get_submit_button( $text, $type, $name, $wrap, $other_attributes ); 
  1761.  
  1762. /** 
  1763. * Returns a submit button, with provided text and appropriate class 
  1764. * 
  1765. * @since 3.1.0 
  1766. * 
  1767. * @param string $text Optional. The text of the button. Default 'Save Changes'. 
  1768. * @param string $type Optional. The type of button. Accepts 'primary', 'secondary',  
  1769. * or 'delete'. Default 'primary large'. 
  1770. * @param string $name Optional. The HTML name of the submit button. Defaults to "submit". 
  1771. * If no id attribute is given in $other_attributes below, `$name` will 
  1772. * be used as the button's id. Default 'submit'. 
  1773. * @param bool $wrap Optional. True if the output button should be wrapped in a paragraph 
  1774. * tag, false otherwise. Default true. 
  1775. * @param array|string $other_attributes Optional. Other attributes that should be output with the button,  
  1776. * mapping attributes to their values, such as `array( 'tabindex' => '1' )`. 
  1777. * These attributes will be output as `attribute="value"`, such as 
  1778. * `tabindex="1"`. Other attributes can also be provided as a string such 
  1779. * as `tabindex="1"`, though the array format is typically cleaner. 
  1780. * Default empty. 
  1781. * @return string Submit button HTML. 
  1782. */ 
  1783. function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) { 
  1784. if ( ! is_array( $type ) ) 
  1785. $type = explode( ' ', $type ); 
  1786.  
  1787. $button_shorthand = array( 'primary', 'small', 'large' ); 
  1788. $classes = array( 'button' ); 
  1789. foreach ( $type as $t ) { 
  1790. if ( 'secondary' === $t || 'button-secondary' === $t ) 
  1791. continue; 
  1792. $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t; 
  1793. $class = implode( ' ', array_unique( $classes ) ); 
  1794.  
  1795. if ( 'delete' === $type ) 
  1796. $class = 'button-secondary delete'; 
  1797.  
  1798. $text = $text ? $text : __( 'Save Changes' ); 
  1799.  
  1800. // Default the id attribute to $name unless an id was specifically provided in $other_attributes 
  1801. $id = $name; 
  1802. if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) { 
  1803. $id = $other_attributes['id']; 
  1804. unset( $other_attributes['id'] ); 
  1805.  
  1806. $attributes = ''; 
  1807. if ( is_array( $other_attributes ) ) { 
  1808. foreach ( $other_attributes as $attribute => $value ) { 
  1809. $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important 
  1810. } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string 
  1811. $attributes = $other_attributes; 
  1812.  
  1813. // Don't output empty name and id attributes. 
  1814. $name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : ''; 
  1815. $id_attr = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 
  1816.  
  1817. $button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr( $class ); 
  1818. $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; 
  1819.  
  1820. if ( $wrap ) { 
  1821. $button = '<p class="submit">' . $button . '</p>'; 
  1822.  
  1823. return $button; 
  1824.  
  1825. /** 
  1826. * 
  1827. * @global bool $is_IE 
  1828. */ 
  1829. function _wp_admin_html_begin() { 
  1830. global $is_IE; 
  1831.  
  1832. $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : ''; 
  1833.  
  1834. if ( $is_IE ) 
  1835. @header('X-UA-Compatible: IE=edge'); 
  1836.  
  1837. ?> 
  1838. <!DOCTYPE html> 
  1839. <!--[if IE 8]> 
  1840. <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php 
  1841. /** 
  1842. * Fires inside the HTML tag in the admin header. 
  1843. * 
  1844. * @since 2.2.0 
  1845. */ 
  1846. do_action( 'admin_xml_ns' ); 
  1847. ?> <?php language_attributes(); ?>> 
  1848. <![endif]--> 
  1849. <!--[if !(IE 8) ]><!--> 
  1850. <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php 
  1851. /** This action is documented in wp-admin/includes/template.php */ 
  1852. do_action( 'admin_xml_ns' ); 
  1853. ?> <?php language_attributes(); ?>> 
  1854. <!--<![endif]--> 
  1855. <head> 
  1856. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 
  1857. <?php 
  1858.  
  1859. /** 
  1860. * Convert a screen string to a screen object 
  1861. * 
  1862. * @since 3.0.0 
  1863. * 
  1864. * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. 
  1865. * @return WP_Screen Screen object. 
  1866. */ 
  1867. function convert_to_screen( $hook_name ) { 
  1868. if ( ! class_exists( 'WP_Screen', false ) ) { 
  1869. _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3.0' ); 
  1870. return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' ); 
  1871.  
  1872. return WP_Screen::get( $hook_name ); 
  1873.  
  1874. /** 
  1875. * Output the HTML for restoring the post data from DOM storage 
  1876. * 
  1877. * @since 3.6.0 
  1878. * @access private 
  1879. */ 
  1880. function _local_storage_notice() { 
  1881. ?> 
  1882. <div id="local-storage-notice" class="hidden notice is-dismissible"> 
  1883. <p class="local-restore"> 
  1884. <?php _e( 'The backup of this post in your browser is different from the version below.' ); ?> 
  1885. <button type="button" class="button restore-backup"><?php _e('Restore the backup'); ?></button> 
  1886. </p> 
  1887. <p class="help"> 
  1888. <?php _e( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' ); ?> 
  1889. </p> 
  1890. </div> 
  1891. <?php 
  1892.  
  1893. /** 
  1894. * Output a HTML element with a star rating for a given rating. 
  1895. * 
  1896. * Outputs a HTML element with the star rating exposed on a 0..5 scale in 
  1897. * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the 
  1898. * number of ratings may also be displayed by passing the $number parameter. 
  1899. * 
  1900. * @since 3.8.0 
  1901. * @since 4.4.0 Introduced the `echo` parameter. 
  1902. * 
  1903. * @param array $args { 
  1904. * Optional. Array of star ratings arguments. 
  1905. * 
  1906. * @type int $rating The rating to display, expressed in either a 0.5 rating increment,  
  1907. * or percentage. Default 0. 
  1908. * @type string $type Format that the $rating is in. Valid values are 'rating' (default),  
  1909. * or, 'percent'. Default 'rating'. 
  1910. * @type int $number The number of ratings that makes up this rating. Default 0. 
  1911. * @type bool $echo Whether to echo the generated markup. False to return the markup instead 
  1912. * of echoing it. Default true. 
  1913. * } 
  1914. */ 
  1915. function wp_star_rating( $args = array() ) { 
  1916. $defaults = array( 
  1917. 'rating' => 0,  
  1918. 'type' => 'rating',  
  1919. 'number' => 0,  
  1920. 'echo' => true,  
  1921. ); 
  1922. $r = wp_parse_args( $args, $defaults ); 
  1923.  
  1924. // Non-english decimal places when the $rating is coming from a string 
  1925. $rating = str_replace( ', ', '.', $r['rating'] ); 
  1926.  
  1927. // Convert Percentage to star rating, 0..5 in .5 increments 
  1928. if ( 'percent' == $r['type'] ) { 
  1929. $rating = round( $rating / 10, 0 ) / 2; 
  1930.  
  1931. // Calculate the number of each type of star needed 
  1932. $full_stars = floor( $rating ); 
  1933. $half_stars = ceil( $rating - $full_stars ); 
  1934. $empty_stars = 5 - $full_stars - $half_stars; 
  1935.  
  1936. if ( $r['number'] ) { 
  1937. /** translators: 1: The rating, 2: The number of ratings */ 
  1938. $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] ); 
  1939. $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) ); 
  1940. } else { 
  1941. /** translators: 1: The rating */ 
  1942. $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); 
  1943.  
  1944. $output = '<div class="star-rating">'; 
  1945. $output .= '<span class="screen-reader-text">' . $title . '</span>'; 
  1946. $output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars ); 
  1947. $output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars ); 
  1948. $output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars ); 
  1949. $output .= '</div>'; 
  1950.  
  1951. if ( $r['echo'] ) { 
  1952. echo $output; 
  1953.  
  1954. return $output; 
  1955.  
  1956. /** 
  1957. * Output a notice when editing the page for posts (internal use only). 
  1958. * 
  1959. * @ignore 
  1960. * @since 4.2.0 
  1961. */ 
  1962. function _wp_posts_page_notice() { 
  1963. echo '<div class="notice notice-warning inline"><p>' . __( 'You are currently editing the page that shows your latest posts.' ) . '</p></div>'; 
.