template.php 79 KB

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