general-template.php 123 KB

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