PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/template.php

https://bitbucket.org/aqge/deptandashboard
PHP | 1834 lines | 1108 code | 211 blank | 515 comment | 211 complexity | b197e48271de061ae9d988d98d4fab7a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1

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

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

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