PageRenderTime 73ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/template.php

https://gitlab.com/math4youbyusgroupillinois/WordPress
PHP | 2175 lines | 1224 code | 254 blank | 697 comment | 225 complexity | 6faaf073dcbaa22a5661c37f11ce94f5 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  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. // Category Checklists
  12. //
  13. /**
  14. * Walker to output an unordered list of category checkbox input elements.
  15. *
  16. * @since 2.5.1
  17. *
  18. * @see Walker
  19. * @see wp_category_checklist()
  20. * @see wp_terms_checklist()
  21. */
  22. class Walker_Category_Checklist extends Walker {
  23. public $tree_type = 'category';
  24. public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  25. /**
  26. * Starts the list before the elements are added.
  27. *
  28. * @see Walker:start_lvl()
  29. *
  30. * @since 2.5.1
  31. *
  32. * @param string $output Passed by reference. Used to append additional content.
  33. * @param int $depth Depth of category. Used for tab indentation.
  34. * @param array $args An array of arguments. @see wp_terms_checklist()
  35. */
  36. public function start_lvl( &$output, $depth = 0, $args = array() ) {
  37. $indent = str_repeat("\t", $depth);
  38. $output .= "$indent<ul class='children'>\n";
  39. }
  40. /**
  41. * Ends the list of after the elements are added.
  42. *
  43. * @see Walker::end_lvl()
  44. *
  45. * @since 2.5.1
  46. *
  47. * @param string $output Passed by reference. Used to append additional content.
  48. * @param int $depth Depth of category. Used for tab indentation.
  49. * @param array $args An array of arguments. @see wp_terms_checklist()
  50. */
  51. public function end_lvl( &$output, $depth = 0, $args = array() ) {
  52. $indent = str_repeat("\t", $depth);
  53. $output .= "$indent</ul>\n";
  54. }
  55. /**
  56. * Start the element output.
  57. *
  58. * @see Walker::start_el()
  59. *
  60. * @since 2.5.1
  61. *
  62. * @param string $output Passed by reference. Used to append additional content.
  63. * @param object $category The current term object.
  64. * @param int $depth Depth of the term in reference to parents. Default 0.
  65. * @param array $args An array of arguments. @see wp_terms_checklist()
  66. * @param int $id ID of the current term.
  67. */
  68. public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  69. if ( empty( $args['taxonomy'] ) ) {
  70. $taxonomy = 'category';
  71. } else {
  72. $taxonomy = $args['taxonomy'];
  73. }
  74. if ( $taxonomy == 'category' ) {
  75. $name = 'post_category';
  76. } else {
  77. $name = 'tax_input[' . $taxonomy . ']';
  78. }
  79. $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
  80. $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
  81. $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
  82. /** This filter is documented in wp-includes/category-template.php */
  83. $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
  84. '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
  85. checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
  86. disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
  87. esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
  88. }
  89. /**
  90. * Ends the element output, if needed.
  91. *
  92. * @see Walker::end_el()
  93. *
  94. * @since 2.5.1
  95. *
  96. * @param string $output Passed by reference. Used to append additional content.
  97. * @param object $category The current term object.
  98. * @param int $depth Depth of the term in reference to parents. Default 0.
  99. * @param array $args An array of arguments. @see wp_terms_checklist()
  100. */
  101. public function end_el( &$output, $category, $depth = 0, $args = array() ) {
  102. $output .= "</li>\n";
  103. }
  104. }
  105. /**
  106. * Output an unordered list of checkbox input elements labelled
  107. * with category names.
  108. *
  109. * @since 2.5.1
  110. *
  111. * @todo Properly document optional arguments as such.
  112. *
  113. * @see wp_terms_checklist()
  114. *
  115. * @param int $post_id Mark categories associated with this post as checked. $selected_cats must not be an array.
  116. * @param int $descendants_and_self ID of the category to output along with its descendents.
  117. * @param bool|array $selected_cats List of categories to mark as checked.
  118. * @param bool|array $popular_cats Override the list of categories that receive the "popular-category" class.
  119. * @param object $walker Walker object to use to build the output.
  120. * @param bool $checked_ontop Move checked items out of the hierarchy and to the top of the list.
  121. */
  122. function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
  123. wp_terms_checklist( $post_id, array(
  124. 'taxonomy' => 'category',
  125. 'descendants_and_self' => $descendants_and_self,
  126. 'selected_cats' => $selected_cats,
  127. 'popular_cats' => $popular_cats,
  128. 'walker' => $walker,
  129. 'checked_ontop' => $checked_ontop
  130. ) );
  131. }
  132. /**
  133. * Output an unordered list of checkbox input elements labelled with term names.
  134. *
  135. * Taxonomy independent version of {@see wp_category_checklist()}.
  136. *
  137. * @since 3.0.0
  138. *
  139. * @todo Properly document optional default arguments.
  140. *
  141. * @param int $post_id Post ID.
  142. * @param array $args Arguments to form the terms checklist.
  143. */
  144. function wp_terms_checklist( $post_id = 0, $args = array() ) {
  145. $defaults = array(
  146. 'descendants_and_self' => 0,
  147. 'selected_cats' => false,
  148. 'popular_cats' => false,
  149. 'walker' => null,
  150. 'taxonomy' => 'category',
  151. 'checked_ontop' => true
  152. );
  153. /**
  154. * Filter the taxonomy terms checklist arguments.
  155. *
  156. * @since 3.4.0
  157. *
  158. * @see wp_terms_checklist()
  159. *
  160. * @param array $args An array of arguments.
  161. * @param int $post_id The post ID.
  162. */
  163. $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
  164. $r = wp_parse_args( $params, $defaults );
  165. if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) {
  166. $walker = new Walker_Category_Checklist;
  167. } else {
  168. $walker = $r['walker'];
  169. }
  170. $taxonomy = $r['taxonomy'];
  171. $descendants_and_self = (int) $r['descendants_and_self'];
  172. $args = array( 'taxonomy' => $taxonomy );
  173. $tax = get_taxonomy( $taxonomy );
  174. $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
  175. if ( is_array( $r['selected_cats'] ) ) {
  176. $args['selected_cats'] = $r['selected_cats'];
  177. } elseif ( $post_id ) {
  178. $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
  179. } else {
  180. $args['selected_cats'] = array();
  181. }
  182. if ( is_array( $r['popular_cats'] ) ) {
  183. $args['popular_cats'] = $r['popular_cats'];
  184. } else {
  185. $args['popular_cats'] = get_terms( $taxonomy, array(
  186. 'fields' => 'ids',
  187. 'orderby' => 'count',
  188. 'order' => 'DESC',
  189. 'number' => 10,
  190. 'hierarchical' => false
  191. ) );
  192. }
  193. if ( $descendants_and_self ) {
  194. $categories = (array) get_terms( $taxonomy, array(
  195. 'child_of' => $descendants_and_self,
  196. 'hierarchical' => 0,
  197. 'hide_empty' => 0
  198. ) );
  199. $self = get_term( $descendants_and_self, $taxonomy );
  200. array_unshift( $categories, $self );
  201. } else {
  202. $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
  203. }
  204. if ( $r['checked_ontop'] ) {
  205. // 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)
  206. $checked_categories = array();
  207. $keys = array_keys( $categories );
  208. foreach( $keys as $k ) {
  209. if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
  210. $checked_categories[] = $categories[$k];
  211. unset( $categories[$k] );
  212. }
  213. }
  214. // Put checked cats on top
  215. echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
  216. }
  217. // Then the rest of them
  218. echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
  219. }
  220. /**
  221. * Retrieve a list of the most popular terms from the specified taxonomy.
  222. *
  223. * If the $echo argument is true then the elements for a list of checkbox
  224. * `<input>` elements labelled with the names of the selected terms is output.
  225. * If the $post_ID global isn't empty then the terms associated with that
  226. * post will be marked as checked.
  227. *
  228. * @since 2.5.0
  229. *
  230. * @param string $taxonomy Taxonomy to retrieve terms from.
  231. * @param int $default Unused.
  232. * @param int $number Number of terms to retrieve. Defaults to 10.
  233. * @param bool $echo Optionally output the list as well. Defaults to true.
  234. * @return array List of popular term IDs.
  235. */
  236. function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
  237. $post = get_post();
  238. if ( $post && $post->ID )
  239. $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
  240. else
  241. $checked_terms = array();
  242. $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
  243. $tax = get_taxonomy($taxonomy);
  244. $popular_ids = array();
  245. foreach ( (array) $terms as $term ) {
  246. $popular_ids[] = $term->term_id;
  247. if ( !$echo ) // hack for AJAX use
  248. continue;
  249. $id = "popular-$taxonomy-$term->term_id";
  250. $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
  251. ?>
  252. <li id="<?php echo $id; ?>" class="popular-category">
  253. <label class="selectit">
  254. <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 ) ); ?> />
  255. <?php
  256. /** This filter is documented in wp-includes/category-template.php */
  257. echo esc_html( apply_filters( 'the_category', $term->name ) );
  258. ?>
  259. </label>
  260. </li>
  261. <?php
  262. }
  263. return $popular_ids;
  264. }
  265. /**
  266. * {@internal Missing Short Description}}
  267. *
  268. * @since 2.5.1
  269. *
  270. * @param int $link_id
  271. */
  272. function wp_link_category_checklist( $link_id = 0 ) {
  273. $default = 1;
  274. $checked_categories = array();
  275. if ( $link_id ) {
  276. $checked_categories = wp_get_link_cats( $link_id );
  277. // No selected categories, strange
  278. if ( ! count( $checked_categories ) ) {
  279. $checked_categories[] = $default;
  280. }
  281. } else {
  282. $checked_categories[] = $default;
  283. }
  284. $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
  285. if ( empty( $categories ) )
  286. return;
  287. foreach ( $categories as $category ) {
  288. $cat_id = $category->term_id;
  289. /** This filter is documented in wp-includes/category-template.php */
  290. $name = esc_html( apply_filters( 'the_category', $category->name ) );
  291. $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
  292. 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>";
  293. }
  294. }
  295. // adds hidden fields with the data for use in the inline editor for posts and pages
  296. /**
  297. * {@internal Missing Short Description}}
  298. *
  299. * @since 2.7.0
  300. *
  301. * @param WP_Post $post
  302. */
  303. function get_inline_data($post) {
  304. $post_type_object = get_post_type_object($post->post_type);
  305. if ( ! current_user_can( 'edit_post', $post->ID ) )
  306. return;
  307. $title = esc_textarea( trim( $post->post_title ) );
  308. /** This filter is documented in wp-admin/edit-tag-form.php */
  309. echo '
  310. <div class="hidden" id="inline_' . $post->ID . '">
  311. <div class="post_title">' . $title . '</div>
  312. <div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div>
  313. <div class="post_author">' . $post->post_author . '</div>
  314. <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
  315. <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
  316. <div class="_status">' . esc_html( $post->post_status ) . '</div>
  317. <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
  318. <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
  319. <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
  320. <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
  321. <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
  322. <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
  323. <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
  324. if ( $post_type_object->hierarchical )
  325. echo '<div class="post_parent">' . $post->post_parent . '</div>';
  326. if ( $post->post_type == 'page' )
  327. echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
  328. if ( post_type_supports( $post->post_type, 'page-attributes' ) )
  329. echo '<div class="menu_order">' . $post->menu_order . '</div>';
  330. $taxonomy_names = get_object_taxonomies( $post->post_type );
  331. foreach ( $taxonomy_names as $taxonomy_name) {
  332. $taxonomy = get_taxonomy( $taxonomy_name );
  333. if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
  334. $terms = get_object_term_cache( $post->ID, $taxonomy_name );
  335. if ( false === $terms ) {
  336. $terms = wp_get_object_terms( $post->ID, $taxonomy_name );
  337. wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' );
  338. }
  339. $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
  340. echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
  341. } elseif ( $taxonomy->show_ui ) {
  342. echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
  343. . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
  344. }
  345. }
  346. if ( !$post_type_object->hierarchical )
  347. echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
  348. if ( post_type_supports( $post->post_type, 'post-formats' ) )
  349. echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
  350. echo '</div>';
  351. }
  352. /**
  353. * {@internal Missing Short Description}}
  354. *
  355. * @since 2.7.0
  356. *
  357. * @param int $position
  358. * @param bool $checkbox
  359. * @param string $mode
  360. * @param bool $table_row
  361. */
  362. function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
  363. global $wp_list_table;
  364. /**
  365. * Filter the in-line comment reply-to form output in the Comments
  366. * list table.
  367. *
  368. * Returning a non-empty value here will short-circuit display
  369. * of the in-line comment-reply form in the Comments list table,
  370. * echoing the returned value instead.
  371. *
  372. * @since 2.7.0
  373. *
  374. * @see wp_comment_reply()
  375. *
  376. * @param string $content The reply-to form content.
  377. * @param array $args An array of default args.
  378. */
  379. $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
  380. if ( ! empty($content) ) {
  381. echo $content;
  382. return;
  383. }
  384. if ( ! $wp_list_table ) {
  385. if ( $mode == 'single' ) {
  386. $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
  387. } else {
  388. $wp_list_table = _get_list_table('WP_Comments_List_Table');
  389. }
  390. }
  391. ?>
  392. <form method="get" action="">
  393. <?php if ( $table_row ) : ?>
  394. <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
  395. <?php else : ?>
  396. <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
  397. <?php endif; ?>
  398. <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
  399. <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div>
  400. <div id="edithead" style="display:none;">
  401. <div class="inside">
  402. <label for="author"><?php _e('Name') ?></label>
  403. <input type="text" name="newcomment_author" size="50" value="" id="author" />
  404. </div>
  405. <div class="inside">
  406. <label for="author-email"><?php _e('E-mail') ?></label>
  407. <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
  408. </div>
  409. <div class="inside">
  410. <label for="author-url"><?php _e('URL') ?></label>
  411. <input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
  412. </div>
  413. <div style="clear:both;"></div>
  414. </div>
  415. <div id="replycontainer">
  416. <?php
  417. $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
  418. wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
  419. ?>
  420. </div>
  421. <p id="replysubmit" class="submit">
  422. <a href="#comments-form" class="save button-primary alignright">
  423. <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
  424. <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
  425. <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
  426. <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
  427. <span class="waiting spinner"></span>
  428. <span class="error" style="display:none;"></span>
  429. <br class="clear" />
  430. </p>
  431. <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
  432. <input type="hidden" name="action" id="action" value="" />
  433. <input type="hidden" name="comment_ID" id="comment_ID" value="" />
  434. <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
  435. <input type="hidden" name="status" id="status" value="" />
  436. <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
  437. <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
  438. <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
  439. <?php
  440. wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
  441. if ( current_user_can( 'unfiltered_html' ) )
  442. wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
  443. ?>
  444. <?php if ( $table_row ) : ?>
  445. </td></tr></tbody></table>
  446. <?php else : ?>
  447. </div></div>
  448. <?php endif; ?>
  449. </form>
  450. <?php
  451. }
  452. /**
  453. * Output 'undo move to trash' text for comments
  454. *
  455. * @since 2.9.0
  456. */
  457. function wp_comment_trashnotice() {
  458. ?>
  459. <div class="hidden" id="trash-undo-holder">
  460. <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>
  461. </div>
  462. <div class="hidden" id="spam-undo-holder">
  463. <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>
  464. </div>
  465. <?php
  466. }
  467. /**
  468. * {@internal Missing Short Description}}
  469. *
  470. * @since 1.2.0
  471. *
  472. * @param array $meta
  473. */
  474. function list_meta( $meta ) {
  475. // Exit if no meta
  476. if ( ! $meta ) {
  477. echo '
  478. <table id="list-table" style="display: none;">
  479. <thead>
  480. <tr>
  481. <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
  482. <th>' . __( 'Value' ) . '</th>
  483. </tr>
  484. </thead>
  485. <tbody id="the-list" data-wp-lists="list:meta">
  486. <tr><td></td></tr>
  487. </tbody>
  488. </table>'; //TBODY needed for list-manipulation JS
  489. return;
  490. }
  491. $count = 0;
  492. ?>
  493. <table id="list-table">
  494. <thead>
  495. <tr>
  496. <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
  497. <th><?php _e( 'Value' ) ?></th>
  498. </tr>
  499. </thead>
  500. <tbody id='the-list' data-wp-lists='list:meta'>
  501. <?php
  502. foreach ( $meta as $entry )
  503. echo _list_meta_row( $entry, $count );
  504. ?>
  505. </tbody>
  506. </table>
  507. <?php
  508. }
  509. /**
  510. * {@internal Missing Short Description}}
  511. *
  512. * @since 2.5.0
  513. *
  514. * @param array $entry
  515. * @param int $count
  516. * @return string
  517. */
  518. function _list_meta_row( $entry, &$count ) {
  519. static $update_nonce = false;
  520. if ( is_protected_meta( $entry['meta_key'], 'post' ) )
  521. return;
  522. if ( !$update_nonce )
  523. $update_nonce = wp_create_nonce( 'add-meta' );
  524. $r = '';
  525. ++ $count;
  526. if ( $count % 2 )
  527. $style = 'alternate';
  528. else
  529. $style = '';
  530. if ( is_serialized( $entry['meta_value'] ) ) {
  531. if ( is_serialized_string( $entry['meta_value'] ) ) {
  532. // This is a serialized string, so we should display it.
  533. $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
  534. } else {
  535. // This is a serialized array/object so we should NOT display it.
  536. --$count;
  537. return;
  538. }
  539. }
  540. $entry['meta_key'] = esc_attr($entry['meta_key']);
  541. $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
  542. $entry['meta_id'] = (int) $entry['meta_id'];
  543. $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
  544. $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
  545. $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']}' />";
  546. $r .= "\n\t\t<div class='submit'>";
  547. $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" ) );
  548. $r .= "\n\t\t";
  549. $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" ) );
  550. $r .= "</div>";
  551. $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
  552. $r .= "</td>";
  553. $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>";
  554. return $r;
  555. }
  556. /**
  557. * Prints the form in the Custom Fields meta box.
  558. *
  559. * @since 1.2.0
  560. *
  561. * @param WP_Post $post Optional. The post being edited.
  562. */
  563. function meta_form( $post = null ) {
  564. global $wpdb;
  565. $post = get_post( $post );
  566. /**
  567. * Filter the number of custom fields to retrieve for the drop-down
  568. * in the Custom Fields meta box.
  569. *
  570. * @since 2.1.0
  571. *
  572. * @param int $limit Number of custom fields to retrieve. Default 30.
  573. */
  574. $limit = apply_filters( 'postmeta_form_limit', 30 );
  575. $sql = "SELECT meta_key
  576. FROM $wpdb->postmeta
  577. GROUP BY meta_key
  578. HAVING meta_key NOT LIKE %s
  579. ORDER BY meta_key
  580. LIMIT %d";
  581. $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
  582. if ( $keys ) {
  583. natcasesort( $keys );
  584. $meta_key_input_id = 'metakeyselect';
  585. } else {
  586. $meta_key_input_id = 'metakeyinput';
  587. }
  588. ?>
  589. <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
  590. <table id="newmeta">
  591. <thead>
  592. <tr>
  593. <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
  594. <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
  595. </tr>
  596. </thead>
  597. <tbody>
  598. <tr>
  599. <td id="newmetaleft" class="left">
  600. <?php if ( $keys ) { ?>
  601. <select id="metakeyselect" name="metakeyselect">
  602. <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
  603. <?php
  604. foreach ( $keys as $key ) {
  605. if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
  606. continue;
  607. echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
  608. }
  609. ?>
  610. </select>
  611. <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
  612. <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
  613. <span id="enternew"><?php _e('Enter new'); ?></span>
  614. <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
  615. <?php } else { ?>
  616. <input type="text" id="metakeyinput" name="metakeyinput" value="" />
  617. <?php } ?>
  618. </td>
  619. <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
  620. </tr>
  621. <tr><td colspan="2">
  622. <div class="submit">
  623. <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
  624. </div>
  625. <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
  626. </td></tr>
  627. </tbody>
  628. </table>
  629. <?php
  630. }
  631. /**
  632. * Print out HTML form date elements for editing post or comment publish date.
  633. *
  634. * @since 0.71
  635. *
  636. * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date.
  637. * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment.
  638. * @param int $tab_index The tabindex attribute to add. Default 0.
  639. * @param int|bool $multi Optional. Whether the additional fields and buttons should be added.
  640. * Default 0|false.
  641. */
  642. function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
  643. global $wp_locale, $comment;
  644. $post = get_post();
  645. if ( $for_post )
  646. $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
  647. $tab_index_attribute = '';
  648. if ( (int) $tab_index > 0 )
  649. $tab_index_attribute = " tabindex=\"$tab_index\"";
  650. // todo: Remove this?
  651. // 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 />';
  652. $time_adj = current_time('timestamp');
  653. $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
  654. $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
  655. $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
  656. $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
  657. $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
  658. $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
  659. $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
  660. $cur_jj = gmdate( 'd', $time_adj );
  661. $cur_mm = gmdate( 'm', $time_adj );
  662. $cur_aa = gmdate( 'Y', $time_adj );
  663. $cur_hh = gmdate( 'H', $time_adj );
  664. $cur_mn = gmdate( 'i', $time_adj );
  665. $month = '<label for="mm" class="screen-reader-text">' . __( 'Month' ) . '</label><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
  666. for ( $i = 1; $i < 13; $i = $i +1 ) {
  667. $monthnum = zeroise($i, 2);
  668. $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>';
  669. /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
  670. $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n";
  671. }
  672. $month .= '</select>';
  673. $day = '<label for="jj" class="screen-reader-text">' . __( 'Day' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  674. $year = '<label for="aa" class="screen-reader-text">' . __( 'Year' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
  675. $hour = '<label for="hh" class="screen-reader-text">' . __( 'Hour' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  676. $minute = '<label for="mn" class="screen-reader-text">' . __( 'Minute' ) . '</label><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  677. echo '<div class="timestamp-wrap">';
  678. /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
  679. printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute );
  680. echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
  681. if ( $multi ) return;
  682. echo "\n\n";
  683. $map = array(
  684. 'mm' => array( $mm, $cur_mm ),
  685. 'jj' => array( $jj, $cur_jj ),
  686. 'aa' => array( $aa, $cur_aa ),
  687. 'hh' => array( $hh, $cur_hh ),
  688. 'mn' => array( $mn, $cur_mn ),
  689. );
  690. foreach ( $map as $timeunit => $value ) {
  691. list( $unit, $curr ) = $value;
  692. echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
  693. $cur_timeunit = 'cur_' . $timeunit;
  694. echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
  695. }
  696. ?>
  697. <p>
  698. <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
  699. <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
  700. </p>
  701. <?php
  702. }
  703. /**
  704. * Print out option HTML elements for the page templates drop-down.
  705. *
  706. * @since 1.5.0
  707. *
  708. * @param string $default Optional. The template file name. Default empty.
  709. */
  710. function page_template_dropdown( $default = '' ) {
  711. $templates = get_page_templates( get_post() );
  712. ksort( $templates );
  713. foreach ( array_keys( $templates ) as $template ) {
  714. $selected = selected( $default, $templates[ $template ], false );
  715. echo "\n\t<option value='" . $templates[ $template ] . "' $selected>$template</option>";
  716. }
  717. }
  718. /**
  719. * Print out option HTML elements for the page parents drop-down.
  720. *
  721. * @since 1.5.0
  722. *
  723. * @param int $default Optional. The default page ID to be pre-selected. Default 0.
  724. * @param int $parent Optional. The parent page ID. Default 0.
  725. * @param int $level Optional. Page depth level. Default 0.
  726. *
  727. * @return null|false Boolean False if page has no children, otherwise print out html elements
  728. */
  729. function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
  730. global $wpdb;
  731. $post = get_post();
  732. $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) );
  733. if ( $items ) {
  734. foreach ( $items as $item ) {
  735. // A page cannot be its own parent.
  736. if ( $post && $post->ID && $item->ID == $post->ID )
  737. continue;
  738. $pad = str_repeat( '&nbsp;', $level * 3 );
  739. $selected = selected( $default, $item->ID, false );
  740. echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
  741. parent_dropdown( $default, $item->ID, $level +1 );
  742. }
  743. } else {
  744. return false;
  745. }
  746. }
  747. /**
  748. * Print out option html elements for role selectors.
  749. *
  750. * @since 2.1.0
  751. *
  752. * @param string $selected slug for the role that should be already selected
  753. */
  754. function wp_dropdown_roles( $selected = false ) {
  755. $p = '';
  756. $r = '';
  757. $editable_roles = array_reverse( get_editable_roles() );
  758. foreach ( $editable_roles as $role => $details ) {
  759. $name = translate_user_role($details['name'] );
  760. if ( $selected == $role ) // preselect specified role
  761. $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
  762. else
  763. $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
  764. }
  765. echo $p . $r;
  766. }
  767. /**
  768. * Outputs the form used by the importers to accept the data to be imported
  769. *
  770. * @since 2.0.0
  771. *
  772. * @param string $action The action attribute for the form.
  773. */
  774. function wp_import_upload_form( $action ) {
  775. /**
  776. * Filter the maximum allowed upload size for import files.
  777. *
  778. * @since 2.3.0
  779. *
  780. * @see wp_max_upload_size()
  781. *
  782. * @param int $max_upload_size Allowed upload size. Default 1 MB.
  783. */
  784. $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
  785. $size = size_format( $bytes );
  786. $upload_dir = wp_upload_dir();
  787. if ( ! empty( $upload_dir['error'] ) ) :
  788. ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
  789. <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
  790. else :
  791. ?>
  792. <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' ) ); ?>">
  793. <p>
  794. <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
  795. <input type="file" id="upload" name="import" size="25" />
  796. <input type="hidden" name="action" value="save" />
  797. <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
  798. </p>
  799. <?php submit_button( __('Upload file and import'), 'button' ); ?>
  800. </form>
  801. <?php
  802. endif;
  803. }
  804. /**
  805. * Add a meta box to an edit form.
  806. *
  807. * @since 2.5.0
  808. *
  809. * @param string $id String for use in the 'id' attribute of tags.
  810. * @param string $title Title of the meta box.
  811. * @param callback $callback Function that fills the box with the desired content.
  812. * The function should echo its output.
  813. * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post
  814. * type, 'link', or 'comment'). Default is the current screen.
  815. * @param string $context Optional. The context within the screen where the boxes
  816. * should display. Available contexts vary from screen to
  817. * screen. Post edit screen contexts include 'normal', 'side',
  818. * and 'advanced'. Comments screen contexts include 'normal'
  819. * and 'side'. Menus meta boxes (accordion sections) all use
  820. * the 'side' context. Global default is 'advanced'.
  821. * @param string $priority Optional. The priority within the context where the boxes
  822. * should show ('high', 'low'). Default 'default'.
  823. * @param array $callback_args Optional. Data that should be set as the $args property
  824. * of the box array (which is the second parameter passed
  825. * to your callback). Default null.
  826. */
  827. function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
  828. global $wp_meta_boxes;
  829. if ( empty( $screen ) )
  830. $screen = get_current_screen();
  831. elseif ( is_string( $screen ) )
  832. $screen = convert_to_screen( $screen );
  833. $page = $screen->id;
  834. if ( !isset($wp_meta_boxes) )
  835. $wp_meta_boxes = array();
  836. if ( !isset($wp_meta_boxes[$page]) )
  837. $wp_meta_boxes[$page] = array();
  838. if ( !isset($wp_meta_boxes[$page][$context]) )
  839. $wp_meta_boxes[$page][$context] = array();
  840. foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
  841. foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
  842. if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
  843. continue;
  844. // If a core box was previously added or removed by a plugin, don't add.
  845. if ( 'core' == $priority ) {
  846. // If core box previously deleted, don't add
  847. if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
  848. return;
  849. /*
  850. * If box was added with default priority, give it core priority to
  851. * maintain sort order.
  852. */
  853. if ( 'default' == $a_priority ) {
  854. $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
  855. unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
  856. }
  857. return;
  858. }
  859. // If no priority given and id already present, use existing priority.
  860. if ( empty($priority) ) {
  861. $priority = $a_priority;
  862. /*
  863. * Else, if we're adding to the sorted priority, we don't know the title
  864. * or callback. Grab them from the previously added context/priority.
  865. */
  866. } elseif ( 'sorted' == $priority ) {
  867. $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
  868. $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
  869. $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
  870. }
  871. // An id can be in only one priority and one context.
  872. if ( $priority != $a_priority || $context != $a_context )
  873. unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
  874. }
  875. }
  876. if ( empty($priority) )
  877. $priority = 'low';
  878. if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
  879. $wp_meta_boxes[$page][$context][$priority] = array();
  880. $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
  881. }
  882. /**
  883. * Meta-Box template function
  884. *
  885. * @since 2.5.0
  886. *
  887. * @staticvar bool $already_sorted
  888. * @param string|WP_Screen $screen Screen identifier
  889. * @param string $context box context
  890. * @param mixed $object gets passed to the box callback function as first parameter
  891. * @return int number of meta_boxes
  892. */
  893. function do_meta_boxes( $screen, $context, $object ) {
  894. global $wp_meta_boxes;
  895. static $already_sorted = false;
  896. if ( empty( $screen ) )
  897. $screen = get_current_screen();
  898. elseif ( is_string( $screen ) )
  899. $screen = convert_to_screen( $screen );
  900. $page = $screen->id;
  901. $hidden = get_hidden_meta_boxes( $screen );
  902. printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
  903. // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
  904. if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
  905. foreach ( $sorted as $box_context => $ids ) {
  906. foreach ( explode( ',', $ids ) as $id ) {
  907. if ( $id && 'dashboard_browser_nag' !== $id ) {
  908. add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
  909. }
  910. }
  911. }
  912. }
  913. $already_sorted = true;
  914. $i = 0;
  915. if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
  916. foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
  917. if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) {
  918. foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
  919. if ( false == $box || ! $box['title'] )
  920. continue;
  921. $i++;
  922. $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
  923. echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
  924. if ( 'dashboard_browser_nag' != $box['id'] )
  925. echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
  926. echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
  927. echo '<div class="inside">' . "\n";
  928. call_user_func($box['callback'], $object, $box);
  929. echo "</div>\n";
  930. echo "</div>\n";
  931. }
  932. }
  933. }
  934. }
  935. echo "</div>";
  936. return $i;
  937. }
  938. /**
  939. * Remove a meta box from an edit form.
  940. *
  941. * @since 2.6.0
  942. *
  943. * @param string $id String for use in the 'id' attribute of tags.
  944. * @param string|object $screen The screen on which to show the box (post, page, link).
  945. * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
  946. */
  947. function remove_meta_box($id, $screen, $context) {
  948. global $wp_meta_boxes;
  949. if ( empty( $screen ) )
  950. $screen = get_current_screen();
  951. elseif ( is_string( $screen ) )
  952. $screen = convert_to_screen( $screen );
  953. $page = $screen->id;
  954. if ( !isset($wp_meta_boxes) )
  955. $wp_meta_boxes = array();
  956. if ( !isset($wp_meta_boxes[$page]) )
  957. $wp_meta_boxes[$page] = array();
  958. if ( !isset($wp_meta_boxes[$page][$context]) )
  959. $wp_meta_boxes[$page][$context] = array();
  960. foreach ( array('high', 'core', 'default', 'low') as $priority )
  961. $wp_meta_boxes[$page][$context][$priority][$id] = false;
  962. }
  963. /**
  964. * Meta Box Accordion Template Function
  965. *
  966. * Largely made up of abstracted code from {@link do_meta_boxes()}, this
  967. * function serves to build meta boxes as list items for display as
  968. * a collapsible accordion.
  969. *
  970. * @since 3.6.0
  971. *
  972. * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
  973. *
  974. * @param string|object $screen The screen identifier.
  975. * @param string $context The meta box context.
  976. * @param mixed $object gets passed to the section callback function as first parameter.
  977. * @return int number of meta boxes as accordion sections.
  978. */
  979. function do_accordion_sections( $screen, $context, $object ) {
  980. global $wp_meta_boxes;
  981. wp_enqueue_script( 'accordion' );
  982. if ( empty( $screen ) )
  983. $screen = get_current_screen();
  984. elseif ( is_string( $screen ) )
  985. $screen = convert_to_screen( $screen );
  986. $page = $screen->id;
  987. $hidden = get_hidden_meta_boxes( $screen );
  988. ?>
  989. <div id="side-sortables" class="accordion-container">
  990. <ul class="outer-border">
  991. <?php
  992. $i = 0;
  993. $first_open = false;
  994. if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
  995. foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
  996. if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
  997. foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
  998. if ( false == $box || ! $box['title'] )
  999. continue;
  1000. $i++;
  1001. $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
  1002. $open_class = '';
  1003. if ( ! $first_open && empty( $hidden_class ) ) {
  1004. $first_open = true;
  1005. $open_class = 'open';
  1006. }
  1007. ?>
  1008. <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'] ); ?>">
  1009. <h3 class="accordion-section-title hndle" tabindex="0">
  1010. <?php echo esc_html( $box['title'] ); ?>
  1011. <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
  1012. </h3>
  1013. <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
  1014. <div class="inside">
  1015. <?php call_user_func( $box['callback'], $object, $box ); ?>
  1016. </div><!-- .inside -->
  1017. </div><!-- .accordion-section-content -->
  1018. </li><!-- .accordion-section -->
  1019. <?php
  1020. }
  1021. }
  1022. }
  1023. }
  1024. ?>
  1025. </ul><!-- .outer-border -->
  1026. </div><!-- .accordion-container -->
  1027. <?php
  1028. return $i;
  1029. }
  1030. /**
  1031. * Add a new section to a settings page.
  1032. *
  1033. * Part of the Settings API. Use this to define new settings sections for an admin page.
  1034. * Show settings sections in your admin page callback function with do_settings_sections().
  1035. * Add settings fields to your section with add_settings_field()
  1036. *
  1037. * The $callback argument should be the name of a function that echoes out any
  1038. * content you want to show at the top of the settings section before the actual
  1039. * fields. It can output nothing if you want.
  1040. *
  1041. * @since 2.7.0
  1042. *
  1043. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  1044. *
  1045. * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
  1046. * @param string $title Formatted title of the section. Shown as the heading for the section.
  1047. * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
  1048. * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
  1049. */
  1050. function add_settings_section($id, $title, $callback, $page) {
  1051. global $wp_settings_sections;
  1052. if ( 'misc' == $page ) {
  1053. _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) );
  1054. $page = 'general';
  1055. }
  1056. if ( 'privacy' == $page ) {
  1057. _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) );
  1058. $page = 'reading';
  1059. }
  1060. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
  1061. }
  1062. /**
  1063. * Add a new field to a section of a settings page
  1064. *
  1065. * Part of the Settings API. Use this to define a settings field that will show
  1066. * as part of a settings section inside a settings page. The fields are shown using
  1067. * do_settings_fields() in do_settings-sections()
  1068. *
  1069. * The $callback argument should be the name of a function that echoes out the
  1070. * html input tags for this setting field. Use get_option() to retrieve existing
  1071. * values to show.
  1072. *
  1073. * @since 2.7.0
  1074. *
  1075. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  1076. *
  1077. * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
  1078. * @param string $title Formatted title of the field. Shown as the label for the field during output.
  1079. * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
  1080. * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
  1081. * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
  1082. * @param array $args Additional arguments
  1083. */
  1084. function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
  1085. global $wp_settings_fields;
  1086. if ( 'misc' == $page ) {
  1087. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  1088. $page = 'general';
  1089. }
  1090. if ( 'privacy' == $page ) {
  1091. _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) );
  1092. $page = 'reading';
  1093. }
  1094. $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
  1095. }
  1096. /**
  1097. * Prints out all settings sections added to a particular settings page
  1098. *
  1099. * Part of the Settings API. Use this in a settings page callback function
  1100. * to output all the sections and fields that were added to that $page with
  1101. * add_settings_section() and add_settings_field()
  1102. *
  1103. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  1104. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  1105. * @since 2.7.0
  1106. *
  1107. * @param string $page The slug name of the page whos settings sections you want to output
  1108. */
  1109. function do_settings_sections( $page ) {
  1110. global $wp_settings_sections, $wp_settings_fields;
  1111. if ( ! isset( $wp_settings_sections[$page] ) )
  1112. return;
  1113. foreach ( (array) $wp_settings_sections[$page] as $section ) {
  1114. if ( $section['title'] )
  1115. echo "<h3>{$section['title']}</h3>\n";
  1116. if ( $section['callback'] )
  1117. call_user_func( $section['callback'], $section );
  1118. if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
  1119. continue;
  1120. echo '<table class="form-table">';
  1121. do_settings_fields( $page, $section['id'] );
  1122. echo '</table>';
  1123. }
  1124. }
  1125. /**
  1126. * Print out the settings fields for a particular settings section
  1127. *
  1128. * Part of the Settings API. Use this in a settings page to output
  1129. * a specific section. Should normally be called by do_settings_sections()
  1130. * rather than directly.
  1131. *
  1132. * @global $wp_settings_fields Storage array of settings fields and their pages/sections
  1133. *
  1134. * @since 2.7.0
  1135. *
  1136. * @param string $page Slug title of the admin page who's settings fields you want to show.
  1137. * @param string $section Slug title of the settings section who's fields you want to show.
  1138. */
  1139. function do_settings_fields($page, $section) {
  1140. global $wp_settings_fields;
  1141. if ( ! isset( $wp_settings_fields[$page][$section] ) )
  1142. return;
  1143. foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
  1144. echo '<tr>';
  1145. if ( !empty($field['args']['label_for']) )
  1146. echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
  1147. else
  1148. echo '<th scope="row">' . $field['title'] . '</th>';
  1149. echo '<td>';
  1150. call_user_func($field['callback'], $field['args']);
  1151. echo '</td>';
  1152. echo '</tr>';
  1153. }
  1154. }
  1155. /**
  1156. * Register a settings error to be displayed to the user
  1157. *
  1158. * Part of the Settings API. Use this to show messages to users about settings validation
  1159. * problems, missing settings or anything else.
  1160. *
  1161. * Settings errors should be added inside the $sanitize_callback function defined in
  1162. * register_setting() for a given setting to give feedback about the submission.
  1163. *
  1164. * By default messages will show immediately after the submission that generated the error.
  1165. * Additional calls to settings_errors() can be used to show errors even when the settings
  1166. * page is first accessed.
  1167. *
  1168. * @since 3.0.0
  1169. *
  1170. * @todo Properly document optional arguments as such.
  1171. *
  1172. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  1173. *
  1174. * @param string $setting Slug title of the setting to which this error applies
  1175. * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
  1176. * @param string $message The formatted message text to display to the user (will be shown inside styled
  1177. * `<div>` and `<p>` tags).
  1178. * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
  1179. */
  1180. function add_settings_error( $setting, $code, $message, $type = 'error' ) {
  1181. global $wp_settings_errors;
  1182. $wp_settings_errors[] = array(
  1183. 'setting' => $setting,
  1184. 'code' => $code,
  1185. 'message' => $message,
  1186. 'type' => $type
  1187. );
  1188. }
  1189. /**
  1190. * Fetch settings errors registered by add_settings_error()
  1191. *
  1192. * Checks the $wp_settings_errors array for any errors declared during the current
  1193. * pageload and returns them.
  1194. *
  1195. * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
  1196. * to the 'settings_errors' transient then those errors will be returned instead. This
  1197. * is used to pass errors back across pageloads.
  1198. *
  1199. * Use the $sanitize argument to manually re-sanitize the option before returning errors.
  1200. * This is useful if you have errors or notices you want to show even when the user
  1201. * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
  1202. *
  1203. * @since 3.0.0
  1204. *
  1205. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  1206. *
  1207. * @param string $setting Optional slug title of a specific setting who's errors you want.
  1208. * @param boolean $sanitize Wheth…

Large files files are truncated, but you can click here to view the full file