template.php 88 KB

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