PageRenderTime 71ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/template.php

https://github.com/davodey/WordPress
PHP | 2134 lines | 1204 code | 251 blank | 679 comment | 227 complexity | 9523712bb021887a9a58dc119ec7358f MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1

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

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