general-template.php 164 KB

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