general-template.php 136 KB

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