PageRenderTime 75ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/includes/template.php

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