暂无描述

template.php 92KB

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