PageRenderTime 47ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

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