PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

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

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