general-template.php 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746
  1. <?php
  2. /**
  3. * General template tags that can go anywhere in a template.
  4. *
  5. * @package WordPress
  6. * @subpackage Template
  7. */
  8. /**
  9. * Load header template.
  10. *
  11. * Includes the header template for a theme or if a name is specified then a
  12. * specialised header will be included.
  13. *
  14. * For the parameter, if the file is called "header-special.php" then specify
  15. * "special".
  16. *
  17. * @since 1.5.0
  18. *
  19. * @param string $name The name of the specialised header.
  20. */
  21. function get_header( $name = null ) {
  22. /**
  23. * Fires before the header template file is loaded.
  24. *
  25. * @since 2.1.0
  26. * @since 2.8.0 $name parameter added.
  27. *
  28. * @param string|null $name Name of the specific header file to use. null for the default header.
  29. */
  30. do_action( 'get_header', $name );
  31. $templates = array();
  32. $name = (string) $name;
  33. if ( '' !== $name ) {
  34. $templates[] = "header-{$name}.php";
  35. }
  36. $templates[] = 'header.php';
  37. locate_template( $templates, true );
  38. }
  39. /**
  40. * Load footer template.
  41. *
  42. * Includes the footer template for a theme or if a name is specified then a
  43. * specialised footer will be included.
  44. *
  45. * For the parameter, if the file is called "footer-special.php" then specify
  46. * "special".
  47. *
  48. * @since 1.5.0
  49. *
  50. * @param string $name The name of the specialised footer.
  51. */
  52. function get_footer( $name = null ) {
  53. /**
  54. * Fires before the footer template file is loaded.
  55. *
  56. * @since 2.1.0
  57. * @since 2.8.0 $name parameter added.
  58. *
  59. * @param string|null $name Name of the specific footer file to use. null for the default footer.
  60. */
  61. do_action( 'get_footer', $name );
  62. $templates = array();
  63. $name = (string) $name;
  64. if ( '' !== $name ) {
  65. $templates[] = "footer-{$name}.php";
  66. }
  67. $templates[] = 'footer.php';
  68. locate_template( $templates, true );
  69. }
  70. /**
  71. * Load sidebar template.
  72. *
  73. * Includes the sidebar template for a theme or if a name is specified then a
  74. * specialised sidebar will be included.
  75. *
  76. * For the parameter, if the file is called "sidebar-special.php" then specify
  77. * "special".
  78. *
  79. * @since 1.5.0
  80. *
  81. * @param string $name The name of the specialised sidebar.
  82. */
  83. function get_sidebar( $name = null ) {
  84. /**
  85. * Fires before the sidebar template file is loaded.
  86. *
  87. * @since 2.2.0
  88. * @since 2.8.0 $name parameter added.
  89. *
  90. * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar.
  91. */
  92. do_action( 'get_sidebar', $name );
  93. $templates = array();
  94. $name = (string) $name;
  95. if ( '' !== $name ) {
  96. $templates[] = "sidebar-{$name}.php";
  97. }
  98. $templates[] = 'sidebar.php';
  99. locate_template( $templates, true );
  100. }
  101. /**
  102. * Loads a template part into a template.
  103. *
  104. * Provides a simple mechanism for child themes to overload reusable sections of code
  105. * in the theme.
  106. *
  107. * Includes the named template part for a theme or if a name is specified then a
  108. * specialised part will be included. If the theme contains no {slug}.php file
  109. * then no template will be included.
  110. *
  111. * The template is included using require, not require_once, so you may include the
  112. * same template part multiple times.
  113. *
  114. * For the $name parameter, if the file is called "{slug}-special.php" then specify
  115. * "special".
  116. *
  117. * @since 3.0.0
  118. *
  119. * @param string $slug The slug name for the generic template.
  120. * @param string $name The name of the specialised template.
  121. */
  122. function get_template_part( $slug, $name = null ) {
  123. /**
  124. * Fires before the specified template part file is loaded.
  125. *
  126. * The dynamic portion of the hook name, `$slug`, refers to the slug name
  127. * for the generic template part.
  128. *
  129. * @since 3.0.0
  130. *
  131. * @param string $slug The slug name for the generic template.
  132. * @param string|null $name The name of the specialized template.
  133. */
  134. do_action( "get_template_part_{$slug}", $slug, $name );
  135. $templates = array();
  136. $name = (string) $name;
  137. if ( '' !== $name ) {
  138. $templates[] = "{$slug}-{$name}.php";
  139. }
  140. $templates[] = "{$slug}.php";
  141. /**
  142. * Fires before a template part is loaded.
  143. *
  144. * @since 5.2.0
  145. *
  146. * @param string $slug The slug name for the generic template.
  147. * @param string $name The name of the specialized template.
  148. * @param string[] $templates Array of template files to search for, in order.
  149. */
  150. do_action( 'get_template_part', $slug, $name, $templates );
  151. locate_template( $templates, true, false );
  152. }
  153. /**
  154. * Display search form.
  155. *
  156. * Will first attempt to locate the searchform.php file in either the child or
  157. * the parent, then load it. If it doesn't exist, then the default search form
  158. * will be displayed. The default search form is HTML, which will be displayed.
  159. * There is a filter applied to the search form HTML in order to edit or replace
  160. * it. The filter is {@see 'get_search_form'}.
  161. *
  162. * This function is primarily used by themes which want to hardcode the search
  163. * form into the sidebar and also by the search widget in WordPress.
  164. *
  165. * There is also an action that is called whenever the function is run called,
  166. * {@see 'pre_get_search_form'}. This can be useful for outputting JavaScript that the
  167. * search relies on or various formatting that applies to the beginning of the
  168. * search. To give a few examples of what it can be used for.
  169. *
  170. * @since 2.7.0
  171. * @since 5.2.0 The $args array parameter was added in place of an $echo boolean flag.
  172. *
  173. * @param array $args {
  174. * Optional. Array of display arguments.
  175. *
  176. * @type bool $echo Whether to echo or return the form. Default true.
  177. * @type string $aria_label ARIA label for the search form. Useful to distinguish
  178. * multiple search forms on the same page and improve
  179. * accessibility. Default empty.
  180. * }
  181. * @return string|void String when the $echo param is false.
  182. */
  183. function get_search_form( $args = array() ) {
  184. /**
  185. * Fires before the search form is retrieved, at the start of get_search_form().
  186. *
  187. * @since 2.7.0 as 'get_search_form' action.
  188. * @since 3.6.0
  189. *
  190. * @link https://core.trac.wordpress.org/ticket/19321
  191. */
  192. do_action( 'pre_get_search_form' );
  193. $echo = true;
  194. if ( ! is_array( $args ) ) {
  195. /*
  196. * Back compat: to ensure previous uses of get_search_form() continue to
  197. * function as expected, we handle a value for the boolean $echo param removed
  198. * in 5.2.0. Then we deal with the $args array and cast its defaults.
  199. */
  200. $echo = (bool) $args;
  201. // Set an empty array and allow default arguments to take over.
  202. $args = array();
  203. }
  204. // Defaults are to echo and to output no custom label on the form.
  205. $defaults = array(
  206. 'echo' => $echo,
  207. 'aria_label' => '',
  208. );
  209. $args = wp_parse_args( $args, $defaults );
  210. /**
  211. * Filters the array of arguments used when generating the search form.
  212. *
  213. * @since 5.2.0
  214. *
  215. * @param array $args The array of arguments for building the search form.
  216. */
  217. $args = apply_filters( 'search_form_args', $args );
  218. $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
  219. /**
  220. * Filters the HTML format of the search form.
  221. *
  222. * @since 3.6.0
  223. *
  224. * @param string $format The type of markup to use in the search form.
  225. * Accepts 'html5', 'xhtml'.
  226. */
  227. $format = apply_filters( 'search_form_format', $format );
  228. $search_form_template = locate_template( 'searchform.php' );
  229. if ( '' != $search_form_template ) {
  230. ob_start();
  231. require( $search_form_template );
  232. $form = ob_get_clean();
  233. } else {
  234. // Build a string containing an aria-label to use for the search form.
  235. if ( isset( $args['aria_label'] ) && $args['aria_label'] ) {
  236. $aria_label = 'aria-label="' . esc_attr( $args['aria_label'] ) . '" ';
  237. } else {
  238. /*
  239. * If there's no custom aria-label, we can set a default here. At the
  240. * moment it's empty as there's uncertainty about what the default should be.
  241. */
  242. $aria_label = '';
  243. }
  244. if ( 'html5' == $format ) {
  245. $form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
  246. <label>
  247. <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
  248. <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
  249. </label>
  250. <input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
  251. </form>';
  252. } else {
  253. $form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
  254. <div>
  255. <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
  256. <input type="text" value="' . get_search_query() . '" name="s" id="s" />
  257. <input type="submit" id="searchsubmit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
  258. </div>
  259. </form>';
  260. }
  261. }
  262. /**
  263. * Filters the HTML output of the search form.
  264. *
  265. * @since 2.7.0
  266. *
  267. * @param string $form The search form HTML output.
  268. */
  269. $result = apply_filters( 'get_search_form', $form );
  270. if ( null === $result ) {
  271. $result = $form;
  272. }
  273. if ( isset( $args['echo'] ) && $args['echo'] ) {
  274. echo $result;
  275. } else {
  276. return $result;
  277. }
  278. }
  279. /**
  280. * Display the Log In/Out link.
  281. *
  282. * Displays a link, which allows users to navigate to the Log In page to log in
  283. * or log out depending on whether they are currently logged in.
  284. *
  285. * @since 1.5.0
  286. *
  287. * @param string $redirect Optional path to redirect to on login/logout.
  288. * @param bool $echo Default to echo and not return the link.
  289. * @return string|void String when retrieving.
  290. */
  291. function wp_loginout( $redirect = '', $echo = true ) {
  292. if ( ! is_user_logged_in() ) {
  293. $link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
  294. } else {
  295. $link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
  296. }
  297. if ( $echo ) {
  298. /**
  299. * Filters the HTML output for the Log In/Log Out link.
  300. *
  301. * @since 1.5.0
  302. *
  303. * @param string $link The HTML link content.
  304. */
  305. echo apply_filters( 'loginout', $link );
  306. } else {
  307. /** This filter is documented in wp-includes/general-template.php */
  308. return apply_filters( 'loginout', $link );
  309. }
  310. }
  311. /**
  312. * Retrieves the logout URL.
  313. *
  314. * Returns the URL that allows the user to log out of the site.
  315. *
  316. * @since 2.7.0
  317. *
  318. * @param string $redirect Path to redirect to on logout.
  319. * @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().
  320. */
  321. function wp_logout_url( $redirect = '' ) {
  322. $args = array();
  323. if ( ! empty( $redirect ) ) {
  324. $args['redirect_to'] = urlencode( $redirect );
  325. }
  326. $logout_url = add_query_arg( $args, site_url( 'wp-login.php?action=logout', 'login' ) );
  327. $logout_url = wp_nonce_url( $logout_url, 'log-out' );
  328. /**
  329. * Filters the logout URL.
  330. *
  331. * @since 2.8.0
  332. *
  333. * @param string $logout_url The HTML-encoded logout URL.
  334. * @param string $redirect Path to redirect to on logout.
  335. */
  336. return apply_filters( 'logout_url', $logout_url, $redirect );
  337. }
  338. /**
  339. * Retrieves the login URL.
  340. *
  341. * @since 2.7.0
  342. *
  343. * @param string $redirect Path to redirect to on log in.
  344. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
  345. * Default false.
  346. * @return string The login URL. Not HTML-encoded.
  347. */
  348. function wp_login_url( $redirect = '', $force_reauth = false ) {
  349. $login_url = site_url( 'wp-login.php', 'login' );
  350. if ( ! empty( $redirect ) ) {
  351. $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
  352. }
  353. if ( $force_reauth ) {
  354. $login_url = add_query_arg( 'reauth', '1', $login_url );
  355. }
  356. /**
  357. * Filters the login URL.
  358. *
  359. * @since 2.8.0
  360. * @since 4.2.0 The `$force_reauth` parameter was added.
  361. *
  362. * @param string $login_url The login URL. Not HTML-encoded.
  363. * @param string $redirect The path to redirect to on login, if supplied.
  364. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
  365. */
  366. return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
  367. }
  368. /**
  369. * Returns the URL that allows the user to register on the site.
  370. *
  371. * @since 3.6.0
  372. *
  373. * @return string User registration URL.
  374. */
  375. function wp_registration_url() {
  376. /**
  377. * Filters the user registration URL.
  378. *
  379. * @since 3.6.0
  380. *
  381. * @param string $register The user registration URL.
  382. */
  383. return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
  384. }
  385. /**
  386. * Provides a simple login form for use anywhere within WordPress.
  387. *
  388. * The login format HTML is echoed by default. Pass a false value for `$echo` to return it instead.
  389. *
  390. * @since 3.0.0
  391. *
  392. * @param array $args {
  393. * Optional. Array of options to control the form output. Default empty array.
  394. *
  395. * @type bool $echo Whether to display the login form or return the form HTML code.
  396. * Default true (echo).
  397. * @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
  398. * Default is to redirect back to the request URI.
  399. * @type string $form_id ID attribute value for the form. Default 'loginform'.
  400. * @type string $label_username Label for the username or email address field. Default 'Username or Email Address'.
  401. * @type string $label_password Label for the password field. Default 'Password'.
  402. * @type string $label_remember Label for the remember field. Default 'Remember Me'.
  403. * @type string $label_log_in Label for the submit button. Default 'Log In'.
  404. * @type string $id_username ID attribute value for the username field. Default 'user_login'.
  405. * @type string $id_password ID attribute value for the password field. Default 'user_pass'.
  406. * @type string $id_remember ID attribute value for the remember field. Default 'rememberme'.
  407. * @type string $id_submit ID attribute value for the submit button. Default 'wp-submit'.
  408. * @type bool $remember Whether to display the "rememberme" checkbox in the form.
  409. * @type string $value_username Default value for the username field. Default empty.
  410. * @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default.
  411. * Default false (unchecked).
  412. *
  413. * }
  414. * @return string|void String when retrieving.
  415. */
  416. function wp_login_form( $args = array() ) {
  417. $defaults = array(
  418. 'echo' => true,
  419. // Default 'redirect' value takes the user back to the request URI.
  420. 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
  421. 'form_id' => 'loginform',
  422. 'label_username' => __( 'Username or Email Address' ),
  423. 'label_password' => __( 'Password' ),
  424. 'label_remember' => __( 'Remember Me' ),
  425. 'label_log_in' => __( 'Log In' ),
  426. 'id_username' => 'user_login',
  427. 'id_password' => 'user_pass',
  428. 'id_remember' => 'rememberme',
  429. 'id_submit' => 'wp-submit',
  430. 'remember' => true,
  431. 'value_username' => '',
  432. // Set 'value_remember' to true to default the "Remember me" checkbox to checked.
  433. 'value_remember' => false,
  434. );
  435. /**
  436. * Filters the default login form output arguments.
  437. *
  438. * @since 3.0.0
  439. *
  440. * @see wp_login_form()
  441. *
  442. * @param array $defaults An array of default login form arguments.
  443. */
  444. $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
  445. /**
  446. * Filters content to display at the top of the login form.
  447. *
  448. * The filter evaluates just following the opening form tag element.
  449. *
  450. * @since 3.0.0
  451. *
  452. * @param string $content Content to display. Default empty.
  453. * @param array $args Array of login form arguments.
  454. */
  455. $login_form_top = apply_filters( 'login_form_top', '', $args );
  456. /**
  457. * Filters content to display in the middle of the login form.
  458. *
  459. * The filter evaluates just following the location where the 'login-password'
  460. * field is displayed.
  461. *
  462. * @since 3.0.0
  463. *
  464. * @param string $content Content to display. Default empty.
  465. * @param array $args Array of login form arguments.
  466. */
  467. $login_form_middle = apply_filters( 'login_form_middle', '', $args );
  468. /**
  469. * Filters content to display at the bottom of the login form.
  470. *
  471. * The filter evaluates just preceding the closing form tag element.
  472. *
  473. * @since 3.0.0
  474. *
  475. * @param string $content Content to display. Default empty.
  476. * @param array $args Array of login form arguments.
  477. */
  478. $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
  479. $form = '
  480. <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
  481. ' . $login_form_top . '
  482. <p class="login-username">
  483. <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
  484. <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
  485. </p>
  486. <p class="login-password">
  487. <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
  488. <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
  489. </p>
  490. ' . $login_form_middle . '
  491. ' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
  492. <p class="login-submit">
  493. <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
  494. <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
  495. </p>
  496. ' . $login_form_bottom . '
  497. </form>';
  498. if ( $args['echo'] ) {
  499. echo $form;
  500. } else {
  501. return $form;
  502. }
  503. }
  504. /**
  505. * Returns the URL that allows the user to retrieve the lost password
  506. *
  507. * @since 2.8.0
  508. *
  509. * @param string $redirect Path to redirect to on login.
  510. * @return string Lost password URL.
  511. */
  512. function wp_lostpassword_url( $redirect = '' ) {
  513. $args = array();
  514. if ( ! empty( $redirect ) ) {
  515. $args['redirect_to'] = urlencode( $redirect );
  516. }
  517. $lostpassword_url = add_query_arg( $args, network_site_url( 'wp-login.php?action=lostpassword', 'login' ) );
  518. /**
  519. * Filters the Lost Password URL.
  520. *
  521. * @since 2.8.0
  522. *
  523. * @param string $lostpassword_url The lost password page URL.
  524. * @param string $redirect The path to redirect to on login.
  525. */
  526. return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
  527. }
  528. /**
  529. * Display the Registration or Admin link.
  530. *
  531. * Display a link which allows the user to navigate to the registration page if
  532. * not logged in and registration is enabled or to the dashboard if logged in.
  533. *
  534. * @since 1.5.0
  535. *
  536. * @param string $before Text to output before the link. Default `<li>`.
  537. * @param string $after Text to output after the link. Default `</li>`.
  538. * @param bool $echo Default to echo and not return the link.
  539. * @return string|void String when retrieving.
  540. */
  541. function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
  542. if ( ! is_user_logged_in() ) {
  543. if ( get_option( 'users_can_register' ) ) {
  544. $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>' . $after;
  545. } else {
  546. $link = '';
  547. }
  548. } elseif ( current_user_can( 'read' ) ) {
  549. $link = $before . '<a href="' . admin_url() . '">' . __( 'Site Admin' ) . '</a>' . $after;
  550. } else {
  551. $link = '';
  552. }
  553. /**
  554. * Filters the HTML link to the Registration or Admin page.
  555. *
  556. * Users are sent to the admin page if logged-in, or the registration page
  557. * if enabled and logged-out.
  558. *
  559. * @since 1.5.0
  560. *
  561. * @param string $link The HTML code for the link to the Registration or Admin page.
  562. */
  563. $link = apply_filters( 'register', $link );
  564. if ( $echo ) {
  565. echo $link;
  566. } else {
  567. return $link;
  568. }
  569. }
  570. /**
  571. * Theme container function for the 'wp_meta' action.
  572. *
  573. * The {@see 'wp_meta'} action can have several purposes, depending on how you use it,
  574. * but one purpose might have been to allow for theme switching.
  575. *
  576. * @since 1.5.0
  577. *
  578. * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
  579. */
  580. function wp_meta() {
  581. /**
  582. * Fires before displaying echoed content in the sidebar.
  583. *
  584. * @since 1.5.0
  585. */
  586. do_action( 'wp_meta' );
  587. }
  588. /**
  589. * Displays information about the current site.
  590. *
  591. * @since 0.71
  592. *
  593. * @see get_bloginfo() For possible `$show` values
  594. *
  595. * @param string $show Optional. Site information to display. Default empty.
  596. */
  597. function bloginfo( $show = '' ) {
  598. echo get_bloginfo( $show, 'display' );
  599. }
  600. /**
  601. * Retrieves information about the current site.
  602. *
  603. * Possible values for `$show` include:
  604. *
  605. * - 'name' - Site title (set in Settings > General)
  606. * - 'description' - Site tagline (set in Settings > General)
  607. * - 'wpurl' - The WordPress address (URL) (set in Settings > General)
  608. * - 'url' - The Site address (URL) (set in Settings > General)
  609. * - 'admin_email' - Admin email (set in Settings > General)
  610. * - 'charset' - The "Encoding for pages and feeds" (set in Settings > Reading)
  611. * - 'version' - The current WordPress version
  612. * - 'html_type' - The content-type (default: "text/html"). Themes and plugins
  613. * can override the default value using the {@see 'pre_option_html_type'} filter
  614. * - 'text_direction' - The text direction determined by the site's language. is_rtl()
  615. * should be used instead
  616. * - 'language' - Language code for the current site
  617. * - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme
  618. * will take precedence over this value
  619. * - 'stylesheet_directory' - Directory path for the active theme. An active child theme
  620. * will take precedence over this value
  621. * - 'template_url' / 'template_directory' - URL of the active theme's directory. An active
  622. * child theme will NOT take precedence over this value
  623. * - 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php)
  624. * - 'atom_url' - The Atom feed URL (/feed/atom)
  625. * - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rdf)
  626. * - 'rss_url' - The RSS 0.92 feed URL (/feed/rss)
  627. * - 'rss2_url' - The RSS 2.0 feed URL (/feed)
  628. * - 'comments_atom_url' - The comments Atom feed URL (/comments/feed)
  629. * - 'comments_rss2_url' - The comments RSS 2.0 feed URL (/comments/feed)
  630. *
  631. * Some `$show` values are deprecated and will be removed in future versions.
  632. * These options will trigger the _deprecated_argument() function.
  633. *
  634. * Deprecated arguments include:
  635. *
  636. * - 'siteurl' - Use 'url' instead
  637. * - 'home' - Use 'url' instead
  638. *
  639. * @since 0.71
  640. *
  641. * @global string $wp_version
  642. *
  643. * @param string $show Optional. Site info to retrieve. Default empty (site name).
  644. * @param string $filter Optional. How to filter what is retrieved. Default 'raw'.
  645. * @return string Mostly string values, might be empty.
  646. */
  647. function get_bloginfo( $show = '', $filter = 'raw' ) {
  648. switch ( $show ) {
  649. case 'home': // DEPRECATED
  650. case 'siteurl': // DEPRECATED
  651. _deprecated_argument(
  652. __FUNCTION__,
  653. '2.2.0',
  654. sprintf(
  655. /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */
  656. __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
  657. '<code>' . $show . '</code>',
  658. '<code>bloginfo()</code>',
  659. '<code>url</code>'
  660. )
  661. );
  662. // Intentional fall-through to be handled by the 'url' case.
  663. case 'url':
  664. $output = home_url();
  665. break;
  666. case 'wpurl':
  667. $output = site_url();
  668. break;
  669. case 'description':
  670. $output = get_option( 'blogdescription' );
  671. break;
  672. case 'rdf_url':
  673. $output = get_feed_link( 'rdf' );
  674. break;
  675. case 'rss_url':
  676. $output = get_feed_link( 'rss' );
  677. break;
  678. case 'rss2_url':
  679. $output = get_feed_link( 'rss2' );
  680. break;
  681. case 'atom_url':
  682. $output = get_feed_link( 'atom' );
  683. break;
  684. case 'comments_atom_url':
  685. $output = get_feed_link( 'comments_atom' );
  686. break;
  687. case 'comments_rss2_url':
  688. $output = get_feed_link( 'comments_rss2' );
  689. break;
  690. case 'pingback_url':
  691. $output = site_url( 'xmlrpc.php' );
  692. break;
  693. case 'stylesheet_url':
  694. $output = get_stylesheet_uri();
  695. break;
  696. case 'stylesheet_directory':
  697. $output = get_stylesheet_directory_uri();
  698. break;
  699. case 'template_directory':
  700. case 'template_url':
  701. $output = get_template_directory_uri();
  702. break;
  703. case 'admin_email':
  704. $output = get_option( 'admin_email' );
  705. break;
  706. case 'charset':
  707. $output = get_option( 'blog_charset' );
  708. if ( '' == $output ) {
  709. $output = 'UTF-8';
  710. }
  711. break;
  712. case 'html_type':
  713. $output = get_option( 'html_type' );
  714. break;
  715. case 'version':
  716. global $wp_version;
  717. $output = $wp_version;
  718. break;
  719. case 'language':
  720. /*
  721. * translators: Translate this to the correct language tag for your locale,
  722. * see https://www.w3.org/International/articles/language-tags/ for reference.
  723. * Do not translate into your own language.
  724. */
  725. $output = __( 'html_lang_attribute' );
  726. if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {
  727. $output = determine_locale();
  728. $output = str_replace( '_', '-', $output );
  729. }
  730. break;
  731. case 'text_direction':
  732. _deprecated_argument(
  733. __FUNCTION__,
  734. '2.2.0',
  735. sprintf(
  736. /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name. */
  737. __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
  738. '<code>' . $show . '</code>',
  739. '<code>bloginfo()</code>',
  740. '<code>is_rtl()</code>'
  741. )
  742. );
  743. if ( function_exists( 'is_rtl' ) ) {
  744. $output = is_rtl() ? 'rtl' : 'ltr';
  745. } else {
  746. $output = 'ltr';
  747. }
  748. break;
  749. case 'name':
  750. default:
  751. $output = get_option( 'blogname' );
  752. break;
  753. }
  754. $url = true;
  755. if ( strpos( $show, 'url' ) === false &&
  756. strpos( $show, 'directory' ) === false &&
  757. strpos( $show, 'home' ) === false ) {
  758. $url = false;
  759. }
  760. if ( 'display' == $filter ) {
  761. if ( $url ) {
  762. /**
  763. * Filters the URL returned by get_bloginfo().
  764. *
  765. * @since 2.0.5
  766. *
  767. * @param mixed $output The URL returned by bloginfo().
  768. * @param mixed $show Type of information requested.
  769. */
  770. $output = apply_filters( 'bloginfo_url', $output, $show );
  771. } else {
  772. /**
  773. * Filters the site information returned by get_bloginfo().
  774. *
  775. * @since 0.71
  776. *
  777. * @param mixed $output The requested non-URL site information.
  778. * @param mixed $show Type of information requested.
  779. */
  780. $output = apply_filters( 'bloginfo', $output, $show );
  781. }
  782. }
  783. return $output;
  784. }
  785. /**
  786. * Returns the Site Icon URL.
  787. *
  788. * @since 4.3.0
  789. *
  790. * @param int $size Optional. Size of the site icon. Default 512 (pixels).
  791. * @param string $url Optional. Fallback url if no site icon is found. Default empty.
  792. * @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
  793. * @return string Site Icon URL.
  794. */
  795. function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
  796. $switched_blog = false;
  797. if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
  798. switch_to_blog( $blog_id );
  799. $switched_blog = true;
  800. }
  801. $site_icon_id = get_option( 'site_icon' );
  802. if ( $site_icon_id ) {
  803. if ( $size >= 512 ) {
  804. $size_data = 'full';
  805. } else {
  806. $size_data = array( $size, $size );
  807. }
  808. $url = wp_get_attachment_image_url( $site_icon_id, $size_data );
  809. }
  810. if ( $switched_blog ) {
  811. restore_current_blog();
  812. }
  813. /**
  814. * Filters the site icon URL.
  815. *
  816. * @since 4.4.0
  817. *
  818. * @param string $url Site icon URL.
  819. * @param int $size Size of the site icon.
  820. * @param int $blog_id ID of the blog to get the site icon for.
  821. */
  822. return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
  823. }
  824. /**
  825. * Displays the Site Icon URL.
  826. *
  827. * @since 4.3.0
  828. *
  829. * @param int $size Optional. Size of the site icon. Default 512 (pixels).
  830. * @param string $url Optional. Fallback url if no site icon is found. Default empty.
  831. * @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
  832. */
  833. function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
  834. echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
  835. }
  836. /**
  837. * Whether the site has a Site Icon.
  838. *
  839. * @since 4.3.0
  840. *
  841. * @param int $blog_id Optional. ID of the blog in question. Default current blog.
  842. * @return bool Whether the site has a site icon or not.
  843. */
  844. function has_site_icon( $blog_id = 0 ) {
  845. return (bool) get_site_icon_url( 512, '', $blog_id );
  846. }
  847. /**
  848. * Determines whether the site has a custom logo.
  849. *
  850. * @since 4.5.0
  851. *
  852. * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
  853. * @return bool Whether the site has a custom logo or not.
  854. */
  855. function has_custom_logo( $blog_id = 0 ) {
  856. $switched_blog = false;
  857. if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
  858. switch_to_blog( $blog_id );
  859. $switched_blog = true;
  860. }
  861. $custom_logo_id = get_theme_mod( 'custom_logo' );
  862. if ( $switched_blog ) {
  863. restore_current_blog();
  864. }
  865. return (bool) $custom_logo_id;
  866. }
  867. /**
  868. * Returns a custom logo, linked to home.
  869. *
  870. * @since 4.5.0
  871. *
  872. * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
  873. * @return string Custom logo markup.
  874. */
  875. function get_custom_logo( $blog_id = 0 ) {
  876. $html = '';
  877. $switched_blog = false;
  878. if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
  879. switch_to_blog( $blog_id );
  880. $switched_blog = true;
  881. }
  882. $custom_logo_id = get_theme_mod( 'custom_logo' );
  883. // We have a logo. Logo is go.
  884. if ( $custom_logo_id ) {
  885. $custom_logo_attr = array(
  886. 'class' => 'custom-logo',
  887. );
  888. /*
  889. * If the logo alt attribute is empty, get the site title and explicitly
  890. * pass it to the attributes used by wp_get_attachment_image().
  891. */
  892. $image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
  893. if ( empty( $image_alt ) ) {
  894. $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
  895. }
  896. /*
  897. * If the alt attribute is not empty, there's no need to explicitly pass
  898. * it because wp_get_attachment_image() already adds the alt attribute.
  899. */
  900. $html = sprintf(
  901. '<a href="%1$s" class="custom-logo-link" rel="home">%2$s</a>',
  902. esc_url( home_url( '/' ) ),
  903. wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
  904. );
  905. } elseif ( is_customize_preview() ) {
  906. // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
  907. $html = sprintf(
  908. '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></a>',
  909. esc_url( home_url( '/' ) )
  910. );
  911. }
  912. if ( $switched_blog ) {
  913. restore_current_blog();
  914. }
  915. /**
  916. * Filters the custom logo output.
  917. *
  918. * @since 4.5.0
  919. * @since 4.6.0 Added the `$blog_id` parameter.
  920. *
  921. * @param string $html Custom logo HTML output.
  922. * @param int $blog_id ID of the blog to get the custom logo for.
  923. */
  924. return apply_filters( 'get_custom_logo', $html, $blog_id );
  925. }
  926. /**
  927. * Displays a custom logo, linked to home.
  928. *
  929. * @since 4.5.0
  930. *
  931. * @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog.
  932. */
  933. function the_custom_logo( $blog_id = 0 ) {
  934. echo get_custom_logo( $blog_id );
  935. }
  936. /**
  937. * Returns document title for the current page.
  938. *
  939. * @since 4.4.0
  940. *
  941. * @global int $page Page number of a single post.
  942. * @global int $paged Page number of a list of posts.
  943. *
  944. * @return string Tag with the document title.
  945. */
  946. function wp_get_document_title() {
  947. /**
  948. * Filters the document title before it is generated.
  949. *
  950. * Passing a non-empty value will short-circuit wp_get_document_title(),
  951. * returning that value instead.
  952. *
  953. * @since 4.4.0
  954. *
  955. * @param string $title The document title. Default empty string.
  956. */
  957. $title = apply_filters( 'pre_get_document_title', '' );
  958. if ( ! empty( $title ) ) {
  959. return $title;
  960. }
  961. global $page, $paged;
  962. $title = array(
  963. 'title' => '',
  964. );
  965. // If it's a 404 page, use a "Page not found" title.
  966. if ( is_404() ) {
  967. $title['title'] = __( 'Page not found' );
  968. // If it's a search, use a dynamic search results title.
  969. } elseif ( is_search() ) {
  970. /* translators: %s: Search query. */
  971. $title['title'] = sprintf( __( 'Search Results for &#8220;%s&#8221;' ), get_search_query() );
  972. // If on the front page, use the site title.
  973. } elseif ( is_front_page() ) {
  974. $title['title'] = get_bloginfo( 'name', 'display' );
  975. // If on a post type archive, use the post type archive title.
  976. } elseif ( is_post_type_archive() ) {
  977. $title['title'] = post_type_archive_title( '', false );
  978. // If on a taxonomy archive, use the term title.
  979. } elseif ( is_tax() ) {
  980. $title['title'] = single_term_title( '', false );
  981. /*
  982. * If we're on the blog page that is not the homepage or
  983. * a single post of any post type, use the post title.
  984. */
  985. } elseif ( is_home() || is_singular() ) {
  986. $title['title'] = single_post_title( '', false );
  987. // If on a category or tag archive, use the term title.
  988. } elseif ( is_category() || is_tag() ) {
  989. $title['title'] = single_term_title( '', false );
  990. // If on an author archive, use the author's display name.
  991. } elseif ( is_author() && get_queried_object() ) {
  992. $author = get_queried_object();
  993. $title['title'] = $author->display_name;
  994. // If it's a date archive, use the date as the title.
  995. } elseif ( is_year() ) {
  996. $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
  997. } elseif ( is_month() ) {
  998. $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
  999. } elseif ( is_day() ) {
  1000. $title['title'] = get_the_date();
  1001. }
  1002. // Add a page number if necessary.
  1003. if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
  1004. /* translators: %s: Page number. */
  1005. $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
  1006. }
  1007. // Append the description or site title to give context.
  1008. if ( is_front_page() ) {
  1009. $title['tagline'] = get_bloginfo( 'description', 'display' );
  1010. } else {
  1011. $title['site'] = get_bloginfo( 'name', 'display' );
  1012. }
  1013. /**
  1014. * Filters the separator for the document title.
  1015. *
  1016. * @since 4.4.0
  1017. *
  1018. * @param string $sep Document title separator. Default '-'.
  1019. */
  1020. $sep = apply_filters( 'document_title_separator', '-' );
  1021. /**
  1022. * Filters the parts of the document title.
  1023. *
  1024. * @since 4.4.0
  1025. *
  1026. * @param array $title {
  1027. * The document title parts.
  1028. *
  1029. * @type string $title Title of the viewed page.
  1030. * @type string $page Optional. Page number if paginated.
  1031. * @type string $tagline Optional. Site description when on home page.
  1032. * @type string $site Optional. Site title when not on home page.
  1033. * }
  1034. */
  1035. $title = apply_filters( 'document_title_parts', $title );
  1036. $title = implode( " $sep ", array_filter( $title ) );
  1037. $title = wptexturize( $title );
  1038. $title = convert_chars( $title );
  1039. $title = esc_html( $title );
  1040. $title = capital_P_dangit( $title );
  1041. return $title;
  1042. }
  1043. /**
  1044. * Displays title tag with content.
  1045. *
  1046. * @ignore
  1047. * @since 4.1.0
  1048. * @since 4.4.0 Improved title output replaced `wp_title()`.
  1049. * @access private
  1050. */
  1051. function _wp_render_title_tag() {
  1052. if ( ! current_theme_supports( 'title-tag' ) ) {
  1053. return;
  1054. }
  1055. echo '<title>' . wp_get_document_title() . '</title>' . "\n";
  1056. }
  1057. /**
  1058. * Display or retrieve page title for all areas of blog.
  1059. *
  1060. * By default, the page title will display the separator before the page title,
  1061. * so that the blog title will be before the page title. This is not good for
  1062. * title display, since the blog title shows up on most tabs and not what is
  1063. * important, which is the page that the user is looking at.
  1064. *
  1065. * There are also SEO benefits to having the blog title after or to the 'right'
  1066. * of the page title. However, it is mostly common sense to have the blog title
  1067. * to the right with most browsers supporting tabs. You can achieve this by
  1068. * using the seplocation parameter and setting the value to 'right'. This change
  1069. * was introduced around 2.5.0, in case backward compatibility of themes is
  1070. * important.
  1071. *
  1072. * @since 1.0.0
  1073. *
  1074. * @global WP_Locale $wp_locale WordPress date and time locale object.
  1075. *
  1076. * @param string $sep Optional, default is '&raquo;'. How to separate the various items
  1077. * within the page title.
  1078. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1079. * @param string $seplocation Optional. Location of the separator ('left' or 'right').
  1080. * @return string|null String on retrieve, null when displaying.
  1081. */
  1082. function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
  1083. global $wp_locale;
  1084. $m = get_query_var( 'm' );
  1085. $year = get_query_var( 'year' );
  1086. $monthnum = get_query_var( 'monthnum' );
  1087. $day = get_query_var( 'day' );
  1088. $search = get_query_var( 's' );
  1089. $title = '';
  1090. $t_sep = '%WP_TITLE_SEP%'; // Temporary separator, for accurate flipping, if necessary
  1091. // If there is a post
  1092. if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
  1093. $title = single_post_title( '', false );
  1094. }
  1095. // If there's a post type archive
  1096. if ( is_post_type_archive() ) {
  1097. $post_type = get_query_var( 'post_type' );
  1098. if ( is_array( $post_type ) ) {
  1099. $post_type = reset( $post_type );
  1100. }
  1101. $post_type_object = get_post_type_object( $post_type );
  1102. if ( ! $post_type_object->has_archive ) {
  1103. $title = post_type_archive_title( '', false );
  1104. }
  1105. }
  1106. // If there's a category or tag
  1107. if ( is_category() || is_tag() ) {
  1108. $title = single_term_title( '', false );
  1109. }
  1110. // If there's a taxonomy
  1111. if ( is_tax() ) {
  1112. $term = get_queried_object();
  1113. if ( $term ) {
  1114. $tax = get_taxonomy( $term->taxonomy );
  1115. $title = single_term_title( $tax->labels->name . $t_sep, false );
  1116. }
  1117. }
  1118. // If there's an author
  1119. if ( is_author() && ! is_post_type_archive() ) {
  1120. $author = get_queried_object();
  1121. if ( $author ) {
  1122. $title = $author->display_name;
  1123. }
  1124. }
  1125. // Post type archives with has_archive should override terms.
  1126. if ( is_post_type_archive() && $post_type_object->has_archive ) {
  1127. $title = post_type_archive_title( '', false );
  1128. }
  1129. // If there's a month
  1130. if ( is_archive() && ! empty( $m ) ) {
  1131. $my_year = substr( $m, 0, 4 );
  1132. $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
  1133. $my_day = intval( substr( $m, 6, 2 ) );
  1134. $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
  1135. }
  1136. // If there's a year
  1137. if ( is_archive() && ! empty( $year ) ) {
  1138. $title = $year;
  1139. if ( ! empty( $monthnum ) ) {
  1140. $title .= $t_sep . $wp_locale->get_month( $monthnum );
  1141. }
  1142. if ( ! empty( $day ) ) {
  1143. $title .= $t_sep . zeroise( $day, 2 );
  1144. }
  1145. }
  1146. // If it's a search
  1147. if ( is_search() ) {
  1148. /* translators: 1: Separator, 2: Search query. */
  1149. $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
  1150. }
  1151. // If it's a 404 page
  1152. if ( is_404() ) {
  1153. $title = __( 'Page not found' );
  1154. }
  1155. $prefix = '';
  1156. if ( ! empty( $title ) ) {
  1157. $prefix = " $sep ";
  1158. }
  1159. /**
  1160. * Filters the parts of the page title.
  1161. *
  1162. * @since 4.0.0
  1163. *
  1164. * @param array $title_array Parts of the page title.
  1165. */
  1166. $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
  1167. // Determines position of the separator and direction of the breadcrumb
  1168. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  1169. $title_array = array_reverse( $title_array );
  1170. $title = implode( " $sep ", $title_array ) . $prefix;
  1171. } else {
  1172. $title = $prefix . implode( " $sep ", $title_array );
  1173. }
  1174. /**
  1175. * Filters the text of the page title.
  1176. *
  1177. * @since 2.0.0
  1178. *
  1179. * @param string $title Page title.
  1180. * @param string $sep Title separator.
  1181. * @param string $seplocation Location of the separator ('left' or 'right').
  1182. */
  1183. $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
  1184. // Send it out
  1185. if ( $display ) {
  1186. echo $title;
  1187. } else {
  1188. return $title;
  1189. }
  1190. }
  1191. /**
  1192. * Display or retrieve page title for post.
  1193. *
  1194. * This is optimized for single.php template file for displaying the post title.
  1195. *
  1196. * It does not support placing the separator after the title, but by leaving the
  1197. * prefix parameter empty, you can set the title separator manually. The prefix
  1198. * does not automatically place a space between the prefix, so if there should
  1199. * be a space, the parameter value will need to have it at the end.
  1200. *
  1201. * @since 0.71
  1202. *
  1203. * @param string $prefix Optional. What to display before the title.
  1204. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1205. * @return string|void Title when retrieving.
  1206. */
  1207. function single_post_title( $prefix = '', $display = true ) {
  1208. $_post = get_queried_object();
  1209. if ( ! isset( $_post->post_title ) ) {
  1210. return;
  1211. }
  1212. /**
  1213. * Filters the page title for a single post.
  1214. *
  1215. * @since 0.71
  1216. *
  1217. * @param string $_post_title The single post page title.
  1218. * @param object $_post The current queried object as returned by get_queried_object().
  1219. */
  1220. $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
  1221. if ( $display ) {
  1222. echo $prefix . $title;
  1223. } else {
  1224. return $prefix . $title;
  1225. }
  1226. }
  1227. /**
  1228. * Display or retrieve title for a post type archive.
  1229. *
  1230. * This is optimized for archive.php and archive-{$post_type}.php template files
  1231. * for displaying the title of the post type.
  1232. *
  1233. * @since 3.1.0
  1234. *
  1235. * @param string $prefix Optional. What to display before the title.
  1236. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1237. * @return string|void Title when retrieving, null when displaying or failure.
  1238. */
  1239. function post_type_archive_title( $prefix = '', $display = true ) {
  1240. if ( ! is_post_type_archive() ) {
  1241. return;
  1242. }
  1243. $post_type = get_query_var( 'post_type' );
  1244. if ( is_array( $post_type ) ) {
  1245. $post_type = reset( $post_type );
  1246. }
  1247. $post_type_obj = get_post_type_object( $post_type );
  1248. /**
  1249. * Filters the post type archive title.
  1250. *
  1251. * @since 3.1.0
  1252. *
  1253. * @param string $post_type_name Post type 'name' label.
  1254. * @param string $post_type Post type.
  1255. */
  1256. $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
  1257. if ( $display ) {
  1258. echo $prefix . $title;
  1259. } else {
  1260. return $prefix . $title;
  1261. }
  1262. }
  1263. /**
  1264. * Display or retrieve page title for category archive.
  1265. *
  1266. * Useful for category template files for displaying the category page title.
  1267. * The prefix does not automatically place a space between the prefix, so if
  1268. * there should be a space, the parameter value will need to have it at the end.
  1269. *
  1270. * @since 0.71
  1271. *
  1272. * @param string $prefix Optional. What to display before the title.
  1273. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1274. * @return string|void Title when retrieving.
  1275. */
  1276. function single_cat_title( $prefix = '', $display = true ) {
  1277. return single_term_title( $prefix, $display );
  1278. }
  1279. /**
  1280. * Display or retrieve page title for tag post archive.
  1281. *
  1282. * Useful for tag template files for displaying the tag page title. The prefix
  1283. * does not automatically place a space between the prefix, so if there should
  1284. * be a space, the parameter value will need to have it at the end.
  1285. *
  1286. * @since 2.3.0
  1287. *
  1288. * @param string $prefix Optional. What to display before the title.
  1289. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1290. * @return string|void Title when retrieving.
  1291. */
  1292. function single_tag_title( $prefix = '', $display = true ) {
  1293. return single_term_title( $prefix, $display );
  1294. }
  1295. /**
  1296. * Display or retrieve page title for taxonomy term archive.
  1297. *
  1298. * Useful for taxonomy term template files for displaying the taxonomy term page title.
  1299. * The prefix does not automatically place a space between the prefix, so if there should
  1300. * be a space, the parameter value will need to have it at the end.
  1301. *
  1302. * @since 3.1.0
  1303. *
  1304. * @param string $prefix Optional. What to display before the title.
  1305. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1306. * @return string|void Title when retrieving.
  1307. */
  1308. function single_term_title( $prefix = '', $display = true ) {
  1309. $term = get_queried_object();
  1310. if ( ! $term ) {
  1311. return;
  1312. }
  1313. if ( is_category() ) {
  1314. /**
  1315. * Filters the category archive page title.
  1316. *
  1317. * @since 2.0.10
  1318. *
  1319. * @param string $term_name Category name for archive being displayed.
  1320. */
  1321. $term_name = apply_filters( 'single_cat_title', $term->name );
  1322. } elseif ( is_tag() ) {
  1323. /**
  1324. * Filters the tag archive page title.
  1325. *
  1326. * @since 2.3.0
  1327. *
  1328. * @param string $term_name Tag name for archive being displayed.
  1329. */
  1330. $term_name = apply_filters( 'single_tag_title', $term->name );
  1331. } elseif ( is_tax() ) {
  1332. /**
  1333. * Filters the custom taxonomy archive page title.
  1334. *
  1335. * @since 3.1.0
  1336. *
  1337. * @param string $term_name Term name for archive being displayed.
  1338. */
  1339. $term_name = apply_filters( 'single_term_title', $term->name );
  1340. } else {
  1341. return;
  1342. }
  1343. if ( empty( $term_name ) ) {
  1344. return;
  1345. }
  1346. if ( $display ) {
  1347. echo $prefix . $term_name;
  1348. } else {
  1349. return $prefix . $term_name;
  1350. }
  1351. }
  1352. /**
  1353. * Display or retrieve page title for post archive based on date.
  1354. *
  1355. * Useful for when the template only needs to display the month and year,
  1356. * if either are available. The prefix does not automatically place a space
  1357. * between the prefix, so if there should be a space, the parameter value
  1358. * will need to have it at the end.
  1359. *
  1360. * @since 0.71
  1361. *
  1362. * @global WP_Locale $wp_locale WordPress date and time locale object.
  1363. *
  1364. * @param string $prefix Optional. What to display before the title.
  1365. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  1366. * @return string|void Title when retrieving.
  1367. */
  1368. function single_month_title( $prefix = '', $display = true ) {
  1369. global $wp_locale;
  1370. $m = get_query_var( 'm' );
  1371. $year = get_query_var( 'year' );
  1372. $monthnum = get_query_var( 'monthnum' );
  1373. if ( ! empty( $monthnum ) && ! empty( $year ) ) {
  1374. $my_year = $year;
  1375. $my_month = $wp_locale->get_month( $monthnum );
  1376. } elseif ( ! empty( $m ) ) {
  1377. $my_year = substr( $m, 0, 4 );
  1378. $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
  1379. }
  1380. if ( empty( $my_month ) ) {
  1381. return false;
  1382. }
  1383. $result = $prefix . $my_month . $prefix . $my_year;
  1384. if ( ! $display ) {
  1385. return $result;
  1386. }
  1387. echo $result;
  1388. }
  1389. /**
  1390. * Display the archive title based on the queried object.
  1391. *
  1392. * @since 4.1.0
  1393. *
  1394. * @see get_the_archive_title()
  1395. *
  1396. * @param string $before Optional. Content to prepend to the title. Default empty.
  1397. * @param string $after Optional. Content to append to the title. Default empty.
  1398. */
  1399. function the_archive_title( $before = '', $after = '' ) {
  1400. $title = get_the_archive_title();
  1401. if ( ! empty( $title ) ) {
  1402. echo $before . $title . $after;
  1403. }
  1404. }
  1405. /**
  1406. * Retrieve the archive title based on the queried object.
  1407. *
  1408. * @since 4.1.0
  1409. *
  1410. * @return string Archive title.
  1411. */
  1412. function get_the_archive_title() {
  1413. $title = __( 'Archives' );
  1414. if ( is_category() ) {
  1415. /* translators: Category archive title. %s: Category name. */
  1416. $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
  1417. } elseif ( is_tag() ) {
  1418. /* translators: Tag archive title. %s: Tag name. */
  1419. $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
  1420. } elseif ( is_author() ) {
  1421. /* translators: Author archive title. %s: Author name. */
  1422. $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
  1423. } elseif ( is_year() ) {
  1424. /* translators: Yearly archive title. %s: Year. */
  1425. $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
  1426. } elseif ( is_month() ) {
  1427. /* translators: Monthly archive title. %s: Month name and year. */
  1428. $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
  1429. } elseif ( is_day() ) {
  1430. /* translators: Daily archive title. %s: Date. */
  1431. $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
  1432. } elseif ( is_tax( 'post_format' ) ) {
  1433. if ( is_tax( 'post_format', 'post-format-aside' ) ) {
  1434. $title = _x( 'Asides', 'post format archive title' );
  1435. } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
  1436. $title = _x( 'Galleries', 'post format archive title' );
  1437. } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
  1438. $title = _x( 'Images', 'post format archive title' );
  1439. } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
  1440. $title = _x( 'Videos', 'post format archive title' );
  1441. } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
  1442. $title = _x( 'Quotes', 'post format archive title' );
  1443. } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
  1444. $title = _x( 'Links', 'post format archive title' );
  1445. } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
  1446. $title = _x( 'Statuses', 'post format archive title' );
  1447. } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
  1448. $title = _x( 'Audio', 'post format archive title' );
  1449. } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
  1450. $title = _x( 'Chats', 'post format archive title' );
  1451. }
  1452. } elseif ( is_post_type_archive() ) {
  1453. /* translators: Post type archive title. %s: Post type name. */
  1454. $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
  1455. } elseif ( is_tax() ) {
  1456. $queried_object = get_queried_object();
  1457. if ( $queried_object ) {
  1458. $tax = get_taxonomy( $queried_object->taxonomy );
  1459. /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term. */
  1460. $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
  1461. }
  1462. }
  1463. /**
  1464. * Filters the archive title.
  1465. *
  1466. * @since 4.1.0
  1467. *
  1468. * @param string $title Archive title to be displayed.
  1469. */
  1470. return apply_filters( 'get_the_archive_title', $title );
  1471. }
  1472. /**
  1473. * Display category, tag, term, or author description.
  1474. *
  1475. * @since 4.1.0
  1476. *
  1477. * @see get_the_archive_description()
  1478. *
  1479. * @param string $before Optional. Content to prepend to the description. Default empty.
  1480. * @param string $after Optional. Content to append to the description. Default empty.
  1481. */
  1482. function the_archive_description( $before = '', $after = '' ) {
  1483. $description = get_the_archive_description();
  1484. if ( $description ) {
  1485. echo $before . $description . $after;
  1486. }
  1487. }
  1488. /**
  1489. * Retrieves the description for an author, post type, or term archive.
  1490. *
  1491. * @since 4.1.0
  1492. * @since 4.7.0 Added support for author archives.
  1493. * @since 4.9.0 Added support for post type archives.
  1494. *
  1495. * @see term_description()
  1496. *
  1497. * @return string Archive description.
  1498. */
  1499. function get_the_archive_description() {
  1500. if ( is_author() ) {
  1501. $description = get_the_author_meta( 'description' );
  1502. } elseif ( is_post_type_archive() ) {
  1503. $description = get_the_post_type_description();
  1504. } else {
  1505. $description = term_description();
  1506. }
  1507. /**
  1508. * Filters the archive description.
  1509. *
  1510. * @since 4.1.0
  1511. *
  1512. * @param string $description Archive description to be displayed.
  1513. */
  1514. return apply_filters( 'get_the_archive_description', $description );
  1515. }
  1516. /**
  1517. * Retrieves the description for a post type archive.
  1518. *
  1519. * @since 4.9.0
  1520. *
  1521. * @return string The post type description.
  1522. */
  1523. function get_the_post_type_description() {
  1524. $post_type = get_query_var( 'post_type' );
  1525. if ( is_array( $post_type ) ) {
  1526. $post_type = reset( $post_type );
  1527. }
  1528. $post_type_obj = get_post_type_object( $post_type );
  1529. // Check if a description is set.
  1530. if ( isset( $post_type_obj->description ) ) {
  1531. $description = $post_type_obj->description;
  1532. } else {
  1533. $description = '';
  1534. }
  1535. /**
  1536. * Filters the description for a post type archive.
  1537. *
  1538. * @since 4.9.0
  1539. *
  1540. * @param string $description The post type description.
  1541. * @param WP_Post_Type $post_type_obj The post type object.
  1542. */
  1543. return apply_filters( 'get_the_post_type_description', $description, $post_type_obj );
  1544. }
  1545. /**
  1546. * Retrieve archive link content based on predefined or custom code.
  1547. *
  1548. * The format can be one of four styles. The 'link' for head element, 'option'
  1549. * for use in the select element, 'html' for use in list (either ol or ul HTML
  1550. * elements). Custom content is also supported using the before and after
  1551. * parameters.
  1552. *
  1553. * The 'link' format uses the `<link>` HTML element with the **archives**
  1554. * relationship. The before and after parameters are not used. The text
  1555. * parameter is used to describe the link.
  1556. *
  1557. * The 'option' format uses the option HTML element for use in select element.
  1558. * The value is the url parameter and the before and after parameters are used
  1559. * between the text description.
  1560. *
  1561. * The 'html' format, which is the default, uses the li HTML element for use in
  1562. * the list HTML elements. The before parameter is before the link and the after
  1563. * parameter is after the closing link.
  1564. *
  1565. * The custom format uses the before parameter before the link ('a' HTML
  1566. * element) and the after parameter after the closing link tag. If the above
  1567. * three values for the format are not used, then custom format is assumed.
  1568. *
  1569. * @since 1.0.0
  1570. * @since 5.2.0 Added the `$selected` parameter.
  1571. *
  1572. * @param string $url URL to archive.
  1573. * @param string $text Archive text description.
  1574. * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
  1575. * @param string $before Optional. Content to prepend to the description. Default empty.
  1576. * @param string $after Optional. Content to append to the description. Default empty.
  1577. * @param bool $selected Optional. Set to true if the current page is the selected archive page.
  1578. * @return string HTML link content for archive.
  1579. */
  1580. function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
  1581. $text = wptexturize( $text );
  1582. $url = esc_url( $url );
  1583. $aria_current = $selected ? ' aria-current="page"' : '';
  1584. if ( 'link' === $format ) {
  1585. $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
  1586. } elseif ( 'option' === $format ) {
  1587. $selected_attr = $selected ? " selected='selected'" : '';
  1588. $link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n";
  1589. } elseif ( 'html' === $format ) {
  1590. $link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n";
  1591. } else { // custom
  1592. $link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n";
  1593. }
  1594. /**
  1595. * Filters the archive link content.
  1596. *
  1597. * @since 2.6.0
  1598. * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
  1599. * @since 5.2.0 Added the `$selected` parameter.
  1600. *
  1601. * @param string $link_html The archive HTML link content.
  1602. * @param string $url URL to archive.
  1603. * @param string $text Archive text description.
  1604. * @param string $format Link format. Can be 'link', 'option', 'html', or custom.
  1605. * @param string $before Content to prepend to the description.
  1606. * @param string $after Content to append to the description.
  1607. * @param bool $selected True if the current page is the selected archive.
  1608. */
  1609. return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
  1610. }
  1611. /**
  1612. * Display archive links based on type and format.
  1613. *
  1614. * @since 1.2.0
  1615. * @since 4.4.0 The `$post_type` argument was added.
  1616. * @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added.
  1617. *
  1618. * @see get_archives_link()
  1619. *
  1620. * @global wpdb $wpdb WordPress database abstraction object.
  1621. * @global WP_Locale $wp_locale WordPress date and time locale object.
  1622. *
  1623. * @param string|array $args {
  1624. * Default archive links arguments. Optional.
  1625. *
  1626. * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
  1627. * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
  1628. * display the same archive link list as well as post titles instead
  1629. * of displaying dates. The difference between the two is that 'alpha'
  1630. * will order by post title and 'postbypost' will order by post date.
  1631. * Default 'monthly'.
  1632. * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
  1633. * @type string $format Format each link should take using the $before and $after args.
  1634. * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
  1635. * (`<li>` tag), or a custom format, which generates a link anchor
  1636. * with $before preceding and $after succeeding. Default 'html'.
  1637. * @type string $before Markup to prepend to the beginning of each link. Default empty.
  1638. * @type string $after Markup to append to the end of each link. Default empty.
  1639. * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
  1640. * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo.
  1641. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
  1642. * Default 'DESC'.
  1643. * @type string $post_type Post type. Default 'post'.
  1644. * @type string $year Year. Default current year.
  1645. * @type string $monthnum Month number. Default current month number.
  1646. * @type string $day Day. Default current day.
  1647. * @type string $w Week. Default current week.
  1648. * }
  1649. * @return string|void String when retrieving.
  1650. */
  1651. function wp_get_archives( $args = '' ) {
  1652. global $wpdb, $wp_locale;
  1653. $defaults = array(
  1654. 'type' => 'monthly',
  1655. 'limit' => '',
  1656. 'format' => 'html',
  1657. 'before' => '',
  1658. 'after' => '',
  1659. 'show_post_count' => false,
  1660. 'echo' => 1,
  1661. 'order' => 'DESC',
  1662. 'post_type' => 'post',
  1663. 'year' => get_query_var( 'year' ),
  1664. 'monthnum' => get_query_var( 'monthnum' ),
  1665. 'day' => get_query_var( 'day' ),
  1666. 'w' => get_query_var( 'w' ),
  1667. );
  1668. $parsed_args = wp_parse_args( $args, $defaults );
  1669. $post_type_object = get_post_type_object( $parsed_args['post_type'] );
  1670. if ( ! is_post_type_viewable( $post_type_object ) ) {
  1671. return;
  1672. }
  1673. $parsed_args['post_type'] = $post_type_object->name;
  1674. if ( '' == $parsed_args['type'] ) {
  1675. $parsed_args['type'] = 'monthly';
  1676. }
  1677. if ( ! empty( $parsed_args['limit'] ) ) {
  1678. $parsed_args['limit'] = absint( $parsed_args['limit'] );
  1679. $parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit'];
  1680. }
  1681. $order = strtoupper( $parsed_args['order'] );
  1682. if ( $order !== 'ASC' ) {
  1683. $order = 'DESC';
  1684. }
  1685. // this is what will separate dates on weekly archive links
  1686. $archive_week_separator = '&#8211;';
  1687. $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $parsed_args['post_type'] );
  1688. /**
  1689. * Filters the SQL WHERE clause for retrieving archives.
  1690. *
  1691. * @since 2.2.0
  1692. *
  1693. * @param string $sql_where Portion of SQL query containing the WHERE clause.
  1694. * @param array $parsed_args An array of default arguments.
  1695. */
  1696. $where = apply_filters( 'getarchives_where', $sql_where, $parsed_args );
  1697. /**
  1698. * Filters the SQL JOIN clause for retrieving archives.
  1699. *
  1700. * @since 2.2.0
  1701. *
  1702. * @param string $sql_join Portion of SQL query containing JOIN clause.
  1703. * @param array $parsed_args An array of default arguments.
  1704. */
  1705. $join = apply_filters( 'getarchives_join', '', $parsed_args );
  1706. $output = '';
  1707. $last_changed = wp_cache_get_last_changed( 'posts' );
  1708. $limit = $parsed_args['limit'];
  1709. if ( 'monthly' == $parsed_args['type'] ) {
  1710. $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
  1711. $key = md5( $query );
  1712. $key = "wp_get_archives:$key:$last_changed";
  1713. $results = wp_cache_get( $key, 'posts' );
  1714. if ( ! $results ) {
  1715. $results = $wpdb->get_results( $query );
  1716. wp_cache_set( $key, $results, 'posts' );
  1717. }
  1718. if ( $results ) {
  1719. $after = $parsed_args['after'];
  1720. foreach ( (array) $results as $result ) {
  1721. $url = get_month_link( $result->year, $result->month );
  1722. if ( 'post' !== $parsed_args['post_type'] ) {
  1723. $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
  1724. }
  1725. /* translators: 1: Month name, 2: 4-digit year. */
  1726. $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
  1727. if ( $parsed_args['show_post_count'] ) {
  1728. $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1729. }
  1730. $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month;
  1731. $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
  1732. }
  1733. }
  1734. } elseif ( 'yearly' == $parsed_args['type'] ) {
  1735. $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
  1736. $key = md5( $query );
  1737. $key = "wp_get_archives:$key:$last_changed";
  1738. $results = wp_cache_get( $key, 'posts' );
  1739. if ( ! $results ) {
  1740. $results = $wpdb->get_results( $query );
  1741. wp_cache_set( $key, $results, 'posts' );
  1742. }
  1743. if ( $results ) {
  1744. $after = $parsed_args['after'];
  1745. foreach ( (array) $results as $result ) {
  1746. $url = get_year_link( $result->year );
  1747. if ( 'post' !== $parsed_args['post_type'] ) {
  1748. $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
  1749. }
  1750. $text = sprintf( '%d', $result->year );
  1751. if ( $parsed_args['show_post_count'] ) {
  1752. $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1753. }
  1754. $selected = is_archive() && (string) $parsed_args['year'] === $result->year;
  1755. $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
  1756. }
  1757. }
  1758. } elseif ( 'daily' == $parsed_args['type'] ) {
  1759. $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
  1760. $key = md5( $query );
  1761. $key = "wp_get_archives:$key:$last_changed";
  1762. $results = wp_cache_get( $key, 'posts' );
  1763. if ( ! $results ) {
  1764. $results = $wpdb->get_results( $query );
  1765. wp_cache_set( $key, $results, 'posts' );
  1766. }
  1767. if ( $results ) {
  1768. $after = $parsed_args['after'];
  1769. foreach ( (array) $results as $result ) {
  1770. $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
  1771. if ( 'post' !== $parsed_args['post_type'] ) {
  1772. $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
  1773. }
  1774. $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
  1775. $text = mysql2date( get_option( 'date_format' ), $date );
  1776. if ( $parsed_args['show_post_count'] ) {
  1777. $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1778. }
  1779. $selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month && (string) $parsed_args['day'] === $result->dayofmonth;
  1780. $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
  1781. }
  1782. }
  1783. } elseif ( 'weekly' == $parsed_args['type'] ) {
  1784. $week = _wp_mysql_week( '`post_date`' );
  1785. $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
  1786. $key = md5( $query );
  1787. $key = "wp_get_archives:$key:$last_changed";
  1788. $results = wp_cache_get( $key, 'posts' );
  1789. if ( ! $results ) {
  1790. $results = $wpdb->get_results( $query );
  1791. wp_cache_set( $key, $results, 'posts' );
  1792. }
  1793. $arc_w_last = '';
  1794. if ( $results ) {
  1795. $after = $parsed_args['after'];
  1796. foreach ( (array) $results as $result ) {
  1797. if ( $result->week != $arc_w_last ) {
  1798. $arc_year = $result->yr;
  1799. $arc_w_last = $result->week;
  1800. $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
  1801. $arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] );
  1802. $arc_week_end = date_i18n( get_option( 'date_format' ), $arc_week['end'] );
  1803. $url = add_query_arg(
  1804. array(
  1805. 'm' => $arc_year,
  1806. 'w' => $result->week,
  1807. ),
  1808. home_url( '/' )
  1809. );
  1810. if ( 'post' !== $parsed_args['post_type'] ) {
  1811. $url = add_query_arg( 'post_type', $parsed_args['post_type'], $url );
  1812. }
  1813. $text = $arc_week_start . $archive_week_separator . $arc_week_end;
  1814. if ( $parsed_args['show_post_count'] ) {
  1815. $parsed_args['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1816. }
  1817. $selected = is_archive() && (string) $parsed_args['year'] === $result->yr && (string) $parsed_args['w'] === $result->week;
  1818. $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
  1819. }
  1820. }
  1821. }
  1822. } elseif ( ( 'postbypost' == $parsed_args['type'] ) || ( 'alpha' == $parsed_args['type'] ) ) {
  1823. $orderby = ( 'alpha' == $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
  1824. $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  1825. $key = md5( $query );
  1826. $key = "wp_get_archives:$key:$last_changed";
  1827. $results = wp_cache_get( $key, 'posts' );
  1828. if ( ! $results ) {
  1829. $results = $wpdb->get_results( $query );
  1830. wp_cache_set( $key, $results, 'posts' );
  1831. }
  1832. if ( $results ) {
  1833. foreach ( (array) $results as $result ) {
  1834. if ( $result->post_date != '0000-00-00 00:00:00' ) {
  1835. $url = get_permalink( $result );
  1836. if ( $result->post_title ) {
  1837. /** This filter is documented in wp-includes/post-template.php */
  1838. $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
  1839. } else {
  1840. $text = $result->ID;
  1841. }
  1842. $selected = $result->ID === get_the_ID();
  1843. $output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected );
  1844. }
  1845. }
  1846. }
  1847. }
  1848. if ( $parsed_args['echo'] ) {
  1849. echo $output;
  1850. } else {
  1851. return $output;
  1852. }
  1853. }
  1854. /**
  1855. * Get number of days since the start of the week.
  1856. *
  1857. * @since 1.5.0
  1858. *
  1859. * @param int $num Number of day.
  1860. * @return float Days since the start of the week.
  1861. */
  1862. function calendar_week_mod( $num ) {
  1863. $base = 7;
  1864. return ( $num - $base * floor( $num / $base ) );
  1865. }
  1866. /**
  1867. * Display calendar with days that have posts as links.
  1868. *
  1869. * The calendar is cached, which will be retrieved, if it exists. If there are
  1870. * no posts for the month, then it will not be displayed.
  1871. *
  1872. * @since 1.0.0
  1873. *
  1874. * @global wpdb $wpdb WordPress database abstraction object.
  1875. * @global int $m
  1876. * @global int $monthnum
  1877. * @global int $year
  1878. * @global WP_Locale $wp_locale WordPress date and time locale object.
  1879. * @global array $posts
  1880. *
  1881. * @param bool $initial Optional, default is true. Use initial calendar names.
  1882. * @param bool $echo Optional, default is true. Set to false for return.
  1883. * @return string|void String when retrieving.
  1884. */
  1885. function get_calendar( $initial = true, $echo = true ) {
  1886. global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  1887. $key = md5( $m . $monthnum . $year );
  1888. $cache = wp_cache_get( 'get_calendar', 'calendar' );
  1889. if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
  1890. /** This filter is documented in wp-includes/general-template.php */
  1891. $output = apply_filters( 'get_calendar', $cache[ $key ] );
  1892. if ( $echo ) {
  1893. echo $output;
  1894. return;
  1895. }
  1896. return $output;
  1897. }
  1898. if ( ! is_array( $cache ) ) {
  1899. $cache = array();
  1900. }
  1901. // Quick check. If we have no posts at all, abort!
  1902. if ( ! $posts ) {
  1903. $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" );
  1904. if ( ! $gotsome ) {
  1905. $cache[ $key ] = '';
  1906. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1907. return;
  1908. }
  1909. }
  1910. if ( isset( $_GET['w'] ) ) {
  1911. $w = (int) $_GET['w'];
  1912. }
  1913. // week_begins = 0 stands for Sunday
  1914. $week_begins = (int) get_option( 'start_of_week' );
  1915. // Let's figure out when we are
  1916. if ( ! empty( $monthnum ) && ! empty( $year ) ) {
  1917. $thismonth = zeroise( intval( $monthnum ), 2 );
  1918. $thisyear = (int) $year;
  1919. } elseif ( ! empty( $w ) ) {
  1920. // We need to get the month from MySQL
  1921. $thisyear = (int) substr( $m, 0, 4 );
  1922. //it seems MySQL's weeks disagree with PHP's
  1923. $d = ( ( $w - 1 ) * 7 ) + 6;
  1924. $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" );
  1925. } elseif ( ! empty( $m ) ) {
  1926. $thisyear = (int) substr( $m, 0, 4 );
  1927. if ( strlen( $m ) < 6 ) {
  1928. $thismonth = '01';
  1929. } else {
  1930. $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
  1931. }
  1932. } else {
  1933. $thisyear = current_time( 'Y' );
  1934. $thismonth = current_time( 'm' );
  1935. }
  1936. $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
  1937. $last_day = gmdate( 't', $unixmonth );
  1938. // Get the next and previous month and year with at least one post
  1939. $previous = $wpdb->get_row(
  1940. "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  1941. FROM $wpdb->posts
  1942. WHERE post_date < '$thisyear-$thismonth-01'
  1943. AND post_type = 'post' AND post_status = 'publish'
  1944. ORDER BY post_date DESC
  1945. LIMIT 1"
  1946. );
  1947. $next = $wpdb->get_row(
  1948. "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  1949. FROM $wpdb->posts
  1950. WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
  1951. AND post_type = 'post' AND post_status = 'publish'
  1952. ORDER BY post_date ASC
  1953. LIMIT 1"
  1954. );
  1955. /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */
  1956. $calendar_caption = _x( '%1$s %2$s', 'calendar caption' );
  1957. $calendar_output = '<table id="wp-calendar">
  1958. <caption>' . sprintf(
  1959. $calendar_caption,
  1960. $wp_locale->get_month( $thismonth ),
  1961. gmdate( 'Y', $unixmonth )
  1962. ) . '</caption>
  1963. <thead>
  1964. <tr>';
  1965. $myweek = array();
  1966. for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) {
  1967. $myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 );
  1968. }
  1969. foreach ( $myweek as $wd ) {
  1970. $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );
  1971. $wd = esc_attr( $wd );
  1972. $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
  1973. }
  1974. $calendar_output .= '
  1975. </tr>
  1976. </thead>
  1977. <tfoot>
  1978. <tr>';
  1979. if ( $previous ) {
  1980. $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">&laquo; ' .
  1981. $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) .
  1982. '</a></td>';
  1983. } else {
  1984. $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
  1985. }
  1986. $calendar_output .= "\n\t\t" . '<td class="pad">&nbsp;</td>';
  1987. if ( $next ) {
  1988. $calendar_output .= "\n\t\t" . '<td colspan="3" id="next"><a href="' . get_month_link( $next->year, $next->month ) . '">' .
  1989. $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) .
  1990. ' &raquo;</a></td>';
  1991. } else {
  1992. $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
  1993. }
  1994. $calendar_output .= '
  1995. </tr>
  1996. </tfoot>
  1997. <tbody>
  1998. <tr>';
  1999. $daywithpost = array();
  2000. // Get days with posts
  2001. $dayswithposts = $wpdb->get_results(
  2002. "SELECT DISTINCT DAYOFMONTH(post_date)
  2003. FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
  2004. AND post_type = 'post' AND post_status = 'publish'
  2005. AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'",
  2006. ARRAY_N
  2007. );
  2008. if ( $dayswithposts ) {
  2009. foreach ( (array) $dayswithposts as $daywith ) {
  2010. $daywithpost[] = $daywith[0];
  2011. }
  2012. }
  2013. // See how much we should pad in the beginning
  2014. $pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins );
  2015. if ( 0 != $pad ) {
  2016. $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad">&nbsp;</td>';
  2017. }
  2018. $newrow = false;
  2019. $daysinmonth = (int) gmdate( 't', $unixmonth );
  2020. for ( $day = 1; $day <= $daysinmonth; ++$day ) {
  2021. if ( isset( $newrow ) && $newrow ) {
  2022. $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
  2023. }
  2024. $newrow = false;
  2025. if ( $day == current_time( 'j' ) &&
  2026. $thismonth == current_time( 'm' ) &&
  2027. $thisyear == current_time( 'Y' ) ) {
  2028. $calendar_output .= '<td id="today">';
  2029. } else {
  2030. $calendar_output .= '<td>';
  2031. }
  2032. if ( in_array( $day, $daywithpost ) ) {
  2033. // any posts today?
  2034. $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
  2035. /* translators: Post calendar label. %s: Date. */
  2036. $label = sprintf( __( 'Posts published on %s' ), $date_format );
  2037. $calendar_output .= sprintf(
  2038. '<a href="%s" aria-label="%s">%s</a>',
  2039. get_day_link( $thisyear, $thismonth, $day ),
  2040. esc_attr( $label ),
  2041. $day
  2042. );
  2043. } else {
  2044. $calendar_output .= $day;
  2045. }
  2046. $calendar_output .= '</td>';
  2047. if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
  2048. $newrow = true;
  2049. }
  2050. }
  2051. $pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
  2052. if ( $pad != 0 && $pad != 7 ) {
  2053. $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '">&nbsp;</td>';
  2054. }
  2055. $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
  2056. $cache[ $key ] = $calendar_output;
  2057. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  2058. if ( $echo ) {
  2059. /**
  2060. * Filters the HTML calendar output.
  2061. *
  2062. * @since 3.0.0
  2063. *
  2064. * @param string $calendar_output HTML output of the calendar.
  2065. */
  2066. echo apply_filters( 'get_calendar', $calendar_output );
  2067. return;
  2068. }
  2069. /** This filter is documented in wp-includes/general-template.php */
  2070. return apply_filters( 'get_calendar', $calendar_output );
  2071. }
  2072. /**
  2073. * Purge the cached results of get_calendar.
  2074. *
  2075. * @see get_calendar
  2076. * @since 2.1.0
  2077. */
  2078. function delete_get_calendar_cache() {
  2079. wp_cache_delete( 'get_calendar', 'calendar' );
  2080. }
  2081. /**
  2082. * Display all of the allowed tags in HTML format with attributes.
  2083. *
  2084. * This is useful for displaying in the comment area, which elements and
  2085. * attributes are supported. As well as any plugins which want to display it.
  2086. *
  2087. * @since 1.0.1
  2088. *
  2089. * @global array $allowedtags
  2090. *
  2091. * @return string HTML allowed tags entity encoded.
  2092. */
  2093. function allowed_tags() {
  2094. global $allowedtags;
  2095. $allowed = '';
  2096. foreach ( (array) $allowedtags as $tag => $attributes ) {
  2097. $allowed .= '<' . $tag;
  2098. if ( 0 < count( $attributes ) ) {
  2099. foreach ( $attributes as $attribute => $limits ) {
  2100. $allowed .= ' ' . $attribute . '=""';
  2101. }
  2102. }
  2103. $allowed .= '> ';
  2104. }
  2105. return htmlentities( $allowed );
  2106. }
  2107. /***** Date/Time tags */
  2108. /**
  2109. * Outputs the date in iso8601 format for xml files.
  2110. *
  2111. * @since 1.0.0
  2112. */
  2113. function the_date_xml() {
  2114. echo mysql2date( 'Y-m-d', get_post()->post_date, false );
  2115. }
  2116. /**
  2117. * Display or Retrieve the date the current post was written (once per date)
  2118. *
  2119. * Will only output the date if the current post's date is different from the
  2120. * previous one output.
  2121. *
  2122. * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  2123. * function is called several times for each post.
  2124. *
  2125. * HTML output can be filtered with 'the_date'.
  2126. * Date string output can be filtered with 'get_the_date'.
  2127. *
  2128. * @since 0.71
  2129. *
  2130. * @global string $currentday The day of the current post in the loop.
  2131. * @global string $previousday The day of the previous post in the loop.
  2132. *
  2133. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  2134. * @param string $before Optional. Output before the date.
  2135. * @param string $after Optional. Output after the date.
  2136. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  2137. * @return string|void String if retrieving.
  2138. */
  2139. function the_date( $d = '', $before = '', $after = '', $echo = true ) {
  2140. global $currentday, $previousday;
  2141. $the_date = '';
  2142. if ( is_new_day() ) {
  2143. $the_date = $before . get_the_date( $d ) . $after;
  2144. $previousday = $currentday;
  2145. }
  2146. /**
  2147. * Filters the date a post was published for display.
  2148. *
  2149. * @since 0.71
  2150. *
  2151. * @param string $the_date The formatted date string.
  2152. * @param string $d PHP date format. Defaults to 'date_format' option
  2153. * if not specified.
  2154. * @param string $before HTML output before the date.
  2155. * @param string $after HTML output after the date.
  2156. */
  2157. $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
  2158. if ( $echo ) {
  2159. echo $the_date;
  2160. } else {
  2161. return $the_date;
  2162. }
  2163. }
  2164. /**
  2165. * Retrieve the date on which the post was written.
  2166. *
  2167. * Unlike the_date() this function will always return the date.
  2168. * Modify output with the {@see 'get_the_date'} filter.
  2169. *
  2170. * @since 3.0.0
  2171. *
  2172. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  2173. * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  2174. * @return false|string Date the current post was written. False on failure.
  2175. */
  2176. function get_the_date( $d = '', $post = null ) {
  2177. $post = get_post( $post );
  2178. if ( ! $post ) {
  2179. return false;
  2180. }
  2181. if ( '' == $d ) {
  2182. $the_date = get_post_time( get_option( 'date_format' ), false, $post, true );
  2183. } else {
  2184. $the_date = get_post_time( $d, false, $post, true );
  2185. }
  2186. /**
  2187. * Filters the date a post was published.
  2188. *
  2189. * @since 3.0.0
  2190. *
  2191. * @param string $the_date The formatted date.
  2192. * @param string $d PHP date format. Defaults to 'date_format' option
  2193. * if not specified.
  2194. * @param int|WP_Post $post The post object or ID.
  2195. */
  2196. return apply_filters( 'get_the_date', $the_date, $d, $post );
  2197. }
  2198. /**
  2199. * Display the date on which the post was last modified.
  2200. *
  2201. * @since 2.1.0
  2202. *
  2203. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  2204. * @param string $before Optional. Output before the date.
  2205. * @param string $after Optional. Output after the date.
  2206. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  2207. * @return string|void String if retrieving.
  2208. */
  2209. function the_modified_date( $d = '', $before = '', $after = '', $echo = true ) {
  2210. $the_modified_date = $before . get_the_modified_date( $d ) . $after;
  2211. /**
  2212. * Filters the date a post was last modified for display.
  2213. *
  2214. * @since 2.1.0
  2215. *
  2216. * @param string $the_modified_date The last modified date.
  2217. * @param string $d PHP date format. Defaults to 'date_format' option
  2218. * if not specified.
  2219. * @param string $before HTML output before the date.
  2220. * @param string $after HTML output after the date.
  2221. */
  2222. $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
  2223. if ( $echo ) {
  2224. echo $the_modified_date;
  2225. } else {
  2226. return $the_modified_date;
  2227. }
  2228. }
  2229. /**
  2230. * Retrieve the date on which the post was last modified.
  2231. *
  2232. * @since 2.1.0
  2233. * @since 4.6.0 Added the `$post` parameter.
  2234. *
  2235. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  2236. * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  2237. * @return false|string Date the current post was modified. False on failure.
  2238. */
  2239. function get_the_modified_date( $d = '', $post = null ) {
  2240. $post = get_post( $post );
  2241. if ( ! $post ) {
  2242. // For backward compatibility, failures go through the filter below.
  2243. $the_time = false;
  2244. } elseif ( empty( $d ) ) {
  2245. $the_time = get_post_modified_time( get_option( 'date_format' ), false, $post, true );
  2246. } else {
  2247. $the_time = get_post_modified_time( $d, false, $post, true );
  2248. }
  2249. /**
  2250. * Filters the date a post was last modified.
  2251. *
  2252. * @since 2.1.0
  2253. * @since 4.6.0 Added the `$post` parameter.
  2254. *
  2255. * @param string|bool $the_time The formatted date or false if no post is found.
  2256. * @param string $d PHP date format. Defaults to value specified in
  2257. * 'date_format' option.
  2258. * @param WP_Post|null $post WP_Post object or null if no post is found.
  2259. */
  2260. return apply_filters( 'get_the_modified_date', $the_time, $d, $post );
  2261. }
  2262. /**
  2263. * Display the time at which the post was written.
  2264. *
  2265. * @since 0.71
  2266. *
  2267. * @param string $d Either 'G', 'U', or php date format.
  2268. */
  2269. function the_time( $d = '' ) {
  2270. /**
  2271. * Filters the time a post was written for display.
  2272. *
  2273. * @since 0.71
  2274. *
  2275. * @param string $get_the_time The formatted time.
  2276. * @param string $d The time format. Accepts 'G', 'U',
  2277. * or php date format.
  2278. */
  2279. echo apply_filters( 'the_time', get_the_time( $d ), $d );
  2280. }
  2281. /**
  2282. * Retrieve the time at which the post was written.
  2283. *
  2284. * @since 1.5.0
  2285. *
  2286. * @param string $d Optional. Format to use for retrieving the time the post
  2287. * was written. Either 'G', 'U', or php date format defaults
  2288. * to the value specified in the time_format option. Default empty.
  2289. * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object.
  2290. * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
  2291. */
  2292. function get_the_time( $d = '', $post = null ) {
  2293. $post = get_post( $post );
  2294. if ( ! $post ) {
  2295. return false;
  2296. }
  2297. if ( '' == $d ) {
  2298. $the_time = get_post_time( get_option( 'time_format' ), false, $post, true );
  2299. } else {
  2300. $the_time = get_post_time( $d, false, $post, true );
  2301. }
  2302. /**
  2303. * Filters the time a post was written.
  2304. *
  2305. * @since 1.5.0
  2306. *
  2307. * @param string $the_time The formatted time.
  2308. * @param string $d Format to use for retrieving the time the post was written.
  2309. * Accepts 'G', 'U', or php date format value specified
  2310. * in 'time_format' option. Default empty.
  2311. * @param int|WP_Post $post WP_Post object or ID.
  2312. */
  2313. return apply_filters( 'get_the_time', $the_time, $d, $post );
  2314. }
  2315. /**
  2316. * Retrieve the time at which the post was written.
  2317. *
  2318. * @since 2.0.0
  2319. *
  2320. * @param string $d Optional. Format to use for retrieving the time the post
  2321. * was written. Either 'G', 'U', or php date format. Default 'U'.
  2322. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
  2323. * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object.
  2324. * @param bool $translate Whether to translate the time string. Default false.
  2325. * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
  2326. */
  2327. function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  2328. $post = get_post( $post );
  2329. if ( ! $post ) {
  2330. return false;
  2331. }
  2332. $source = ( $gmt ) ? 'gmt' : 'local';
  2333. $datetime = get_post_datetime( $post, 'date', $source );
  2334. if ( false === $datetime ) {
  2335. return false;
  2336. }
  2337. if ( 'U' === $d || 'G' === $d ) {
  2338. $time = $datetime->getTimestamp();
  2339. // Returns a sum of timestamp with timezone offset. Ideally should never be used.
  2340. if ( ! $gmt ) {
  2341. $time += $datetime->getOffset();
  2342. }
  2343. } elseif ( $translate ) {
  2344. $time = wp_date( $d, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
  2345. } else {
  2346. if ( $gmt ) {
  2347. $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
  2348. }
  2349. $time = $datetime->format( $d );
  2350. }
  2351. /**
  2352. * Filters the localized time a post was written.
  2353. *
  2354. * @since 2.6.0
  2355. *
  2356. * @param string $time The formatted time.
  2357. * @param string $d Format to use for retrieving the time the post was written.
  2358. * Accepts 'G', 'U', or php date format. Default 'U'.
  2359. * @param bool $gmt Whether to retrieve the GMT time. Default false.
  2360. */
  2361. return apply_filters( 'get_post_time', $time, $d, $gmt );
  2362. }
  2363. /**
  2364. * Retrieve post published or modified time as a `DateTimeImmutable` object instance.
  2365. *
  2366. * The object will be set to the timezone from WordPress settings.
  2367. *
  2368. * For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.
  2369. * Normally this should make no difference to the result. However, the values might get out of sync in database,
  2370. * typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards
  2371. * compatible behaviors in such cases.
  2372. *
  2373. * @since 5.3.0
  2374. *
  2375. * @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object.
  2376. * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
  2377. * Default 'date'.
  2378. * @param string $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'.
  2379. * Default 'local'.
  2380. * @return DateTimeImmutable|false Time object on success, false on failure.
  2381. */
  2382. function get_post_datetime( $post = null, $field = 'date', $source = 'local' ) {
  2383. $post = get_post( $post );
  2384. if ( ! $post ) {
  2385. return false;
  2386. }
  2387. $wp_timezone = wp_timezone();
  2388. if ( 'gmt' === $source ) {
  2389. $time = ( 'modified' === $field ) ? $post->post_modified_gmt : $post->post_date_gmt;
  2390. $timezone = new DateTimeZone( 'UTC' );
  2391. } else {
  2392. $time = ( 'modified' === $field ) ? $post->post_modified : $post->post_date;
  2393. $timezone = $wp_timezone;
  2394. }
  2395. if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) {
  2396. return false;
  2397. }
  2398. $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time, $timezone );
  2399. if ( false === $datetime ) {
  2400. return false;
  2401. }
  2402. return $datetime->setTimezone( $wp_timezone );
  2403. }
  2404. /**
  2405. * Retrieve post published or modified time as a Unix timestamp.
  2406. *
  2407. * Note that this function returns a true Unix timestamp, not summed with timezone offset
  2408. * like older WP functions.
  2409. *
  2410. * @since 5.3.0
  2411. *
  2412. * @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object.
  2413. * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
  2414. * Default 'date'.
  2415. * @return int|false Unix timestamp on success, false on failure.
  2416. */
  2417. function get_post_timestamp( $post = null, $field = 'date' ) {
  2418. $datetime = get_post_datetime( $post, $field );
  2419. if ( false === $datetime ) {
  2420. return false;
  2421. }
  2422. return $datetime->getTimestamp();
  2423. }
  2424. /**
  2425. * Display the time at which the post was last modified.
  2426. *
  2427. * @since 2.0.0
  2428. *
  2429. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  2430. */
  2431. function the_modified_time( $d = '' ) {
  2432. /**
  2433. * Filters the localized time a post was last modified, for display.
  2434. *
  2435. * @since 2.0.0
  2436. *
  2437. * @param string $get_the_modified_time The formatted time.
  2438. * @param string $d The time format. Accepts 'G', 'U',
  2439. * or php date format. Defaults to value
  2440. * specified in 'time_format' option.
  2441. */
  2442. echo apply_filters( 'the_modified_time', get_the_modified_time( $d ), $d );
  2443. }
  2444. /**
  2445. * Retrieve the time at which the post was last modified.
  2446. *
  2447. * @since 2.0.0
  2448. * @since 4.6.0 Added the `$post` parameter.
  2449. *
  2450. * @param string $d Optional. Format to use for retrieving the time the post
  2451. * was modified. Either 'G', 'U', or php date format defaults
  2452. * to the value specified in the time_format option. Default empty.
  2453. * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  2454. * @return false|string Formatted date string or Unix timestamp. False on failure.
  2455. */
  2456. function get_the_modified_time( $d = '', $post = null ) {
  2457. $post = get_post( $post );
  2458. if ( ! $post ) {
  2459. // For backward compatibility, failures go through the filter below.
  2460. $the_time = false;
  2461. } elseif ( empty( $d ) ) {
  2462. $the_time = get_post_modified_time( get_option( 'time_format' ), false, $post, true );
  2463. } else {
  2464. $the_time = get_post_modified_time( $d, false, $post, true );
  2465. }
  2466. /**
  2467. * Filters the localized time a post was last modified.
  2468. *
  2469. * @since 2.0.0
  2470. * @since 4.6.0 Added the `$post` parameter.
  2471. *
  2472. * @param string|bool $the_time The formatted time or false if no post is found.
  2473. * @param string $d Format to use for retrieving the time the post was
  2474. * written. Accepts 'G', 'U', or php date format. Defaults
  2475. * to value specified in 'time_format' option.
  2476. * @param WP_Post|null $post WP_Post object or null if no post is found.
  2477. */
  2478. return apply_filters( 'get_the_modified_time', $the_time, $d, $post );
  2479. }
  2480. /**
  2481. * Retrieve the time at which the post was last modified.
  2482. *
  2483. * @since 2.0.0
  2484. *
  2485. * @param string $d Optional. Format to use for retrieving the time the post
  2486. * was modified. Either 'G', 'U', or php date format. Default 'U'.
  2487. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
  2488. * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object.
  2489. * @param bool $translate Whether to translate the time string. Default false.
  2490. * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure.
  2491. */
  2492. function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  2493. $post = get_post( $post );
  2494. if ( ! $post ) {
  2495. return false;
  2496. }
  2497. $source = ( $gmt ) ? 'gmt' : 'local';
  2498. $datetime = get_post_datetime( $post, 'modified', $source );
  2499. if ( false === $datetime ) {
  2500. return false;
  2501. }
  2502. if ( 'U' === $d || 'G' === $d ) {
  2503. $time = $datetime->getTimestamp();
  2504. // Returns a sum of timestamp with timezone offset. Ideally should never be used.
  2505. if ( ! $gmt ) {
  2506. $time += $datetime->getOffset();
  2507. }
  2508. } elseif ( $translate ) {
  2509. $time = wp_date( $d, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
  2510. } else {
  2511. if ( $gmt ) {
  2512. $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
  2513. }
  2514. $time = $datetime->format( $d );
  2515. }
  2516. /**
  2517. * Filters the localized time a post was last modified.
  2518. *
  2519. * @since 2.8.0
  2520. *
  2521. * @param string $time The formatted time.
  2522. * @param string $d Format to use for retrieving the time the post was modified.
  2523. * Accepts 'G', 'U', or php date format. Default 'U'.
  2524. * @param bool $gmt Whether to retrieve the GMT time. Default false.
  2525. */
  2526. return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
  2527. }
  2528. /**
  2529. * Display the weekday on which the post was written.
  2530. *
  2531. * @since 0.71
  2532. *
  2533. * @global WP_Locale $wp_locale WordPress date and time locale object.
  2534. */
  2535. function the_weekday() {
  2536. global $wp_locale;
  2537. $post = get_post();
  2538. if ( ! $post ) {
  2539. return;
  2540. }
  2541. $the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
  2542. /**
  2543. * Filters the weekday on which the post was written, for display.
  2544. *
  2545. * @since 0.71
  2546. *
  2547. * @param string $the_weekday
  2548. */
  2549. echo apply_filters( 'the_weekday', $the_weekday );
  2550. }
  2551. /**
  2552. * Display the weekday on which the post was written.
  2553. *
  2554. * Will only output the weekday if the current post's weekday is different from
  2555. * the previous one output.
  2556. *
  2557. * @since 0.71
  2558. *
  2559. * @global WP_Locale $wp_locale WordPress date and time locale object.
  2560. * @global string $currentday The day of the current post in the loop.
  2561. * @global string $previousweekday The day of the previous post in the loop.
  2562. *
  2563. * @param string $before Optional. Output before the date.
  2564. * @param string $after Optional. Output after the date.
  2565. */
  2566. function the_weekday_date( $before = '', $after = '' ) {
  2567. global $wp_locale, $currentday, $previousweekday;
  2568. $post = get_post();
  2569. if ( ! $post ) {
  2570. return;
  2571. }
  2572. $the_weekday_date = '';
  2573. if ( $currentday !== $previousweekday ) {
  2574. $the_weekday_date .= $before;
  2575. $the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
  2576. $the_weekday_date .= $after;
  2577. $previousweekday = $currentday;
  2578. }
  2579. /**
  2580. * Filters the localized date on which the post was written, for display.
  2581. *
  2582. * @since 0.71
  2583. *
  2584. * @param string $the_weekday_date The weekday on which the post was written.
  2585. * @param string $before The HTML to output before the date.
  2586. * @param string $after The HTML to output after the date.
  2587. */
  2588. echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
  2589. }
  2590. /**
  2591. * Fire the wp_head action.
  2592. *
  2593. * See {@see 'wp_head'}.
  2594. *
  2595. * @since 1.2.0
  2596. */
  2597. function wp_head() {
  2598. /**
  2599. * Prints scripts or data in the head tag on the front end.
  2600. *
  2601. * @since 1.5.0
  2602. */
  2603. do_action( 'wp_head' );
  2604. }
  2605. /**
  2606. * Fire the wp_footer action.
  2607. *
  2608. * See {@see 'wp_footer'}.
  2609. *
  2610. * @since 1.5.1
  2611. */
  2612. function wp_footer() {
  2613. /**
  2614. * Prints scripts or data before the closing body tag on the front end.
  2615. *
  2616. * @since 1.5.1
  2617. */
  2618. do_action( 'wp_footer' );
  2619. }
  2620. /**
  2621. * Fire the wp_body_open action.
  2622. *
  2623. * * See {@see 'wp_body_open'}.
  2624. *
  2625. * @since 5.2.0
  2626. */
  2627. function wp_body_open() {
  2628. /**
  2629. * Triggered after the opening <body> tag.
  2630. *
  2631. * @since 5.2.0
  2632. */
  2633. do_action( 'wp_body_open' );
  2634. }
  2635. /**
  2636. * Display the links to the general feeds.
  2637. *
  2638. * @since 2.8.0
  2639. *
  2640. * @param array $args Optional arguments.
  2641. */
  2642. function feed_links( $args = array() ) {
  2643. if ( ! current_theme_supports( 'automatic-feed-links' ) ) {
  2644. return;
  2645. }
  2646. $defaults = array(
  2647. /* translators: Separator between blog name and feed type in feed links. */
  2648. 'separator' => _x( '&raquo;', 'feed link' ),
  2649. /* translators: 1: Blog title, 2: Separator (raquo). */
  2650. 'feedtitle' => __( '%1$s %2$s Feed' ),
  2651. /* translators: 1: Blog title, 2: Separator (raquo). */
  2652. 'comstitle' => __( '%1$s %2$s Comments Feed' ),
  2653. );
  2654. $args = wp_parse_args( $args, $defaults );
  2655. /**
  2656. * Filters whether to display the posts feed link.
  2657. *
  2658. * @since 4.4.0
  2659. *
  2660. * @param bool $show Whether to display the posts feed link. Default true.
  2661. */
  2662. if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
  2663. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
  2664. }
  2665. /**
  2666. * Filters whether to display the comments feed link.
  2667. *
  2668. * @since 4.4.0
  2669. *
  2670. * @param bool $show Whether to display the comments feed link. Default true.
  2671. */
  2672. if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
  2673. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
  2674. }
  2675. }
  2676. /**
  2677. * Display the links to the extra feeds such as category feeds.
  2678. *
  2679. * @since 2.8.0
  2680. *
  2681. * @param array $args Optional arguments.
  2682. */
  2683. function feed_links_extra( $args = array() ) {
  2684. $defaults = array(
  2685. /* translators: Separator between blog name and feed type in feed links. */
  2686. 'separator' => _x( '&raquo;', 'feed link' ),
  2687. /* translators: 1: Blog name, 2: Separator (raquo), 3: Post title. */
  2688. 'singletitle' => __( '%1$s %2$s %3$s Comments Feed' ),
  2689. /* translators: 1: Blog name, 2: Separator (raquo), 3: Category name. */
  2690. 'cattitle' => __( '%1$s %2$s %3$s Category Feed' ),
  2691. /* translators: 1: Blog name, 2: Separator (raquo), 3: Tag name. */
  2692. 'tagtitle' => __( '%1$s %2$s %3$s Tag Feed' ),
  2693. /* translators: 1: Blog name, 2: Separator (raquo), 3: Term name, 4: Taxonomy singular name. */
  2694. 'taxtitle' => __( '%1$s %2$s %3$s %4$s Feed' ),
  2695. /* translators: 1: Blog name, 2: Separator (raquo), 3: Author name. */
  2696. 'authortitle' => __( '%1$s %2$s Posts by %3$s Feed' ),
  2697. /* translators: 1: Blog name, 2: Separator (raquo), 3: Search query. */
  2698. 'searchtitle' => __( '%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed' ),
  2699. /* translators: 1: Blog name, 2: Separator (raquo), 3: Post type name. */
  2700. 'posttypetitle' => __( '%1$s %2$s %3$s Feed' ),
  2701. );
  2702. $args = wp_parse_args( $args, $defaults );
  2703. if ( is_singular() ) {
  2704. $id = 0;
  2705. $post = get_post( $id );
  2706. if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
  2707. $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
  2708. $href = get_post_comments_feed_link( $post->ID );
  2709. }
  2710. } elseif ( is_post_type_archive() ) {
  2711. $post_type = get_query_var( 'post_type' );
  2712. if ( is_array( $post_type ) ) {
  2713. $post_type = reset( $post_type );
  2714. }
  2715. $post_type_obj = get_post_type_object( $post_type );
  2716. $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
  2717. $href = get_post_type_archive_feed_link( $post_type_obj->name );
  2718. } elseif ( is_category() ) {
  2719. $term = get_queried_object();
  2720. if ( $term ) {
  2721. $title = sprintf( $args['cattitle'], get_bloginfo( 'name' ), $args['separator'], $term->name );
  2722. $href = get_category_feed_link( $term->term_id );
  2723. }
  2724. } elseif ( is_tag() ) {
  2725. $term = get_queried_object();
  2726. if ( $term ) {
  2727. $title = sprintf( $args['tagtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name );
  2728. $href = get_tag_feed_link( $term->term_id );
  2729. }
  2730. } elseif ( is_tax() ) {
  2731. $term = get_queried_object();
  2732. if ( $term ) {
  2733. $tax = get_taxonomy( $term->taxonomy );
  2734. $title = sprintf( $args['taxtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name, $tax->labels->singular_name );
  2735. $href = get_term_feed_link( $term->term_id, $term->taxonomy );
  2736. }
  2737. } elseif ( is_author() ) {
  2738. $author_id = intval( get_query_var( 'author' ) );
  2739. $title = sprintf( $args['authortitle'], get_bloginfo( 'name' ), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
  2740. $href = get_author_feed_link( $author_id );
  2741. } elseif ( is_search() ) {
  2742. $title = sprintf( $args['searchtitle'], get_bloginfo( 'name' ), $args['separator'], get_search_query( false ) );
  2743. $href = get_search_feed_link();
  2744. } elseif ( is_post_type_archive() ) {
  2745. $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], post_type_archive_title( '', false ) );
  2746. $post_type_obj = get_queried_object();
  2747. if ( $post_type_obj ) {
  2748. $href = get_post_type_archive_feed_link( $post_type_obj->name );
  2749. }
  2750. }
  2751. if ( isset( $title ) && isset( $href ) ) {
  2752. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
  2753. }
  2754. }
  2755. /**
  2756. * Display the link to the Really Simple Discovery service endpoint.
  2757. *
  2758. * @link http://archipelago.phrasewise.com/rsd
  2759. * @since 2.0.0
  2760. */
  2761. function rsd_link() {
  2762. echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n";
  2763. }
  2764. /**
  2765. * Display the link to the Windows Live Writer manifest file.
  2766. *
  2767. * @link https://msdn.microsoft.com/en-us/library/bb463265.aspx
  2768. * @since 2.3.1
  2769. */
  2770. function wlwmanifest_link() {
  2771. echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="' . includes_url( 'wlwmanifest.xml' ) . '" /> ' . "\n";
  2772. }
  2773. /**
  2774. * Displays a noindex meta tag if required by the blog configuration.
  2775. *
  2776. * If a blog is marked as not being public then the noindex meta tag will be
  2777. * output to tell web robots not to index the page content. Add this to the
  2778. * {@see 'wp_head'} action.
  2779. *
  2780. * Typical usage is as a {@see 'wp_head'} callback:
  2781. *
  2782. * add_action( 'wp_head', 'noindex' );
  2783. *
  2784. * @see wp_no_robots
  2785. *
  2786. * @since 2.1.0
  2787. */
  2788. function noindex() {
  2789. // If the blog is not public, tell robots to go away.
  2790. if ( '0' == get_option( 'blog_public' ) ) {
  2791. wp_no_robots();
  2792. }
  2793. }
  2794. /**
  2795. * Display a noindex meta tag.
  2796. *
  2797. * Outputs a noindex meta tag that tells web robots not to index the page content.
  2798. * Typical usage is as a {@see 'wp_head'} callback. add_action( 'wp_head', 'wp_no_robots' );
  2799. *
  2800. * @since 3.3.0
  2801. * @since 5.3.0 Echo "noindex,nofollow" if search engine visibility is discouraged.
  2802. */
  2803. function wp_no_robots() {
  2804. if ( get_option( 'blog_public' ) ) {
  2805. echo "<meta name='robots' content='noindex,follow' />\n";
  2806. return;
  2807. }
  2808. echo "<meta name='robots' content='noindex,nofollow' />\n";
  2809. }
  2810. /**
  2811. * Display a noindex,noarchive meta tag and referrer origin-when-cross-origin meta tag.
  2812. *
  2813. * Outputs a noindex,noarchive meta tag that tells web robots not to index or cache the page content.
  2814. * Outputs a referrer origin-when-cross-origin meta tag that tells the browser not to send the full
  2815. * url as a referrer to other sites when cross-origin assets are loaded.
  2816. *
  2817. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_sensitive_page_meta' );
  2818. *
  2819. * @since 5.0.1
  2820. */
  2821. function wp_sensitive_page_meta() {
  2822. ?>
  2823. <meta name='robots' content='noindex,noarchive' />
  2824. <meta name='referrer' content='strict-origin-when-cross-origin' />
  2825. <?php
  2826. }
  2827. /**
  2828. * Display site icon meta tags.
  2829. *
  2830. * @since 4.3.0
  2831. *
  2832. * @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
  2833. */
  2834. function wp_site_icon() {
  2835. if ( ! has_site_icon() && ! is_customize_preview() ) {
  2836. return;
  2837. }
  2838. $meta_tags = array();
  2839. $icon_32 = get_site_icon_url( 32 );
  2840. if ( empty( $icon_32 ) && is_customize_preview() ) {
  2841. $icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview.
  2842. }
  2843. if ( $icon_32 ) {
  2844. $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) );
  2845. }
  2846. $icon_192 = get_site_icon_url( 192 );
  2847. if ( $icon_192 ) {
  2848. $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) );
  2849. }
  2850. $icon_180 = get_site_icon_url( 180 );
  2851. if ( $icon_180 ) {
  2852. $meta_tags[] = sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( $icon_180 ) );
  2853. }
  2854. $icon_270 = get_site_icon_url( 270 );
  2855. if ( $icon_270 ) {
  2856. $meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) );
  2857. }
  2858. /**
  2859. * Filters the site icon meta tags, so plugins can add their own.
  2860. *
  2861. * @since 4.3.0
  2862. *
  2863. * @param string[] $meta_tags Array of Site Icon meta tags.
  2864. */
  2865. $meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags );
  2866. $meta_tags = array_filter( $meta_tags );
  2867. foreach ( $meta_tags as $meta_tag ) {
  2868. echo "$meta_tag\n";
  2869. }
  2870. }
  2871. /**
  2872. * Prints resource hints to browsers for pre-fetching, pre-rendering
  2873. * and pre-connecting to web sites.
  2874. *
  2875. * Gives hints to browsers to prefetch specific pages or render them
  2876. * in the background, to perform DNS lookups or to begin the connection
  2877. * handshake (DNS, TCP, TLS) in the background.
  2878. *
  2879. * These performance improving indicators work by using `<link rel"…">`.
  2880. *
  2881. * @since 4.6.0
  2882. */
  2883. function wp_resource_hints() {
  2884. $hints = array(
  2885. 'dns-prefetch' => wp_dependencies_unique_hosts(),
  2886. 'preconnect' => array(),
  2887. 'prefetch' => array(),
  2888. 'prerender' => array(),
  2889. );
  2890. /*
  2891. * Add DNS prefetch for the Emoji CDN.
  2892. * The path is removed in the foreach loop below.
  2893. */
  2894. /** This filter is documented in wp-includes/formatting.php */
  2895. $hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/12.0.0-1/svg/' );
  2896. foreach ( $hints as $relation_type => $urls ) {
  2897. $unique_urls = array();
  2898. /**
  2899. * Filters domains and URLs for resource hints of relation type.
  2900. *
  2901. * @since 4.6.0
  2902. *
  2903. * @param array $urls URLs to print for resource hints.
  2904. * @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'.
  2905. */
  2906. $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
  2907. foreach ( $urls as $key => $url ) {
  2908. $atts = array();
  2909. if ( is_array( $url ) ) {
  2910. if ( isset( $url['href'] ) ) {
  2911. $atts = $url;
  2912. $url = $url['href'];
  2913. } else {
  2914. continue;
  2915. }
  2916. }
  2917. $url = esc_url( $url, array( 'http', 'https' ) );
  2918. if ( ! $url ) {
  2919. continue;
  2920. }
  2921. if ( isset( $unique_urls[ $url ] ) ) {
  2922. continue;
  2923. }
  2924. if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
  2925. $parsed = wp_parse_url( $url );
  2926. if ( empty( $parsed['host'] ) ) {
  2927. continue;
  2928. }
  2929. if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) {
  2930. $url = $parsed['scheme'] . '://' . $parsed['host'];
  2931. } else {
  2932. // Use protocol-relative URLs for dns-prefetch or if scheme is missing.
  2933. $url = '//' . $parsed['host'];
  2934. }
  2935. }
  2936. $atts['rel'] = $relation_type;
  2937. $atts['href'] = $url;
  2938. $unique_urls[ $url ] = $atts;
  2939. }
  2940. foreach ( $unique_urls as $atts ) {
  2941. $html = '';
  2942. foreach ( $atts as $attr => $value ) {
  2943. if ( ! is_scalar( $value ) ||
  2944. ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) ) ) {
  2945. continue;
  2946. }
  2947. $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
  2948. if ( ! is_string( $attr ) ) {
  2949. $html .= " $value";
  2950. } else {
  2951. $html .= " $attr='$value'";
  2952. }
  2953. }
  2954. $html = trim( $html );
  2955. echo "<link $html />\n";
  2956. }
  2957. }
  2958. }
  2959. /**
  2960. * Retrieves a list of unique hosts of all enqueued scripts and styles.
  2961. *
  2962. * @since 4.6.0
  2963. *
  2964. * @return array A list of unique hosts of enqueued scripts and styles.
  2965. */
  2966. function wp_dependencies_unique_hosts() {
  2967. global $wp_scripts, $wp_styles;
  2968. $unique_hosts = array();
  2969. foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
  2970. if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
  2971. foreach ( $dependencies->queue as $handle ) {
  2972. if ( ! isset( $dependencies->registered[ $handle ] ) ) {
  2973. continue;
  2974. }
  2975. /* @var _WP_Dependency $dependency */
  2976. $dependency = $dependencies->registered[ $handle ];
  2977. $parsed = wp_parse_url( $dependency->src );
  2978. if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) {
  2979. $unique_hosts[] = $parsed['host'];
  2980. }
  2981. }
  2982. }
  2983. }
  2984. return $unique_hosts;
  2985. }
  2986. /**
  2987. * Whether the user can access the visual editor.
  2988. *
  2989. * Checks if the user can access the visual editor and that it's supported by the user's browser.
  2990. *
  2991. * @since 2.0.0
  2992. *
  2993. * @global bool $wp_rich_edit Whether the user can access the visual editor.
  2994. * @global bool $is_gecko Whether the browser is Gecko-based.
  2995. * @global bool $is_opera Whether the browser is Opera.
  2996. * @global bool $is_safari Whether the browser is Safari.
  2997. * @global bool $is_chrome Whether the browser is Chrome.
  2998. * @global bool $is_IE Whether the browser is Internet Explorer.
  2999. * @global bool $is_edge Whether the browser is Microsoft Edge.
  3000. *
  3001. * @return bool True if the user can access the visual editor, false otherwise.
  3002. */
  3003. function user_can_richedit() {
  3004. global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;
  3005. if ( ! isset( $wp_rich_edit ) ) {
  3006. $wp_rich_edit = false;
  3007. if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
  3008. if ( $is_safari ) {
  3009. $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
  3010. } elseif ( $is_IE ) {
  3011. $wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false );
  3012. } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
  3013. $wp_rich_edit = true;
  3014. }
  3015. }
  3016. }
  3017. /**
  3018. * Filters whether the user can access the visual editor.
  3019. *
  3020. * @since 2.1.0
  3021. *
  3022. * @param bool $wp_rich_edit Whether the user can access the visual editor.
  3023. */
  3024. return apply_filters( 'user_can_richedit', $wp_rich_edit );
  3025. }
  3026. /**
  3027. * Find out which editor should be displayed by default.
  3028. *
  3029. * Works out which of the two editors to display as the current editor for a
  3030. * user. The 'html' setting is for the "Text" editor tab.
  3031. *
  3032. * @since 2.5.0
  3033. *
  3034. * @return string Either 'tinymce', or 'html', or 'test'
  3035. */
  3036. function wp_default_editor() {
  3037. $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
  3038. if ( wp_get_current_user() ) { // look for cookie
  3039. $ed = get_user_setting( 'editor', 'tinymce' );
  3040. $r = ( in_array( $ed, array( 'tinymce', 'html', 'test' ) ) ) ? $ed : $r;
  3041. }
  3042. /**
  3043. * Filters which editor should be displayed by default.
  3044. *
  3045. * @since 2.5.0
  3046. *
  3047. * @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'.
  3048. */
  3049. return apply_filters( 'wp_default_editor', $r );
  3050. }
  3051. /**
  3052. * Renders an editor.
  3053. *
  3054. * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
  3055. * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
  3056. *
  3057. * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
  3058. * running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used.
  3059. * On the post edit screen several actions can be used to include additional editors
  3060. * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
  3061. * See https://core.trac.wordpress.org/ticket/19173 for more information.
  3062. *
  3063. * @see _WP_Editors::editor()
  3064. * @since 3.3.0
  3065. *
  3066. * @param string $content Initial content for the editor.
  3067. * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
  3068. * @param array $settings See _WP_Editors::editor().
  3069. */
  3070. function wp_editor( $content, $editor_id, $settings = array() ) {
  3071. if ( ! class_exists( '_WP_Editors', false ) ) {
  3072. require( ABSPATH . WPINC . '/class-wp-editor.php' );
  3073. }
  3074. _WP_Editors::editor( $content, $editor_id, $settings );
  3075. }
  3076. /**
  3077. * Outputs the editor scripts, stylesheets, and default settings.
  3078. *
  3079. * The editor can be initialized when needed after page load.
  3080. * See wp.editor.initialize() in wp-admin/js/editor.js for initialization options.
  3081. *
  3082. * @uses _WP_Editors
  3083. * @since 4.8.0
  3084. */
  3085. function wp_enqueue_editor() {
  3086. if ( ! class_exists( '_WP_Editors', false ) ) {
  3087. require( ABSPATH . WPINC . '/class-wp-editor.php' );
  3088. }
  3089. _WP_Editors::enqueue_default_editor();
  3090. }
  3091. /**
  3092. * Enqueue assets needed by the code editor for the given settings.
  3093. *
  3094. * @since 4.9.0
  3095. *
  3096. * @see wp_enqueue_editor()
  3097. * @see wp_get_code_editor_settings();
  3098. * @see _WP_Editors::parse_settings()
  3099. *
  3100. * @param array $args {
  3101. * Args.
  3102. *
  3103. * @type string $type The MIME type of the file to be edited.
  3104. * @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
  3105. * @type WP_Theme $theme Theme being edited when on theme editor.
  3106. * @type string $plugin Plugin being edited when on plugin editor.
  3107. * @type array $codemirror Additional CodeMirror setting overrides.
  3108. * @type array $csslint CSSLint rule overrides.
  3109. * @type array $jshint JSHint rule overrides.
  3110. * @type array $htmlhint JSHint rule overrides.
  3111. * }
  3112. * @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued.
  3113. */
  3114. function wp_enqueue_code_editor( $args ) {
  3115. if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) {
  3116. return false;
  3117. }
  3118. $settings = wp_get_code_editor_settings( $args );
  3119. if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {
  3120. return false;
  3121. }
  3122. wp_enqueue_script( 'code-editor' );
  3123. wp_enqueue_style( 'code-editor' );
  3124. if ( isset( $settings['codemirror']['mode'] ) ) {
  3125. $mode = $settings['codemirror']['mode'];
  3126. if ( is_string( $mode ) ) {
  3127. $mode = array(
  3128. 'name' => $mode,
  3129. );
  3130. }
  3131. if ( ! empty( $settings['codemirror']['lint'] ) ) {
  3132. switch ( $mode['name'] ) {
  3133. case 'css':
  3134. case 'text/css':
  3135. case 'text/x-scss':
  3136. case 'text/x-less':
  3137. wp_enqueue_script( 'csslint' );
  3138. break;
  3139. case 'htmlmixed':
  3140. case 'text/html':
  3141. case 'php':
  3142. case 'application/x-httpd-php':
  3143. case 'text/x-php':
  3144. wp_enqueue_script( 'htmlhint' );
  3145. wp_enqueue_script( 'csslint' );
  3146. wp_enqueue_script( 'jshint' );
  3147. if ( ! current_user_can( 'unfiltered_html' ) ) {
  3148. wp_enqueue_script( 'htmlhint-kses' );
  3149. }
  3150. break;
  3151. case 'javascript':
  3152. case 'application/ecmascript':
  3153. case 'application/json':
  3154. case 'application/javascript':
  3155. case 'application/ld+json':
  3156. case 'text/typescript':
  3157. case 'application/typescript':
  3158. wp_enqueue_script( 'jshint' );
  3159. wp_enqueue_script( 'jsonlint' );
  3160. break;
  3161. }
  3162. }
  3163. }
  3164. wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) );
  3165. /**
  3166. * Fires when scripts and styles are enqueued for the code editor.
  3167. *
  3168. * @since 4.9.0
  3169. *
  3170. * @param array $settings Settings for the enqueued code editor.
  3171. */
  3172. do_action( 'wp_enqueue_code_editor', $settings );
  3173. return $settings;
  3174. }
  3175. /**
  3176. * Generate and return code editor settings.
  3177. *
  3178. * @since 5.0.0
  3179. *
  3180. * @see wp_enqueue_code_editor()
  3181. *
  3182. * @param array $args {
  3183. * Args.
  3184. *
  3185. * @type string $type The MIME type of the file to be edited.
  3186. * @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
  3187. * @type WP_Theme $theme Theme being edited when on theme editor.
  3188. * @type string $plugin Plugin being edited when on plugin editor.
  3189. * @type array $codemirror Additional CodeMirror setting overrides.
  3190. * @type array $csslint CSSLint rule overrides.
  3191. * @type array $jshint JSHint rule overrides.
  3192. * @type array $htmlhint JSHint rule overrides.
  3193. * }
  3194. * @return array|false Settings for the code editor.
  3195. */
  3196. function wp_get_code_editor_settings( $args ) {
  3197. $settings = array(
  3198. 'codemirror' => array(
  3199. 'indentUnit' => 4,
  3200. 'indentWithTabs' => true,
  3201. 'inputStyle' => 'contenteditable',
  3202. 'lineNumbers' => true,
  3203. 'lineWrapping' => true,
  3204. 'styleActiveLine' => true,
  3205. 'continueComments' => true,
  3206. 'extraKeys' => array(
  3207. 'Ctrl-Space' => 'autocomplete',
  3208. 'Ctrl-/' => 'toggleComment',
  3209. 'Cmd-/' => 'toggleComment',
  3210. 'Alt-F' => 'findPersistent',
  3211. 'Ctrl-F' => 'findPersistent',
  3212. 'Cmd-F' => 'findPersistent',
  3213. ),
  3214. 'direction' => 'ltr', // Code is shown in LTR even in RTL languages.
  3215. 'gutters' => array(),
  3216. ),
  3217. 'csslint' => array(
  3218. 'errors' => true, // Parsing errors.
  3219. 'box-model' => true,
  3220. 'display-property-grouping' => true,
  3221. 'duplicate-properties' => true,
  3222. 'known-properties' => true,
  3223. 'outline-none' => true,
  3224. ),
  3225. 'jshint' => array(
  3226. // The following are copied from <https://github.com/WordPress/wordpress-develop/blob/4.8.1/.jshintrc>.
  3227. 'boss' => true,
  3228. 'curly' => true,
  3229. 'eqeqeq' => true,
  3230. 'eqnull' => true,
  3231. 'es3' => true,
  3232. 'expr' => true,
  3233. 'immed' => true,
  3234. 'noarg' => true,
  3235. 'nonbsp' => true,
  3236. 'onevar' => true,
  3237. 'quotmark' => 'single',
  3238. 'trailing' => true,
  3239. 'undef' => true,
  3240. 'unused' => true,
  3241. 'browser' => true,
  3242. 'globals' => array(
  3243. '_' => false,
  3244. 'Backbone' => false,
  3245. 'jQuery' => false,
  3246. 'JSON' => false,
  3247. 'wp' => false,
  3248. ),
  3249. ),
  3250. 'htmlhint' => array(
  3251. 'tagname-lowercase' => true,
  3252. 'attr-lowercase' => true,
  3253. 'attr-value-double-quotes' => false,
  3254. 'doctype-first' => false,
  3255. 'tag-pair' => true,
  3256. 'spec-char-escape' => true,
  3257. 'id-unique' => true,
  3258. 'src-not-empty' => true,
  3259. 'attr-no-duplication' => true,
  3260. 'alt-require' => true,
  3261. 'space-tab-mixed-disabled' => 'tab',
  3262. 'attr-unsafe-chars' => true,
  3263. ),
  3264. );
  3265. $type = '';
  3266. if ( isset( $args['type'] ) ) {
  3267. $type = $args['type'];
  3268. // Remap MIME types to ones that CodeMirror modes will recognize.
  3269. if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) {
  3270. $type = 'text/x-diff';
  3271. }
  3272. } elseif ( isset( $args['file'] ) && false !== strpos( basename( $args['file'] ), '.' ) ) {
  3273. $extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) );
  3274. foreach ( wp_get_mime_types() as $exts => $mime ) {
  3275. if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
  3276. $type = $mime;
  3277. break;
  3278. }
  3279. }
  3280. // Supply any types that are not matched by wp_get_mime_types().
  3281. if ( empty( $type ) ) {
  3282. switch ( $extension ) {
  3283. case 'conf':
  3284. $type = 'text/nginx';
  3285. break;
  3286. case 'css':
  3287. $type = 'text/css';
  3288. break;
  3289. case 'diff':
  3290. case 'patch':
  3291. $type = 'text/x-diff';
  3292. break;
  3293. case 'html':
  3294. case 'htm':
  3295. $type = 'text/html';
  3296. break;
  3297. case 'http':
  3298. $type = 'message/http';
  3299. break;
  3300. case 'js':
  3301. $type = 'text/javascript';
  3302. break;
  3303. case 'json':
  3304. $type = 'application/json';
  3305. break;
  3306. case 'jsx':
  3307. $type = 'text/jsx';
  3308. break;
  3309. case 'less':
  3310. $type = 'text/x-less';
  3311. break;
  3312. case 'md':
  3313. $type = 'text/x-gfm';
  3314. break;
  3315. case 'php':
  3316. case 'phtml':
  3317. case 'php3':
  3318. case 'php4':
  3319. case 'php5':
  3320. case 'php7':
  3321. case 'phps':
  3322. $type = 'application/x-httpd-php';
  3323. break;
  3324. case 'scss':
  3325. $type = 'text/x-scss';
  3326. break;
  3327. case 'sass':
  3328. $type = 'text/x-sass';
  3329. break;
  3330. case 'sh':
  3331. case 'bash':
  3332. $type = 'text/x-sh';
  3333. break;
  3334. case 'sql':
  3335. $type = 'text/x-sql';
  3336. break;
  3337. case 'svg':
  3338. $type = 'application/svg+xml';
  3339. break;
  3340. case 'xml':
  3341. $type = 'text/xml';
  3342. break;
  3343. case 'yml':
  3344. case 'yaml':
  3345. $type = 'text/x-yaml';
  3346. break;
  3347. case 'txt':
  3348. default:
  3349. $type = 'text/plain';
  3350. break;
  3351. }
  3352. }
  3353. }
  3354. if ( 'text/css' === $type ) {
  3355. $settings['codemirror'] = array_merge(
  3356. $settings['codemirror'],
  3357. array(
  3358. 'mode' => 'css',
  3359. 'lint' => true,
  3360. 'autoCloseBrackets' => true,
  3361. 'matchBrackets' => true,
  3362. )
  3363. );
  3364. } elseif ( 'text/x-scss' === $type || 'text/x-less' === $type || 'text/x-sass' === $type ) {
  3365. $settings['codemirror'] = array_merge(
  3366. $settings['codemirror'],
  3367. array(
  3368. 'mode' => $type,
  3369. 'lint' => false,
  3370. 'autoCloseBrackets' => true,
  3371. 'matchBrackets' => true,
  3372. )
  3373. );
  3374. } elseif ( 'text/x-diff' === $type ) {
  3375. $settings['codemirror'] = array_merge(
  3376. $settings['codemirror'],
  3377. array(
  3378. 'mode' => 'diff',
  3379. )
  3380. );
  3381. } elseif ( 'text/html' === $type ) {
  3382. $settings['codemirror'] = array_merge(
  3383. $settings['codemirror'],
  3384. array(
  3385. 'mode' => 'htmlmixed',
  3386. 'lint' => true,
  3387. 'autoCloseBrackets' => true,
  3388. 'autoCloseTags' => true,
  3389. 'matchTags' => array(
  3390. 'bothTags' => true,
  3391. ),
  3392. )
  3393. );
  3394. if ( ! current_user_can( 'unfiltered_html' ) ) {
  3395. $settings['htmlhint']['kses'] = wp_kses_allowed_html( 'post' );
  3396. }
  3397. } elseif ( 'text/x-gfm' === $type ) {
  3398. $settings['codemirror'] = array_merge(
  3399. $settings['codemirror'],
  3400. array(
  3401. 'mode' => 'gfm',
  3402. 'highlightFormatting' => true,
  3403. )
  3404. );
  3405. } elseif ( 'application/javascript' === $type || 'text/javascript' === $type ) {
  3406. $settings['codemirror'] = array_merge(
  3407. $settings['codemirror'],
  3408. array(
  3409. 'mode' => 'javascript',
  3410. 'lint' => true,
  3411. 'autoCloseBrackets' => true,
  3412. 'matchBrackets' => true,
  3413. )
  3414. );
  3415. } elseif ( false !== strpos( $type, 'json' ) ) {
  3416. $settings['codemirror'] = array_merge(
  3417. $settings['codemirror'],
  3418. array(
  3419. 'mode' => array(
  3420. 'name' => 'javascript',
  3421. ),
  3422. 'lint' => true,
  3423. 'autoCloseBrackets' => true,
  3424. 'matchBrackets' => true,
  3425. )
  3426. );
  3427. if ( 'application/ld+json' === $type ) {
  3428. $settings['codemirror']['mode']['jsonld'] = true;
  3429. } else {
  3430. $settings['codemirror']['mode']['json'] = true;
  3431. }
  3432. } elseif ( false !== strpos( $type, 'jsx' ) ) {
  3433. $settings['codemirror'] = array_merge(
  3434. $settings['codemirror'],
  3435. array(
  3436. 'mode' => 'jsx',
  3437. 'autoCloseBrackets' => true,
  3438. 'matchBrackets' => true,
  3439. )
  3440. );
  3441. } elseif ( 'text/x-markdown' === $type ) {
  3442. $settings['codemirror'] = array_merge(
  3443. $settings['codemirror'],
  3444. array(
  3445. 'mode' => 'markdown',
  3446. 'highlightFormatting' => true,
  3447. )
  3448. );
  3449. } elseif ( 'text/nginx' === $type ) {
  3450. $settings['codemirror'] = array_merge(
  3451. $settings['codemirror'],
  3452. array(
  3453. 'mode' => 'nginx',
  3454. )
  3455. );
  3456. } elseif ( 'application/x-httpd-php' === $type ) {
  3457. $settings['codemirror'] = array_merge(
  3458. $settings['codemirror'],
  3459. array(
  3460. 'mode' => 'php',
  3461. 'autoCloseBrackets' => true,
  3462. 'autoCloseTags' => true,
  3463. 'matchBrackets' => true,
  3464. 'matchTags' => array(
  3465. 'bothTags' => true,
  3466. ),
  3467. )
  3468. );
  3469. } elseif ( 'text/x-sql' === $type || 'text/x-mysql' === $type ) {
  3470. $settings['codemirror'] = array_merge(
  3471. $settings['codemirror'],
  3472. array(
  3473. 'mode' => 'sql',
  3474. 'autoCloseBrackets' => true,
  3475. 'matchBrackets' => true,
  3476. )
  3477. );
  3478. } elseif ( false !== strpos( $type, 'xml' ) ) {
  3479. $settings['codemirror'] = array_merge(
  3480. $settings['codemirror'],
  3481. array(
  3482. 'mode' => 'xml',
  3483. 'autoCloseBrackets' => true,
  3484. 'autoCloseTags' => true,
  3485. 'matchTags' => array(
  3486. 'bothTags' => true,
  3487. ),
  3488. )
  3489. );
  3490. } elseif ( 'text/x-yaml' === $type ) {
  3491. $settings['codemirror'] = array_merge(
  3492. $settings['codemirror'],
  3493. array(
  3494. 'mode' => 'yaml',
  3495. )
  3496. );
  3497. } else {
  3498. $settings['codemirror']['mode'] = $type;
  3499. }
  3500. if ( ! empty( $settings['codemirror']['lint'] ) ) {
  3501. $settings['codemirror']['gutters'][] = 'CodeMirror-lint-markers';
  3502. }
  3503. // Let settings supplied via args override any defaults.
  3504. foreach ( wp_array_slice_assoc( $args, array( 'codemirror', 'csslint', 'jshint', 'htmlhint' ) ) as $key => $value ) {
  3505. $settings[ $key ] = array_merge(
  3506. $settings[ $key ],
  3507. $value
  3508. );
  3509. }
  3510. /**
  3511. * Filters settings that are passed into the code editor.
  3512. *
  3513. * Returning a falsey value will disable the syntax-highlighting code editor.
  3514. *
  3515. * @since 4.9.0
  3516. *
  3517. * @param array $settings The array of settings passed to the code editor. A falsey value disables the editor.
  3518. * @param array $args {
  3519. * Args passed when calling `get_code_editor_settings()`.
  3520. *
  3521. * @type string $type The MIME type of the file to be edited.
  3522. * @type string $file Filename being edited.
  3523. * @type WP_Theme $theme Theme being edited when on theme editor.
  3524. * @type string $plugin Plugin being edited when on plugin editor.
  3525. * @type array $codemirror Additional CodeMirror setting overrides.
  3526. * @type array $csslint CSSLint rule overrides.
  3527. * @type array $jshint JSHint rule overrides.
  3528. * @type array $htmlhint JSHint rule overrides.
  3529. * }
  3530. */
  3531. return apply_filters( 'wp_code_editor_settings', $settings, $args );
  3532. }
  3533. /**
  3534. * Retrieves the contents of the search WordPress query variable.
  3535. *
  3536. * The search query string is passed through esc_attr() to ensure that it is safe
  3537. * for placing in an html attribute.
  3538. *
  3539. * @since 2.3.0
  3540. *
  3541. * @param bool $escaped Whether the result is escaped. Default true.
  3542. * Only use when you are later escaping it. Do not use unescaped.
  3543. * @return string
  3544. */
  3545. function get_search_query( $escaped = true ) {
  3546. /**
  3547. * Filters the contents of the search query variable.
  3548. *
  3549. * @since 2.3.0
  3550. *
  3551. * @param mixed $search Contents of the search query variable.
  3552. */
  3553. $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
  3554. if ( $escaped ) {
  3555. $query = esc_attr( $query );
  3556. }
  3557. return $query;
  3558. }
  3559. /**
  3560. * Displays the contents of the search query variable.
  3561. *
  3562. * The search query string is passed through esc_attr() to ensure that it is safe
  3563. * for placing in an html attribute.
  3564. *
  3565. * @since 2.1.0
  3566. */
  3567. function the_search_query() {
  3568. /**
  3569. * Filters the contents of the search query variable for display.
  3570. *
  3571. * @since 2.3.0
  3572. *
  3573. * @param mixed $search Contents of the search query variable.
  3574. */
  3575. echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
  3576. }
  3577. /**
  3578. * Gets the language attributes for the html tag.
  3579. *
  3580. * Builds up a set of html attributes containing the text direction and language
  3581. * information for the page.
  3582. *
  3583. * @since 4.3.0
  3584. *
  3585. * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
  3586. */
  3587. function get_language_attributes( $doctype = 'html' ) {
  3588. $attributes = array();
  3589. if ( function_exists( 'is_rtl' ) && is_rtl() ) {
  3590. $attributes[] = 'dir="rtl"';
  3591. }
  3592. $lang = get_bloginfo( 'language' );
  3593. if ( $lang ) {
  3594. if ( get_option( 'html_type' ) == 'text/html' || $doctype == 'html' ) {
  3595. $attributes[] = 'lang="' . esc_attr( $lang ) . '"';
  3596. }
  3597. if ( get_option( 'html_type' ) != 'text/html' || $doctype == 'xhtml' ) {
  3598. $attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"';
  3599. }
  3600. }
  3601. $output = implode( ' ', $attributes );
  3602. /**
  3603. * Filters the language attributes for display in the html tag.
  3604. *
  3605. * @since 2.5.0
  3606. * @since 4.3.0 Added the `$doctype` parameter.
  3607. *
  3608. * @param string $output A space-separated list of language attributes.
  3609. * @param string $doctype The type of html document (xhtml|html).
  3610. */
  3611. return apply_filters( 'language_attributes', $output, $doctype );
  3612. }
  3613. /**
  3614. * Displays the language attributes for the html tag.
  3615. *
  3616. * Builds up a set of html attributes containing the text direction and language
  3617. * information for the page.
  3618. *
  3619. * @since 2.1.0
  3620. * @since 4.3.0 Converted into a wrapper for get_language_attributes().
  3621. *
  3622. * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
  3623. */
  3624. function language_attributes( $doctype = 'html' ) {
  3625. echo get_language_attributes( $doctype );
  3626. }
  3627. /**
  3628. * Retrieve paginated link for archive post pages.
  3629. *
  3630. * Technically, the function can be used to create paginated link list for any
  3631. * area. The 'base' argument is used to reference the url, which will be used to
  3632. * create the paginated links. The 'format' argument is then used for replacing
  3633. * the page number. It is however, most likely and by default, to be used on the
  3634. * archive post pages.
  3635. *
  3636. * The 'type' argument controls format of the returned value. The default is
  3637. * 'plain', which is just a string with the links separated by a newline
  3638. * character. The other possible values are either 'array' or 'list'. The
  3639. * 'array' value will return an array of the paginated link list to offer full
  3640. * control of display. The 'list' value will place all of the paginated links in
  3641. * an unordered HTML list.
  3642. *
  3643. * The 'total' argument is the total amount of pages and is an integer. The
  3644. * 'current' argument is the current page number and is also an integer.
  3645. *
  3646. * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
  3647. * and the '%_%' is required. The '%_%' will be replaced by the contents of in
  3648. * the 'format' argument. An example for the 'format' argument is "?page=%#%"
  3649. * and the '%#%' is also required. The '%#%' will be replaced with the page
  3650. * number.
  3651. *
  3652. * You can include the previous and next links in the list by setting the
  3653. * 'prev_next' argument to true, which it is by default. You can set the
  3654. * previous text, by using the 'prev_text' argument. You can set the next text
  3655. * by setting the 'next_text' argument.
  3656. *
  3657. * If the 'show_all' argument is set to true, then it will show all of the pages
  3658. * instead of a short list of the pages near the current page. By default, the
  3659. * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
  3660. * arguments. The 'end_size' argument is how many numbers on either the start
  3661. * and the end list edges, by default is 1. The 'mid_size' argument is how many
  3662. * numbers to either side of current page, but not including current page.
  3663. *
  3664. * It is possible to add query vars to the link by using the 'add_args' argument
  3665. * and see add_query_arg() for more information.
  3666. *
  3667. * The 'before_page_number' and 'after_page_number' arguments allow users to
  3668. * augment the links themselves. Typically this might be to add context to the
  3669. * numbered links so that screen reader users understand what the links are for.
  3670. * The text strings are added before and after the page number - within the
  3671. * anchor tag.
  3672. *
  3673. * @since 2.1.0
  3674. * @since 4.9.0 Added the `aria_current` argument.
  3675. *
  3676. * @global WP_Query $wp_query WordPress Query object.
  3677. * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  3678. *
  3679. * @param string|array $args {
  3680. * Optional. Array or string of arguments for generating paginated links for archives.
  3681. *
  3682. * @type string $base Base of the paginated url. Default empty.
  3683. * @type string $format Format for the pagination structure. Default empty.
  3684. * @type int $total The total amount of pages. Default is the value WP_Query's
  3685. * `max_num_pages` or 1.
  3686. * @type int $current The current page number. Default is 'paged' query var or 1.
  3687. * @type string $aria_current The value for the aria-current attribute. Possible values are 'page',
  3688. * 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
  3689. * @type bool $show_all Whether to show all pages. Default false.
  3690. * @type int $end_size How many numbers on either the start and the end list edges.
  3691. * Default 1.
  3692. * @type int $mid_size How many numbers to either side of the current pages. Default 2.
  3693. * @type bool $prev_next Whether to include the previous and next links in the list. Default true.
  3694. * @type bool $prev_text The previous page text. Default '&laquo; Previous'.
  3695. * @type bool $next_text The next page text. Default 'Next &raquo;'.
  3696. * @type string $type Controls format of the returned value. Possible values are 'plain',
  3697. * 'array' and 'list'. Default is 'plain'.
  3698. * @type array $add_args An array of query args to add. Default false.
  3699. * @type string $add_fragment A string to append to each link. Default empty.
  3700. * @type string $before_page_number A string to appear before the page number. Default empty.
  3701. * @type string $after_page_number A string to append after the page number. Default empty.
  3702. * }
  3703. * @return string|array|void String of page links or array of page links.
  3704. */
  3705. function paginate_links( $args = '' ) {
  3706. global $wp_query, $wp_rewrite;
  3707. // Setting up default values based on the current URL.
  3708. $pagenum_link = html_entity_decode( get_pagenum_link() );
  3709. $url_parts = explode( '?', $pagenum_link );
  3710. // Get max pages and current page out of the current query, if available.
  3711. $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
  3712. $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  3713. // Append the format placeholder to the base URL.
  3714. $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
  3715. // URL base depends on permalink settings.
  3716. $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  3717. $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
  3718. $defaults = array(
  3719. 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  3720. 'format' => $format, // ?page=%#% : %#% is replaced by the page number
  3721. 'total' => $total,
  3722. 'current' => $current,
  3723. 'aria_current' => 'page',
  3724. 'show_all' => false,
  3725. 'prev_next' => true,
  3726. 'prev_text' => __( '&laquo; Previous' ),
  3727. 'next_text' => __( 'Next &raquo;' ),
  3728. 'end_size' => 1,
  3729. 'mid_size' => 2,
  3730. 'type' => 'plain',
  3731. 'add_args' => array(), // array of query args to add
  3732. 'add_fragment' => '',
  3733. 'before_page_number' => '',
  3734. 'after_page_number' => '',
  3735. );
  3736. $args = wp_parse_args( $args, $defaults );
  3737. if ( ! is_array( $args['add_args'] ) ) {
  3738. $args['add_args'] = array();
  3739. }
  3740. // Merge additional query vars found in the original URL into 'add_args' array.
  3741. if ( isset( $url_parts[1] ) ) {
  3742. // Find the format argument.
  3743. $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
  3744. $format_query = isset( $format[1] ) ? $format[1] : '';
  3745. wp_parse_str( $format_query, $format_args );
  3746. // Find the query args of the requested URL.
  3747. wp_parse_str( $url_parts[1], $url_query_args );
  3748. // Remove the format argument from the array of query arguments, to avoid overwriting custom format.
  3749. foreach ( $format_args as $format_arg => $format_arg_value ) {
  3750. unset( $url_query_args[ $format_arg ] );
  3751. }
  3752. $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
  3753. }
  3754. // Who knows what else people pass in $args
  3755. $total = (int) $args['total'];
  3756. if ( $total < 2 ) {
  3757. return;
  3758. }
  3759. $current = (int) $args['current'];
  3760. $end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
  3761. if ( $end_size < 1 ) {
  3762. $end_size = 1;
  3763. }
  3764. $mid_size = (int) $args['mid_size'];
  3765. if ( $mid_size < 0 ) {
  3766. $mid_size = 2;
  3767. }
  3768. $add_args = $args['add_args'];
  3769. $r = '';
  3770. $page_links = array();
  3771. $dots = false;
  3772. if ( $args['prev_next'] && $current && 1 < $current ) :
  3773. $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
  3774. $link = str_replace( '%#%', $current - 1, $link );
  3775. if ( $add_args ) {
  3776. $link = add_query_arg( $add_args, $link );
  3777. }
  3778. $link .= $args['add_fragment'];
  3779. $page_links[] = sprintf(
  3780. '<a class="prev page-numbers" href="%s">%s</a>',
  3781. /**
  3782. * Filters the paginated links for the given archive pages.
  3783. *
  3784. * @since 3.0.0
  3785. *
  3786. * @param string $link The paginated link URL.
  3787. */
  3788. esc_url( apply_filters( 'paginate_links', $link ) ),
  3789. $args['prev_text']
  3790. );
  3791. endif;
  3792. for ( $n = 1; $n <= $total; $n++ ) :
  3793. if ( $n == $current ) :
  3794. $page_links[] = sprintf(
  3795. '<span aria-current="%s" class="page-numbers current">%s</span>',
  3796. esc_attr( $args['aria_current'] ),
  3797. $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
  3798. );
  3799. $dots = true;
  3800. else :
  3801. if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  3802. $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
  3803. $link = str_replace( '%#%', $n, $link );
  3804. if ( $add_args ) {
  3805. $link = add_query_arg( $add_args, $link );
  3806. }
  3807. $link .= $args['add_fragment'];
  3808. $page_links[] = sprintf(
  3809. '<a class="page-numbers" href="%s">%s</a>',
  3810. /** This filter is documented in wp-includes/general-template.php */
  3811. esc_url( apply_filters( 'paginate_links', $link ) ),
  3812. $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number']
  3813. );
  3814. $dots = true;
  3815. elseif ( $dots && ! $args['show_all'] ) :
  3816. $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
  3817. $dots = false;
  3818. endif;
  3819. endif;
  3820. endfor;
  3821. if ( $args['prev_next'] && $current && $current < $total ) :
  3822. $link = str_replace( '%_%', $args['format'], $args['base'] );
  3823. $link = str_replace( '%#%', $current + 1, $link );
  3824. if ( $add_args ) {
  3825. $link = add_query_arg( $add_args, $link );
  3826. }
  3827. $link .= $args['add_fragment'];
  3828. $page_links[] = sprintf(
  3829. '<a class="next page-numbers" href="%s">%s</a>',
  3830. /** This filter is documented in wp-includes/general-template.php */
  3831. esc_url( apply_filters( 'paginate_links', $link ) ),
  3832. $args['next_text']
  3833. );
  3834. endif;
  3835. switch ( $args['type'] ) {
  3836. case 'array':
  3837. return $page_links;
  3838. case 'list':
  3839. $r .= "<ul class='page-numbers'>\n\t<li>";
  3840. $r .= join( "</li>\n\t<li>", $page_links );
  3841. $r .= "</li>\n</ul>\n";
  3842. break;
  3843. default:
  3844. $r = join( "\n", $page_links );
  3845. break;
  3846. }
  3847. return $r;
  3848. }
  3849. /**
  3850. * Registers an admin color scheme css file.
  3851. *
  3852. * Allows a plugin to register a new admin color scheme. For example:
  3853. *
  3854. * wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
  3855. * '#07273E', '#14568A', '#D54E21', '#2683AE'
  3856. * ) );
  3857. *
  3858. * @since 2.5.0
  3859. *
  3860. * @global array $_wp_admin_css_colors
  3861. *
  3862. * @param string $key The unique key for this theme.
  3863. * @param string $name The name of the theme.
  3864. * @param string $url The URL of the CSS file containing the color scheme.
  3865. * @param array $colors Optional. An array of CSS color definition strings which are used
  3866. * to give the user a feel for the theme.
  3867. * @param array $icons {
  3868. * Optional. CSS color definitions used to color any SVG icons.
  3869. *
  3870. * @type string $base SVG icon base color.
  3871. * @type string $focus SVG icon color on focus.
  3872. * @type string $current SVG icon color of current admin menu link.
  3873. * }
  3874. */
  3875. function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
  3876. global $_wp_admin_css_colors;
  3877. if ( ! isset( $_wp_admin_css_colors ) ) {
  3878. $_wp_admin_css_colors = array();
  3879. }
  3880. $_wp_admin_css_colors[ $key ] = (object) array(
  3881. 'name' => $name,
  3882. 'url' => $url,
  3883. 'colors' => $colors,
  3884. 'icon_colors' => $icons,
  3885. );
  3886. }
  3887. /**
  3888. * Registers the default admin color schemes.
  3889. *
  3890. * Registers the initial set of eight color schemes in the Profile section
  3891. * of the dashboard which allows for styling the admin menu and toolbar.
  3892. *
  3893. * @see wp_admin_css_color()
  3894. *
  3895. * @since 3.0.0
  3896. */
  3897. function register_admin_color_schemes() {
  3898. $suffix = is_rtl() ? '-rtl' : '';
  3899. $suffix .= SCRIPT_DEBUG ? '' : '.min';
  3900. wp_admin_css_color(
  3901. 'fresh',
  3902. _x( 'Default', 'admin color scheme' ),
  3903. false,
  3904. array( '#222', '#333', '#0073aa', '#00a0d2' ),
  3905. array(
  3906. 'base' => '#a0a5aa',
  3907. 'focus' => '#00a0d2',
  3908. 'current' => '#fff',
  3909. )
  3910. );
  3911. // Other color schemes are not available when running out of src
  3912. if ( false !== strpos( get_bloginfo( 'version' ), '-src' ) ) {
  3913. return;
  3914. }
  3915. wp_admin_css_color(
  3916. 'light',
  3917. _x( 'Light', 'admin color scheme' ),
  3918. admin_url( "css/colors/light/colors$suffix.css" ),
  3919. array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
  3920. array(
  3921. 'base' => '#999',
  3922. 'focus' => '#ccc',
  3923. 'current' => '#ccc',
  3924. )
  3925. );
  3926. wp_admin_css_color(
  3927. 'blue',
  3928. _x( 'Blue', 'admin color scheme' ),
  3929. admin_url( "css/colors/blue/colors$suffix.css" ),
  3930. array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
  3931. array(
  3932. 'base' => '#e5f8ff',
  3933. 'focus' => '#fff',
  3934. 'current' => '#fff',
  3935. )
  3936. );
  3937. wp_admin_css_color(
  3938. 'midnight',
  3939. _x( 'Midnight', 'admin color scheme' ),
  3940. admin_url( "css/colors/midnight/colors$suffix.css" ),
  3941. array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
  3942. array(
  3943. 'base' => '#f1f2f3',
  3944. 'focus' => '#fff',
  3945. 'current' => '#fff',
  3946. )
  3947. );
  3948. wp_admin_css_color(
  3949. 'sunrise',
  3950. _x( 'Sunrise', 'admin color scheme' ),
  3951. admin_url( "css/colors/sunrise/colors$suffix.css" ),
  3952. array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
  3953. array(
  3954. 'base' => '#f3f1f1',
  3955. 'focus' => '#fff',
  3956. 'current' => '#fff',
  3957. )
  3958. );
  3959. wp_admin_css_color(
  3960. 'ectoplasm',
  3961. _x( 'Ectoplasm', 'admin color scheme' ),
  3962. admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
  3963. array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
  3964. array(
  3965. 'base' => '#ece6f6',
  3966. 'focus' => '#fff',
  3967. 'current' => '#fff',
  3968. )
  3969. );
  3970. wp_admin_css_color(
  3971. 'ocean',
  3972. _x( 'Ocean', 'admin color scheme' ),
  3973. admin_url( "css/colors/ocean/colors$suffix.css" ),
  3974. array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
  3975. array(
  3976. 'base' => '#f2fcff',
  3977. 'focus' => '#fff',
  3978. 'current' => '#fff',
  3979. )
  3980. );
  3981. wp_admin_css_color(
  3982. 'coffee',
  3983. _x( 'Coffee', 'admin color scheme' ),
  3984. admin_url( "css/colors/coffee/colors$suffix.css" ),
  3985. array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
  3986. array(
  3987. 'base' => '#f3f2f1',
  3988. 'focus' => '#fff',
  3989. 'current' => '#fff',
  3990. )
  3991. );
  3992. }
  3993. /**
  3994. * Displays the URL of a WordPress admin CSS file.
  3995. *
  3996. * @see WP_Styles::_css_href and its {@see 'style_loader_src'} filter.
  3997. *
  3998. * @since 2.3.0
  3999. *
  4000. * @param string $file file relative to wp-admin/ without its ".css" extension.
  4001. * @return string
  4002. */
  4003. function wp_admin_css_uri( $file = 'wp-admin' ) {
  4004. if ( defined( 'WP_INSTALLING' ) ) {
  4005. $_file = "./$file.css";
  4006. } else {
  4007. $_file = admin_url( "$file.css" );
  4008. }
  4009. $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
  4010. /**
  4011. * Filters the URI of a WordPress admin CSS file.
  4012. *
  4013. * @since 2.3.0
  4014. *
  4015. * @param string $_file Relative path to the file with query arguments attached.
  4016. * @param string $file Relative path to the file, minus its ".css" extension.
  4017. */
  4018. return apply_filters( 'wp_admin_css_uri', $_file, $file );
  4019. }
  4020. /**
  4021. * Enqueues or directly prints a stylesheet link to the specified CSS file.
  4022. *
  4023. * "Intelligently" decides to enqueue or to print the CSS file. If the
  4024. * {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be
  4025. * enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will
  4026. * be printed. Printing may be forced by passing true as the $force_echo
  4027. * (second) parameter.
  4028. *
  4029. * For backward compatibility with WordPress 2.3 calling method: If the $file
  4030. * (first) parameter does not correspond to a registered CSS file, we assume
  4031. * $file is a file relative to wp-admin/ without its ".css" extension. A
  4032. * stylesheet link to that generated URL is printed.
  4033. *
  4034. * @since 2.3.0
  4035. *
  4036. * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
  4037. * to wp-admin/. Defaults to 'wp-admin'.
  4038. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  4039. */
  4040. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  4041. // For backward compatibility.
  4042. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  4043. if ( wp_styles()->query( $handle ) ) {
  4044. if ( $force_echo || did_action( 'wp_print_styles' ) ) {
  4045. // We already printed the style queue. Print this one immediately.
  4046. wp_print_styles( $handle );
  4047. } else {
  4048. // Add to style queue.
  4049. wp_enqueue_style( $handle );
  4050. }
  4051. return;
  4052. }
  4053. $stylesheet_link = sprintf(
  4054. "<link rel='stylesheet' href='%s' type='text/css' />\n",
  4055. esc_url( wp_admin_css_uri( $file ) )
  4056. );
  4057. /**
  4058. * Filters the stylesheet link to the specified CSS file.
  4059. *
  4060. * If the site is set to display right-to-left, the RTL stylesheet link
  4061. * will be used instead.
  4062. *
  4063. * @since 2.3.0
  4064. * @param string $stylesheet_link HTML link element for the stylesheet.
  4065. * @param string $file Style handle name or filename (without ".css" extension)
  4066. * relative to wp-admin/. Defaults to 'wp-admin'.
  4067. */
  4068. echo apply_filters( 'wp_admin_css', $stylesheet_link, $file );
  4069. if ( function_exists( 'is_rtl' ) && is_rtl() ) {
  4070. $rtl_stylesheet_link = sprintf(
  4071. "<link rel='stylesheet' href='%s' type='text/css' />\n",
  4072. esc_url( wp_admin_css_uri( "$file-rtl" ) )
  4073. );
  4074. /** This filter is documented in wp-includes/general-template.php */
  4075. echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" );
  4076. }
  4077. }
  4078. /**
  4079. * Enqueues the default ThickBox js and css.
  4080. *
  4081. * If any of the settings need to be changed, this can be done with another js
  4082. * file similar to media-upload.js. That file should
  4083. * require array('thickbox') to ensure it is loaded after.
  4084. *
  4085. * @since 2.5.0
  4086. */
  4087. function add_thickbox() {
  4088. wp_enqueue_script( 'thickbox' );
  4089. wp_enqueue_style( 'thickbox' );
  4090. if ( is_network_admin() ) {
  4091. add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
  4092. }
  4093. }
  4094. /**
  4095. * Displays the XHTML generator that is generated on the wp_head hook.
  4096. *
  4097. * See {@see 'wp_head'}.
  4098. *
  4099. * @since 2.5.0
  4100. */
  4101. function wp_generator() {
  4102. /**
  4103. * Filters the output of the XHTML generator tag.
  4104. *
  4105. * @since 2.5.0
  4106. *
  4107. * @param string $generator_type The XHTML generator.
  4108. */
  4109. the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  4110. }
  4111. /**
  4112. * Display the generator XML or Comment for RSS, ATOM, etc.
  4113. *
  4114. * Returns the correct generator type for the requested output format. Allows
  4115. * for a plugin to filter generators overall the {@see 'the_generator'} filter.
  4116. *
  4117. * @since 2.5.0
  4118. *
  4119. * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
  4120. */
  4121. function the_generator( $type ) {
  4122. /**
  4123. * Filters the output of the XHTML generator tag for display.
  4124. *
  4125. * @since 2.5.0
  4126. *
  4127. * @param string $generator_type The generator output.
  4128. * @param string $type The type of generator to output. Accepts 'html',
  4129. * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
  4130. */
  4131. echo apply_filters( 'the_generator', get_the_generator( $type ), $type ) . "\n";
  4132. }
  4133. /**
  4134. * Creates the generator XML or Comment for RSS, ATOM, etc.
  4135. *
  4136. * Returns the correct generator type for the requested output format. Allows
  4137. * for a plugin to filter generators on an individual basis using the
  4138. * {@see 'get_the_generator_$type'} filter.
  4139. *
  4140. * @since 2.5.0
  4141. *
  4142. * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
  4143. * @return string|void The HTML content for the generator.
  4144. */
  4145. function get_the_generator( $type = '' ) {
  4146. if ( empty( $type ) ) {
  4147. $current_filter = current_filter();
  4148. if ( empty( $current_filter ) ) {
  4149. return;
  4150. }
  4151. switch ( $current_filter ) {
  4152. case 'rss2_head':
  4153. case 'commentsrss2_head':
  4154. $type = 'rss2';
  4155. break;
  4156. case 'rss_head':
  4157. case 'opml_head':
  4158. $type = 'comment';
  4159. break;
  4160. case 'rdf_header':
  4161. $type = 'rdf';
  4162. break;
  4163. case 'atom_head':
  4164. case 'comments_atom_head':
  4165. case 'app_head':
  4166. $type = 'atom';
  4167. break;
  4168. }
  4169. }
  4170. switch ( $type ) {
  4171. case 'html':
  4172. $gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '">';
  4173. break;
  4174. case 'xhtml':
  4175. $gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '" />';
  4176. break;
  4177. case 'atom':
  4178. $gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>';
  4179. break;
  4180. case 'rss2':
  4181. $gen = '<generator>' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>';
  4182. break;
  4183. case 'rdf':
  4184. $gen = '<admin:generatorAgent rdf:resource="' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />';
  4185. break;
  4186. case 'comment':
  4187. $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->';
  4188. break;
  4189. case 'export':
  4190. $gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . gmdate( 'Y-m-d H:i' ) . '" -->';
  4191. break;
  4192. }
  4193. /**
  4194. * Filters the HTML for the retrieved generator type.
  4195. *
  4196. * The dynamic portion of the hook name, `$type`, refers to the generator type.
  4197. *
  4198. * @since 2.5.0
  4199. *
  4200. * @param string $gen The HTML markup output to wp_head().
  4201. * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
  4202. * 'rss2', 'rdf', 'comment', 'export'.
  4203. */
  4204. return apply_filters( "get_the_generator_{$type}", $gen, $type );
  4205. }
  4206. /**
  4207. * Outputs the html checked attribute.
  4208. *
  4209. * Compares the first two arguments and if identical marks as checked
  4210. *
  4211. * @since 1.0.0
  4212. *
  4213. * @param mixed $checked One of the values to compare
  4214. * @param mixed $current (true) The other value to compare if not just true
  4215. * @param bool $echo Whether to echo or just return the string
  4216. * @return string html attribute or empty string
  4217. */
  4218. function checked( $checked, $current = true, $echo = true ) {
  4219. return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  4220. }
  4221. /**
  4222. * Outputs the html selected attribute.
  4223. *
  4224. * Compares the first two arguments and if identical marks as selected
  4225. *
  4226. * @since 1.0.0
  4227. *
  4228. * @param mixed $selected One of the values to compare
  4229. * @param mixed $current (true) The other value to compare if not just true
  4230. * @param bool $echo Whether to echo or just return the string
  4231. * @return string html attribute or empty string
  4232. */
  4233. function selected( $selected, $current = true, $echo = true ) {
  4234. return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  4235. }
  4236. /**
  4237. * Outputs the html disabled attribute.
  4238. *
  4239. * Compares the first two arguments and if identical marks as disabled
  4240. *
  4241. * @since 3.0.0
  4242. *
  4243. * @param mixed $disabled One of the values to compare
  4244. * @param mixed $current (true) The other value to compare if not just true
  4245. * @param bool $echo Whether to echo or just return the string
  4246. * @return string html attribute or empty string
  4247. */
  4248. function disabled( $disabled, $current = true, $echo = true ) {
  4249. return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
  4250. }
  4251. /**
  4252. * Outputs the html readonly attribute.
  4253. *
  4254. * Compares the first two arguments and if identical marks as readonly
  4255. *
  4256. * @since 4.9.0
  4257. *
  4258. * @param mixed $readonly One of the values to compare
  4259. * @param mixed $current (true) The other value to compare if not just true
  4260. * @param bool $echo Whether to echo or just return the string
  4261. * @return string html attribute or empty string
  4262. */
  4263. function readonly( $readonly, $current = true, $echo = true ) {
  4264. return __checked_selected_helper( $readonly, $current, $echo, 'readonly' );
  4265. }
  4266. /**
  4267. * Private helper function for checked, selected, disabled and readonly.
  4268. *
  4269. * Compares the first two arguments and if identical marks as $type
  4270. *
  4271. * @since 2.8.0
  4272. * @access private
  4273. *
  4274. * @param mixed $helper One of the values to compare
  4275. * @param mixed $current (true) The other value to compare if not just true
  4276. * @param bool $echo Whether to echo or just return the string
  4277. * @param string $type The type of checked|selected|disabled|readonly we are doing
  4278. * @return string html attribute or empty string
  4279. */
  4280. function __checked_selected_helper( $helper, $current, $echo, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
  4281. if ( (string) $helper === (string) $current ) {
  4282. $result = " $type='$type'";
  4283. } else {
  4284. $result = '';
  4285. }
  4286. if ( $echo ) {
  4287. echo $result;
  4288. }
  4289. return $result;
  4290. }
  4291. /**
  4292. * Default settings for heartbeat
  4293. *
  4294. * Outputs the nonce used in the heartbeat XHR
  4295. *
  4296. * @since 3.6.0
  4297. *
  4298. * @param array $settings
  4299. * @return array $settings
  4300. */
  4301. function wp_heartbeat_settings( $settings ) {
  4302. if ( ! is_admin() ) {
  4303. $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
  4304. }
  4305. if ( is_user_logged_in() ) {
  4306. $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
  4307. }
  4308. return $settings;
  4309. }