PageRenderTime 61ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/template.php

https://bitbucket.org/space87/wordpressstart
PHP | 1902 lines | 1148 code | 216 blank | 538 comment | 214 complexity | a089475a31c322ed94e651d3a0d637f7 MD5 | raw file

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

  1. <?php
  2. /**
  3. * Template WordPress Administration API.
  4. *
  5. * A Big Mess. Also some neat functions that are nicely written.
  6. *
  7. * @package WordPress
  8. * @subpackage Administration
  9. */
  10. //
  11. // Category Checklists
  12. //
  13. /**
  14. * Walker to output an unordered list of category checkbox <input> elements.
  15. *
  16. * @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. global $post_ID;
  148. if ( $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="" tabindex="101" 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="" tabindex="102" 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="" tabindex="103" />
  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, 'tabindex' => 104 ) );
  303. ?>
  304. </div>
  305. <p id="replysubmit" class="submit">
  306. <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
  307. <a href="#comments-form" class="save button-primary alignright" tabindex="104">
  308. <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span>
  309. <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
  310. <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
  311. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  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]' tabindex='6' 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", "deletemeta[{$entry['meta_id']}]", false, array( 'tabindex' => '6' ) );
  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" , 'updatemeta', false, array( 'tabindex' => '6' ) );
  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]' tabindex='6' 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" tabindex="7">
  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" tabindex="7" 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" tabindex="7" value="" />
  484. <?php } ?>
  485. </td>
  486. <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
  487. </tr>
  488. <tr><td colspan="2" class="submit">
  489. <?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'addmetasub', 'tabindex' => '9' ) ); ?>
  490. <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
  491. </td></tr>
  492. </tbody>
  493. </table>
  494. <?php
  495. }
  496. /**
  497. * {@internal Missing Short Description}}
  498. *
  499. * @since 0.71
  500. *
  501. * @param unknown_type $edit
  502. * @param unknown_type $for_post
  503. * @param unknown_type $tab_index
  504. * @param unknown_type $multi
  505. */
  506. function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
  507. global $wp_locale, $post, $comment;
  508. if ( $for_post )
  509. $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
  510. $tab_index_attribute = '';
  511. if ( (int) $tab_index > 0 )
  512. $tab_index_attribute = " tabindex=\"$tab_index\"";
  513. // 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 />';
  514. $time_adj = current_time('timestamp');
  515. $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
  516. $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
  517. $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
  518. $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
  519. $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
  520. $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
  521. $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
  522. $cur_jj = gmdate( 'd', $time_adj );
  523. $cur_mm = gmdate( 'm', $time_adj );
  524. $cur_aa = gmdate( 'Y', $time_adj );
  525. $cur_hh = gmdate( 'H', $time_adj );
  526. $cur_mn = gmdate( 'i', $time_adj );
  527. $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
  528. for ( $i = 1; $i < 13; $i = $i +1 ) {
  529. $monthnum = zeroise($i, 2);
  530. $month .= "\t\t\t" . '<option value="' . $monthnum . '"';
  531. if ( $i == $mm )
  532. $month .= ' selected="selected"';
  533. /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
  534. $month .= '>' . sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n";
  535. }
  536. $month .= '</select>';
  537. $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  538. $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
  539. $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  540. $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  541. echo '<div class="timestamp-wrap">';
  542. /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
  543. printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
  544. echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
  545. if ( $multi ) return;
  546. echo "\n\n";
  547. foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
  548. echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
  549. $cur_timeunit = 'cur_' . $timeunit;
  550. echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
  551. }
  552. ?>
  553. <p>
  554. <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
  555. <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
  556. </p>
  557. <?php
  558. }
  559. /**
  560. * {@internal Missing Short Description}}
  561. *
  562. * @since 1.5.0
  563. *
  564. * @param unknown_type $default
  565. */
  566. function page_template_dropdown( $default = '' ) {
  567. $templates = get_page_templates();
  568. ksort( $templates );
  569. foreach (array_keys( $templates ) as $template )
  570. : if ( $default == $templates[$template] )
  571. $selected = " selected='selected'";
  572. else
  573. $selected = '';
  574. echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
  575. endforeach;
  576. }
  577. /**
  578. * {@internal Missing Short Description}}
  579. *
  580. * @since 1.5.0
  581. *
  582. * @param unknown_type $default
  583. * @param unknown_type $parent
  584. * @param unknown_type $level
  585. * @return unknown
  586. */
  587. function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
  588. global $wpdb, $post_ID;
  589. $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) );
  590. if ( $items ) {
  591. foreach ( $items as $item ) {
  592. // A page cannot be its own parent.
  593. if (!empty ( $post_ID ) ) {
  594. if ( $item->ID == $post_ID ) {
  595. continue;
  596. }
  597. }
  598. $pad = str_repeat( '&nbsp;', $level * 3 );
  599. if ( $item->ID == $default)
  600. $current = ' selected="selected"';
  601. else
  602. $current = '';
  603. echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
  604. parent_dropdown( $default, $item->ID, $level +1 );
  605. }
  606. } else {
  607. return false;
  608. }
  609. }
  610. /**
  611. * {@internal Missing Short Description}}
  612. *
  613. * @since 2.0.0
  614. *
  615. * @param unknown_type $id
  616. * @return unknown
  617. */
  618. function the_attachment_links( $id = false ) {
  619. $id = (int) $id;
  620. $post = & get_post( $id );
  621. if ( $post->post_type != 'attachment' )
  622. return false;
  623. $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
  624. $attachment_data = wp_get_attachment_metadata( $id );
  625. $thumb = isset( $attachment_data['thumb'] );
  626. ?>
  627. <form id="the-attachment-links">
  628. <table>
  629. <col />
  630. <col class="widefat" />
  631. <tr>
  632. <th scope="row"><?php _e( 'URL' ) ?></th>
  633. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo esc_textarea( wp_get_attachment_url() ); ?></textarea></td>
  634. </tr>
  635. <?php if ( $icon ) : ?>
  636. <tr>
  637. <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
  638. <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>
  639. </tr>
  640. <tr>
  641. <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
  642. <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>
  643. </tr>
  644. <?php else : ?>
  645. <tr>
  646. <th scope="row"><?php _e( 'Link to file' ) ?></th>
  647. <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>
  648. </tr>
  649. <tr>
  650. <th scope="row"><?php _e( 'Link to page' ) ?></th>
  651. <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>
  652. </tr>
  653. <?php endif; ?>
  654. </table>
  655. </form>
  656. <?php
  657. }
  658. /**
  659. * Print out <option> html elements for role selectors
  660. *
  661. * @since 2.1.0
  662. *
  663. * @param string $selected slug for the role that should be already selected
  664. */
  665. function wp_dropdown_roles( $selected = false ) {
  666. $p = '';
  667. $r = '';
  668. $editable_roles = get_editable_roles();
  669. foreach ( $editable_roles as $role => $details ) {
  670. $name = translate_user_role($details['name'] );
  671. if ( $selected == $role ) // preselect specified role
  672. $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
  673. else
  674. $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
  675. }
  676. echo $p . $r;
  677. }
  678. /**
  679. * {@internal Missing Short Description}}
  680. *
  681. * @since 2.3.0
  682. *
  683. * @param unknown_type $size
  684. * @return unknown
  685. */
  686. function wp_convert_hr_to_bytes( $size ) {
  687. $size = strtolower($size);
  688. $bytes = (int) $size;
  689. if ( strpos($size, 'k') !== false )
  690. $bytes = intval($size) * 1024;
  691. elseif ( strpos($size, 'm') !== false )
  692. $bytes = intval($size) * 1024 * 1024;
  693. elseif ( strpos($size, 'g') !== false )
  694. $bytes = intval($size) * 1024 * 1024 * 1024;
  695. return $bytes;
  696. }
  697. /**
  698. * {@internal Missing Short Description}}
  699. *
  700. * @since 2.3.0
  701. *
  702. * @param unknown_type $bytes
  703. * @return unknown
  704. */
  705. function wp_convert_bytes_to_hr( $bytes ) {
  706. $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
  707. $log = log( $bytes, 1024 );
  708. $power = (int) $log;
  709. $size = pow(1024, $log - $power);
  710. return $size . $units[$power];
  711. }
  712. /**
  713. * {@internal Missing Short Description}}
  714. *
  715. * @since 2.5.0
  716. *
  717. * @return unknown
  718. */
  719. function wp_max_upload_size() {
  720. $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
  721. $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
  722. $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
  723. return $bytes;
  724. }
  725. /**
  726. * Outputs the form used by the importers to accept the data to be imported
  727. *
  728. * @since 2.0.0
  729. *
  730. * @param string $action The action attribute for the form.
  731. */
  732. function wp_import_upload_form( $action ) {
  733. $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
  734. $size = wp_convert_bytes_to_hr( $bytes );
  735. $upload_dir = wp_upload_dir();
  736. if ( ! empty( $upload_dir['error'] ) ) :
  737. ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
  738. <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
  739. else :
  740. ?>
  741. <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
  742. <p>
  743. <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
  744. <input type="file" id="upload" name="import" size="25" />
  745. <input type="hidden" name="action" value="save" />
  746. <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
  747. </p>
  748. <?php submit_button( __('Upload file and import'), 'button' ); ?>
  749. </form>
  750. <?php
  751. endif;
  752. }
  753. /**
  754. * Add a meta box to an edit form.
  755. *
  756. * @since 2.5.0
  757. *
  758. * @param string $id String for use in the 'id' attribute of tags.
  759. * @param string $title Title of the meta box.
  760. * @param string $callback Function that fills the box with the desired content. The function should echo its output.
  761. * @param string|object $screen Optional. The screen on which to show the box (post, page, link). Defaults to current screen.
  762. * @param string $context Optional. The context within the page where the boxes should show ('normal', 'advanced').
  763. * @param string $priority Optional. The priority within the context where the boxes should show ('high', 'low').
  764. */
  765. function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
  766. global $wp_meta_boxes;
  767. if ( empty( $screen ) )
  768. $screen = get_current_screen();
  769. elseif ( is_string( $screen ) )
  770. $screen = convert_to_screen( $screen );
  771. $page = $screen->id;
  772. if ( !isset($wp_meta_boxes) )
  773. $wp_meta_boxes = array();
  774. if ( !isset($wp_meta_boxes[$page]) )
  775. $wp_meta_boxes[$page] = array();
  776. if ( !isset($wp_meta_boxes[$page][$context]) )
  777. $wp_meta_boxes[$page][$context] = array();
  778. foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
  779. foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
  780. if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
  781. continue;
  782. // If a core box was previously added or removed by a plugin, don't add.
  783. if ( 'core' == $priority ) {
  784. // If core box previously deleted, don't add
  785. if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
  786. return;
  787. // If box was added with default priority, give it core priority to maintain sort order
  788. if ( 'default' == $a_priority ) {
  789. $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
  790. unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
  791. }
  792. return;
  793. }
  794. // If no priority given and id already present, use existing priority
  795. if ( empty($priority) ) {
  796. $priority = $a_priority;
  797. // 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.
  798. } elseif ( 'sorted' == $priority ) {
  799. $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
  800. $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
  801. $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
  802. }
  803. // An id can be in only one priority and one context
  804. if ( $priority != $a_priority || $context != $a_context )
  805. unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
  806. }
  807. }
  808. if ( empty($priority) )
  809. $priority = 'low';
  810. if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
  811. $wp_meta_boxes[$page][$context][$priority] = array();
  812. $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
  813. }
  814. /**
  815. * Meta-Box template function
  816. *
  817. * @since 2.5.0
  818. *
  819. * @param string|object $screen Screen identifier
  820. * @param string $context box context
  821. * @param mixed $object gets passed to the box callback function as first parameter
  822. * @return int number of meta_boxes
  823. */
  824. function do_meta_boxes( $screen, $context, $object ) {
  825. global $wp_meta_boxes;
  826. static $already_sorted = false;
  827. if ( empty( $screen ) )
  828. $screen = get_current_screen();
  829. elseif ( is_string( $screen ) )
  830. $screen = convert_to_screen( $screen );
  831. $page = $screen->id;
  832. $hidden = get_hidden_meta_boxes( $screen );
  833. printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
  834. $i = 0;
  835. do {
  836. // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
  837. if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
  838. foreach ( $sorted as $box_context => $ids ) {
  839. foreach ( explode(',', $ids ) as $id ) {
  840. if ( $id && 'dashboard_browser_nag' !== $id )
  841. add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
  842. }
  843. }
  844. }
  845. $already_sorted = true;
  846. if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
  847. break;
  848. foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
  849. if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
  850. foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
  851. if ( false == $box || ! $box['title'] )
  852. continue;
  853. $i++;
  854. $style = '';
  855. $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
  856. echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
  857. if ( 'dashboard_browser_nag' != $box['id'] )
  858. echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
  859. echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
  860. echo '<div class="inside">' . "\n";
  861. call_user_func($box['callback'], $object, $box);
  862. echo "</div>\n";
  863. echo "</div>\n";
  864. }
  865. }
  866. }
  867. } while(0);
  868. echo "</div>";
  869. return $i;
  870. }
  871. /**
  872. * Remove a meta box from an edit form.
  873. *
  874. * @since 2.6.0
  875. *
  876. * @param string $id String for use in the 'id' attribute of tags.
  877. * @param string|object $screen The screen on which to show the box (post, page, link).
  878. * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
  879. */
  880. function remove_meta_box($id, $screen, $context) {
  881. global $wp_meta_boxes;
  882. if ( empty( $screen ) )
  883. $screen = get_current_screen();
  884. elseif ( is_string( $screen ) )
  885. $screen = convert_to_screen( $screen );
  886. $page = $screen->id;
  887. if ( !isset($wp_meta_boxes) )
  888. $wp_meta_boxes = array();
  889. if ( !isset($wp_meta_boxes[$page]) )
  890. $wp_meta_boxes[$page] = array();
  891. if ( !isset($wp_meta_boxes[$page][$context]) )
  892. $wp_meta_boxes[$page][$context] = array();
  893. foreach ( array('high', 'core', 'default', 'low') as $priority )
  894. $wp_meta_boxes[$page][$context][$priority][$id] = false;
  895. }
  896. /**
  897. * Add a new section to a settings page.
  898. *
  899. * Part of the Settings API. Use this to define new settings sections for an admin page.
  900. * Show settings sections in your admin page callback function with do_settings_sections().
  901. * Add settings fields to your section with add_settings_field()
  902. *
  903. * The $callback argument should be the name of a function that echoes out any
  904. * content you want to show at the top of the settings section before the actual
  905. * fields. It can output nothing if you want.
  906. *
  907. * @since 2.7.0
  908. *
  909. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  910. *
  911. * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
  912. * @param string $title Formatted title of the section. Shown as the heading for the section.
  913. * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
  914. * @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();
  915. */
  916. function add_settings_section($id, $title, $callback, $page) {
  917. global $wp_settings_sections;
  918. if ( 'misc' == $page ) {
  919. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  920. $page = 'general';
  921. }
  922. if ( !isset($wp_settings_sections) )
  923. $wp_settings_sections = array();
  924. if ( !isset($wp_settings_sections[$page]) )
  925. $wp_settings_sections[$page] = array();
  926. if ( !isset($wp_settings_sections[$page][$id]) )
  927. $wp_settings_sections[$page][$id] = array();
  928. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
  929. }
  930. /**
  931. * Add a new field to a section of a settings page
  932. *
  933. * Part of the Settings API. Use this to define a settings field that will show
  934. * as part of a settings section inside a settings page. The fields are shown using
  935. * do_settings_fields() in do_settings-sections()
  936. *
  937. * The $callback argument should be the name of a function that echoes out the
  938. * html input tags for this setting field. Use get_option() to retrieve existing
  939. * values to show.
  940. *
  941. * @since 2.7.0
  942. *
  943. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  944. *
  945. * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
  946. * @param string $title Formatted title of the field. Shown as the label for the field during output.
  947. * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
  948. * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
  949. * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
  950. * @param array $args Additional arguments
  951. */
  952. function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
  953. global $wp_settings_fields;
  954. if ( 'misc' == $page ) {
  955. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  956. $page = 'general';
  957. }
  958. if ( !isset($wp_settings_fields) )
  959. $wp_settings_fields = array();
  960. if ( !isset($wp_settings_fields[$page]) )
  961. $wp_settings_fields[$page] = array();
  962. if ( !isset($wp_settings_fields[$page][$section]) )
  963. $wp_settings_fields[$page][$section] = array();
  964. $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
  965. }
  966. /**
  967. * Prints out all settings sections added to a particular settings page
  968. *
  969. * Part of the Settings API. Use this in a settings page callback function
  970. * to output all the sections and fields that were added to that $page with
  971. * add_settings_section() and add_settings_field()
  972. *
  973. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  974. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  975. * @since 2.7.0
  976. *
  977. * @param string $page The slug name of the page whos settings sections you want to output
  978. */
  979. function do_settings_sections($page) {
  980. global $wp_settings_sections, $wp_settings_fields;
  981. if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
  982. return;
  983. foreach ( (array) $wp_settings_sections[$page] as $section ) {
  984. if ( $section['title'] )
  985. echo "<h3>{$section['title']}</h3>\n";
  986. call_user_func($section['callback'], $section);
  987. if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
  988. continue;
  989. echo '<table class="form-table">';
  990. do_settings_fields($page, $section['id']);
  991. echo '</table>';
  992. }
  993. }
  994. /**
  995. * Print out the settings fields for a particular settings section
  996. *
  997. * Part of the Settings API. Use this in a settings page to output
  998. * a specific section. Should normally be called by do_settings_sections()
  999. * rather than directly.
  1000. *
  1001. * @global $wp_settings_fields Storage array of settings fields and their pages/sections
  1002. *
  1003. * @since 2.7.0
  1004. *
  1005. * @param string $page Slug title of the admin page who's settings fields you want to show.
  1006. * @param section $section Slug title of the settings section who's fields you want to show.
  1007. */
  1008. function do_settings_fields($page, $section) {
  1009. global $wp_settings_fields;
  1010. if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
  1011. return;
  1012. foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
  1013. echo '<tr valign="top">';
  1014. if ( !empty($field['args']['label_for']) )
  1015. echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
  1016. else
  1017. echo '<th scope="row">' . $field['title'] . '</th>';
  1018. echo '<td>';
  1019. call_user_func($field['callback'], $field['args']);
  1020. echo '</td>';
  1021. echo '</tr>';
  1022. }
  1023. }
  1024. /**
  1025. * Register a settings error to be displayed to the user
  1026. *
  1027. * Part of the Settings API. Use this to show messages to users about settings validation
  1028. * problems, missing settings or anything else.
  1029. *
  1030. * Settings errors should be added inside the $sanitize_callback function defined in
  1031. * register_setting() for a given setting to give feedback about the submission.
  1032. *
  1033. * By default messages will show immediately after the submission that generated the error.
  1034. * Additional calls to settings_errors() can be used to show errors even when the settings
  1035. * page is first accessed.
  1036. *
  1037. * @since 3.0.0
  1038. *
  1039. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  1040. *
  1041. * @param string $setting Slug title of the setting to which this error applies
  1042. * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
  1043. * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
  1044. * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
  1045. */
  1046. function add_settings_error( $setting, $code, $message, $type = 'error' ) {
  1047. global $wp_settings_errors;
  1048. if ( !isset($wp_settings_errors) )
  1049. $wp_settings_errors = array();
  1050. $new_error = array(
  1051. 'setting' => $setting,
  1052. 'code' => $code,
  1053. 'message' => $message,
  1054. 'type' => $type
  1055. );
  1056. $wp_settings_errors[] = $new_error;
  1057. }
  1058. /**
  1059. * Fetch settings errors registered by add_settings_error()
  1060. *
  1061. * Checks the $wp_settings_errors array for any errors declared during the current
  1062. * pageload and returns them.
  1063. *
  1064. * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
  1065. * to the 'settings_errors' transient then those errors will be returned instead. This
  1066. * is used to pass errors back across pageloads.
  1067. *
  1068. * Use the $sanitize argument to manually re-sanitize the option before returning errors.
  1069. * This is useful if you have errors or notices you want to show even when the user
  1070. * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
  1071. *
  1072. * @since 3.0.0
  1073. *
  1074. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  1075. *
  1076. * @param string $setting Optional slug title of a specific setting who's errors you want.
  1077. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
  1078. * @return array Array of settings errors
  1079. */
  1080. function get_settings_errors( $setting = '', $sanitize = false ) {
  1081. global $wp_settings_errors;
  1082. // If $sanitize is true, manually re-run the sanitizisation for this option
  1083. // This allows the $sanitize_callback from register_setting() to run, adding
  1084. // any settings errors you want to show by default.
  1085. if ( $sanitize )
  1086. sanitize_option( $setting, get_option($setting));
  1087. // If settings were passed back from options.php then use them
  1088. // Ignore transients if $sanitize is true, we don't want the old values anyway
  1089. if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) {
  1090. $settings_errors = get_transient('settings_errors');
  1091. delete_transient('settings_errors');
  1092. // Otherwise check global in case validation has been run on this pageload
  1093. } elseif ( count( $wp_settings_errors ) ) {
  1094. $settings_errors = $wp_settings_errors;
  1095. } else {
  1096. return;
  1097. }
  1098. // Filter the results to those of a specific setting if one was set
  1099. if ( $setting ) {
  1100. foreach ( (array) $settings_errors as $key => $details )
  1101. if ( $setting != $details['setting'] )
  1102. unset( $settings_errors[$key] );
  1103. }
  1104. return $settings_errors;
  1105. }
  1106. /**
  1107. * Display settings errors registered by add_settings_error()
  1108. *
  1109. * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
  1110. *
  1111. * This is called automatically after a settings page based on the Settings API is submitted.
  1112. * Errors should be added during the validation callback function for a setting defined in register_setting()
  1113. *
  1114. * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
  1115. * on its current value.
  1116. *
  1117. * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
  1118. * if the user has already saved new values it will be hidden to avoid repeating messages already
  1119. * shown in the default error reporting after submission. This is useful to show general errors like missing
  1120. * settings when the user arrives at the settings page.
  1121. *
  1122. * @since 3.0.0
  1123. *
  1124. * @param string $setting Optional slug title of a specific setting who's errors you want.
  1125. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
  1126. * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
  1127. */
  1128. function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
  1129. if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
  1130. return;
  1131. $settings_errors = get_settings_errors( $setting, $sanitize );
  1132. if ( ! is_array( $settings_errors ) )
  1133. return;
  1134. $output = '';
  1135. foreach ( $settings_errors as $key => $details ) {
  1136. $css_id = 'setting-error-' . $details['code'];
  1137. $css_class = $details['type'] . ' settings-error';
  1138. $output .= "<div id='$css_id' class='$css_class'> \n";
  1139. $output .= "<p><strong>{$details['message']}</strong></p>";
  1140. $output .= "</div> \n";
  1141. }
  1142. echo $output;
  1143. }
  1144. /**
  1145. * {@internal Missing Short Description}}
  1146. *
  1147. * @since 2.7.0
  1148. *
  1149. * @param unknown_type $found_action
  1150. */
  1151. function find_posts_div($found_action = '') {
  1152. ?>
  1153. <div id="find-posts" class="find-box" style="display:none;">
  1154. <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
  1155. <div class="find-box-inside">
  1156. <div class="find-box-search">
  1157. <?php if ( $found_action ) { ?>
  1158. <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
  1159. <?php } ?>
  1160. <input type="hidden" name="affected" id="affected" value="" />
  1161. <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
  1162. <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
  1163. <input type="text" id="find-posts-input" name="ps" value="" />
  1164. <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
  1165. <?php
  1166. $post_types = get_post_types( array('public' => true), 'objects' );
  1167. foreach ( $post_types as $post ) {
  1168. if ( 'attachment' == $post->name )
  1169. continue;
  1170. ?>
  1171. <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'); ?> />
  1172. <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
  1173. <?php
  1174. } ?>
  1175. </div>
  1176. <div id="find-posts-response"></div>
  1177. </div>
  1178. <div class="find-box-buttons">
  1179. <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
  1180. <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
  1181. </div>
  1182. </div>
  1183. <?php
  1184. }
  1185. /**
  1186. * Display the post password.
  1187. *
  1188. * The password is passed through {@link esc_attr()} to ensure that it
  1189. * is safe for placing in an html attribute.
  1190. *
  1191. * @uses attr
  1192. * @since 2.7.0
  1193. */
  1194. function the_post_password() {
  1195. global $post;

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