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

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

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 2228 lines | 1413 code | 271 blank | 544 comment | 303 complexity | 464d437f2a8ed6a264d9a3e9a3b12c19 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Template WordPress Administration API.
  4. *
  5. * A Big Mess. Also some neat functions that are nicely written.
  6. *
  7. * @package WordPress
  8. * @subpackage Administration
  9. */
  10. //
  11. // Category Checklists
  12. //
  13. /**
  14. * {@internal Missing Short Description}}
  15. *
  16. * @since 2.5.1
  17. */
  18. class Walker_Category_Checklist extends Walker {
  19. var $tree_type = 'category';
  20. var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  21. function start_lvl(&$output, $depth, $args) {
  22. $indent = str_repeat("\t", $depth);
  23. $output .= "$indent<ul class='children'>\n";
  24. }
  25. function end_lvl(&$output, $depth, $args) {
  26. $indent = str_repeat("\t", $depth);
  27. $output .= "$indent</ul>\n";
  28. }
  29. function start_el(&$output, $category, $depth, $args) {
  30. extract($args);
  31. if ( empty($taxonomy) )
  32. $taxonomy = 'category';
  33. if ( $taxonomy == 'category' )
  34. $name = 'post_category';
  35. else
  36. $name = 'tax_input['.$taxonomy.']';
  37. $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
  38. $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
  39. }
  40. function end_el(&$output, $category, $depth, $args) {
  41. $output .= "</li>\n";
  42. }
  43. }
  44. /**
  45. * {@internal Missing Short Description}}
  46. *
  47. * @since 2.5.1
  48. *
  49. * @param unknown_type $post_id
  50. * @param unknown_type $descendants_and_self
  51. * @param unknown_type $selected_cats
  52. * @param unknown_type $popular_cats
  53. */
  54. function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
  55. wp_terms_checklist($post_id,
  56. array(
  57. 'taxonomy' => 'category',
  58. 'descendants_and_self' => $descendants_and_self,
  59. 'selected_cats' => $selected_cats,
  60. 'popular_cats' => $popular_cats,
  61. 'walker' => $walker,
  62. 'checked_ontop' => $checked_ontop
  63. ));
  64. }
  65. /**
  66. * Taxonomy independent version of wp_category_checklist
  67. *
  68. * @since 3.0.0
  69. *
  70. * @param int $post_id
  71. * @param array $args
  72. */
  73. function wp_terms_checklist($post_id = 0, $args = array()) {
  74. $defaults = array(
  75. 'descendants_and_self' => 0,
  76. 'selected_cats' => false,
  77. 'popular_cats' => false,
  78. 'walker' => null,
  79. 'taxonomy' => 'category',
  80. 'checked_ontop' => true
  81. );
  82. extract( wp_parse_args($args, $defaults), EXTR_SKIP );
  83. if ( empty($walker) || !is_a($walker, 'Walker') )
  84. $walker = new Walker_Category_Checklist;
  85. $descendants_and_self = (int) $descendants_and_self;
  86. $args = array('taxonomy' => $taxonomy);
  87. $tax = get_taxonomy($taxonomy);
  88. $args['disabled'] = !current_user_can($tax->cap->assign_terms);
  89. if ( is_array( $selected_cats ) )
  90. $args['selected_cats'] = $selected_cats;
  91. elseif ( $post_id )
  92. $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
  93. else
  94. $args['selected_cats'] = array();
  95. if ( is_array( $popular_cats ) )
  96. $args['popular_cats'] = $popular_cats;
  97. else
  98. $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  99. if ( $descendants_and_self ) {
  100. $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
  101. $self = get_term( $descendants_and_self, $taxonomy );
  102. array_unshift( $categories, $self );
  103. } else {
  104. $categories = (array) get_terms($taxonomy, array('get' => 'all'));
  105. }
  106. if ( $checked_ontop ) {
  107. // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
  108. $checked_categories = array();
  109. $keys = array_keys( $categories );
  110. foreach( $keys as $k ) {
  111. if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
  112. $checked_categories[] = $categories[$k];
  113. unset( $categories[$k] );
  114. }
  115. }
  116. // Put checked cats on top
  117. echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
  118. }
  119. // Then the rest of them
  120. echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
  121. }
  122. /**
  123. * {@internal Missing Short Description}}
  124. *
  125. * @since 2.5.0
  126. *
  127. * @param unknown_type $taxonomy
  128. * @param unknown_type $default
  129. * @param unknown_type $number
  130. * @param unknown_type $echo
  131. * @return unknown
  132. */
  133. function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
  134. global $post_ID;
  135. if ( $post_ID )
  136. $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids'));
  137. else
  138. $checked_terms = array();
  139. $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
  140. $tax = get_taxonomy($taxonomy);
  141. if ( ! current_user_can($tax->cap->assign_terms) )
  142. $disabled = 'disabled="disabled"';
  143. else
  144. $disabled = '';
  145. $popular_ids = array();
  146. foreach ( (array) $terms as $term ) {
  147. $popular_ids[] = $term->term_id;
  148. if ( !$echo ) // hack for AJAX use
  149. continue;
  150. $id = "popular-$taxonomy-$term->term_id";
  151. $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
  152. ?>
  153. <li id="<?php echo $id; ?>" class="popular-category">
  154. <label class="selectit">
  155. <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/>
  156. <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?>
  157. </label>
  158. </li>
  159. <?php
  160. }
  161. return $popular_ids;
  162. }
  163. /**
  164. * {@internal Missing Short Description}}
  165. *
  166. * @since 2.5.1
  167. *
  168. * @param unknown_type $link_id
  169. */
  170. function wp_link_category_checklist( $link_id = 0 ) {
  171. $default = 1;
  172. if ( $link_id ) {
  173. $checked_categories = wp_get_link_cats( $link_id );
  174. // No selected categories, strange
  175. if ( ! count( $checked_categories ) )
  176. $checked_categories[] = $default;
  177. } else {
  178. $checked_categories[] = $default;
  179. }
  180. $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
  181. if ( empty( $categories ) )
  182. return;
  183. foreach ( $categories as $category ) {
  184. $cat_id = $category->term_id;
  185. $name = esc_html( apply_filters( 'the_category', $category->name ) );
  186. $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
  187. echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
  188. }
  189. }
  190. /**
  191. * Get the column headers for a screen
  192. *
  193. * @since 2.7.0
  194. *
  195. * @param string|object $screen The screen you want the headers for
  196. * @return array Containing the headers in the format id => UI String
  197. */
  198. function get_column_headers( $screen ) {
  199. if ( is_string( $screen ) )
  200. $screen = convert_to_screen( $screen );
  201. global $_wp_column_headers;
  202. if ( !isset( $_wp_column_headers[ $screen->id ] ) ) {
  203. $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
  204. }
  205. return $_wp_column_headers[ $screen->id ];
  206. }
  207. /**
  208. * Get a list of hidden columns.
  209. *
  210. * @since 2.7.0
  211. *
  212. * @param string|object $screen The screen you want the hidden columns for
  213. * @return array
  214. */
  215. function get_hidden_columns( $screen ) {
  216. if ( is_string( $screen ) )
  217. $screen = convert_to_screen( $screen );
  218. return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
  219. }
  220. // adds hidden fields with the data for use in the inline editor for posts and pages
  221. /**
  222. * {@internal Missing Short Description}}
  223. *
  224. * @since 2.7.0
  225. *
  226. * @param unknown_type $post
  227. */
  228. function get_inline_data($post) {
  229. $post_type_object = get_post_type_object($post->post_type);
  230. if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) )
  231. return;
  232. $title = esc_textarea( trim( $post->post_title ) );
  233. echo '
  234. <div class="hidden" id="inline_' . $post->ID . '">
  235. <div class="post_title">' . $title . '</div>
  236. <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div>
  237. <div class="post_author">' . $post->post_author . '</div>
  238. <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
  239. <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
  240. <div class="_status">' . esc_html( $post->post_status ) . '</div>
  241. <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
  242. <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
  243. <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
  244. <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
  245. <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
  246. <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
  247. <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
  248. if ( $post_type_object->hierarchical )
  249. echo '<div class="post_parent">' . $post->post_parent . '</div>';
  250. if ( $post->post_type == 'page' )
  251. echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
  252. if ( $post_type_object->hierarchical )
  253. echo '<div class="menu_order">' . $post->menu_order . '</div>';
  254. $taxonomy_names = get_object_taxonomies( $post->post_type );
  255. foreach ( $taxonomy_names as $taxonomy_name) {
  256. $taxonomy = get_taxonomy( $taxonomy_name );
  257. if ( $taxonomy->hierarchical && $taxonomy->show_ui )
  258. echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
  259. elseif ( $taxonomy->show_ui )
  260. echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
  261. }
  262. if ( !$post_type_object->hierarchical )
  263. echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
  264. echo '</div>';
  265. }
  266. /**
  267. * {@internal Missing Short Description}}
  268. *
  269. * @since 2.7.0
  270. *
  271. * @param unknown_type $position
  272. * @param unknown_type $checkbox
  273. * @param unknown_type $mode
  274. */
  275. function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
  276. // allow plugin to replace the popup content
  277. $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
  278. if ( ! empty($content) ) {
  279. echo $content;
  280. return;
  281. }
  282. if ( $mode == 'single' ) {
  283. $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
  284. } else {
  285. $wp_list_table = _get_list_table('WP_Comments_List_Table');
  286. }
  287. ?>
  288. <form method="get" action="">
  289. <?php if ( $table_row ) : ?>
  290. <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
  291. <?php else : ?>
  292. <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
  293. <?php endif; ?>
  294. <div id="replyhead" style="display:none;"><?php _e('Reply to Comment'); ?></div>
  295. <div id="edithead" style="display:none;">
  296. <div class="inside">
  297. <label for="author"><?php _e('Name') ?></label>
  298. <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
  299. </div>
  300. <div class="inside">
  301. <label for="author-email"><?php _e('E-mail') ?></label>
  302. <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
  303. </div>
  304. <div class="inside">
  305. <label for="author-url"><?php _e('URL') ?></label>
  306. <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
  307. </div>
  308. <div style="clear:both;"></div>
  309. </div>
  310. <div id="replycontainer"><textarea rows="8" cols="40" name="replycontent" tabindex="104" id="replycontent"></textarea></div>
  311. <p id="replysubmit" class="submit">
  312. <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
  313. <a href="#comments-form" class="save button-primary alignright" tabindex="104">
  314. <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
  315. <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
  316. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  317. <span class="error" style="display:none;"></span>
  318. <br class="clear" />
  319. </p>
  320. <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
  321. <input type="hidden" name="action" id="action" value="" />
  322. <input type="hidden" name="comment_ID" id="comment_ID" value="" />
  323. <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
  324. <input type="hidden" name="status" id="status" value="" />
  325. <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
  326. <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
  327. <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
  328. <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); ?>
  329. <?php wp_comment_form_unfiltered_html_nonce(); ?>
  330. <?php if ( $table_row ) : ?>
  331. </td></tr></tbody></table>
  332. <?php else : ?>
  333. </div></div>
  334. <?php endif; ?>
  335. </form>
  336. <?php
  337. }
  338. /**
  339. * Output 'undo move to trash' text for comments
  340. *
  341. * @since 2.9.0
  342. */
  343. function wp_comment_trashnotice() {
  344. ?>
  345. <div class="hidden" id="trash-undo-holder">
  346. <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
  347. </div>
  348. <div class="hidden" id="spam-undo-holder">
  349. <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
  350. </div>
  351. <?php
  352. }
  353. /**
  354. * {@internal Missing Short Description}}
  355. *
  356. * @since 1.2.0
  357. *
  358. * @param unknown_type $meta
  359. */
  360. function list_meta( $meta ) {
  361. // Exit if no meta
  362. if ( ! $meta ) {
  363. echo '
  364. <table id="list-table" style="display: none;">
  365. <thead>
  366. <tr>
  367. <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
  368. <th>' . __( 'Value' ) . '</th>
  369. </tr>
  370. </thead>
  371. <tbody id="the-list" class="list:meta">
  372. <tr><td></td></tr>
  373. </tbody>
  374. </table>'; //TBODY needed for list-manipulation JS
  375. return;
  376. }
  377. $count = 0;
  378. ?>
  379. <table id="list-table">
  380. <thead>
  381. <tr>
  382. <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
  383. <th><?php _e( 'Value' ) ?></th>
  384. </tr>
  385. </thead>
  386. <tbody id='the-list' class='list:meta'>
  387. <?php
  388. foreach ( $meta as $entry )
  389. echo _list_meta_row( $entry, $count );
  390. ?>
  391. </tbody>
  392. </table>
  393. <?php
  394. }
  395. /**
  396. * {@internal Missing Short Description}}
  397. *
  398. * @since 2.5.0
  399. *
  400. * @param unknown_type $entry
  401. * @param unknown_type $count
  402. * @return unknown
  403. */
  404. function _list_meta_row( $entry, &$count ) {
  405. static $update_nonce = false;
  406. if ( is_protected_meta( $entry['meta_key'] ) )
  407. return;
  408. if ( !$update_nonce )
  409. $update_nonce = wp_create_nonce( 'add-meta' );
  410. $r = '';
  411. ++ $count;
  412. if ( $count % 2 )
  413. $style = 'alternate';
  414. else
  415. $style = '';
  416. if ('_' == $entry['meta_key'] { 0 } )
  417. $style .= ' hidden';
  418. if ( is_serialized( $entry['meta_value'] ) ) {
  419. if ( is_serialized_string( $entry['meta_value'] ) ) {
  420. // this is a serialized string, so we should display it
  421. $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
  422. } else {
  423. // this is a serialized array/object so we should NOT display it
  424. --$count;
  425. return;
  426. }
  427. }
  428. $entry['meta_key'] = esc_attr($entry['meta_key']);
  429. $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
  430. $entry['meta_id'] = (int) $entry['meta_id'];
  431. $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
  432. $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
  433. $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta[{$entry['meta_id']}][key]'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' />";
  434. $r .= "\n\t\t<div class='submit'>";
  435. $r .= get_submit_button( __( 'Delete' ), "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta", "deletemeta[{$entry['meta_id']}]", false, array( 'tabindex' => '6' ) );
  436. $r .= "\n\t\t";
  437. $r .= get_submit_button( __( 'Update' ), "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta" , 'updatemeta', false, array( 'tabindex' => '6' ) );
  438. $r .= "</div>";
  439. $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
  440. $r .= "</td>";
  441. $r .= "\n\t\t<td><label class='screen-reader-text' for='meta[{$entry['meta_id']}][value]'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
  442. return $r;
  443. }
  444. /**
  445. * {@internal Missing Short Description}}
  446. *
  447. * @since 1.2.0
  448. */
  449. function meta_form() {
  450. global $wpdb;
  451. $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
  452. $keys = $wpdb->get_col( "
  453. SELECT meta_key
  454. FROM $wpdb->postmeta
  455. GROUP BY meta_key
  456. HAVING meta_key NOT LIKE '\_%'
  457. ORDER BY meta_key
  458. LIMIT $limit" );
  459. if ( $keys )
  460. natcasesort($keys);
  461. ?>
  462. <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
  463. <table id="newmeta">
  464. <thead>
  465. <tr>
  466. <th class="left"><label for="metakeyselect"><?php _ex( 'Name', 'meta name' ) ?></label></th>
  467. <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
  468. </tr>
  469. </thead>
  470. <tbody>
  471. <tr>
  472. <td id="newmetaleft" class="left">
  473. <?php if ( $keys ) { ?>
  474. <select id="metakeyselect" name="metakeyselect" tabindex="7">
  475. <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
  476. <?php
  477. foreach ( $keys as $key ) {
  478. echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
  479. }
  480. ?>
  481. </select>
  482. <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
  483. <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
  484. <span id="enternew"><?php _e('Enter new'); ?></span>
  485. <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
  486. <?php } else { ?>
  487. <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
  488. <?php } ?>
  489. </td>
  490. <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
  491. </tr>
  492. <tr><td colspan="2" class="submit">
  493. <?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'addmetasub', 'tabindex' => '9' ) ); ?>
  494. <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
  495. </td></tr>
  496. </tbody>
  497. </table>
  498. <?php
  499. }
  500. /**
  501. * {@internal Missing Short Description}}
  502. *
  503. * @since 0.71
  504. *
  505. * @param unknown_type $edit
  506. * @param unknown_type $for_post
  507. * @param unknown_type $tab_index
  508. * @param unknown_type $multi
  509. */
  510. function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
  511. global $wp_locale, $post, $comment;
  512. if ( $for_post )
  513. $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
  514. $tab_index_attribute = '';
  515. if ( (int) $tab_index > 0 )
  516. $tab_index_attribute = " tabindex=\"$tab_index\"";
  517. // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
  518. $time_adj = current_time('timestamp');
  519. $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
  520. $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
  521. $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
  522. $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
  523. $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
  524. $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
  525. $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
  526. $cur_jj = gmdate( 'd', $time_adj );
  527. $cur_mm = gmdate( 'm', $time_adj );
  528. $cur_aa = gmdate( 'Y', $time_adj );
  529. $cur_hh = gmdate( 'H', $time_adj );
  530. $cur_mn = gmdate( 'i', $time_adj );
  531. $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
  532. for ( $i = 1; $i < 13; $i = $i +1 ) {
  533. $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
  534. if ( $i == $mm )
  535. $month .= ' selected="selected"';
  536. $month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
  537. }
  538. $month .= '</select>';
  539. $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  540. $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
  541. $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  542. $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  543. echo '<div class="timestamp-wrap">';
  544. /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
  545. printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
  546. echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
  547. if ( $multi ) return;
  548. echo "\n\n";
  549. foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
  550. echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
  551. $cur_timeunit = 'cur_' . $timeunit;
  552. echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
  553. }
  554. ?>
  555. <p>
  556. <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
  557. <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
  558. </p>
  559. <?php
  560. }
  561. /**
  562. * {@internal Missing Short Description}}
  563. *
  564. * @since 1.5.0
  565. *
  566. * @param unknown_type $default
  567. */
  568. function page_template_dropdown( $default = '' ) {
  569. $templates = get_page_templates();
  570. ksort( $templates );
  571. foreach (array_keys( $templates ) as $template )
  572. : if ( $default == $templates[$template] )
  573. $selected = " selected='selected'";
  574. else
  575. $selected = '';
  576. echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
  577. endforeach;
  578. }
  579. /**
  580. * {@internal Missing Short Description}}
  581. *
  582. * @since 1.5.0
  583. *
  584. * @param unknown_type $default
  585. * @param unknown_type $parent
  586. * @param unknown_type $level
  587. * @return unknown
  588. */
  589. function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
  590. global $wpdb, $post_ID;
  591. $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
  592. if ( $items ) {
  593. foreach ( $items as $item ) {
  594. // A page cannot be its own parent.
  595. if (!empty ( $post_ID ) ) {
  596. if ( $item->ID == $post_ID ) {
  597. continue;
  598. }
  599. }
  600. $pad = str_repeat( '&nbsp;', $level * 3 );
  601. if ( $item->ID == $default)
  602. $current = ' selected="selected"';
  603. else
  604. $current = '';
  605. echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
  606. parent_dropdown( $default, $item->ID, $level +1 );
  607. }
  608. } else {
  609. return false;
  610. }
  611. }
  612. /**
  613. * {@internal Missing Short Description}}
  614. *
  615. * @since 2.0.0
  616. *
  617. * @param unknown_type $id
  618. * @return unknown
  619. */
  620. function the_attachment_links( $id = false ) {
  621. $id = (int) $id;
  622. $post = & get_post( $id );
  623. if ( $post->post_type != 'attachment' )
  624. return false;
  625. $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
  626. $attachment_data = wp_get_attachment_metadata( $id );
  627. $thumb = isset( $attachment_data['thumb'] );
  628. ?>
  629. <form id="the-attachment-links">
  630. <table>
  631. <col />
  632. <col class="widefat" />
  633. <tr>
  634. <th scope="row"><?php _e( 'URL' ) ?></th>
  635. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo esc_textarea( wp_get_attachment_url() ); ?></textarea></td>
  636. </tr>
  637. <?php if ( $icon ) : ?>
  638. <tr>
  639. <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
  640. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
  641. </tr>
  642. <tr>
  643. <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
  644. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
  645. </tr>
  646. <?php else : ?>
  647. <tr>
  648. <th scope="row"><?php _e( 'Link to file' ) ?></th>
  649. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td>
  650. </tr>
  651. <tr>
  652. <th scope="row"><?php _e( 'Link to page' ) ?></th>
  653. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
  654. </tr>
  655. <?php endif; ?>
  656. </table>
  657. </form>
  658. <?php
  659. }
  660. /**
  661. * Print out <option> html elements for role selectors
  662. *
  663. * @since 2.1.0
  664. *
  665. * @param string $selected slug for the role that should be already selected
  666. */
  667. function wp_dropdown_roles( $selected = false ) {
  668. $p = '';
  669. $r = '';
  670. $editable_roles = get_editable_roles();
  671. foreach ( $editable_roles as $role => $details ) {
  672. $name = translate_user_role($details['name'] );
  673. if ( $selected == $role ) // preselect specified role
  674. $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
  675. else
  676. $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
  677. }
  678. echo $p . $r;
  679. }
  680. /**
  681. * {@internal Missing Short Description}}
  682. *
  683. * @since 2.3.0
  684. *
  685. * @param unknown_type $size
  686. * @return unknown
  687. */
  688. function wp_convert_hr_to_bytes( $size ) {
  689. $size = strtolower($size);
  690. $bytes = (int) $size;
  691. if ( strpos($size, 'k') !== false )
  692. $bytes = intval($size) * 1024;
  693. elseif ( strpos($size, 'm') !== false )
  694. $bytes = intval($size) * 1024 * 1024;
  695. elseif ( strpos($size, 'g') !== false )
  696. $bytes = intval($size) * 1024 * 1024 * 1024;
  697. return $bytes;
  698. }
  699. /**
  700. * {@internal Missing Short Description}}
  701. *
  702. * @since 2.3.0
  703. *
  704. * @param unknown_type $bytes
  705. * @return unknown
  706. */
  707. function wp_convert_bytes_to_hr( $bytes ) {
  708. $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
  709. $log = log( $bytes, 1024 );
  710. $power = (int) $log;
  711. $size = pow(1024, $log - $power);
  712. return $size . $units[$power];
  713. }
  714. /**
  715. * {@internal Missing Short Description}}
  716. *
  717. * @since 2.5.0
  718. *
  719. * @return unknown
  720. */
  721. function wp_max_upload_size() {
  722. $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
  723. $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
  724. $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
  725. return $bytes;
  726. }
  727. /**
  728. * Outputs the form used by the importers to accept the data to be imported
  729. *
  730. * @since 2.0.0
  731. *
  732. * @param string $action The action attribute for the form.
  733. */
  734. function wp_import_upload_form( $action ) {
  735. $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
  736. $size = wp_convert_bytes_to_hr( $bytes );
  737. $upload_dir = wp_upload_dir();
  738. if ( ! empty( $upload_dir['error'] ) ) :
  739. ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
  740. <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
  741. else :
  742. ?>
  743. <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
  744. <p>
  745. <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
  746. <input type="file" id="upload" name="import" size="25" />
  747. <input type="hidden" name="action" value="save" />
  748. <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
  749. </p>
  750. <?php submit_button( __('Upload file and import'), 'button' ); ?>
  751. </form>
  752. <?php
  753. endif;
  754. }
  755. /**
  756. * Add a meta box to an edit form.
  757. *
  758. * @since 2.5.0
  759. *
  760. * @param string $id String for use in the 'id' attribute of tags.
  761. * @param string $title Title of the meta box.
  762. * @param string $callback Function that fills the box with the desired content. The function should echo its output.
  763. * @param string $page The type of edit page on which to show the box (post, page, link).
  764. * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
  765. * @param string $priority The priority within the context where the boxes should show ('high', 'low').
  766. */
  767. function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
  768. global $wp_meta_boxes;
  769. if ( !isset($wp_meta_boxes) )
  770. $wp_meta_boxes = array();
  771. if ( !isset($wp_meta_boxes[$page]) )
  772. $wp_meta_boxes[$page] = array();
  773. if ( !isset($wp_meta_boxes[$page][$context]) )
  774. $wp_meta_boxes[$page][$context] = array();
  775. foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
  776. foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
  777. if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
  778. continue;
  779. // If a core box was previously added or removed by a plugin, don't add.
  780. if ( 'core' == $priority ) {
  781. // If core box previously deleted, don't add
  782. if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
  783. return;
  784. // If box was added with default priority, give it core priority to maintain sort order
  785. if ( 'default' == $a_priority ) {
  786. $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
  787. unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
  788. }
  789. return;
  790. }
  791. // If no priority given and id already present, use existing priority
  792. if ( empty($priority) ) {
  793. $priority = $a_priority;
  794. // else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority.
  795. } elseif ( 'sorted' == $priority ) {
  796. $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
  797. $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
  798. $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
  799. }
  800. // An id can be in only one priority and one context
  801. if ( $priority != $a_priority || $context != $a_context )
  802. unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
  803. }
  804. }
  805. if ( empty($priority) )
  806. $priority = 'low';
  807. if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
  808. $wp_meta_boxes[$page][$context][$priority] = array();
  809. $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
  810. }
  811. /**
  812. * Meta-Box template function
  813. *
  814. * @since 2.5.0
  815. *
  816. * @param string $page page identifier, also known as screen identifier
  817. * @param string $context box context
  818. * @param mixed $object gets passed to the box callback function as first parameter
  819. * @return int number of meta_boxes
  820. */
  821. function do_meta_boxes($page, $context, $object) {
  822. global $wp_meta_boxes;
  823. static $already_sorted = false;
  824. $hidden = get_hidden_meta_boxes($page);
  825. printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
  826. $i = 0;
  827. do {
  828. // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
  829. if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
  830. foreach ( $sorted as $box_context => $ids ) {
  831. foreach ( explode(',', $ids ) as $id ) {
  832. if ( $id && 'dashboard_browser_nag' !== $id )
  833. add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
  834. }
  835. }
  836. }
  837. $already_sorted = true;
  838. if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
  839. break;
  840. foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
  841. if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
  842. foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
  843. if ( false == $box || ! $box['title'] )
  844. continue;
  845. $i++;
  846. $style = '';
  847. $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
  848. echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
  849. if ( 'dashboard_browser_nag' != $box['id'] )
  850. echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
  851. echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
  852. echo '<div class="inside">' . "\n";
  853. call_user_func($box['callback'], $object, $box);
  854. echo "</div>\n";
  855. echo "</div>\n";
  856. }
  857. }
  858. }
  859. } while(0);
  860. echo "</div>";
  861. return $i;
  862. }
  863. /**
  864. * Remove a meta box from an edit form.
  865. *
  866. * @since 2.6.0
  867. *
  868. * @param string $id String for use in the 'id' attribute of tags.
  869. * @param string $page The type of edit page on which to show the box (post, page, link).
  870. * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
  871. */
  872. function remove_meta_box($id, $page, $context) {
  873. global $wp_meta_boxes;
  874. if ( !isset($wp_meta_boxes) )
  875. $wp_meta_boxes = array();
  876. if ( !isset($wp_meta_boxes[$page]) )
  877. $wp_meta_boxes[$page] = array();
  878. if ( !isset($wp_meta_boxes[$page][$context]) )
  879. $wp_meta_boxes[$page][$context] = array();
  880. foreach ( array('high', 'core', 'default', 'low') as $priority )
  881. $wp_meta_boxes[$page][$context][$priority][$id] = false;
  882. }
  883. /**
  884. * {@internal Missing Short Description}}
  885. *
  886. * @since 2.7.0
  887. *
  888. * @param unknown_type $screen
  889. */
  890. function meta_box_prefs($screen) {
  891. global $wp_meta_boxes;
  892. if ( is_string($screen) )
  893. $screen = convert_to_screen($screen);
  894. if ( empty($wp_meta_boxes[$screen->id]) )
  895. return;
  896. $hidden = get_hidden_meta_boxes($screen);
  897. foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
  898. foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
  899. foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
  900. if ( false == $box || ! $box['title'] )
  901. continue;
  902. // Submit box cannot be hidden
  903. if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
  904. continue;
  905. $box_id = $box['id'];
  906. echo '<label for="' . $box_id . '-hide">';
  907. echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
  908. echo "{$box['title']}</label>\n";
  909. }
  910. }
  911. }
  912. }
  913. /**
  914. * Get Hidden Meta Boxes
  915. *
  916. * @since 2.7.0
  917. *
  918. * @param string|object $screen Screen identifier
  919. * @return array Hidden Meta Boxes
  920. */
  921. function get_hidden_meta_boxes( $screen ) {
  922. if ( is_string( $screen ) )
  923. $screen = convert_to_screen( $screen );
  924. $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
  925. // Hide slug boxes by default
  926. if ( !is_array( $hidden ) ) {
  927. if ( 'post' == $screen->base || 'page' == $screen->base )
  928. $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
  929. else
  930. $hidden = array( 'slugdiv' );
  931. $hidden = apply_filters('default_hidden_meta_boxes', $hidden, $screen);
  932. }
  933. return $hidden;
  934. }
  935. /**
  936. * Add a new section to a settings page.
  937. *
  938. * Part of the Settings API. Use this to define new settings sections for an admin page.
  939. * Show settings sections in your admin page callback function with do_settings_sections().
  940. * Add settings fields to your section with add_settings_field()
  941. *
  942. * The $callback argument should be the name of a function that echoes out any
  943. * content you want to show at the top of the settings section before the actual
  944. * fields. It can output nothing if you want.
  945. *
  946. * @since 2.7.0
  947. *
  948. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  949. *
  950. * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
  951. * @param string $title Formatted title of the section. Shown as the heading for the section.
  952. * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
  953. * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
  954. */
  955. function add_settings_section($id, $title, $callback, $page) {
  956. global $wp_settings_sections;
  957. if ( 'misc' == $page ) {
  958. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  959. $page = 'general';
  960. }
  961. if ( !isset($wp_settings_sections) )
  962. $wp_settings_sections = array();
  963. if ( !isset($wp_settings_sections[$page]) )
  964. $wp_settings_sections[$page] = array();
  965. if ( !isset($wp_settings_sections[$page][$id]) )
  966. $wp_settings_sections[$page][$id] = array();
  967. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
  968. }
  969. /**
  970. * Add a new field to a section of a settings page
  971. *
  972. * Part of the Settings API. Use this to define a settings field that will show
  973. * as part of a settings section inside a settings page. The fields are shown using
  974. * do_settings_fields() in do_settings-sections()
  975. *
  976. * The $callback argument should be the name of a function that echoes out the
  977. * html input tags for this setting field. Use get_option() to retrive existing
  978. * values to show.
  979. *
  980. * @since 2.7.0
  981. *
  982. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  983. *
  984. * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
  985. * @param string $title Formatted title of the field. Shown as the label for the field during output.
  986. * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
  987. * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
  988. * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...).
  989. * @param array $args Additional arguments
  990. */
  991. function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
  992. global $wp_settings_fields;
  993. if ( 'misc' == $page ) {
  994. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  995. $page = 'general';
  996. }
  997. if ( !isset($wp_settings_fields) )
  998. $wp_settings_fields = array();
  999. if ( !isset($wp_settings_fields[$page]) )
  1000. $wp_settings_fields[$page] = array();
  1001. if ( !isset($wp_settings_fields[$page][$section]) )
  1002. $wp_settings_fields[$page][$section] = array();
  1003. $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
  1004. }
  1005. /**
  1006. * Prints out all settings sections added to a particular settings page
  1007. *
  1008. * Part of the Settings API. Use this in a settings page callback function
  1009. * to output all the sections and fields that were added to that $page with
  1010. * add_settings_section() and add_settings_field()
  1011. *
  1012. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  1013. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  1014. * @since 2.7.0
  1015. *
  1016. * @param string $page The slug name of the page whos settings sections you want to output
  1017. */
  1018. function do_settings_sections($page) {
  1019. global $wp_settings_sections, $wp_settings_fields;
  1020. if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
  1021. return;
  1022. foreach ( (array) $wp_settings_sections[$page] as $section ) {
  1023. echo "<h3>{$section['title']}</h3>\n";
  1024. call_user_func($section['callback'], $section);
  1025. if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
  1026. continue;
  1027. echo '<table class="form-table">';
  1028. do_settings_fields($page, $section['id']);
  1029. echo '</table>';
  1030. }
  1031. }
  1032. /**
  1033. * Print out the settings fields for a particular settings section
  1034. *
  1035. * Part of the Settings API. Use this in a settings page to output
  1036. * a specific section. Should normally be called by do_settings_sections()
  1037. * rather than directly.
  1038. *
  1039. * @global $wp_settings_fields Storage array of settings fields and their pages/sections
  1040. *
  1041. * @since 2.7.0
  1042. *
  1043. * @param string $page Slug title of the admin page who's settings fields you want to show.
  1044. * @param section $section Slug title of the settings section who's fields you want to show.
  1045. */
  1046. function do_settings_fields($page, $section) {
  1047. global $wp_settings_fields;
  1048. if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
  1049. return;
  1050. foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
  1051. echo '<tr valign="top">';
  1052. if ( !empty($field['args']['label_for']) )
  1053. echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
  1054. else
  1055. echo '<th scope="row">' . $field['title'] . '</th>';
  1056. echo '<td>';
  1057. call_user_func($field['callback'], $field['args']);
  1058. echo '</td>';
  1059. echo '</tr>';
  1060. }
  1061. }
  1062. /**
  1063. * Register a settings error to be displayed to the user
  1064. *
  1065. * Part of the Settings API. Use this to show messages to users about settings validation
  1066. * problems, missing settings or anything else.
  1067. *
  1068. * Settings errors should be added inside the $sanitize_callback function defined in
  1069. * register_setting() for a given setting to give feedback about the submission.
  1070. *
  1071. * By default messages will show immediately after the submission that generated the error.
  1072. * Additional calls to settings_errors() can be used to show errors even when the settings
  1073. * page is first accessed.
  1074. *
  1075. * @since 3.0.0
  1076. *
  1077. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  1078. *
  1079. * @param string $setting Slug title of the setting to which this error applies
  1080. * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
  1081. * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
  1082. * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
  1083. */
  1084. function add_settings_error( $setting, $code, $message, $type = 'error' ) {
  1085. global $wp_settings_errors;
  1086. if ( !isset($wp_settings_errors) )
  1087. $wp_settings_errors = array();
  1088. $new_error = array(
  1089. 'setting' => $setting,
  1090. 'code' => $code,
  1091. 'message' => $message,
  1092. 'type' => $type
  1093. );
  1094. $wp_settings_errors[] = $new_error;
  1095. }
  1096. /**
  1097. * Fetch settings errors registered by add_settings_error()
  1098. *
  1099. * Checks the $wp_settings_errors array for any errors declared during the current
  1100. * pageload and returns them.
  1101. *
  1102. * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
  1103. * to the 'settings_errors' transient then those errors will be returned instead. This
  1104. * is used to pass errors back across pageloads.
  1105. *
  1106. * Use the $sanitize argument to manually re-sanitize the option before returning errors.
  1107. * This is useful if you have errors or notices you want to show even when the user
  1108. * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
  1109. *
  1110. * @since 3.0.0
  1111. *
  1112. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  1113. *
  1114. * @param string $setting Optional slug title of a specific setting who's errors you want.
  1115. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
  1116. * @return array Array of settings errors
  1117. */
  1118. function get_settings_errors( $setting = '', $sanitize = FALSE ) {
  1119. global $wp_settings_errors;
  1120. // If $sanitize is true, manually re-run the sanitizisation for this option
  1121. // This allows the $sanitize_callback from register_setting() to run, adding
  1122. // any settings errors you want to show by default.
  1123. if ( $sanitize )
  1124. sanitize_option( $setting, get_option($setting));
  1125. // If settings were passed back from options.php then use them
  1126. // Ignore transients if $sanitize is true, we dont' want the old values anyway
  1127. if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) {
  1128. $settings_errors = get_transient('settings_errors');
  1129. delete_transient('settings_errors');
  1130. // Otherwise check global in case validation has been run on this pageload
  1131. } elseif ( count( $wp_settings_errors ) ) {
  1132. $settings_errors = $wp_settings_errors;
  1133. } else {
  1134. return;
  1135. }
  1136. // Filter the results to those of a specific setting if one was set
  1137. if ( $setting ) {
  1138. foreach ( (array) $settings_errors as $key => $details )
  1139. if ( $setting != $details['setting'] )
  1140. unset( $settings_errors[$key] );
  1141. }
  1142. return $settings_errors;
  1143. }
  1144. /**
  1145. * Display settings errors registered by add_settings_error()
  1146. *
  1147. * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
  1148. *
  1149. * This is called automatically after a settings page based on the Settings API is submitted.
  1150. * Errors should be added during the validation callback function for a setting defined in register_setting()
  1151. *
  1152. * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
  1153. * on its current value.
  1154. *
  1155. * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
  1156. * if the user has already saved new values it will be hidden to avoid repeating messages already
  1157. * shown in the default error reporting after submission. This is useful to show general errors like missing
  1158. * settings when the user arrives at the settings page.
  1159. *
  1160. * @since 3.0.0
  1161. *
  1162. * @param string $setting Optional slug title of a specific setting who's errors you want.
  1163. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
  1164. * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
  1165. */
  1166. function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
  1167. if ($hide_on_update AND $_GET['settings-updated']) return;
  1168. $settings_errors = get_settings_errors( $setting, $sanitize );
  1169. if ( !is_array($settings_errors) ) return;
  1170. $output = '';
  1171. foreach ( $settings_errors as $key => $details ) {
  1172. $css_id = 'setting-error-' . $details['code'];
  1173. $css_class = $details['type'] . ' settings-error';
  1174. $output .= "<div id='$css_id' class='$css_class'> \n";
  1175. $output .= "<p><strong>{$details['message']}</strong></p>";
  1176. $output .= "</div> \n";
  1177. }
  1178. echo $output;
  1179. }
  1180. /**
  1181. * {@internal Missing Short Description}}
  1182. *
  1183. * @since 2.7.0
  1184. *
  1185. * @param unknown_type $found_action
  1186. */
  1187. function find_posts_div($found_action = '') {
  1188. ?>
  1189. <div id="find-posts" class="find-box" style="display:none;">
  1190. <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
  1191. <div class="find-box-inside">
  1192. <div class="find-box-search">
  1193. <?php if ( $found_action ) { ?>
  1194. <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
  1195. <?php } ?>
  1196. <input type="hidden" name="affected" id="affected" value="" />
  1197. <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
  1198. <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
  1199. <input type="text" id="find-posts-input" name="ps" value="" />
  1200. <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
  1201. <?php
  1202. $post_types = get_post_types( array('public' => true), 'objects' );
  1203. foreach ( $post_types as $post ) {
  1204. if ( 'attachment' == $post->name )
  1205. continue;
  1206. ?>
  1207. <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'); ?> />
  1208. <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
  1209. <?php
  1210. } ?>
  1211. </div>
  1212. <div id="find-posts-response"></div>
  1213. </div>
  1214. <div class="find-box-buttons">
  1215. <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
  1216. <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
  1217. </div>
  1218. </div>
  1219. <?php
  1220. }
  1221. /**
  1222. * Display the post password.
  1223. *
  1224. * The password is passed through {@link esc_attr()} to ensure that it
  1225. * is safe for placing in an html attribute.
  1226. *
  1227. * @uses attr
  1228. * @since 2.7.0
  1229. */
  1230. function the_post_password() {
  1231. global $post;
  1232. if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
  1233. }
  1234. /**
  1235. * {@internal Missing Short Description}}
  1236. *
  1237. * @since 2.7.0
  1238. */
  1239. function favorite_actions( $screen = null ) {
  1240. $default_action = false;
  1241. if ( is_string($screen) )
  1242. $screen = convert_to_screen($screen);
  1243. if ( $screen->is_user )
  1244. return;
  1245. if ( isset($screen->post_type) ) {
  1246. $post_type_object = get_post_type_object($screen->post_type);
  1247. if ( 'add' != $screen->action )
  1248. $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts));
  1249. else
  1250. $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
  1251. }
  1252. if ( !$default_action ) {
  1253. if ( $screen->is_network ) {
  1254. $default_action = array('sites.php' => array( __('Sites'), 'manage_sites'));
  1255. } else {
  1256. switch ( $screen->id ) {
  1257. case 'upload':
  1258. $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
  1259. break;
  1260. case 'media':
  1261. $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
  1262. break;
  1263. case 'link-manager':
  1264. case 'link':
  1265. if ( 'add' != $screen->action )
  1266. $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
  1267. else
  1268. $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
  1269. break;
  1270. case 'users':
  1271. $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
  1272. break;
  1273. case 'user':
  1274. $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
  1275. break;
  1276. case 'plugins':
  1277. $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
  1278. break;
  1279. case 'plugin-install':
  1280. $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
  1281. break;
  1282. case 'themes':
  1283. $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
  1284. break;
  1285. case 'theme-install':
  1286. $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
  1287. break;
  1288. default:
  1289. $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. if ( !$screen->is_network ) {
  1295. $actions = array(
  1296. 'post-new.php' => array(__('New Post'), 'edit_posts'),
  1297. 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
  1298. 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
  1299. 'media-new.php' => array(__('Upload'), 'upload_files'),
  1300. 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
  1301. );
  1302. } else {
  1303. $actions = array(
  1304. 'sites.php' => array( __('Sites'), 'manage_sites'),
  1305. 'users.php' => array( __('Users'), 'manage_network_users')
  1306. );
  1307. }
  1308. $default_key = array_keys($default_action);
  1309. $default_key = $default_key[0];
  1310. if ( isset($actions[$default_key]) )
  1311. unset($actions[$default_key]);
  1312. $actions = array_merge($default_action, $actions);
  1313. $actions = apply_filters( 'favorite_actions', $actions, $screen );
  1314. $allowed_actions = array();
  1315. foreach ( $actions as $action => $data ) {
  1316. if ( current_user_can($data[1]) )
  1317. $allowed_actions[$action] = $data[0];
  1318. }
  1319. if ( empty($allowed_actions) )
  1320. return;
  1321. $first = array_keys($allowed_actions);
  1322. $first = $first[0];
  1323. echo '<div id="favorite-actions">';
  1324. echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
  1325. echo '<div id="favorite-inside">';
  1326. array_shift($allowed_actions);
  1327. foreach ( $allowed_actions as $action => $label) {
  1328. echo "<div class='favorite-action'><a href='$action'>";
  1329. echo $label;
  1330. echo "</a></div>\n";
  1331. }
  1332. echo "</div></div>\n";
  1333. }
  1334. /**
  1335. * Get the post title.
  1336. *
  1337. * The post title is fetched and if it is blank then a default string is
  1338. * returned.
  1339. *
  1340. * @since 2.7.0
  1341. * @param int $post_id The post id. If not supplied the global $post is used.
  1342. * @return string The post title if set
  1343. */
  1344. function _draft_or_post_title( $post_id = 0 ) {
  1345. $title = get_the_title($post_id);
  1346. if ( empty($title) )
  1347. $title = __('(no title)');
  1348. return $title;
  1349. }
  1350. /**
  1351. * Display the search query.
  1352. *
  1353. * A simple wrapper to display the "s" parameter in a GET URI. This function
  1354. * should only be used when {@link the_search_query()} cannot.
  1355. *
  1356. * @uses attr
  1357. * @since 2.7.0
  1358. *
  1359. */
  1360. function _admin_search_query() {
  1361. echo isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
  1362. }
  1363. /**
  1364. * Generic Iframe header for use with Thickbox
  1365. *
  1366. * @since 2.7.0
  1367. * @param string $title Title of the Iframe page.
  1368. * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
  1369. *
  1370. */
  1371. function iframe_header( $title = '', $limit_styles = false ) {
  1372. show_admin_bar( false );
  1373. global $hook_suffix, $current_screen, $current_user, $admin_body_class, $wp_locale;
  1374. $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
  1375. $admin_body_class .= ' iframe';
  1376. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1377. <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
  1378. <head>
  1379. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
  1380. <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
  1381. <?php
  1382. wp_enqueue_style( 'global' );
  1383. if ( ! $limit_styles )
  1384. wp_enqueue_style( 'wp-admin' );
  1385. wp_enqueue_style( 'colors' );
  1386. ?>
  1387. <script type="text/javascript">
  1388. //<![CDATA[
  1389. addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
  1390. function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
  1391. var userSettings = {
  1392. 'url': '<?php echo SITECOOKIEPATH; ?>',
  1393. 'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>',
  1394. 'time':'<?php echo time() ?>'
  1395. },
  1396. ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
  1397. pagenow = '<?php echo $current_screen->id; ?>',
  1398. typenow = '<?php if ( isset($current_screen->post_type) ) echo $current_screen->post_type; ?>',
  1399. adminpage = '<?php echo $admin_body_class; ?>',
  1400. thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
  1401. decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
  1402. isRtl = <?php echo (int) is_rtl(); ?>;
  1403. //]]>
  1404. </script>
  1405. <?php
  1406. do_action('admin_enqueue_scripts', $hook_suffix);
  1407. do_action("admin_print_styles-$hook_suffix");
  1408. do_action('admin_print_styles');
  1409. do_action("admin_print_scripts-$hook_suffix");
  1410. do_action('admin_print_scripts');
  1411. do_action("admin_head-$hook_suffix");
  1412. do_action('admin_head');
  1413. ?>
  1414. </head>
  1415. <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js <?php echo $admin_body_class; ?>">
  1416. <script type="text/javascript">
  1417. //<![CDATA[
  1418. (function(){
  1419. var c = document.body.className;
  1420. c = c.replace(/no-js/, 'js');
  1421. document.body.className = c;
  1422. })();
  1423. //]]>
  1424. </script>
  1425. <?php
  1426. }
  1427. /**
  1428. * Generic Iframe footer for use with Thickbox
  1429. *
  1430. * @since 2.7.0
  1431. *
  1432. */
  1433. function iframe_footer() {
  1434. //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
  1435. <div class="hidden">
  1436. <?php
  1437. do_action('admin_footer', '');
  1438. do_action('admin_print_footer_scripts'); ?>
  1439. </div>
  1440. <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
  1441. </body>
  1442. </html>
  1443. <?php
  1444. }
  1445. function _post_states($post) {
  1446. $post_states = array();
  1447. if ( isset($_GET['post_status']) )
  1448. $post_status = $_GET['post_status'];
  1449. else
  1450. $post_status = '';
  1451. if ( !empty($post->post_password) )
  1452. $post_states['protected'] = __('Password protected');
  1453. if ( 'private' == $post->post_status && 'private' != $post_status )
  1454. $post_states['private'] = __('Private');
  1455. if ( 'draft' == $post->post_status && 'draft' != $post_status )
  1456. $post_states['draft'] = __('Draft');
  1457. if ( 'pending' == $post->post_status && 'pending' != $post_status )
  1458. /* translators: post state */
  1459. $post_states['pending'] = _x('Pending', 'post state');
  1460. if ( is_sticky($post->ID) )
  1461. $post_states['sticky'] = __('Sticky');
  1462. $post_states = apply_filters( 'display_post_states', $post_states );
  1463. if ( ! empty($post_states) ) {
  1464. $state_count = count($post_states);
  1465. $i = 0;
  1466. echo ' - ';
  1467. foreach ( $post_states as $state ) {
  1468. ++$i;
  1469. ( $i == $state_count ) ? $sep = '' : $sep = ', ';
  1470. echo "<span class='post-state'>$state$sep</span>";
  1471. }
  1472. }
  1473. if ( get_post_format( $post->ID ) )
  1474. echo ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>';
  1475. }
  1476. function _media_states( $post ) {
  1477. $media_states = array();
  1478. $stylesheet = get_option('stylesheet');
  1479. if ( current_theme_supports( 'custom-header') ) {
  1480. $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
  1481. if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
  1482. $media_states[] = __( 'Header Image' );
  1483. }
  1484. if ( current_theme_supports( 'custom-background') ) {
  1485. $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
  1486. if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
  1487. $media_states[] = __( 'Background Image' );
  1488. }
  1489. $media_states = apply_filters( 'display_media_states', $media_states );
  1490. if ( ! empty( $media_states ) ) {
  1491. $state_count = count( $media_states );
  1492. $i = 0;
  1493. echo ' - ';
  1494. foreach ( $media_states as $state ) {
  1495. ++$i;
  1496. ( $i == $state_count ) ? $sep = '' : $sep = ', ';
  1497. echo "<span class='post-state'>$state$sep</span>";
  1498. }
  1499. }
  1500. }
  1501. /**
  1502. * Convert a screen string to a screen object
  1503. *
  1504. * @since 3.0.0
  1505. *
  1506. * @param string $screen The name of the screen
  1507. * @return object An object containing the safe screen name and id
  1508. */
  1509. function convert_to_screen( $screen ) {
  1510. $screen = str_replace( array('.php', '-new', '-add', '-network', '-user' ), '', $screen);
  1511. if ( is_network_admin() )
  1512. $screen .= '-network';
  1513. elseif ( is_user_admin() )
  1514. $screen .= '-user';
  1515. $screen = (string) apply_filters( 'screen_meta_screen', $screen );
  1516. $screen = (object) array('id' => $screen, 'base' => $screen);
  1517. return $screen;
  1518. }
  1519. function screen_meta($screen) {
  1520. global $wp_meta_boxes, $_wp_contextual_help, $wp_list_table, $wp_current_screen_options;
  1521. if ( is_string($screen) )
  1522. $screen = convert_to_screen($screen);
  1523. $columns = get_column_headers( $screen );
  1524. $hidden = get_hidden_columns( $screen );
  1525. $meta_screens = array('index' => 'dashboard');
  1526. if ( isset($meta_screens[$screen->id]) ) {
  1527. $screen->id = $meta_screens[$screen->id];
  1528. $screen->base = $screen->id;
  1529. }
  1530. $show_screen = false;
  1531. if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) )
  1532. $show_screen = true;
  1533. $screen_options = screen_options($screen);
  1534. if ( $screen_options )
  1535. $show_screen = true;
  1536. if ( !isset($_wp_contextual_help) )
  1537. $_wp_contextual_help = array();
  1538. $settings = apply_filters('screen_settings', '', $screen);
  1539. switch ( $screen->id ) {
  1540. case 'widgets':
  1541. $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
  1542. $show_screen = true;
  1543. break;
  1544. }
  1545. if ( ! empty( $settings ) )
  1546. $show_screen = true;
  1547. if ( !empty($wp_current_screen_options) )
  1548. $show_screen = true;
  1549. $show_screen = apply_filters('screen_options_show_screen', $show_screen, $screen);
  1550. ?>
  1551. <div id="screen-meta">
  1552. <?php if ( $show_screen ) : ?>
  1553. <div id="screen-options-wrap" class="hidden">
  1554. <form id="adv-settings" action="" method="post">
  1555. <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
  1556. <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
  1557. <div class="metabox-prefs">
  1558. <?php meta_box_prefs($screen); ?>
  1559. <br class="clear" />
  1560. </div>
  1561. <?php endif;
  1562. if ( ! empty($columns) ) : ?>
  1563. <h5><?php echo ( isset( $columns['_title'] ) ? $columns['_title'] : _x('Show on screen', 'Columns') ) ?></h5>
  1564. <div class="metabox-prefs">
  1565. <?php
  1566. $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname');
  1567. foreach ( $columns as $column => $title ) {
  1568. // Can't hide these for they are special
  1569. if ( in_array( $column, $special ) )
  1570. continue;
  1571. if ( empty( $title ) )
  1572. continue;
  1573. if ( 'comments' == $column )
  1574. $title = __( 'Comments' );
  1575. $id = "$column-hide";
  1576. echo '<label for="' . $id . '">';
  1577. echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
  1578. echo "$title</label>\n";
  1579. }
  1580. ?>
  1581. <br class="clear" />
  1582. </div>
  1583. <?php endif;
  1584. echo screen_layout($screen);
  1585. if ( !empty( $screen_options ) ) {
  1586. ?>
  1587. <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
  1588. <?php
  1589. }
  1590. echo $screen_options;
  1591. echo $settings; ?>
  1592. <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
  1593. </form>
  1594. </div>
  1595. <?php endif; // $show_screen
  1596. $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
  1597. ?>
  1598. <div id="contextual-help-wrap" class="hidden">
  1599. <?php
  1600. $contextual_help = '';
  1601. if ( isset($_wp_contextual_help[$screen->id]) ) {
  1602. $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n";
  1603. } else {
  1604. $contextual_help .= '<div class="metabox-prefs">';
  1605. $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
  1606. $default_help .= '<br />';
  1607. $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
  1608. $contextual_help .= apply_filters('default_contextual_help', $default_help);
  1609. $contextual_help .= "</div>\n";
  1610. }
  1611. echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
  1612. ?>
  1613. </div>
  1614. <div id="screen-meta-links">
  1615. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
  1616. <a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
  1617. </div>
  1618. <?php if ( $show_screen ) { ?>
  1619. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
  1620. <a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
  1621. </div>
  1622. <?php } ?>
  1623. </div>
  1624. </div>
  1625. <?php
  1626. }
  1627. /**
  1628. * Add contextual help text for a page
  1629. *
  1630. * @since 2.7.0
  1631. *
  1632. * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
  1633. * @param string $help Arbitrary help text
  1634. */
  1635. function add_contextual_help($screen, $help) {
  1636. global $_wp_contextual_help;
  1637. if ( is_string($screen) )
  1638. $screen = convert_to_screen($screen);
  1639. if ( !isset($_wp_contextual_help) )
  1640. $_wp_contextual_help = array();
  1641. $_wp_contextual_help[$screen->id] = $help;
  1642. }
  1643. function screen_layout($screen) {
  1644. global $screen_layout_columns, $wp_current_screen_options;
  1645. if ( is_string($screen) )
  1646. $screen = convert_to_screen($screen);
  1647. // Back compat for plugins using the filter instead of add_screen_option()
  1648. $columns = apply_filters('screen_layout_columns', array(), $screen->id, $screen);
  1649. if ( !empty($columns) && isset($columns[$screen->id]) )
  1650. add_screen_option('layout_columns', array('max' => $columns[$screen->id]) );
  1651. if ( !isset($wp_current_screen_options['layout_columns']) ) {
  1652. $screen_layout_columns = 0;
  1653. return '';
  1654. }
  1655. $screen_layout_columns = get_user_option("screen_layout_$screen->id");
  1656. $num = $wp_current_screen_options['layout_columns']['max'];
  1657. if ( ! $screen_layout_columns ) {
  1658. if ( isset($wp_current_screen_options['layout_columns']['default']) )
  1659. $screen_layout_columns = $wp_current_screen_options['layout_columns']['default'];
  1660. else
  1661. $screen_layout_columns = 2;
  1662. }
  1663. $i = 1;
  1664. $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
  1665. while ( $i <= $num ) {
  1666. $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
  1667. ++$i;
  1668. }
  1669. $return .= "</div>\n";
  1670. return $return;
  1671. }
  1672. /**
  1673. * Register and configure an admin screen option
  1674. *
  1675. * @since 3.1.0
  1676. *
  1677. * @param string $option An option name.
  1678. * @param mixed $args Option dependent arguments
  1679. * @return void
  1680. */
  1681. function add_screen_option( $option, $args = array() ) {
  1682. global $wp_current_screen_options;
  1683. if ( !isset($wp_current_screen_options) )
  1684. $wp_current_screen_options = array();
  1685. $wp_current_screen_options[$option] = $args;
  1686. }
  1687. function screen_options($screen) {
  1688. global $wp_current_screen_options;
  1689. if ( is_string($screen) )
  1690. $screen = convert_to_screen($screen);
  1691. if ( !isset($wp_current_screen_options['per_page']) )
  1692. return '';
  1693. $per_page_label = $wp_current_screen_options['per_page']['label'];
  1694. if ( empty($wp_current_screen_options['per_page']['option']) ) {
  1695. $option = str_replace( '-', '_', "{$screen->id}_per_page" );
  1696. } else {
  1697. $option = $wp_current_screen_options['per_page']['option'];
  1698. }
  1699. $per_page = (int) get_user_option( $option );
  1700. if ( empty( $per_page ) || $per_page < 1 ) {
  1701. if ( isset($wp_current_screen_options['per_page']['default']) )
  1702. $per_page = $wp_current_screen_options['per_page']['default'];
  1703. else
  1704. $per_page = 20;
  1705. }
  1706. if ( 'edit_comments_per_page' == $option )
  1707. $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
  1708. elseif ( 'categories_per_page' == $option )
  1709. $per_page = apply_filters( 'edit_categories_per_page', $per_page );
  1710. else
  1711. $per_page = apply_filters( $option, $per_page );
  1712. // Back compat
  1713. if ( isset( $screen->post_type ) )
  1714. $per_page = apply_filters( 'edit_posts_per_page', $per_page, $screen->post_type );
  1715. $return = "<div class='screen-options'>\n";
  1716. if ( !empty($per_page_label) )
  1717. $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n";
  1718. $return .= get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false );
  1719. $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
  1720. $return .= "</div>\n";
  1721. return $return;
  1722. }
  1723. function screen_icon( $screen = '' ) {
  1724. echo get_screen_icon( $screen );
  1725. }
  1726. function get_screen_icon( $screen = '' ) {
  1727. global $current_screen, $typenow;
  1728. if ( empty($screen) )
  1729. $screen = $current_screen;
  1730. elseif ( is_string($screen) )
  1731. $name = $screen;
  1732. $class = 'icon32';
  1733. if ( empty($name) ) {
  1734. if ( !empty($screen->parent_base) )
  1735. $name = $screen->parent_base;
  1736. else
  1737. $name = $screen->base;
  1738. if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
  1739. $name = 'edit-pages';
  1740. $post_type = '';
  1741. if ( isset( $screen->post_type ) )
  1742. $post_type = $screen->post_type;
  1743. elseif ( $current_screen == $screen )
  1744. $post_type = $typenow;
  1745. if ( $post_type )
  1746. $class .= ' ' . sanitize_html_class( 'icon32-posts-' . $post_type );
  1747. }
  1748. return '<div id="icon-' . esc_attr( $name ) . '" class="' . $class . '"><br /></div>';
  1749. }
  1750. /**
  1751. * Test support for compressing JavaScript from PHP
  1752. *
  1753. * Outputs JavaScript that tests if compression from PHP works as expected
  1754. * and sets an option with the result. Has no effect when the current user
  1755. * is not an administrator. To run the test again the option 'can_compress_scripts'
  1756. * has to be deleted.
  1757. *
  1758. * @since 2.8.0
  1759. */
  1760. function compression_test() {
  1761. ?>
  1762. <script type="text/javascript">
  1763. /* <![CDATA[ */
  1764. var testCompression = {
  1765. get : function(test) {
  1766. var x;
  1767. if ( window.XMLHttpRequest ) {
  1768. x = new XMLHttpRequest();
  1769. } else {
  1770. try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
  1771. }
  1772. if (x) {
  1773. x.onreadystatechange = function() {
  1774. var r, h;
  1775. if ( x.readyState == 4 ) {
  1776. r = x.responseText.substr(0, 18);
  1777. h = x.getResponseHeader('Content-Encoding');
  1778. testCompression.check(r, h, test);
  1779. }
  1780. }
  1781. x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
  1782. x.send('');
  1783. }
  1784. },
  1785. check : function(r, h, test) {
  1786. if ( ! r && ! test )
  1787. this.get(1);
  1788. if ( 1 == test ) {
  1789. if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
  1790. this.get('no');
  1791. else
  1792. this.get(2);
  1793. return;
  1794. }
  1795. if ( 2 == test ) {
  1796. if ( '"wpCompressionTest' == r )
  1797. this.get('yes');
  1798. else
  1799. this.get('no');
  1800. }
  1801. }
  1802. };
  1803. testCompression.check();
  1804. /* ]]> */
  1805. </script>
  1806. <?php
  1807. }
  1808. /**
  1809. * Get the current screen object
  1810. *
  1811. * @since 3.1.0
  1812. *
  1813. * @return object Current screen object
  1814. */
  1815. function get_current_screen() {
  1816. global $current_screen;
  1817. if ( !isset($current_screen) )
  1818. return null;
  1819. return $current_screen;
  1820. }
  1821. /**
  1822. * Set the current screen object
  1823. *
  1824. * @since 3.0.0
  1825. *
  1826. * @uses $current_screen
  1827. *
  1828. * @param string $id Screen id, optional.
  1829. */
  1830. function set_current_screen( $id = '' ) {
  1831. global $current_screen, $hook_suffix, $typenow, $taxnow;
  1832. $action = '';
  1833. if ( empty($id) ) {
  1834. $current_screen = $hook_suffix;
  1835. $current_screen = str_replace('.php', '', $current_screen);
  1836. if ( preg_match('/-add|-new$/', $current_screen) )
  1837. $action = 'add';
  1838. $current_screen = str_replace('-new', '', $current_screen);
  1839. $current_screen = str_replace('-add', '', $current_screen);
  1840. $current_screen = array('id' => $current_screen, 'base' => $current_screen);
  1841. } else {
  1842. $id = sanitize_key($id);
  1843. if ( false !== strpos($id, '-') ) {
  1844. list( $id, $typenow ) = explode('-', $id, 2);
  1845. if ( taxonomy_exists( $typenow ) ) {
  1846. $id = 'edit-tags';
  1847. $taxnow = $typenow;
  1848. $typenow = '';
  1849. }
  1850. }
  1851. $current_screen = array('id' => $id, 'base' => $id);
  1852. }
  1853. $current_screen = (object) $current_screen;
  1854. $current_screen->action = $action;
  1855. // Map index to dashboard
  1856. if ( 'index' == $current_screen->base )
  1857. $current_screen->base = 'dashboard';
  1858. if ( 'index' == $current_screen->id )
  1859. $current_screen->id = 'dashboard';
  1860. if ( 'edit' == $current_screen->id ) {
  1861. if ( empty($typenow) )
  1862. $typenow = 'post';
  1863. $current_screen->id .= '-' . $typenow;
  1864. $current_screen->post_type = $typenow;
  1865. } elseif ( 'post' == $current_screen->id ) {
  1866. if ( empty($typenow) )
  1867. $typenow = 'post';
  1868. $current_screen->id = $typenow;
  1869. $current_screen->post_type = $typenow;
  1870. } elseif ( 'edit-tags' == $current_screen->id ) {
  1871. if ( empty($taxnow) )
  1872. $taxnow = 'post_tag';
  1873. $current_screen->id = 'edit-' . $taxnow;
  1874. $current_screen->taxonomy = $taxnow;
  1875. }
  1876. $current_screen->is_network = is_network_admin();
  1877. $current_screen->is_user = is_user_admin();
  1878. if ( $current_screen->is_network ) {
  1879. $current_screen->base .= '-network';
  1880. $current_screen->id .= '-network';
  1881. } elseif ( $current_screen->is_user ) {
  1882. $current_screen->base .= '-user';
  1883. $current_screen->id .= '-user';
  1884. }
  1885. $current_screen = apply_filters('current_screen', $current_screen);
  1886. }
  1887. /**
  1888. * Echos a submit button, with provided text and appropriate class
  1889. *
  1890. * @since 3.1.0
  1891. *
  1892. * @param string $text The text of the button (defaults to 'Save Changes')
  1893. * @param string $type The type of button. One of: primary, secondary, delete
  1894. * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
  1895. * is given in $other_attributes below, $name will be used as the button's id.
  1896. * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
  1897. * false otherwise. Defaults to true
  1898. * @param array|string $other_attributes Other attributes that should be output with the button,
  1899. * mapping attributes to their values, such as array( 'tabindex' => '1' ).
  1900. * These attributes will be ouput as attribute="value", such as tabindex="1".
  1901. * Defaults to no other attributes. Other attributes can also be provided as a
  1902. * string such as 'tabindex="1"', though the array format is typically cleaner.
  1903. */
  1904. function submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
  1905. echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
  1906. }
  1907. /**
  1908. * Returns a submit button, with provided text and appropriate class
  1909. *
  1910. * @since 3.1.0
  1911. *
  1912. * @param string $text The text of the button (defaults to 'Save Changes')
  1913. * @param string $type The type of button. One of: primary, secondary, delete
  1914. * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
  1915. * is given in $other_attributes below, $name will be used as the button's id.
  1916. * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
  1917. * false otherwise. Defaults to true
  1918. * @param array|string $other_attributes Other attributes that should be output with the button,
  1919. * mapping attributes to their values, such as array( 'tabindex' => '1' ).
  1920. * These attributes will be ouput as attribute="value", such as tabindex="1".
  1921. * Defaults to no other attributes. Other attributes can also be provided as a
  1922. * string such as 'tabindex="1"', though the array format is typically cleaner.
  1923. */
  1924. function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
  1925. switch ( $type ) :
  1926. case 'primary' :
  1927. case 'secondary' :
  1928. $class = 'button-' . $type;
  1929. break;
  1930. case 'delete' :
  1931. $class = 'button-secondary delete';
  1932. break;
  1933. default :
  1934. $class = $type; // Custom cases can just pass in the classes they want to be used
  1935. endswitch;
  1936. $text = ( NULL == $text ) ? __( 'Save Changes' ) : $text;
  1937. // Default the id attribute to $name unless an id was specifically provided in $other_attributes
  1938. $id = $name;
  1939. if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
  1940. $id = $other_attributes['id'];
  1941. unset( $other_attributes['id'] );
  1942. }
  1943. $attributes = '';
  1944. if ( is_array( $other_attributes ) ) {
  1945. foreach ( $other_attributes as $attribute => $value ) {
  1946. $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
  1947. }
  1948. } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
  1949. $attributes = $other_attributes;
  1950. }
  1951. $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
  1952. $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
  1953. if ( $wrap ) {
  1954. $button = '<p class="submit">' . $button . '</p>';
  1955. }
  1956. return $button;
  1957. }