PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

https://bitbucket.org/acipriani/madeinapulia.com
PHP | 3115 lines | 1737 code | 228 blank | 1150 comment | 259 complexity | 8ab12dbe8ec04d257fb1e3d8d4c24787 MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  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 $name Name of the specific header file to use.
  33. */
  34. do_action( 'get_header', $name );
  35. $templates = array();
  36. $name = (string) $name;
  37. if ( '' !== $name )
  38. $templates[] = "header-{$name}.php";
  39. $templates[] = 'header.php';
  40. // Backward compat code will be removed in a future release
  41. if ('' == locate_template($templates, true))
  42. load_template( ABSPATH . WPINC . '/theme-compat/header.php');
  43. }
  44. /**
  45. * Load footer template.
  46. *
  47. * Includes the footer template for a theme or if a name is specified then a
  48. * specialised footer will be included.
  49. *
  50. * For the parameter, if the file is called "footer-special.php" then specify
  51. * "special".
  52. *
  53. * @since 1.5.0
  54. *
  55. * @param string $name The name of the specialised footer.
  56. */
  57. function get_footer( $name = null ) {
  58. /**
  59. * Fires before the footer template file is loaded.
  60. *
  61. * The hook allows a specific footer template file to be used in place of the
  62. * default footer template file. If your file is called footer-new.php,
  63. * you would specify the filename in the hook as get_footer( 'new' ).
  64. *
  65. * @since 2.1.0
  66. * @since 2.8.0 $name parameter added.
  67. *
  68. * @param string $name Name of the specific footer file to use.
  69. */
  70. do_action( 'get_footer', $name );
  71. $templates = array();
  72. $name = (string) $name;
  73. if ( '' !== $name )
  74. $templates[] = "footer-{$name}.php";
  75. $templates[] = 'footer.php';
  76. // Backward compat code will be removed in a future release
  77. if ('' == locate_template($templates, true))
  78. load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
  79. }
  80. /**
  81. * Load sidebar template.
  82. *
  83. * Includes the sidebar template for a theme or if a name is specified then a
  84. * specialised sidebar will be included.
  85. *
  86. * For the parameter, if the file is called "sidebar-special.php" then specify
  87. * "special".
  88. *
  89. * @since 1.5.0
  90. *
  91. * @param string $name The name of the specialised sidebar.
  92. */
  93. function get_sidebar( $name = null ) {
  94. /**
  95. * Fires before the sidebar template file is loaded.
  96. *
  97. * The hook allows a specific sidebar template file to be used in place of the
  98. * default sidebar template file. If your file is called sidebar-new.php,
  99. * you would specify the filename in the hook as get_sidebar( 'new' ).
  100. *
  101. * @since 2.2.0
  102. * @since 2.8.0 $name parameter added.
  103. *
  104. * @param string $name Name of the specific sidebar file to use.
  105. */
  106. do_action( 'get_sidebar', $name );
  107. $templates = array();
  108. $name = (string) $name;
  109. if ( '' !== $name )
  110. $templates[] = "sidebar-{$name}.php";
  111. $templates[] = 'sidebar.php';
  112. // Backward compat code will be removed in a future release
  113. if ('' == locate_template($templates, true))
  114. load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
  115. }
  116. /**
  117. * Load a template part into a template
  118. *
  119. * Makes it easy for a theme to reuse sections of code in a easy to overload way
  120. * for child themes.
  121. *
  122. * Includes the named template part for a theme or if a name is specified then a
  123. * specialised part will be included. If the theme contains no {slug}.php file
  124. * then no template will be included.
  125. *
  126. * The template is included using require, not require_once, so you may include the
  127. * same template part multiple times.
  128. *
  129. * For the $name parameter, if the file is called "{slug}-special.php" then specify
  130. * "special".
  131. *
  132. * @since 3.0.0
  133. *
  134. * @param string $slug The slug name for the generic template.
  135. * @param string $name The name of the specialised template.
  136. */
  137. function get_template_part( $slug, $name = null ) {
  138. /**
  139. * Fires before the specified template part file is loaded.
  140. *
  141. * The dynamic portion of the hook name, `$slug`, refers to the slug name
  142. * for the generic template part.
  143. *
  144. * @since 3.0.0
  145. *
  146. * @param string $slug The slug name for the generic template.
  147. * @param string $name The name of the specialized template.
  148. */
  149. do_action( "get_template_part_{$slug}", $slug, $name );
  150. $templates = array();
  151. $name = (string) $name;
  152. if ( '' !== $name )
  153. $templates[] = "{$slug}-{$name}.php";
  154. $templates[] = "{$slug}.php";
  155. locate_template($templates, true, false);
  156. }
  157. /**
  158. * Display search form.
  159. *
  160. * Will first attempt to locate the searchform.php file in either the child or
  161. * the parent, then load it. If it doesn't exist, then the default search form
  162. * will be displayed. The default search form is HTML, which will be displayed.
  163. * There is a filter applied to the search form HTML in order to edit or replace
  164. * it. The filter is 'get_search_form'.
  165. *
  166. * This function is primarily used by themes which want to hardcode the search
  167. * form into the sidebar and also by the search widget in WordPress.
  168. *
  169. * There is also an action that is called whenever the function is run called,
  170. * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
  171. * search relies on or various formatting that applies to the beginning of the
  172. * search. To give a few examples of what it can be used for.
  173. *
  174. * @since 2.7.0
  175. *
  176. * @param boolean $echo Default to echo and not return the form.
  177. * @return string|null String when retrieving, null when displaying or if searchform.php exists.
  178. */
  179. function get_search_form( $echo = true ) {
  180. /**
  181. * Fires before the search form is retrieved, at the start of get_search_form().
  182. *
  183. * @since 2.7.0 as 'get_search_form' action.
  184. * @since 3.6.0
  185. *
  186. * @link https://core.trac.wordpress.org/ticket/19321
  187. */
  188. do_action( 'pre_get_search_form' );
  189. $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
  190. /**
  191. * Filter the HTML format of the search form.
  192. *
  193. * @since 3.6.0
  194. *
  195. * @param string $format The type of markup to use in the search form.
  196. * Accepts 'html5', 'xhtml'.
  197. */
  198. $format = apply_filters( 'search_form_format', $format );
  199. $search_form_template = locate_template( 'searchform.php' );
  200. if ( '' != $search_form_template ) {
  201. ob_start();
  202. require( $search_form_template );
  203. $form = ob_get_clean();
  204. } else {
  205. if ( 'html5' == $format ) {
  206. $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
  207. <label>
  208. <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
  209. <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
  210. </label>
  211. <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
  212. </form>';
  213. } else {
  214. $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
  215. <div>
  216. <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
  217. <input type="text" value="' . get_search_query() . '" name="s" id="s" />
  218. <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
  219. </div>
  220. </form>';
  221. }
  222. }
  223. /**
  224. * Filter the HTML output of the search form.
  225. *
  226. * @since 2.7.0
  227. *
  228. * @param string $form The search form HTML output.
  229. */
  230. $result = apply_filters( 'get_search_form', $form );
  231. if ( null === $result )
  232. $result = $form;
  233. if ( $echo )
  234. echo $result;
  235. else
  236. return $result;
  237. }
  238. /**
  239. * Display the Log In/Out link.
  240. *
  241. * Displays a link, which allows users to navigate to the Log In page to log in
  242. * or log out depending on whether they are currently logged in.
  243. *
  244. * @since 1.5.0
  245. *
  246. * @param string $redirect Optional path to redirect to on login/logout.
  247. * @param boolean $echo Default to echo and not return the link.
  248. * @return string|null String when retrieving, null when displaying.
  249. */
  250. function wp_loginout($redirect = '', $echo = true) {
  251. if ( ! is_user_logged_in() )
  252. $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
  253. else
  254. $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
  255. if ( $echo ) {
  256. /**
  257. * Filter the HTML output for the Log In/Log Out link.
  258. *
  259. * @since 1.5.0
  260. *
  261. * @param string $link The HTML link content.
  262. */
  263. echo apply_filters( 'loginout', $link );
  264. } else {
  265. /** This filter is documented in wp-includes/general-template.php */
  266. return apply_filters( 'loginout', $link );
  267. }
  268. }
  269. /**
  270. * Returns the Log Out URL.
  271. *
  272. * Returns the URL that allows the user to log out of the site.
  273. *
  274. * @since 2.7.0
  275. *
  276. * @param string $redirect Path to redirect to on logout.
  277. * @return string A log out URL.
  278. */
  279. function wp_logout_url($redirect = '') {
  280. $args = array( 'action' => 'logout' );
  281. if ( !empty($redirect) ) {
  282. $args['redirect_to'] = urlencode( $redirect );
  283. }
  284. $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
  285. $logout_url = wp_nonce_url( $logout_url, 'log-out' );
  286. /**
  287. * Filter the logout URL.
  288. *
  289. * @since 2.8.0
  290. *
  291. * @param string $logout_url The Log Out URL.
  292. * @param string $redirect Path to redirect to on logout.
  293. */
  294. return apply_filters( 'logout_url', $logout_url, $redirect );
  295. }
  296. /**
  297. * Returns the Log In URL.
  298. *
  299. * Returns the URL that allows the user to log in to the site.
  300. *
  301. * @since 2.7.0
  302. *
  303. * @param string $redirect Path to redirect to on login.
  304. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
  305. * @return string A log in URL.
  306. */
  307. function wp_login_url($redirect = '', $force_reauth = false) {
  308. $login_url = site_url('wp-login.php', 'login');
  309. if ( !empty($redirect) )
  310. $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
  311. if ( $force_reauth )
  312. $login_url = add_query_arg('reauth', '1', $login_url);
  313. /**
  314. * Filter the login URL.
  315. *
  316. * @since 2.8.0
  317. *
  318. * @param string $login_url The login URL.
  319. * @param string $redirect The path to redirect to on login, if supplied.
  320. */
  321. return apply_filters( 'login_url', $login_url, $redirect );
  322. }
  323. /**
  324. * Returns the user registration URL.
  325. *
  326. * Returns the URL that allows the user to register on the site.
  327. *
  328. * @since 3.6.0
  329. *
  330. * @return string User registration URL.
  331. */
  332. function wp_registration_url() {
  333. /**
  334. * Filter the user registration URL.
  335. *
  336. * @since 3.6.0
  337. *
  338. * @param string $register The user registration URL.
  339. */
  340. return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
  341. }
  342. /**
  343. * Provides a simple login form for use anywhere within WordPress. By default, it echoes
  344. * the HTML immediately. Pass array('echo'=>false) to return the string instead.
  345. *
  346. * @since 3.0.0
  347. *
  348. * @param array $args Configuration options to modify the form output.
  349. * @return string|null String when retrieving, null when displaying.
  350. */
  351. function wp_login_form( $args = array() ) {
  352. $defaults = array(
  353. 'echo' => true,
  354. 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
  355. 'form_id' => 'loginform',
  356. 'label_username' => __( 'Username' ),
  357. 'label_password' => __( 'Password' ),
  358. 'label_remember' => __( 'Remember Me' ),
  359. 'label_log_in' => __( 'Log In' ),
  360. 'id_username' => 'user_login',
  361. 'id_password' => 'user_pass',
  362. 'id_remember' => 'rememberme',
  363. 'id_submit' => 'wp-submit',
  364. 'remember' => true,
  365. 'value_username' => '',
  366. 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
  367. );
  368. /**
  369. * Filter the default login form output arguments.
  370. *
  371. * @since 3.0.0
  372. *
  373. * @see wp_login_form()
  374. *
  375. * @param array $defaults An array of default login form arguments.
  376. */
  377. $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
  378. /**
  379. * Filter content to display at the top of the login form.
  380. *
  381. * The filter evaluates just following the opening form tag element.
  382. *
  383. * @since 3.0.0
  384. *
  385. * @param string $content Content to display. Default empty.
  386. * @param array $args Array of login form arguments.
  387. */
  388. $login_form_top = apply_filters( 'login_form_top', '', $args );
  389. /**
  390. * Filter content to display in the middle of the login form.
  391. *
  392. * The filter evaluates just following the location where the 'login-password'
  393. * field is displayed.
  394. *
  395. * @since 3.0.0
  396. *
  397. * @param string $content Content to display. Default empty.
  398. * @param array $args Array of login form arguments.
  399. */
  400. $login_form_middle = apply_filters( 'login_form_middle', '', $args );
  401. /**
  402. * Filter content to display at the bottom of the login form.
  403. *
  404. * The filter evaluates just preceding the closing form tag element.
  405. *
  406. * @since 3.0.0
  407. *
  408. * @param string $content Content to display. Default empty.
  409. * @param array $args Array of login form arguments.
  410. */
  411. $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
  412. $form = '
  413. <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
  414. ' . $login_form_top . '
  415. <p class="login-username">
  416. <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
  417. <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
  418. </p>
  419. <p class="login-password">
  420. <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
  421. <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
  422. </p>
  423. ' . $login_form_middle . '
  424. ' . ( $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>' : '' ) . '
  425. <p class="login-submit">
  426. <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
  427. <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
  428. </p>
  429. ' . $login_form_bottom . '
  430. </form>';
  431. if ( $args['echo'] )
  432. echo $form;
  433. else
  434. return $form;
  435. }
  436. /**
  437. * Returns the Lost Password URL.
  438. *
  439. * Returns the URL that allows the user to retrieve the lost password
  440. *
  441. * @since 2.8.0
  442. *
  443. * @param string $redirect Path to redirect to on login.
  444. * @return string Lost password URL.
  445. */
  446. function wp_lostpassword_url( $redirect = '' ) {
  447. $args = array( 'action' => 'lostpassword' );
  448. if ( !empty($redirect) ) {
  449. $args['redirect_to'] = $redirect;
  450. }
  451. $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
  452. /**
  453. * Filter the Lost Password URL.
  454. *
  455. * @since 2.8.0
  456. *
  457. * @param string $lostpassword_url The lost password page URL.
  458. * @param string $redirect The path to redirect to on login.
  459. */
  460. return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
  461. }
  462. /**
  463. * Display the Registration or Admin link.
  464. *
  465. * Display a link which allows the user to navigate to the registration page if
  466. * not logged in and registration is enabled or to the dashboard if logged in.
  467. *
  468. * @since 1.5.0
  469. *
  470. * @param string $before Text to output before the link. Default `<li>`.
  471. * @param string $after Text to output after the link. Default `</li>`.
  472. * @param boolean $echo Default to echo and not return the link.
  473. * @return string|null String when retrieving, null when displaying.
  474. */
  475. function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
  476. if ( ! is_user_logged_in() ) {
  477. if ( get_option('users_can_register') )
  478. $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
  479. else
  480. $link = '';
  481. } else {
  482. $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
  483. }
  484. /**
  485. * Filter the HTML link to the Registration or Admin page.
  486. *
  487. * Users are sent to the admin page if logged-in, or the registration page
  488. * if enabled and logged-out.
  489. *
  490. * @since 1.5.0
  491. *
  492. * @param string $link The HTML code for the link to the Registration or Admin page.
  493. */
  494. $link = apply_filters( 'register', $link );
  495. if ( $echo ) {
  496. echo $link;
  497. } else {
  498. return $link;
  499. }
  500. }
  501. /**
  502. * Theme container function for the 'wp_meta' action.
  503. *
  504. * The 'wp_meta' action can have several purposes, depending on how you use it,
  505. * but one purpose might have been to allow for theme switching.
  506. *
  507. * @since 1.5.0
  508. *
  509. * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
  510. */
  511. function wp_meta() {
  512. /**
  513. * Fires before displaying echoed content in the sidebar.
  514. *
  515. * @since 1.5.0
  516. */
  517. do_action( 'wp_meta' );
  518. }
  519. /**
  520. * Display information about the blog.
  521. *
  522. * @see get_bloginfo() For possible values for the parameter.
  523. * @since 0.71
  524. *
  525. * @param string $show What to display.
  526. */
  527. function bloginfo( $show='' ) {
  528. echo get_bloginfo( $show, 'display' );
  529. }
  530. /**
  531. * Retrieve information about the blog.
  532. *
  533. * Some show parameter values are deprecated and will be removed in future
  534. * versions. These options will trigger the {@see _deprecated_argument()}
  535. * function. The deprecated blog info options are listed in the function
  536. * contents.
  537. *
  538. * The possible values for the 'show' parameter are listed below.
  539. *
  540. * 1. url - Blog URI to homepage.
  541. * 2. wpurl - Blog URI path to WordPress.
  542. * 3. description - Secondary title
  543. *
  544. * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
  545. * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
  546. * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
  547. * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
  548. *
  549. * @since 0.71
  550. *
  551. * @param string $show Blog info to retrieve.
  552. * @param string $filter How to filter what is retrieved.
  553. * @return string Mostly string values, might be empty.
  554. */
  555. function get_bloginfo( $show = '', $filter = 'raw' ) {
  556. switch( $show ) {
  557. case 'home' : // DEPRECATED
  558. case 'siteurl' : // DEPRECATED
  559. _deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> option instead.' ), 'url' ) );
  560. case 'url' :
  561. $output = home_url();
  562. break;
  563. case 'wpurl' :
  564. $output = site_url();
  565. break;
  566. case 'description':
  567. $output = get_option('blogdescription');
  568. break;
  569. case 'rdf_url':
  570. $output = get_feed_link('rdf');
  571. break;
  572. case 'rss_url':
  573. $output = get_feed_link('rss');
  574. break;
  575. case 'rss2_url':
  576. $output = get_feed_link('rss2');
  577. break;
  578. case 'atom_url':
  579. $output = get_feed_link('atom');
  580. break;
  581. case 'comments_atom_url':
  582. $output = get_feed_link('comments_atom');
  583. break;
  584. case 'comments_rss2_url':
  585. $output = get_feed_link('comments_rss2');
  586. break;
  587. case 'pingback_url':
  588. $output = site_url( 'xmlrpc.php' );
  589. break;
  590. case 'stylesheet_url':
  591. $output = get_stylesheet_uri();
  592. break;
  593. case 'stylesheet_directory':
  594. $output = get_stylesheet_directory_uri();
  595. break;
  596. case 'template_directory':
  597. case 'template_url':
  598. $output = get_template_directory_uri();
  599. break;
  600. case 'admin_email':
  601. $output = get_option('admin_email');
  602. break;
  603. case 'charset':
  604. $output = get_option('blog_charset');
  605. if ('' == $output) $output = 'UTF-8';
  606. break;
  607. case 'html_type' :
  608. $output = get_option('html_type');
  609. break;
  610. case 'version':
  611. global $wp_version;
  612. $output = $wp_version;
  613. break;
  614. case 'language':
  615. $output = get_locale();
  616. $output = str_replace('_', '-', $output);
  617. break;
  618. case 'text_direction':
  619. //_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> function instead.' ), 'is_rtl()' ) );
  620. if ( function_exists( 'is_rtl' ) ) {
  621. $output = is_rtl() ? 'rtl' : 'ltr';
  622. } else {
  623. $output = 'ltr';
  624. }
  625. break;
  626. case 'name':
  627. default:
  628. $output = get_option('blogname');
  629. break;
  630. }
  631. $url = true;
  632. if (strpos($show, 'url') === false &&
  633. strpos($show, 'directory') === false &&
  634. strpos($show, 'home') === false)
  635. $url = false;
  636. if ( 'display' == $filter ) {
  637. if ( $url ) {
  638. /**
  639. * Filter the URL returned by get_bloginfo().
  640. *
  641. * @since 2.0.5
  642. *
  643. * @param mixed $output The URL returned by bloginfo().
  644. * @param mixed $show Type of information requested.
  645. */
  646. $output = apply_filters( 'bloginfo_url', $output, $show );
  647. } else {
  648. /**
  649. * Filter the site information returned by get_bloginfo().
  650. *
  651. * @since 0.71
  652. *
  653. * @param mixed $output The requested non-URL site information.
  654. * @param mixed $show Type of information requested.
  655. */
  656. $output = apply_filters( 'bloginfo', $output, $show );
  657. }
  658. }
  659. return $output;
  660. }
  661. /**
  662. * Display title tag with contents.
  663. *
  664. * @since 4.1.0
  665. * @access private
  666. * @internal
  667. *
  668. * @see wp_title()
  669. */
  670. function _wp_render_title_tag() {
  671. if ( ! current_theme_supports( 'title-tag' ) ) {
  672. return;
  673. }
  674. // This can only work internally on wp_head.
  675. if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
  676. return;
  677. }
  678. echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
  679. }
  680. /**
  681. * Display or retrieve page title for all areas of blog.
  682. *
  683. * By default, the page title will display the separator before the page title,
  684. * so that the blog title will be before the page title. This is not good for
  685. * title display, since the blog title shows up on most tabs and not what is
  686. * important, which is the page that the user is looking at.
  687. *
  688. * There are also SEO benefits to having the blog title after or to the 'right'
  689. * or the page title. However, it is mostly common sense to have the blog title
  690. * to the right with most browsers supporting tabs. You can achieve this by
  691. * using the seplocation parameter and setting the value to 'right'. This change
  692. * was introduced around 2.5.0, in case backwards compatibility of themes is
  693. * important.
  694. *
  695. * @since 1.0.0
  696. *
  697. * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
  698. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  699. * @param string $seplocation Optional. Direction to display title, 'right'.
  700. * @return string|null String on retrieve, null when displaying.
  701. */
  702. function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
  703. global $wp_locale, $page, $paged;
  704. $m = get_query_var('m');
  705. $year = get_query_var('year');
  706. $monthnum = get_query_var('monthnum');
  707. $day = get_query_var('day');
  708. $search = get_query_var('s');
  709. $title = '';
  710. $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
  711. // If there is a post
  712. if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
  713. $title = single_post_title( '', false );
  714. }
  715. // If there's a post type archive
  716. if ( is_post_type_archive() ) {
  717. $post_type = get_query_var( 'post_type' );
  718. if ( is_array( $post_type ) )
  719. $post_type = reset( $post_type );
  720. $post_type_object = get_post_type_object( $post_type );
  721. if ( ! $post_type_object->has_archive )
  722. $title = post_type_archive_title( '', false );
  723. }
  724. // If there's a category or tag
  725. if ( is_category() || is_tag() ) {
  726. $title = single_term_title( '', false );
  727. }
  728. // If there's a taxonomy
  729. if ( is_tax() ) {
  730. $term = get_queried_object();
  731. if ( $term ) {
  732. $tax = get_taxonomy( $term->taxonomy );
  733. $title = single_term_title( $tax->labels->name . $t_sep, false );
  734. }
  735. }
  736. // If there's an author
  737. if ( is_author() && ! is_post_type_archive() ) {
  738. $author = get_queried_object();
  739. if ( $author )
  740. $title = $author->display_name;
  741. }
  742. // Post type archives with has_archive should override terms.
  743. if ( is_post_type_archive() && $post_type_object->has_archive )
  744. $title = post_type_archive_title( '', false );
  745. // If there's a month
  746. if ( is_archive() && !empty($m) ) {
  747. $my_year = substr($m, 0, 4);
  748. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  749. $my_day = intval(substr($m, 6, 2));
  750. $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
  751. }
  752. // If there's a year
  753. if ( is_archive() && !empty($year) ) {
  754. $title = $year;
  755. if ( !empty($monthnum) )
  756. $title .= $t_sep . $wp_locale->get_month($monthnum);
  757. if ( !empty($day) )
  758. $title .= $t_sep . zeroise($day, 2);
  759. }
  760. // If it's a search
  761. if ( is_search() ) {
  762. /* translators: 1: separator, 2: search phrase */
  763. $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
  764. }
  765. // If it's a 404 page
  766. if ( is_404() ) {
  767. $title = __('Page not found');
  768. }
  769. $prefix = '';
  770. if ( !empty($title) )
  771. $prefix = " $sep ";
  772. /**
  773. * Filter the parts of the page title.
  774. *
  775. * @since 4.0.0
  776. *
  777. * @param array $title_array Parts of the page title.
  778. */
  779. $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
  780. // Determines position of the separator and direction of the breadcrumb
  781. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  782. $title_array = array_reverse( $title_array );
  783. $title = implode( " $sep ", $title_array ) . $prefix;
  784. } else {
  785. $title = $prefix . implode( " $sep ", $title_array );
  786. }
  787. if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
  788. $title .= get_bloginfo( 'name', 'display' );
  789. $site_description = get_bloginfo( 'description', 'display' );
  790. if ( $site_description && ( is_home() || is_front_page() ) ) {
  791. $title .= " $sep $site_description";
  792. }
  793. if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
  794. $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
  795. }
  796. }
  797. /**
  798. * Filter the text of the page title.
  799. *
  800. * @since 2.0.0
  801. *
  802. * @param string $title Page title.
  803. * @param string $sep Title separator.
  804. * @param string $seplocation Location of the separator (left or right).
  805. */
  806. $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
  807. // Send it out
  808. if ( $display )
  809. echo $title;
  810. else
  811. return $title;
  812. }
  813. /**
  814. * Display or retrieve page title for post.
  815. *
  816. * This is optimized for single.php template file for displaying the post title.
  817. *
  818. * It does not support placing the separator after the title, but by leaving the
  819. * prefix parameter empty, you can set the title separator manually. The prefix
  820. * does not automatically place a space between the prefix, so if there should
  821. * be a space, the parameter value will need to have it at the end.
  822. *
  823. * @since 0.71
  824. *
  825. * @param string $prefix Optional. What to display before the title.
  826. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  827. * @return string|null Title when retrieving, null when displaying or failure.
  828. */
  829. function single_post_title($prefix = '', $display = true) {
  830. $_post = get_queried_object();
  831. if ( !isset($_post->post_title) )
  832. return;
  833. /**
  834. * Filter the page title for a single post.
  835. *
  836. * @since 0.71
  837. *
  838. * @param string $_post_title The single post page title.
  839. * @param object $_post The current queried object as returned by get_queried_object().
  840. */
  841. $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
  842. if ( $display )
  843. echo $prefix . $title;
  844. else
  845. return $prefix . $title;
  846. }
  847. /**
  848. * Display or retrieve title for a post type archive.
  849. *
  850. * This is optimized for archive.php and archive-{$post_type}.php template files
  851. * for displaying the title of the post type.
  852. *
  853. * @since 3.1.0
  854. *
  855. * @param string $prefix Optional. What to display before the title.
  856. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  857. * @return string|null Title when retrieving, null when displaying or failure.
  858. */
  859. function post_type_archive_title( $prefix = '', $display = true ) {
  860. if ( ! is_post_type_archive() )
  861. return;
  862. $post_type = get_query_var( 'post_type' );
  863. if ( is_array( $post_type ) )
  864. $post_type = reset( $post_type );
  865. $post_type_obj = get_post_type_object( $post_type );
  866. /**
  867. * Filter the post type archive title.
  868. *
  869. * @since 3.1.0
  870. *
  871. * @param string $post_type_name Post type 'name' label.
  872. * @param string $post_type Post type.
  873. */
  874. $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
  875. if ( $display )
  876. echo $prefix . $title;
  877. else
  878. return $prefix . $title;
  879. }
  880. /**
  881. * Display or retrieve page title for category archive.
  882. *
  883. * This is useful for category template file or files, because it is optimized
  884. * for category page title and with less overhead than {@link wp_title()}.
  885. *
  886. * It does not support placing the separator after the title, but by leaving the
  887. * prefix parameter empty, you can set the title separator manually. The prefix
  888. * does not automatically place a space between the prefix, so if there should
  889. * be a space, the parameter value will need to have it at the end.
  890. *
  891. * @since 0.71
  892. *
  893. * @param string $prefix Optional. What to display before the title.
  894. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  895. * @return string|null Title when retrieving, null when displaying or failure.
  896. */
  897. function single_cat_title( $prefix = '', $display = true ) {
  898. return single_term_title( $prefix, $display );
  899. }
  900. /**
  901. * Display or retrieve page title for tag post archive.
  902. *
  903. * Useful for tag template files for displaying the tag page title. It has less
  904. * overhead than {@link wp_title()}, because of its limited implementation.
  905. *
  906. * It does not support placing the separator after the title, but by leaving the
  907. * prefix parameter empty, you can set the title separator manually. The prefix
  908. * does not automatically place a space between the prefix, so if there should
  909. * be a space, the parameter value will need to have it at the end.
  910. *
  911. * @since 2.3.0
  912. *
  913. * @param string $prefix Optional. What to display before the title.
  914. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  915. * @return string|null Title when retrieving, null when displaying or failure.
  916. */
  917. function single_tag_title( $prefix = '', $display = true ) {
  918. return single_term_title( $prefix, $display );
  919. }
  920. /**
  921. * Display or retrieve page title for taxonomy term archive.
  922. *
  923. * Useful for taxonomy term template files for displaying the taxonomy term page title.
  924. * It has less overhead than {@link wp_title()}, because of its limited implementation.
  925. *
  926. * It does not support placing the separator after the title, but by leaving the
  927. * prefix parameter empty, you can set the title separator manually. The prefix
  928. * does not automatically place a space between the prefix, so if there should
  929. * be a space, the parameter value will need to have it at the end.
  930. *
  931. * @since 3.1.0
  932. *
  933. * @param string $prefix Optional. What to display before the title.
  934. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  935. * @return string|null Title when retrieving, null when displaying or failure.
  936. */
  937. function single_term_title( $prefix = '', $display = true ) {
  938. $term = get_queried_object();
  939. if ( !$term )
  940. return;
  941. if ( is_category() ) {
  942. /**
  943. * Filter the category archive page title.
  944. *
  945. * @since 2.0.10
  946. *
  947. * @param string $term_name Category name for archive being displayed.
  948. */
  949. $term_name = apply_filters( 'single_cat_title', $term->name );
  950. } elseif ( is_tag() ) {
  951. /**
  952. * Filter the tag archive page title.
  953. *
  954. * @since 2.3.0
  955. *
  956. * @param string $term_name Tag name for archive being displayed.
  957. */
  958. $term_name = apply_filters( 'single_tag_title', $term->name );
  959. } elseif ( is_tax() ) {
  960. /**
  961. * Filter the custom taxonomy archive page title.
  962. *
  963. * @since 3.1.0
  964. *
  965. * @param string $term_name Term name for archive being displayed.
  966. */
  967. $term_name = apply_filters( 'single_term_title', $term->name );
  968. } else {
  969. return;
  970. }
  971. if ( empty( $term_name ) )
  972. return;
  973. if ( $display )
  974. echo $prefix . $term_name;
  975. else
  976. return $prefix . $term_name;
  977. }
  978. /**
  979. * Display or retrieve page title for post archive based on date.
  980. *
  981. * Useful for when the template only needs to display the month and year, if
  982. * either are available. Optimized for just this purpose, so if it is all that
  983. * is needed, should be better than {@link wp_title()}.
  984. *
  985. * It does not support placing the separator after the title, but by leaving the
  986. * prefix parameter empty, you can set the title separator manually. The prefix
  987. * does not automatically place a space between the prefix, so if there should
  988. * be a space, the parameter value will need to have it at the end.
  989. *
  990. * @since 0.71
  991. *
  992. * @param string $prefix Optional. What to display before the title.
  993. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  994. * @return string|null Title when retrieving, null when displaying or failure.
  995. */
  996. function single_month_title($prefix = '', $display = true ) {
  997. global $wp_locale;
  998. $m = get_query_var('m');
  999. $year = get_query_var('year');
  1000. $monthnum = get_query_var('monthnum');
  1001. if ( !empty($monthnum) && !empty($year) ) {
  1002. $my_year = $year;
  1003. $my_month = $wp_locale->get_month($monthnum);
  1004. } elseif ( !empty($m) ) {
  1005. $my_year = substr($m, 0, 4);
  1006. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  1007. }
  1008. if ( empty($my_month) )
  1009. return false;
  1010. $result = $prefix . $my_month . $prefix . $my_year;
  1011. if ( !$display )
  1012. return $result;
  1013. echo $result;
  1014. }
  1015. /**
  1016. * Display the archive title based on the queried object.
  1017. *
  1018. * @since 4.1.0
  1019. *
  1020. * @see get_the_archive_title()
  1021. *
  1022. * @param string $before Optional. Content to prepend to the title. Default empty.
  1023. * @param string $after Optional. Content to append to the title. Default empty.
  1024. */
  1025. function the_archive_title( $before = '', $after = '' ) {
  1026. $title = get_the_archive_title();
  1027. if ( ! empty( $title ) ) {
  1028. echo $before . $title . $after;
  1029. }
  1030. }
  1031. /**
  1032. * Retrieve the archive title based on the queried object.
  1033. *
  1034. * @since 4.1.0
  1035. *
  1036. * @return string Archive title.
  1037. */
  1038. function get_the_archive_title() {
  1039. if ( is_category() ) {
  1040. $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
  1041. } elseif ( is_tag() ) {
  1042. $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
  1043. } elseif ( is_author() ) {
  1044. $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
  1045. } elseif ( is_year() ) {
  1046. $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
  1047. } elseif ( is_month() ) {
  1048. $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
  1049. } elseif ( is_day() ) {
  1050. $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
  1051. } elseif ( is_tax( 'post_format' ) ) {
  1052. if ( is_tax( 'post_format', 'post-format-aside' ) ) {
  1053. $title = _x( 'Asides', 'post format archive title' );
  1054. } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
  1055. $title = _x( 'Galleries', 'post format archive title' );
  1056. } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
  1057. $title = _x( 'Images', 'post format archive title' );
  1058. } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
  1059. $title = _x( 'Videos', 'post format archive title' );
  1060. } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
  1061. $title = _x( 'Quotes', 'post format archive title' );
  1062. } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
  1063. $title = _x( 'Links', 'post format archive title' );
  1064. } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
  1065. $title = _x( 'Statuses', 'post format archive title' );
  1066. } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
  1067. $title = _x( 'Audio', 'post format archive title' );
  1068. } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
  1069. $title = _x( 'Chats', 'post format archive title' );
  1070. }
  1071. } elseif ( is_post_type_archive() ) {
  1072. $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
  1073. } elseif ( is_tax() ) {
  1074. $tax = get_taxonomy( get_queried_object()->taxonomy );
  1075. /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
  1076. $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
  1077. } else {
  1078. $title = __( 'Archives' );
  1079. }
  1080. /**
  1081. * Filter the archive title.
  1082. *
  1083. * @since 4.1.0
  1084. *
  1085. * @param string $title Archive title to be displayed.
  1086. */
  1087. return apply_filters( 'get_the_archive_title', $title );
  1088. }
  1089. /**
  1090. * Display category, tag, or term description.
  1091. *
  1092. * @since 4.1.0
  1093. *
  1094. * @see get_the_archive_description()
  1095. *
  1096. * @param string $before Optional. Content to prepend to the description. Default empty.
  1097. * @param string $after Optional. Content to append to the description. Default empty.
  1098. */
  1099. function the_archive_description( $before = '', $after = '' ) {
  1100. $description = get_the_archive_description();
  1101. if ( $description ) {
  1102. echo $before . $description . $after;
  1103. }
  1104. }
  1105. /**
  1106. * Retrieve category, tag, or term description.
  1107. *
  1108. * @since 4.1.0
  1109. *
  1110. * @return string Archive description.
  1111. */
  1112. function get_the_archive_description() {
  1113. /**
  1114. * Filter the archive description.
  1115. *
  1116. * @since 4.1.0
  1117. *
  1118. * @see term_description()
  1119. *
  1120. * @param string $description Archive description to be displayed.
  1121. */
  1122. return apply_filters( 'get_the_archive_description', term_description() );
  1123. }
  1124. /**
  1125. * Retrieve archive link content based on predefined or custom code.
  1126. *
  1127. * The format can be one of four styles. The 'link' for head element, 'option'
  1128. * for use in the select element, 'html' for use in list (either ol or ul HTML
  1129. * elements). Custom content is also supported using the before and after
  1130. * parameters.
  1131. *
  1132. * The 'link' format uses the `<link>` HTML element with the **archives**
  1133. * relationship. The before and after parameters are not used. The text
  1134. * parameter is used to describe the link.
  1135. *
  1136. * The 'option' format uses the option HTML element for use in select element.
  1137. * The value is the url parameter and the before and after parameters are used
  1138. * between the text description.
  1139. *
  1140. * The 'html' format, which is the default, uses the li HTML element for use in
  1141. * the list HTML elements. The before parameter is before the link and the after
  1142. * parameter is after the closing link.
  1143. *
  1144. * The custom format uses the before parameter before the link ('a' HTML
  1145. * element) and the after parameter after the closing link tag. If the above
  1146. * three values for the format are not used, then custom format is assumed.
  1147. *
  1148. * @since 1.0.0
  1149. *
  1150. * @todo Properly document optional arguments as such
  1151. *
  1152. * @param string $url URL to archive.
  1153. * @param string $text Archive text description.
  1154. * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
  1155. * @param string $before Optional.
  1156. * @param string $after Optional.
  1157. * @return string HTML link content for archive.
  1158. */
  1159. function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
  1160. $text = wptexturize($text);
  1161. $url = esc_url($url);
  1162. if ('link' == $format)
  1163. $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
  1164. elseif ('option' == $format)
  1165. $link_html = "\t<option value='$url'>$before $text $after</option>\n";
  1166. elseif ('html' == $format)
  1167. $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
  1168. else // custom
  1169. $link_html = "\t$before<a href='$url'>$text</a>$after\n";
  1170. /**
  1171. * Filter the archive link content.
  1172. *
  1173. * @since 2.6.0
  1174. *
  1175. * @param string $link_html The archive HTML link content.
  1176. */
  1177. $link_html = apply_filters( 'get_archives_link', $link_html );
  1178. return $link_html;
  1179. }
  1180. /**
  1181. * Display archive links based on type and format.
  1182. *
  1183. * @since 1.2.0
  1184. *
  1185. * @see get_archives_link()
  1186. *
  1187. * @param string|array $args {
  1188. * Default archive links arguments. Optional.
  1189. *
  1190. * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
  1191. * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
  1192. * display the same archive link list as well as post titles instead
  1193. * of displaying dates. The difference between the two is that 'alpha'
  1194. * will order by post title and 'postbypost' will order by post date.
  1195. * Default 'monthly'.
  1196. * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
  1197. * @type string $format Format each link should take using the $before and $after args.
  1198. * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
  1199. * (`<li>` tag), or a custom format, which generates a link anchor
  1200. * with $before preceding and $after succeeding. Default 'html'.
  1201. * @type string $before Markup to prepend to the beginning of each link. Default empty.
  1202. * @type string $after Markup to append to the end of each link. Default empty.
  1203. * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
  1204. * @type bool $echo Whether to echo or return the links list. Default 1|true to echo.
  1205. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
  1206. * Default 'DESC'.
  1207. * }
  1208. * @return string|null String when retrieving, null when displaying.
  1209. */
  1210. function wp_get_archives( $args = '' ) {
  1211. global $wpdb, $wp_locale;
  1212. $defaults = array(
  1213. 'type' => 'monthly', 'limit' => '',
  1214. 'format' => 'html', 'before' => '',
  1215. 'after' => '', 'show_post_count' => false,
  1216. 'echo' => 1, 'order' => 'DESC',
  1217. );
  1218. $r = wp_parse_args( $args, $defaults );
  1219. if ( '' == $r['type'] ) {
  1220. $r['type'] = 'monthly';
  1221. }
  1222. if ( ! empty( $r['limit'] ) ) {
  1223. $r['limit'] = absint( $r['limit'] );
  1224. $r['limit'] = ' LIMIT ' . $r['limit'];
  1225. }
  1226. $order = strtoupper( $r['order'] );
  1227. if ( $order !== 'ASC' ) {
  1228. $order = 'DESC';
  1229. }
  1230. // this is what will separate dates on weekly archive links
  1231. $archive_week_separator = '&#8211;';
  1232. // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
  1233. $archive_date_format_over_ride = 0;
  1234. // options for daily archive (only if you over-ride the general date format)
  1235. $archive_day_date_format = 'Y/m/d';
  1236. // options for weekly archive (only if you over-ride the general date format)
  1237. $archive_week_start_date_format = 'Y/m/d';
  1238. $archive_week_end_date_format = 'Y/m/d';
  1239. if ( ! $archive_date_format_over_ride ) {
  1240. $archive_day_date_format = get_option( 'date_format' );
  1241. $archive_week_start_date_format = get_option( 'date_format' );
  1242. $archive_week_end_date_format = get_option( 'date_format' );
  1243. }
  1244. /**
  1245. * Filter the SQL WHERE clause for retrieving archives.
  1246. *
  1247. * @since 2.2.0
  1248. *
  1249. * @param string $sql_where Portion of SQL query containing the WHERE clause.
  1250. * @param array $r An array of default arguments.
  1251. */
  1252. $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
  1253. /**
  1254. * Filter the SQL JOIN clause for retrieving archives.
  1255. *
  1256. * @since 2.2.0
  1257. *
  1258. * @param string $sql_join Portion of SQL query containing JOIN clause.
  1259. * @param array $r An array of default arguments.
  1260. */
  1261. $join = apply_filters( 'getarchives_join', '', $r );
  1262. $output = '';
  1263. $last_changed = wp_cache_get( 'last_changed', 'posts' );
  1264. if ( ! $last_changed ) {
  1265. $last_changed = microtime();
  1266. wp_cache_set( 'last_changed', $last_changed, 'posts' );
  1267. }
  1268. $limit = $r['limit'];
  1269. if ( 'monthly' == $r['type'] ) {
  1270. $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";
  1271. $key = md5( $query );
  1272. $key = "wp_get_archives:$key:$last_changed";
  1273. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1274. $results = $wpdb->get_results( $query );
  1275. wp_cache_set( $key, $results, 'posts' );
  1276. }
  1277. if ( $results ) {
  1278. $after = $r['after'];
  1279. foreach ( (array) $results as $result ) {
  1280. $url = get_month_link( $result->year, $result->month );
  1281. /* translators: 1: month name, 2: 4-digit year */
  1282. $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
  1283. if ( $r['show_post_count'] ) {
  1284. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1285. }
  1286. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1287. }
  1288. }
  1289. } elseif ( 'yearly' == $r['type'] ) {
  1290. $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";
  1291. $key = md5( $query );
  1292. $key = "wp_get_archives:$key:$last_changed";
  1293. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1294. $results = $wpdb->get_results( $query );
  1295. wp_cache_set( $key, $results, 'posts' );
  1296. }
  1297. if ( $results ) {
  1298. $after = $r['after'];
  1299. foreach ( (array) $results as $result) {
  1300. $url = get_year_link( $result->year );
  1301. $text = sprintf( '%d', $result->year );
  1302. if ( $r['show_post_count'] ) {
  1303. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1304. }
  1305. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1306. }
  1307. }
  1308. } elseif ( 'daily' == $r['type'] ) {
  1309. $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";
  1310. $key = md5( $query );
  1311. $key = "wp_get_archives:$key:$last_changed";
  1312. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1313. $results = $wpdb->get_results( $query );
  1314. $cache[ $key ] = $results;
  1315. wp_cache_set( $key, $results, 'posts' );
  1316. }
  1317. if ( $results ) {
  1318. $after = $r['after'];
  1319. foreach ( (array) $results as $result ) {
  1320. $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
  1321. $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
  1322. $text = mysql2date( $archive_day_date_format, $date );
  1323. if ( $r['show_post_count'] ) {
  1324. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1325. }
  1326. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1327. }
  1328. }
  1329. } elseif ( 'weekly' == $r['type'] ) {
  1330. $week = _wp_mysql_week( '`post_date`' );
  1331. $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";
  1332. $key = md5( $query );
  1333. $key = "wp_get_archives:$key:$last_changed";
  1334. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1335. $results = $wpdb->get_results( $query );
  1336. wp_cache_set( $key, $results, 'posts' );
  1337. }
  1338. $arc_w_last = '';
  1339. if ( $results ) {
  1340. $after = $r['after'];
  1341. foreach ( (array) $results as $result ) {
  1342. if ( $result->week != $arc_w_last ) {
  1343. $arc_year = $result->yr;
  1344. $arc_w_last = $result->week;
  1345. $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
  1346. $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
  1347. $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
  1348. $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&amp;', '=', $result->week );
  1349. $text = $arc_week_start . $archive_week_separator . $arc_week_end;
  1350. if ( $r['show_post_count'] ) {
  1351. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1352. }
  1353. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1354. }
  1355. }
  1356. }
  1357. } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
  1358. $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC ';
  1359. $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  1360. $key = md5( $query );
  1361. $key = "wp_get_archives:$key:$last_changed";
  1362. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1363. $results = $wpdb->get_results( $query );
  1364. wp_cache_set( $key, $results, 'posts' );
  1365. }
  1366. if ( $results ) {
  1367. foreach ( (array) $results as $result ) {
  1368. if ( $result->post_date != '0000-00-00 00:00:00' ) {
  1369. $url = get_permalink( $result );
  1370. if ( $result->post_title ) {
  1371. /** This filter is documented in wp-includes/post-template.php */
  1372. $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
  1373. } else {
  1374. $text = $result->ID;
  1375. }
  1376. $output .= get_archives_link( $url, $text, $r['format'], $r['before'

Large files files are truncated, but you can click here to view the full file