PageRenderTime 86ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/template.php

https://bitbucket.org/opehei/wordpress-trunk
PHP | 1875 lines | 1138 code | 223 blank | 514 comment | 221 complexity | 0abd87d9d49077798d797cf2d8025561 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0

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

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