PageRenderTime 128ms CodeModel.GetById 15ms RepoModel.GetById 11ms app.codeStats 0ms

/wp-admin/wp-admin/includes/template.php

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

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