Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

2128 linhas
76 KiB

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