PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 2982 lines | 1661 code | 216 blank | 1105 comment | 243 complexity | 9504d637c151893fdd5bd263ade7f493 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
  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. * @uses locate_template()
  20. *
  21. * @param string $name The name of the specialised header.
  22. */
  23. function get_header( $name = null ) {
  24. /**
  25. * Fires before the header template file is loaded.
  26. *
  27. * The hook allows a specific header template file to be used in place of the
  28. * default header template file. If your file is called header-new.php,
  29. * you would specify the filename in the hook as get_header( 'new' ).
  30. *
  31. * @since 2.1.0
  32. * @since 2.8.0 $name parameter added.
  33. *
  34. * @param string $name Name of the specific header file to use.
  35. */
  36. do_action( 'get_header', $name );
  37. $templates = array();
  38. $name = (string) $name;
  39. if ( '' !== $name )
  40. $templates[] = "header-{$name}.php";
  41. $templates[] = 'header.php';
  42. // Backward compat code will be removed in a future release
  43. if ('' == locate_template($templates, true))
  44. load_template( ABSPATH . WPINC . '/theme-compat/header.php');
  45. }
  46. /**
  47. * Load footer template.
  48. *
  49. * Includes the footer template for a theme or if a name is specified then a
  50. * specialised footer will be included.
  51. *
  52. * For the parameter, if the file is called "footer-special.php" then specify
  53. * "special".
  54. *
  55. * @since 1.5.0
  56. *
  57. * @uses locate_template()
  58. *
  59. * @param string $name The name of the specialised footer.
  60. */
  61. function get_footer( $name = null ) {
  62. /**
  63. * Fires before the footer template file is loaded.
  64. *
  65. * The hook allows a specific footer template file to be used in place of the
  66. * default footer template file. If your file is called footer-new.php,
  67. * you would specify the filename in the hook as get_footer( 'new' ).
  68. *
  69. * @since 2.1.0
  70. * @since 2.8.0 $name parameter added.
  71. *
  72. * @param string $name Name of the specific footer file to use.
  73. */
  74. do_action( 'get_footer', $name );
  75. $templates = array();
  76. $name = (string) $name;
  77. if ( '' !== $name )
  78. $templates[] = "footer-{$name}.php";
  79. $templates[] = 'footer.php';
  80. // Backward compat code will be removed in a future release
  81. if ('' == locate_template($templates, true))
  82. load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
  83. }
  84. /**
  85. * Load sidebar template.
  86. *
  87. * Includes the sidebar template for a theme or if a name is specified then a
  88. * specialised sidebar will be included.
  89. *
  90. * For the parameter, if the file is called "sidebar-special.php" then specify
  91. * "special".
  92. *
  93. * @since 1.5.0
  94. *
  95. * @uses locate_template()
  96. *
  97. * @param string $name The name of the specialised sidebar.
  98. */
  99. function get_sidebar( $name = null ) {
  100. /**
  101. * Fires before the sidebar template file is loaded.
  102. *
  103. * The hook allows a specific sidebar template file to be used in place of the
  104. * default sidebar template file. If your file is called sidebar-new.php,
  105. * you would specify the filename in the hook as get_sidebar( 'new' ).
  106. *
  107. * @since 2.2.0
  108. * @since 2.8.0 $name parameter added.
  109. *
  110. * @param string $name Name of the specific sidebar file to use.
  111. */
  112. do_action( 'get_sidebar', $name );
  113. $templates = array();
  114. $name = (string) $name;
  115. if ( '' !== $name )
  116. $templates[] = "sidebar-{$name}.php";
  117. $templates[] = 'sidebar.php';
  118. // Backward compat code will be removed in a future release
  119. if ('' == locate_template($templates, true))
  120. load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
  121. }
  122. /**
  123. * Load a template part into a template
  124. *
  125. * Makes it easy for a theme to reuse sections of code in a easy to overload way
  126. * for child themes.
  127. *
  128. * Includes the named template part for a theme or if a name is specified then a
  129. * specialised part will be included. If the theme contains no {slug}.php file
  130. * then no template will be included.
  131. *
  132. * The template is included using require, not require_once, so you may include the
  133. * same template part multiple times.
  134. *
  135. * For the $name parameter, if the file is called "{slug}-special.php" then specify
  136. * "special".
  137. *
  138. * @since 3.0.0
  139. *
  140. * @uses locate_template()
  141. *
  142. * @param string $slug The slug name for the generic template.
  143. * @param string $name The name of the specialised template.
  144. */
  145. function get_template_part( $slug, $name = null ) {
  146. /**
  147. * Fires before the specified template part file is loaded.
  148. *
  149. * The dynamic portion of the hook name, $slug, refers to the slug name
  150. * for the generic template part.
  151. *
  152. * @since 3.0.0
  153. *
  154. * @param string $slug The slug name for the generic template.
  155. * @param string $name The name of the specialized template.
  156. */
  157. do_action( "get_template_part_{$slug}", $slug, $name );
  158. $templates = array();
  159. $name = (string) $name;
  160. if ( '' !== $name )
  161. $templates[] = "{$slug}-{$name}.php";
  162. $templates[] = "{$slug}.php";
  163. locate_template($templates, true, false);
  164. }
  165. /**
  166. * Display search form.
  167. *
  168. * Will first attempt to locate the searchform.php file in either the child or
  169. * the parent, then load it. If it doesn't exist, then the default search form
  170. * will be displayed. The default search form is HTML, which will be displayed.
  171. * There is a filter applied to the search form HTML in order to edit or replace
  172. * it. The filter is 'get_search_form'.
  173. *
  174. * This function is primarily used by themes which want to hardcode the search
  175. * form into the sidebar and also by the search widget in WordPress.
  176. *
  177. * There is also an action that is called whenever the function is run called,
  178. * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
  179. * search relies on or various formatting that applies to the beginning of the
  180. * search. To give a few examples of what it can be used for.
  181. *
  182. * @since 2.7.0
  183. *
  184. * @param boolean $echo Default to echo and not return the form.
  185. * @return string|null String when retrieving, null when displaying or if searchform.php exists.
  186. */
  187. function get_search_form( $echo = true ) {
  188. /**
  189. * Fires before the search form is retrieved, at the start of get_search_form().
  190. *
  191. * @since 2.7.0 as 'get_search_form' action.
  192. * @since 3.6.0
  193. *
  194. * @link https://core.trac.wordpress.org/ticket/19321
  195. */
  196. do_action( 'pre_get_search_form' );
  197. $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
  198. /**
  199. * Filter the HTML format of the search form.
  200. *
  201. * @since 3.6.0
  202. *
  203. * @param string $format The type of markup to use in the search form.
  204. * Accepts 'html5', 'xhtml'.
  205. */
  206. $format = apply_filters( 'search_form_format', $format );
  207. $search_form_template = locate_template( 'searchform.php' );
  208. if ( '' != $search_form_template ) {
  209. ob_start();
  210. require( $search_form_template );
  211. $form = ob_get_clean();
  212. } else {
  213. if ( 'html5' == $format ) {
  214. $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
  215. <label>
  216. <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
  217. <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' ) . '" />
  218. </label>
  219. <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
  220. </form>';
  221. } else {
  222. $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
  223. <div>
  224. <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
  225. <input type="text" value="' . get_search_query() . '" name="s" id="s" />
  226. <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
  227. </div>
  228. </form>';
  229. }
  230. }
  231. /**
  232. * Filter the HTML output of the search form.
  233. *
  234. * @since 2.7.0
  235. *
  236. * @param string $form The search form HTML output.
  237. */
  238. $result = apply_filters( 'get_search_form', $form );
  239. if ( null === $result )
  240. $result = $form;
  241. if ( $echo )
  242. echo $result;
  243. else
  244. return $result;
  245. }
  246. /**
  247. * Display the Log In/Out link.
  248. *
  249. * Displays a link, which allows users to navigate to the Log In page to log in
  250. * or log out depending on whether they are currently logged in.
  251. *
  252. * @since 1.5.0
  253. *
  254. * @param string $redirect Optional path to redirect to on login/logout.
  255. * @param boolean $echo Default to echo and not return the link.
  256. * @return string|null String when retrieving, null when displaying.
  257. */
  258. function wp_loginout($redirect = '', $echo = true) {
  259. if ( ! is_user_logged_in() )
  260. $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
  261. else
  262. $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
  263. if ( $echo ) {
  264. /**
  265. * Filter the HTML output for the Log In/Log Out link.
  266. *
  267. * @since 1.5.0
  268. *
  269. * @param string $link The HTML link content.
  270. */
  271. echo apply_filters( 'loginout', $link );
  272. } else {
  273. /** This filter is documented in wp-includes/general-template.php */
  274. return apply_filters( 'loginout', $link );
  275. }
  276. }
  277. /**
  278. * Returns the Log Out URL.
  279. *
  280. * Returns the URL that allows the user to log out of the site.
  281. *
  282. * @since 2.7.0
  283. *
  284. * @uses wp_nonce_url() To protect against CSRF.
  285. * @uses site_url() To generate the log out URL.
  286. *
  287. * @param string $redirect Path to redirect to on logout.
  288. * @return string A log out URL.
  289. */
  290. function wp_logout_url($redirect = '') {
  291. $args = array( 'action' => 'logout' );
  292. if ( !empty($redirect) ) {
  293. $args['redirect_to'] = urlencode( $redirect );
  294. }
  295. $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
  296. $logout_url = wp_nonce_url( $logout_url, 'log-out' );
  297. /**
  298. * Filter the logout URL.
  299. *
  300. * @since 2.8.0
  301. *
  302. * @param string $logout_url The Log Out URL.
  303. * @param string $redirect Path to redirect to on logout.
  304. */
  305. return apply_filters( 'logout_url', $logout_url, $redirect );
  306. }
  307. /**
  308. * Returns the Log In URL.
  309. *
  310. * Returns the URL that allows the user to log in to the site.
  311. *
  312. * @since 2.7.0
  313. *
  314. * @uses site_url() To generate the log in URL.
  315. *
  316. * @param string $redirect Path to redirect to on login.
  317. * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
  318. * @return string A log in URL.
  319. */
  320. function wp_login_url($redirect = '', $force_reauth = false) {
  321. $login_url = site_url('wp-login.php', 'login');
  322. if ( !empty($redirect) )
  323. $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
  324. if ( $force_reauth )
  325. $login_url = add_query_arg('reauth', '1', $login_url);
  326. /**
  327. * Filter the login URL.
  328. *
  329. * @since 2.8.0
  330. *
  331. * @param string $login_url The login URL.
  332. * @param string $redirect The path to redirect to on login, if supplied.
  333. */
  334. return apply_filters( 'login_url', $login_url, $redirect );
  335. }
  336. /**
  337. * Returns the user registration URL.
  338. *
  339. * Returns the URL that allows the user to register on the site.
  340. *
  341. * @since 3.6.0
  342. *
  343. * @uses site_url() To generate the registration URL.
  344. *
  345. * @return string User registration URL.
  346. */
  347. function wp_registration_url() {
  348. /**
  349. * Filter the user registration URL.
  350. *
  351. * @since 3.6.0
  352. *
  353. * @param string $register The user registration URL.
  354. */
  355. return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
  356. }
  357. /**
  358. * Provides a simple login form for use anywhere within WordPress. By default, it echoes
  359. * the HTML immediately. Pass array('echo'=>false) to return the string instead.
  360. *
  361. * @since 3.0.0
  362. *
  363. * @param array $args Configuration options to modify the form output.
  364. * @return string|null String when retrieving, null when displaying.
  365. */
  366. function wp_login_form( $args = array() ) {
  367. $defaults = array(
  368. 'echo' => true,
  369. 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
  370. 'form_id' => 'loginform',
  371. 'label_username' => __( 'Username' ),
  372. 'label_password' => __( 'Password' ),
  373. 'label_remember' => __( 'Remember Me' ),
  374. 'label_log_in' => __( 'Log In' ),
  375. 'id_username' => 'user_login',
  376. 'id_password' => 'user_pass',
  377. 'id_remember' => 'rememberme',
  378. 'id_submit' => 'wp-submit',
  379. 'remember' => true,
  380. 'value_username' => '',
  381. 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
  382. );
  383. /**
  384. * Filter the default login form output arguments.
  385. *
  386. * @since 3.0.0
  387. *
  388. * @see wp_login_form()
  389. *
  390. * @param array $defaults An array of default login form arguments.
  391. */
  392. $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
  393. /**
  394. * Filter content to display at the top of the login form.
  395. *
  396. * The filter evaluates just following the opening form tag element.
  397. *
  398. * @since 3.0.0
  399. *
  400. * @param string $content Content to display. Default empty.
  401. * @param array $args Array of login form arguments.
  402. */
  403. $login_form_top = apply_filters( 'login_form_top', '', $args );
  404. /**
  405. * Filter content to display in the middle of the login form.
  406. *
  407. * The filter evaluates just following the location where the 'login-password'
  408. * field is displayed.
  409. *
  410. * @since 3.0.0
  411. *
  412. * @param string $content Content to display. Default empty.
  413. * @param array $args Array of login form arguments.
  414. */
  415. $login_form_middle = apply_filters( 'login_form_middle', '', $args );
  416. /**
  417. * Filter content to display at the bottom of the login form.
  418. *
  419. * The filter evaluates just preceding the closing form tag element.
  420. *
  421. * @since 3.0.0
  422. *
  423. * @param string $content Content to display. Default empty.
  424. * @param array $args Array of login form arguments.
  425. */
  426. $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
  427. $form = '
  428. <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
  429. ' . $login_form_top . '
  430. <p class="login-username">
  431. <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
  432. <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
  433. </p>
  434. <p class="login-password">
  435. <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
  436. <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
  437. </p>
  438. ' . $login_form_middle . '
  439. ' . ( $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>' : '' ) . '
  440. <p class="login-submit">
  441. <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
  442. <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
  443. </p>
  444. ' . $login_form_bottom . '
  445. </form>';
  446. if ( $args['echo'] )
  447. echo $form;
  448. else
  449. return $form;
  450. }
  451. /**
  452. * Returns the Lost Password URL.
  453. *
  454. * Returns the URL that allows the user to retrieve the lost password
  455. *
  456. * @since 2.8.0
  457. *
  458. * @uses site_url() To generate the lost password URL
  459. *
  460. * @param string $redirect Path to redirect to on login.
  461. * @return string Lost password URL.
  462. */
  463. function wp_lostpassword_url( $redirect = '' ) {
  464. $args = array( 'action' => 'lostpassword' );
  465. if ( !empty($redirect) ) {
  466. $args['redirect_to'] = $redirect;
  467. }
  468. $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
  469. /**
  470. * Filter the Lost Password URL.
  471. *
  472. * @since 2.8.0
  473. *
  474. * @param string $lostpassword_url The lost password page URL.
  475. * @param string $redirect The path to redirect to on login.
  476. */
  477. return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
  478. }
  479. /**
  480. * Display the Registration or Admin link.
  481. *
  482. * Display a link which allows the user to navigate to the registration page if
  483. * not logged in and registration is enabled or to the dashboard if logged in.
  484. *
  485. * @since 1.5.0
  486. *
  487. * @param string $before Text to output before the link (defaults to <li>).
  488. * @param string $after Text to output after the link (defaults to </li>).
  489. * @param boolean $echo Default to echo and not return the link.
  490. * @return string|null String when retrieving, null when displaying.
  491. */
  492. function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
  493. if ( ! is_user_logged_in() ) {
  494. if ( get_option('users_can_register') )
  495. $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
  496. else
  497. $link = '';
  498. } else {
  499. $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
  500. }
  501. /**
  502. * Filter the HTML link to the Registration or Admin page.
  503. *
  504. * Users are sent to the admin page if logged-in, or the registration page
  505. * if enabled and logged-out.
  506. *
  507. * @since 1.5.0
  508. *
  509. * @param string $link The HTML code for the link to the Registration or Admin page.
  510. */
  511. $link = apply_filters( 'register', $link );
  512. if ( $echo ) {
  513. echo $link;
  514. } else {
  515. return $link;
  516. }
  517. }
  518. /**
  519. * Theme container function for the 'wp_meta' action.
  520. *
  521. * The 'wp_meta' action can have several purposes, depending on how you use it,
  522. * but one purpose might have been to allow for theme switching.
  523. *
  524. * @since 1.5.0
  525. *
  526. * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
  527. */
  528. function wp_meta() {
  529. /**
  530. * Fires before displaying echoed content in the sidebar.
  531. *
  532. * @since 1.5.0
  533. */
  534. do_action( 'wp_meta' );
  535. }
  536. /**
  537. * Display information about the blog.
  538. *
  539. * @see get_bloginfo() For possible values for the parameter.
  540. * @since 0.71
  541. *
  542. * @param string $show What to display.
  543. */
  544. function bloginfo( $show='' ) {
  545. echo get_bloginfo( $show, 'display' );
  546. }
  547. /**
  548. * Retrieve information about the blog.
  549. *
  550. * Some show parameter values are deprecated and will be removed in future
  551. * versions. These options will trigger the _deprecated_argument() function.
  552. * The deprecated blog info options are listed in the function contents.
  553. *
  554. * The possible values for the 'show' parameter are listed below.
  555. * <ol>
  556. * <li><strong>url</strong> - Blog URI to homepage.</li>
  557. * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
  558. * <li><strong>description</strong> - Secondary title</li>
  559. * </ol>
  560. *
  561. * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
  562. * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
  563. * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
  564. * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
  565. *
  566. * @since 0.71
  567. *
  568. * @param string $show Blog info to retrieve.
  569. * @param string $filter How to filter what is retrieved.
  570. * @return string Mostly string values, might be empty.
  571. */
  572. function get_bloginfo( $show = '', $filter = 'raw' ) {
  573. switch( $show ) {
  574. case 'home' : // DEPRECATED
  575. case 'siteurl' : // DEPRECATED
  576. _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' ) );
  577. case 'url' :
  578. $output = home_url();
  579. break;
  580. case 'wpurl' :
  581. $output = site_url();
  582. break;
  583. case 'description':
  584. $output = get_option('blogdescription');
  585. break;
  586. case 'rdf_url':
  587. $output = get_feed_link('rdf');
  588. break;
  589. case 'rss_url':
  590. $output = get_feed_link('rss');
  591. break;
  592. case 'rss2_url':
  593. $output = get_feed_link('rss2');
  594. break;
  595. case 'atom_url':
  596. $output = get_feed_link('atom');
  597. break;
  598. case 'comments_atom_url':
  599. $output = get_feed_link('comments_atom');
  600. break;
  601. case 'comments_rss2_url':
  602. $output = get_feed_link('comments_rss2');
  603. break;
  604. case 'pingback_url':
  605. $output = site_url( 'xmlrpc.php' );
  606. break;
  607. case 'stylesheet_url':
  608. $output = get_stylesheet_uri();
  609. break;
  610. case 'stylesheet_directory':
  611. $output = get_stylesheet_directory_uri();
  612. break;
  613. case 'template_directory':
  614. case 'template_url':
  615. $output = get_template_directory_uri();
  616. break;
  617. case 'admin_email':
  618. $output = get_option('admin_email');
  619. break;
  620. case 'charset':
  621. $output = get_option('blog_charset');
  622. if ('' == $output) $output = 'UTF-8';
  623. break;
  624. case 'html_type' :
  625. $output = get_option('html_type');
  626. break;
  627. case 'version':
  628. global $wp_version;
  629. $output = $wp_version;
  630. break;
  631. case 'language':
  632. $output = get_locale();
  633. $output = str_replace('_', '-', $output);
  634. break;
  635. case 'text_direction':
  636. //_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()' ) );
  637. if ( function_exists( 'is_rtl' ) ) {
  638. $output = is_rtl() ? 'rtl' : 'ltr';
  639. } else {
  640. $output = 'ltr';
  641. }
  642. break;
  643. case 'name':
  644. default:
  645. $output = get_option('blogname');
  646. break;
  647. }
  648. $url = true;
  649. if (strpos($show, 'url') === false &&
  650. strpos($show, 'directory') === false &&
  651. strpos($show, 'home') === false)
  652. $url = false;
  653. if ( 'display' == $filter ) {
  654. if ( $url ) {
  655. /**
  656. * Filter the URL returned by get_bloginfo().
  657. *
  658. * @since 2.0.5
  659. *
  660. * @param mixed $output The URL returned by bloginfo().
  661. * @param mixed $show Type of information requested.
  662. */
  663. $output = apply_filters( 'bloginfo_url', $output, $show );
  664. } else {
  665. /**
  666. * Filter the site information returned by get_bloginfo().
  667. *
  668. * @since 0.71
  669. *
  670. * @param mixed $output The requested non-URL site information.
  671. * @param mixed $show Type of information requested.
  672. */
  673. $output = apply_filters( 'bloginfo', $output, $show );
  674. }
  675. }
  676. return $output;
  677. }
  678. /**
  679. * Display or retrieve page title for all areas of blog.
  680. *
  681. * By default, the page title will display the separator before the page title,
  682. * so that the blog title will be before the page title. This is not good for
  683. * title display, since the blog title shows up on most tabs and not what is
  684. * important, which is the page that the user is looking at.
  685. *
  686. * There are also SEO benefits to having the blog title after or to the 'right'
  687. * or the page title. However, it is mostly common sense to have the blog title
  688. * to the right with most browsers supporting tabs. You can achieve this by
  689. * using the seplocation parameter and setting the value to 'right'. This change
  690. * was introduced around 2.5.0, in case backwards compatibility of themes is
  691. * important.
  692. *
  693. * @since 1.0.0
  694. *
  695. * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
  696. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  697. * @param string $seplocation Optional. Direction to display title, 'right'.
  698. * @return string|null String on retrieve, null when displaying.
  699. */
  700. function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
  701. global $wp_locale;
  702. $m = get_query_var('m');
  703. $year = get_query_var('year');
  704. $monthnum = get_query_var('monthnum');
  705. $day = get_query_var('day');
  706. $search = get_query_var('s');
  707. $title = '';
  708. $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
  709. // If there is a post
  710. if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
  711. $title = single_post_title( '', false );
  712. }
  713. // If there's a post type archive
  714. if ( is_post_type_archive() ) {
  715. $post_type = get_query_var( 'post_type' );
  716. if ( is_array( $post_type ) )
  717. $post_type = reset( $post_type );
  718. $post_type_object = get_post_type_object( $post_type );
  719. if ( ! $post_type_object->has_archive )
  720. $title = post_type_archive_title( '', false );
  721. }
  722. // If there's a category or tag
  723. if ( is_category() || is_tag() ) {
  724. $title = single_term_title( '', false );
  725. }
  726. // If there's a taxonomy
  727. if ( is_tax() ) {
  728. $term = get_queried_object();
  729. if ( $term ) {
  730. $tax = get_taxonomy( $term->taxonomy );
  731. $title = single_term_title( $tax->labels->name . $t_sep, false );
  732. }
  733. }
  734. // If there's an author
  735. if ( is_author() && ! is_post_type_archive() ) {
  736. $author = get_queried_object();
  737. if ( $author )
  738. $title = $author->display_name;
  739. }
  740. // Post type archives with has_archive should override terms.
  741. if ( is_post_type_archive() && $post_type_object->has_archive )
  742. $title = post_type_archive_title( '', false );
  743. // If there's a month
  744. if ( is_archive() && !empty($m) ) {
  745. $my_year = substr($m, 0, 4);
  746. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  747. $my_day = intval(substr($m, 6, 2));
  748. $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
  749. }
  750. // If there's a year
  751. if ( is_archive() && !empty($year) ) {
  752. $title = $year;
  753. if ( !empty($monthnum) )
  754. $title .= $t_sep . $wp_locale->get_month($monthnum);
  755. if ( !empty($day) )
  756. $title .= $t_sep . zeroise($day, 2);
  757. }
  758. // If it's a search
  759. if ( is_search() ) {
  760. /* translators: 1: separator, 2: search phrase */
  761. $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
  762. }
  763. // If it's a 404 page
  764. if ( is_404() ) {
  765. $title = __('Page not found');
  766. }
  767. $prefix = '';
  768. if ( !empty($title) )
  769. $prefix = " $sep ";
  770. /**
  771. * Filter the parts of the page title.
  772. *
  773. * @since 4.0.0
  774. *
  775. * @param array $title_array Parts of the page title.
  776. */
  777. $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
  778. // Determines position of the separator and direction of the breadcrumb
  779. if ( 'right' == $seplocation ) { // sep on right, so reverse the order
  780. $title_array = array_reverse( $title_array );
  781. $title = implode( " $sep ", $title_array ) . $prefix;
  782. } else {
  783. $title = $prefix . implode( " $sep ", $title_array );
  784. }
  785. /**
  786. * Filter the text of the page title.
  787. *
  788. * @since 2.0.0
  789. *
  790. * @param string $title Page title.
  791. * @param string $sep Title separator.
  792. * @param string $seplocation Location of the separator (left or right).
  793. */
  794. $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
  795. // Send it out
  796. if ( $display )
  797. echo $title;
  798. else
  799. return $title;
  800. }
  801. /**
  802. * Display or retrieve page title for post.
  803. *
  804. * This is optimized for single.php template file for displaying the post title.
  805. *
  806. * It does not support placing the separator after the title, but by leaving the
  807. * prefix parameter empty, you can set the title separator manually. The prefix
  808. * does not automatically place a space between the prefix, so if there should
  809. * be a space, the parameter value will need to have it at the end.
  810. *
  811. * @since 0.71
  812. *
  813. * @param string $prefix Optional. What to display before the title.
  814. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  815. * @return string|null Title when retrieving, null when displaying or failure.
  816. */
  817. function single_post_title($prefix = '', $display = true) {
  818. $_post = get_queried_object();
  819. if ( !isset($_post->post_title) )
  820. return;
  821. /**
  822. * Filter the page title for a single post.
  823. *
  824. * @since 0.71
  825. *
  826. * @param string $_post_title The single post page title.
  827. * @param object $_post The current queried object as returned by get_queried_object().
  828. */
  829. $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
  830. if ( $display )
  831. echo $prefix . $title;
  832. else
  833. return $prefix . $title;
  834. }
  835. /**
  836. * Display or retrieve title for a post type archive.
  837. *
  838. * This is optimized for archive.php and archive-{$post_type}.php template files
  839. * for displaying the title of the post type.
  840. *
  841. * @since 3.1.0
  842. *
  843. * @param string $prefix Optional. What to display before the title.
  844. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  845. * @return string|null Title when retrieving, null when displaying or failure.
  846. */
  847. function post_type_archive_title( $prefix = '', $display = true ) {
  848. if ( ! is_post_type_archive() )
  849. return;
  850. $post_type = get_query_var( 'post_type' );
  851. if ( is_array( $post_type ) )
  852. $post_type = reset( $post_type );
  853. $post_type_obj = get_post_type_object( $post_type );
  854. /**
  855. * Filter the post type archive title.
  856. *
  857. * @since 3.1.0
  858. *
  859. * @param string $post_type_name Post type 'name' label.
  860. * @param string $post_type Post type.
  861. */
  862. $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
  863. if ( $display )
  864. echo $prefix . $title;
  865. else
  866. return $prefix . $title;
  867. }
  868. /**
  869. * Display or retrieve page title for category archive.
  870. *
  871. * This is useful for category template file or files, because it is optimized
  872. * for category page title and with less overhead than {@link wp_title()}.
  873. *
  874. * It does not support placing the separator after the title, but by leaving the
  875. * prefix parameter empty, you can set the title separator manually. The prefix
  876. * does not automatically place a space between the prefix, so if there should
  877. * be a space, the parameter value will need to have it at the end.
  878. *
  879. * @since 0.71
  880. *
  881. * @param string $prefix Optional. What to display before the title.
  882. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  883. * @return string|null Title when retrieving, null when displaying or failure.
  884. */
  885. function single_cat_title( $prefix = '', $display = true ) {
  886. return single_term_title( $prefix, $display );
  887. }
  888. /**
  889. * Display or retrieve page title for tag post archive.
  890. *
  891. * Useful for tag template files for displaying the tag page title. It has less
  892. * overhead than {@link wp_title()}, because of its limited implementation.
  893. *
  894. * It does not support placing the separator after the title, but by leaving the
  895. * prefix parameter empty, you can set the title separator manually. The prefix
  896. * does not automatically place a space between the prefix, so if there should
  897. * be a space, the parameter value will need to have it at the end.
  898. *
  899. * @since 2.3.0
  900. *
  901. * @param string $prefix Optional. What to display before the title.
  902. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  903. * @return string|null Title when retrieving, null when displaying or failure.
  904. */
  905. function single_tag_title( $prefix = '', $display = true ) {
  906. return single_term_title( $prefix, $display );
  907. }
  908. /**
  909. * Display or retrieve page title for taxonomy term archive.
  910. *
  911. * Useful for taxonomy term template files for displaying the taxonomy term page title.
  912. * It has less overhead than {@link wp_title()}, because of its limited implementation.
  913. *
  914. * It does not support placing the separator after the title, but by leaving the
  915. * prefix parameter empty, you can set the title separator manually. The prefix
  916. * does not automatically place a space between the prefix, so if there should
  917. * be a space, the parameter value will need to have it at the end.
  918. *
  919. * @since 3.1.0
  920. *
  921. * @param string $prefix Optional. What to display before the title.
  922. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  923. * @return string|null Title when retrieving, null when displaying or failure.
  924. */
  925. function single_term_title( $prefix = '', $display = true ) {
  926. $term = get_queried_object();
  927. if ( !$term )
  928. return;
  929. if ( is_category() ) {
  930. /**
  931. * Filter the category archive page title.
  932. *
  933. * @since 2.0.10
  934. *
  935. * @param string $term_name Category name for archive being displayed.
  936. */
  937. $term_name = apply_filters( 'single_cat_title', $term->name );
  938. } elseif ( is_tag() ) {
  939. /**
  940. * Filter the tag archive page title.
  941. *
  942. * @since 2.3.0
  943. *
  944. * @param string $term_name Tag name for archive being displayed.
  945. */
  946. $term_name = apply_filters( 'single_tag_title', $term->name );
  947. } elseif ( is_tax() ) {
  948. /**
  949. * Filter the custom taxonomy archive page title.
  950. *
  951. * @since 3.1.0
  952. *
  953. * @param string $term_name Term name for archive being displayed.
  954. */
  955. $term_name = apply_filters( 'single_term_title', $term->name );
  956. } else {
  957. return;
  958. }
  959. if ( empty( $term_name ) )
  960. return;
  961. if ( $display )
  962. echo $prefix . $term_name;
  963. else
  964. return $prefix . $term_name;
  965. }
  966. /**
  967. * Display or retrieve page title for post archive based on date.
  968. *
  969. * Useful for when the template only needs to display the month and year, if
  970. * either are available. Optimized for just this purpose, so if it is all that
  971. * is needed, should be better than {@link wp_title()}.
  972. *
  973. * It does not support placing the separator after the title, but by leaving the
  974. * prefix parameter empty, you can set the title separator manually. The prefix
  975. * does not automatically place a space between the prefix, so if there should
  976. * be a space, the parameter value will need to have it at the end.
  977. *
  978. * @since 0.71
  979. *
  980. * @param string $prefix Optional. What to display before the title.
  981. * @param bool $display Optional, default is true. Whether to display or retrieve title.
  982. * @return string|null Title when retrieving, null when displaying or failure.
  983. */
  984. function single_month_title($prefix = '', $display = true ) {
  985. global $wp_locale;
  986. $m = get_query_var('m');
  987. $year = get_query_var('year');
  988. $monthnum = get_query_var('monthnum');
  989. if ( !empty($monthnum) && !empty($year) ) {
  990. $my_year = $year;
  991. $my_month = $wp_locale->get_month($monthnum);
  992. } elseif ( !empty($m) ) {
  993. $my_year = substr($m, 0, 4);
  994. $my_month = $wp_locale->get_month(substr($m, 4, 2));
  995. }
  996. if ( empty($my_month) )
  997. return false;
  998. $result = $prefix . $my_month . $prefix . $my_year;
  999. if ( !$display )
  1000. return $result;
  1001. echo $result;
  1002. }
  1003. /**
  1004. * Retrieve archive link content based on predefined or custom code.
  1005. *
  1006. * The format can be one of four styles. The 'link' for head element, 'option'
  1007. * for use in the select element, 'html' for use in list (either ol or ul HTML
  1008. * elements). Custom content is also supported using the before and after
  1009. * parameters.
  1010. *
  1011. * The 'link' format uses the link HTML element with the <em>archives</em>
  1012. * relationship. The before and after parameters are not used. The text
  1013. * parameter is used to describe the link.
  1014. *
  1015. * The 'option' format uses the option HTML element for use in select element.
  1016. * The value is the url parameter and the before and after parameters are used
  1017. * between the text description.
  1018. *
  1019. * The 'html' format, which is the default, uses the li HTML element for use in
  1020. * the list HTML elements. The before parameter is before the link and the after
  1021. * parameter is after the closing link.
  1022. *
  1023. * The custom format uses the before parameter before the link ('a' HTML
  1024. * element) and the after parameter after the closing link tag. If the above
  1025. * three values for the format are not used, then custom format is assumed.
  1026. *
  1027. * @since 1.0.0
  1028. *
  1029. * @param string $url URL to archive.
  1030. * @param string $text Archive text description.
  1031. * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
  1032. * @param string $before Optional.
  1033. * @param string $after Optional.
  1034. * @return string HTML link content for archive.
  1035. */
  1036. function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
  1037. $text = wptexturize($text);
  1038. $url = esc_url($url);
  1039. if ('link' == $format)
  1040. $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
  1041. elseif ('option' == $format)
  1042. $link_html = "\t<option value='$url'>$before $text $after</option>\n";
  1043. elseif ('html' == $format)
  1044. $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
  1045. else // custom
  1046. $link_html = "\t$before<a href='$url'>$text</a>$after\n";
  1047. /**
  1048. * Filter the archive link content.
  1049. *
  1050. * @since 2.6.0
  1051. *
  1052. * @param string $link_html The archive HTML link content.
  1053. */
  1054. $link_html = apply_filters( 'get_archives_link', $link_html );
  1055. return $link_html;
  1056. }
  1057. /**
  1058. * Display archive links based on type and format.
  1059. *
  1060. * @since 1.2.0
  1061. *
  1062. * @see get_archives_link()
  1063. *
  1064. * @param string|array $args {
  1065. * Default archive links arguments. Optional.
  1066. *
  1067. * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
  1068. * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
  1069. * display the same archive link list as well as post titles instead
  1070. * of displaying dates. The difference between the two is that 'alpha'
  1071. * will order by post title and 'postbypost' will order by post date.
  1072. * Default 'monthly'.
  1073. * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
  1074. * @type string $format Format each link should take using the $before and $after args.
  1075. * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
  1076. * (`<li>` tag), or a custom format, which generates a link anchor
  1077. * with $before preceding and $after succeeding. Default 'html'.
  1078. * @type string $before Markup to prepend to the beginning of each link. Default empty.
  1079. * @type string $after Markup to append to the end of each link. Default empty.
  1080. * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
  1081. * @type bool $echo Whether to echo or return the links list. Default 1|true to echo.
  1082. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
  1083. * Default 'DESC'.
  1084. * }
  1085. * @return string|null String when retrieving, null when displaying.
  1086. */
  1087. function wp_get_archives( $args = '' ) {
  1088. global $wpdb, $wp_locale;
  1089. $defaults = array(
  1090. 'type' => 'monthly', 'limit' => '',
  1091. 'format' => 'html', 'before' => '',
  1092. 'after' => '', 'show_post_count' => false,
  1093. 'echo' => 1, 'order' => 'DESC',
  1094. );
  1095. $r = wp_parse_args( $args, $defaults );
  1096. if ( '' == $r['type'] ) {
  1097. $r['type'] = 'monthly';
  1098. }
  1099. if ( ! empty( $r['limit'] ) ) {
  1100. $r['limit'] = absint( $r['limit'] );
  1101. $r['limit'] = ' LIMIT ' . $r['limit'];
  1102. }
  1103. $order = strtoupper( $r['order'] );
  1104. if ( $order !== 'ASC' ) {
  1105. $order = 'DESC';
  1106. }
  1107. // this is what will separate dates on weekly archive links
  1108. $archive_week_separator = '&#8211;';
  1109. // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
  1110. $archive_date_format_over_ride = 0;
  1111. // options for daily archive (only if you over-ride the general date format)
  1112. $archive_day_date_format = 'Y/m/d';
  1113. // options for weekly archive (only if you over-ride the general date format)
  1114. $archive_week_start_date_format = 'Y/m/d';
  1115. $archive_week_end_date_format = 'Y/m/d';
  1116. if ( ! $archive_date_format_over_ride ) {
  1117. $archive_day_date_format = get_option( 'date_format' );
  1118. $archive_week_start_date_format = get_option( 'date_format' );
  1119. $archive_week_end_date_format = get_option( 'date_format' );
  1120. }
  1121. /**
  1122. * Filter the SQL WHERE clause for retrieving archives.
  1123. *
  1124. * @since 2.2.0
  1125. *
  1126. * @param string $sql_where Portion of SQL query containing the WHERE clause.
  1127. * @param array $r An array of default arguments.
  1128. */
  1129. $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
  1130. /**
  1131. * Filter the SQL JOIN clause for retrieving archives.
  1132. *
  1133. * @since 2.2.0
  1134. *
  1135. * @param string $sql_join Portion of SQL query containing JOIN clause.
  1136. * @param array $r An array of default arguments.
  1137. */
  1138. $join = apply_filters( 'getarchives_join', '', $r );
  1139. $output = '';
  1140. $last_changed = wp_cache_get( 'last_changed', 'posts' );
  1141. if ( ! $last_changed ) {
  1142. $last_changed = microtime();
  1143. wp_cache_set( 'last_changed', $last_changed, 'posts' );
  1144. }
  1145. $limit = $r['limit'];
  1146. if ( 'monthly' == $r['type'] ) {
  1147. $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";
  1148. $key = md5( $query );
  1149. $key = "wp_get_archives:$key:$last_changed";
  1150. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1151. $results = $wpdb->get_results( $query );
  1152. wp_cache_set( $key, $results, 'posts' );
  1153. }
  1154. if ( $results ) {
  1155. $after = $r['after'];
  1156. foreach ( (array) $results as $result ) {
  1157. $url = get_month_link( $result->year, $result->month );
  1158. /* translators: 1: month name, 2: 4-digit year */
  1159. $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
  1160. if ( $r['show_post_count'] ) {
  1161. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1162. }
  1163. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1164. }
  1165. }
  1166. } elseif ( 'yearly' == $r['type'] ) {
  1167. $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";
  1168. $key = md5( $query );
  1169. $key = "wp_get_archives:$key:$last_changed";
  1170. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1171. $results = $wpdb->get_results( $query );
  1172. wp_cache_set( $key, $results, 'posts' );
  1173. }
  1174. if ( $results ) {
  1175. $after = $r['after'];
  1176. foreach ( (array) $results as $result) {
  1177. $url = get_year_link( $result->year );
  1178. $text = sprintf( '%d', $result->year );
  1179. if ( $r['show_post_count'] ) {
  1180. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1181. }
  1182. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1183. }
  1184. }
  1185. } elseif ( 'daily' == $r['type'] ) {
  1186. $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";
  1187. $key = md5( $query );
  1188. $key = "wp_get_archives:$key:$last_changed";
  1189. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1190. $results = $wpdb->get_results( $query );
  1191. $cache[ $key ] = $results;
  1192. wp_cache_set( $key, $results, 'posts' );
  1193. }
  1194. if ( $results ) {
  1195. $after = $r['after'];
  1196. foreach ( (array) $results as $result ) {
  1197. $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
  1198. $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
  1199. $text = mysql2date( $archive_day_date_format, $date );
  1200. if ( $r['show_post_count'] ) {
  1201. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1202. }
  1203. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1204. }
  1205. }
  1206. } elseif ( 'weekly' == $r['type'] ) {
  1207. $week = _wp_mysql_week( '`post_date`' );
  1208. $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";
  1209. $key = md5( $query );
  1210. $key = "wp_get_archives:$key:$last_changed";
  1211. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1212. $results = $wpdb->get_results( $query );
  1213. wp_cache_set( $key, $results, 'posts' );
  1214. }
  1215. $arc_w_last = '';
  1216. if ( $results ) {
  1217. $after = $r['after'];
  1218. foreach ( (array) $results as $result ) {
  1219. if ( $result->week != $arc_w_last ) {
  1220. $arc_year = $result->yr;
  1221. $arc_w_last = $result->week;
  1222. $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
  1223. $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
  1224. $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
  1225. $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 );
  1226. $text = $arc_week_start . $archive_week_separator . $arc_week_end;
  1227. if ( $r['show_post_count'] ) {
  1228. $r['after'] = '&nbsp;(' . $result->posts . ')' . $after;
  1229. }
  1230. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1231. }
  1232. }
  1233. }
  1234. } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
  1235. $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC ';
  1236. $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
  1237. $key = md5( $query );
  1238. $key = "wp_get_archives:$key:$last_changed";
  1239. if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
  1240. $results = $wpdb->get_results( $query );
  1241. wp_cache_set( $key, $results, 'posts' );
  1242. }
  1243. if ( $results ) {
  1244. foreach ( (array) $results as $result ) {
  1245. if ( $result->post_date != '0000-00-00 00:00:00' ) {
  1246. $url = get_permalink( $result );
  1247. if ( $result->post_title ) {
  1248. /** This filter is documented in wp-includes/post-template.php */
  1249. $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
  1250. } else {
  1251. $text = $result->ID;
  1252. }
  1253. $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
  1254. }
  1255. }
  1256. }
  1257. }
  1258. if ( $r['echo'] ) {
  1259. echo $output;
  1260. } else {
  1261. return $output;
  1262. }
  1263. }
  1264. /**
  1265. * Get number of days since the start of the week.
  1266. *
  1267. * @since 1.5.0
  1268. *
  1269. * @param int $num Number of day.
  1270. * @return int Days since the start of the week.
  1271. */
  1272. function calendar_week_mod($num) {
  1273. $base = 7;
  1274. return ($num - $base*floor($num/$base));
  1275. }
  1276. /**
  1277. * Display calendar with days that have posts as links.
  1278. *
  1279. * The calendar is cached, which will be retrieved, if it exists. If there are
  1280. * no posts for the month, then it will not be displayed.
  1281. *
  1282. * @since 1.0.0
  1283. * @uses calendar_week_mod()
  1284. *
  1285. * @param bool $initial Optional, default is true. Use initial calendar names.
  1286. * @param bool $echo Optional, default is true. Set to false for return.
  1287. * @return string|null String when retrieving, null when displaying.
  1288. */
  1289. function get_calendar($initial = true, $echo = true) {
  1290. global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
  1291. $key = md5( $m . $monthnum . $year );
  1292. if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
  1293. if ( is_array($cache) && isset( $cache[ $key ] ) ) {
  1294. if ( $echo ) {
  1295. /** This filter is documented in wp-includes/general-template.php */
  1296. echo apply_filters( 'get_calendar', $cache[$key] );
  1297. return;
  1298. } else {
  1299. /** This filter is documented in wp-includes/general-template.php */
  1300. return apply_filters( 'get_calendar', $cache[$key] );
  1301. }
  1302. }
  1303. }
  1304. if ( !is_array($cache) )
  1305. $cache = array();
  1306. // Quick check. If we have no posts at all, abort!
  1307. if ( !$posts ) {
  1308. $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
  1309. if ( !$gotsome ) {
  1310. $cache[ $key ] = '';
  1311. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1312. return;
  1313. }
  1314. }
  1315. if ( isset($_GET['w']) )
  1316. $w = ''.intval($_GET['w']);
  1317. // week_begins = 0 stands for Sunday
  1318. $week_begins = intval(get_option('start_of_week'));
  1319. // Let's figure out when we are
  1320. if ( !empty($monthnum) && !empty($year) ) {
  1321. $thismonth = ''.zeroise(intval($monthnum), 2);
  1322. $thisyear = ''.intval($year);
  1323. } elseif ( !empty($w) ) {
  1324. // We need to get the month from MySQL
  1325. $thisyear = ''.intval(substr($m, 0, 4));
  1326. $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
  1327. $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
  1328. } elseif ( !empty($m) ) {
  1329. $thisyear = ''.intval(substr($m, 0, 4));
  1330. if ( strlen($m) < 6 )
  1331. $thismonth = '01';
  1332. else
  1333. $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
  1334. } else {
  1335. $thisyear = gmdate('Y', current_time('timestamp'));
  1336. $thismonth = gmdate('m', current_time('timestamp'));
  1337. }
  1338. $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
  1339. $last_day = date('t', $unixmonth);
  1340. // Get the next and previous month and year with at least one post
  1341. $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  1342. FROM $wpdb->posts
  1343. WHERE post_date < '$thisyear-$thismonth-01'
  1344. AND post_type = 'post' AND post_status = 'publish'
  1345. ORDER BY post_date DESC
  1346. LIMIT 1");
  1347. $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
  1348. FROM $wpdb->posts
  1349. WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
  1350. AND post_type = 'post' AND post_status = 'publish'
  1351. ORDER BY post_date ASC
  1352. LIMIT 1");
  1353. /* translators: Calendar caption: 1: month name, 2: 4-digit year */
  1354. $calendar_caption = _x('%1$s %2$s', 'calendar caption');
  1355. $calendar_output = '<table id="wp-calendar">
  1356. <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
  1357. <thead>
  1358. <tr>';
  1359. $myweek = array();
  1360. for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
  1361. $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
  1362. }
  1363. foreach ( $myweek as $wd ) {
  1364. $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
  1365. $wd = esc_attr($wd);
  1366. $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
  1367. }
  1368. $calendar_output .= '
  1369. </tr>
  1370. </thead>
  1371. <tfoot>
  1372. <tr>';
  1373. if ( $previous ) {
  1374. $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
  1375. } else {
  1376. $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
  1377. }
  1378. $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
  1379. if ( $next ) {
  1380. $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
  1381. } else {
  1382. $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
  1383. }
  1384. $calendar_output .= '
  1385. </tr>
  1386. </tfoot>
  1387. <tbody>
  1388. <tr>';
  1389. // Get days with posts
  1390. $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
  1391. FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
  1392. AND post_type = 'post' AND post_status = 'publish'
  1393. AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
  1394. if ( $dayswithposts ) {
  1395. foreach ( (array) $dayswithposts as $daywith ) {
  1396. $daywithpost[] = $daywith[0];
  1397. }
  1398. } else {
  1399. $daywithpost = array();
  1400. }
  1401. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
  1402. $ak_title_separator = "\n";
  1403. else
  1404. $ak_title_separator = ', ';
  1405. $ak_titles_for_day = array();
  1406. $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
  1407. ."FROM $wpdb->posts "
  1408. ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
  1409. ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
  1410. ."AND post_type = 'post' AND post_status = 'publish'"
  1411. );
  1412. if ( $ak_post_titles ) {
  1413. foreach ( (array) $ak_post_titles as $ak_post_title ) {
  1414. /** This filter is documented in wp-includes/post-template.php */
  1415. $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
  1416. if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
  1417. $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
  1418. if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
  1419. $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
  1420. else
  1421. $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
  1422. }
  1423. }
  1424. // See how much we should pad in the beginning
  1425. $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
  1426. if ( 0 != $pad )
  1427. $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
  1428. $daysinmonth = intval(date('t', $unixmonth));
  1429. for ( $day = 1; $day <= $daysinmonth; ++$day ) {
  1430. if ( isset($newrow) && $newrow )
  1431. $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
  1432. $newrow = false;
  1433. if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
  1434. $calendar_output .= '<td id="today">';
  1435. else
  1436. $calendar_output .= '<td>';
  1437. if ( in_array($day, $daywithpost) ) // any posts today?
  1438. $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
  1439. else
  1440. $calendar_output .= $day;
  1441. $calendar_output .= '</td>';
  1442. if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
  1443. $newrow = true;
  1444. }
  1445. $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
  1446. if ( $pad != 0 && $pad != 7 )
  1447. $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
  1448. $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
  1449. $cache[ $key ] = $calendar_output;
  1450. wp_cache_set( 'get_calendar', $cache, 'calendar' );
  1451. if ( $echo ) {
  1452. /**
  1453. * Filter the HTML calendar output.
  1454. *
  1455. * @since 3.0.0
  1456. *
  1457. * @param string $calendar_output HTML output of the calendar.
  1458. */
  1459. echo apply_filters( 'get_calendar', $calendar_output );
  1460. } else {
  1461. /** This filter is documented in wp-includes/general-template.php */
  1462. return apply_filters( 'get_calendar', $calendar_output );
  1463. }
  1464. }
  1465. /**
  1466. * Purge the cached results of get_calendar.
  1467. *
  1468. * @see get_calendar
  1469. * @since 2.1.0
  1470. */
  1471. function delete_get_calendar_cache() {
  1472. wp_cache_delete( 'get_calendar', 'calendar' );
  1473. }
  1474. add_action( 'save_post', 'delete_get_calendar_cache' );
  1475. add_action( 'delete_post', 'delete_get_calendar_cache' );
  1476. add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
  1477. add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
  1478. /**
  1479. * Display all of the allowed tags in HTML format with attributes.
  1480. *
  1481. * This is useful for displaying in the comment area, which elements and
  1482. * attributes are supported. As well as any plugins which want to display it.
  1483. *
  1484. * @since 1.0.1
  1485. * @uses $allowedtags
  1486. *
  1487. * @return string HTML allowed tags entity encoded.
  1488. */
  1489. function allowed_tags() {
  1490. global $allowedtags;
  1491. $allowed = '';
  1492. foreach ( (array) $allowedtags as $tag => $attributes ) {
  1493. $allowed .= '<'.$tag;
  1494. if ( 0 < count($attributes) ) {
  1495. foreach ( $attributes as $attribute => $limits ) {
  1496. $allowed .= ' '.$attribute.'=""';
  1497. }
  1498. }
  1499. $allowed .= '> ';
  1500. }
  1501. return htmlentities($allowed);
  1502. }
  1503. /***** Date/Time tags *****/
  1504. /**
  1505. * Outputs the date in iso8601 format for xml files.
  1506. *
  1507. * @since 1.0.0
  1508. */
  1509. function the_date_xml() {
  1510. echo mysql2date( 'Y-m-d', get_post()->post_date, false );
  1511. }
  1512. /**
  1513. * Display or Retrieve the date the current post was written (once per date)
  1514. *
  1515. * Will only output the date if the current post's date is different from the
  1516. * previous one output.
  1517. *
  1518. * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
  1519. * function is called several times for each post.
  1520. *
  1521. * HTML output can be filtered with 'the_date'.
  1522. * Date string output can be filtered with 'get_the_date'.
  1523. *
  1524. * @since 0.71
  1525. *
  1526. * @uses get_the_date()
  1527. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1528. * @param string $before Optional. Output before the date.
  1529. * @param string $after Optional. Output after the date.
  1530. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1531. * @return string|null Null if displaying, string if retrieving.
  1532. */
  1533. function the_date( $d = '', $before = '', $after = '', $echo = true ) {
  1534. global $currentday, $previousday;
  1535. if ( $currentday != $previousday ) {
  1536. $the_date = $before . get_the_date( $d ) . $after;
  1537. $previousday = $currentday;
  1538. /**
  1539. * Filter the date a post was published for display.
  1540. *
  1541. * @since 0.71
  1542. *
  1543. * @param string $the_date The formatted date string.
  1544. * @param string $d PHP date format. Defaults to 'date_format' option
  1545. * if not specified.
  1546. * @param string $before HTML output before the date.
  1547. * @param string $after HTML output after the date.
  1548. */
  1549. $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
  1550. if ( $echo )
  1551. echo $the_date;
  1552. else
  1553. return $the_date;
  1554. }
  1555. return null;
  1556. }
  1557. /**
  1558. * Retrieve the date on which the post was written.
  1559. *
  1560. * Unlike the_date() this function will always return the date.
  1561. * Modify output with 'get_the_date' filter.
  1562. *
  1563. * @since 3.0.0
  1564. *
  1565. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1566. * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  1567. * @return string|bool Date the current post was written. False on failure.
  1568. */
  1569. function get_the_date( $d = '', $post = null ) {
  1570. $post = get_post( $post );
  1571. if ( ! $post ) {
  1572. return false;
  1573. }
  1574. if ( '' == $d ) {
  1575. $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
  1576. } else {
  1577. $the_date = mysql2date( $d, $post->post_date );
  1578. }
  1579. /**
  1580. * Filter the date a post was published.
  1581. *
  1582. * @since 3.0.0
  1583. *
  1584. * @param string $the_date The formatted date.
  1585. * @param string $d PHP date format. Defaults to 'date_format' option
  1586. * if not specified.
  1587. * @param int|WP_Post $post The post object or ID.
  1588. */
  1589. return apply_filters( 'get_the_date', $the_date, $d, $post );
  1590. }
  1591. /**
  1592. * Display the date on which the post was last modified.
  1593. *
  1594. * @since 2.1.0
  1595. *
  1596. * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
  1597. * @param string $before Optional. Output before the date.
  1598. * @param string $after Optional. Output after the date.
  1599. * @param bool $echo Optional, default is display. Whether to echo the date or return it.
  1600. * @return string|null Null if displaying, string if retrieving.
  1601. */
  1602. function the_modified_date($d = '', $before='', $after='', $echo = true) {
  1603. $the_modified_date = $before . get_the_modified_date($d) . $after;
  1604. /**
  1605. * Filter the date a post was last modified for display.
  1606. *
  1607. * @since 2.1.0
  1608. *
  1609. * @param string $the_modified_date The last modified date.
  1610. * @param string $d PHP date format. Defaults to 'date_format' option
  1611. * if not specified.
  1612. * @param string $before HTML output before the date.
  1613. * @param string $after HTML output after the date.
  1614. */
  1615. $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
  1616. if ( $echo )
  1617. echo $the_modified_date;
  1618. else
  1619. return $the_modified_date;
  1620. }
  1621. /**
  1622. * Retrieve the date on which the post was last modified.
  1623. *
  1624. * @since 2.1.0
  1625. *
  1626. * @param string $d Optional. PHP date format. Defaults to the "date_format" option
  1627. * @return string
  1628. */
  1629. function get_the_modified_date($d = '') {
  1630. if ( '' == $d )
  1631. $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
  1632. else
  1633. $the_time = get_post_modified_time($d, null, null, true);
  1634. /**
  1635. * Filter the date a post was last modified.
  1636. *
  1637. * @since 2.1.0
  1638. *
  1639. * @param string $the_time The formatted date.
  1640. * @param string $d PHP date format. Defaults to value specified in
  1641. * 'date_format' option.
  1642. */
  1643. return apply_filters( 'get_the_modified_date', $the_time, $d );
  1644. }
  1645. /**
  1646. * Display the time at which the post was written.
  1647. *
  1648. * @since 0.71
  1649. *
  1650. * @param string $d Either 'G', 'U', or php date format.
  1651. */
  1652. function the_time( $d = '' ) {
  1653. /**
  1654. * Filter the time a post was written for display.
  1655. *
  1656. * @since 0.71
  1657. *
  1658. * @param string $get_the_time The formatted time.
  1659. * @param string $d The time format. Accepts 'G', 'U',
  1660. * or php date format.
  1661. */
  1662. echo apply_filters( 'the_time', get_the_time( $d ), $d );
  1663. }
  1664. /**
  1665. * Retrieve the time at which the post was written.
  1666. *
  1667. * @since 1.5.0
  1668. *
  1669. * @param string $d Optional. Format to use for retrieving the time the post
  1670. * was written. Either 'G', 'U', or php date format defaults
  1671. * to the value specified in the time_format option. Default empty.
  1672. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
  1673. * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
  1674. */
  1675. function get_the_time( $d = '', $post = null ) {
  1676. $post = get_post($post);
  1677. if ( ! $post ) {
  1678. return false;
  1679. }
  1680. if ( '' == $d )
  1681. $the_time = get_post_time(get_option('time_format'), false, $post, true);
  1682. else
  1683. $the_time = get_post_time($d, false, $post, true);
  1684. /**
  1685. * Filter the time a post was written.
  1686. *
  1687. * @since 1.5.0
  1688. *
  1689. * @param string $the_time The formatted time.
  1690. * @param string $d Format to use for retrieving the time the post was written.
  1691. * Accepts 'G', 'U', or php date format value specified
  1692. * in 'time_format' option. Default empty.
  1693. * @param int|WP_Post $post WP_Post object or ID.
  1694. */
  1695. return apply_filters( 'get_the_time', $the_time, $d, $post );
  1696. }
  1697. /**
  1698. * Retrieve the time at which the post was written.
  1699. *
  1700. * @since 2.0.0
  1701. *
  1702. * @param string $d Optional. Format to use for retrieving the time the post
  1703. * was written. Either 'G', 'U', or php date format. Default 'U'.
  1704. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
  1705. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
  1706. * @param bool $translate Whether to translate the time string. Default false.
  1707. * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
  1708. */
  1709. function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  1710. $post = get_post($post);
  1711. if ( ! $post ) {
  1712. return false;
  1713. }
  1714. if ( $gmt )
  1715. $time = $post->post_date_gmt;
  1716. else
  1717. $time = $post->post_date;
  1718. $time = mysql2date($d, $time, $translate);
  1719. /**
  1720. * Filter the localized time a post was written.
  1721. *
  1722. * @since 2.6.0
  1723. *
  1724. * @param string $time The formatted time.
  1725. * @param string $d Format to use for retrieving the time the post was written.
  1726. * Accepts 'G', 'U', or php date format. Default 'U'.
  1727. * @param bool $gmt Whether to retrieve the GMT time. Default false.
  1728. */
  1729. return apply_filters( 'get_post_time', $time, $d, $gmt );
  1730. }
  1731. /**
  1732. * Display the time at which the post was last modified.
  1733. *
  1734. * @since 2.0.0
  1735. *
  1736. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1737. */
  1738. function the_modified_time($d = '') {
  1739. /**
  1740. * Filter the localized time a post was last modified, for display.
  1741. *
  1742. * @since 2.0.0
  1743. *
  1744. * @param string $get_the_modified_time The formatted time.
  1745. * @param string $d The time format. Accepts 'G', 'U',
  1746. * or php date format. Defaults to value
  1747. * specified in 'time_format' option.
  1748. */
  1749. echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
  1750. }
  1751. /**
  1752. * Retrieve the time at which the post was last modified.
  1753. *
  1754. * @since 2.0.0
  1755. *
  1756. * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
  1757. * @return string
  1758. */
  1759. function get_the_modified_time($d = '') {
  1760. if ( '' == $d )
  1761. $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
  1762. else
  1763. $the_time = get_post_modified_time($d, null, null, true);
  1764. /**
  1765. * Filter the localized time a post was last modified.
  1766. *
  1767. * @since 2.0.0
  1768. *
  1769. * @param string $the_time The formatted time.
  1770. * @param string $d Format to use for retrieving the time the post was
  1771. * written. Accepts 'G', 'U', or php date format. Defaults
  1772. * to value specified in 'time_format' option.
  1773. */
  1774. return apply_filters( 'get_the_modified_time', $the_time, $d );
  1775. }
  1776. /**
  1777. * Retrieve the time at which the post was last modified.
  1778. *
  1779. * @since 2.0.0
  1780. *
  1781. * @param string $d Optional. Format to use for retrieving the time the post
  1782. * was modified. Either 'G', 'U', or php date format. Default 'U'.
  1783. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
  1784. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
  1785. * @param bool $translate Whether to translate the time string. Default false.
  1786. * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
  1787. */
  1788. function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
  1789. $post = get_post($post);
  1790. if ( ! $post ) {
  1791. return false;
  1792. }
  1793. if ( $gmt )
  1794. $time = $post->post_modified_gmt;
  1795. else
  1796. $time = $post->post_modified;
  1797. $time = mysql2date($d, $time, $translate);
  1798. /**
  1799. * Filter the localized time a post was last modified.
  1800. *
  1801. * @since 2.8.0
  1802. *
  1803. * @param string $time The formatted time.
  1804. * @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'.
  1805. * @param bool $gmt Whether to return the GMT time. Default false.
  1806. */
  1807. return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
  1808. }
  1809. /**
  1810. * Display the weekday on which the post was written.
  1811. *
  1812. * @since 0.71
  1813. * @uses $wp_locale
  1814. * @uses $post
  1815. */
  1816. function the_weekday() {
  1817. global $wp_locale;
  1818. $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
  1819. /**
  1820. * Filter the weekday on which the post was written, for display.
  1821. *
  1822. * @since 0.71
  1823. *
  1824. * @param string $the_weekday
  1825. */
  1826. $the_weekday = apply_filters( 'the_weekday', $the_weekday );
  1827. echo $the_weekday;
  1828. }
  1829. /**
  1830. * Display the weekday on which the post was written.
  1831. *
  1832. * Will only output the weekday if the current post's weekday is different from
  1833. * the previous one output.
  1834. *
  1835. * @since 0.71
  1836. *
  1837. * @param string $before Optional Output before the date.
  1838. * @param string $after Optional Output after the date.
  1839. */
  1840. function the_weekday_date($before='',$after='') {
  1841. global $wp_locale, $currentday, $previousweekday;
  1842. $the_weekday_date = '';
  1843. if ( $currentday != $previousweekday ) {
  1844. $the_weekday_date .= $before;
  1845. $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
  1846. $the_weekday_date .= $after;
  1847. $previousweekday = $currentday;
  1848. }
  1849. /**
  1850. * Filter the localized date on which the post was written, for display.
  1851. *
  1852. * @since 0.71
  1853. *
  1854. * @param string $the_weekday_date
  1855. * @param string $before The HTML to output before the date.
  1856. * @param string $after The HTML to output after the date.
  1857. */
  1858. $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
  1859. echo $the_weekday_date;
  1860. }
  1861. /**
  1862. * Fire the wp_head action
  1863. *
  1864. * @since 1.2.0
  1865. */
  1866. function wp_head() {
  1867. /**
  1868. * Print scripts or data in the head tag on the front end.
  1869. *
  1870. * @since 1.5.0
  1871. */
  1872. do_action( 'wp_head' );
  1873. }
  1874. /**
  1875. * Fire the wp_footer action
  1876. *
  1877. * @since 1.5.1
  1878. */
  1879. function wp_footer() {
  1880. /**
  1881. * Print scripts or data before the closing body tag on the front end.
  1882. *
  1883. * @since 1.5.1
  1884. */
  1885. do_action( 'wp_footer' );
  1886. }
  1887. /**
  1888. * Display the links to the general feeds.
  1889. *
  1890. * @since 2.8.0
  1891. *
  1892. * @param array $args Optional arguments.
  1893. */
  1894. function feed_links( $args = array() ) {
  1895. if ( !current_theme_supports('automatic-feed-links') )
  1896. return;
  1897. $defaults = array(
  1898. /* translators: Separator between blog name and feed type in feed links */
  1899. 'separator' => _x('&raquo;', 'feed link'),
  1900. /* translators: 1: blog title, 2: separator (raquo) */
  1901. 'feedtitle' => __('%1$s %2$s Feed'),
  1902. /* translators: 1: blog title, 2: separator (raquo) */
  1903. 'comstitle' => __('%1$s %2$s Comments Feed'),
  1904. );
  1905. $args = wp_parse_args( $args, $defaults );
  1906. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
  1907. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
  1908. }
  1909. /**
  1910. * Display the links to the extra feeds such as category feeds.
  1911. *
  1912. * @since 2.8.0
  1913. *
  1914. * @param array $args Optional arguments.
  1915. */
  1916. function feed_links_extra( $args = array() ) {
  1917. $defaults = array(
  1918. /* translators: Separator between blog name and feed type in feed links */
  1919. 'separator' => _x('&raquo;', 'feed link'),
  1920. /* translators: 1: blog name, 2: separator(raquo), 3: post title */
  1921. 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
  1922. /* translators: 1: blog name, 2: separator(raquo), 3: category name */
  1923. 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
  1924. /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
  1925. 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
  1926. /* translators: 1: blog name, 2: separator(raquo), 3: author name */
  1927. 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
  1928. /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
  1929. 'searchtitle' => __('%1$s %2$s Search Results for &#8220;%3$s&#8221; Feed'),
  1930. /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
  1931. 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
  1932. );
  1933. $args = wp_parse_args( $args, $defaults );
  1934. if ( is_singular() ) {
  1935. $id = 0;
  1936. $post = get_post( $id );
  1937. if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
  1938. $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
  1939. $href = get_post_comments_feed_link( $post->ID );
  1940. }
  1941. } elseif ( is_post_type_archive() ) {
  1942. $post_type = get_query_var( 'post_type' );
  1943. if ( is_array( $post_type ) )
  1944. $post_type = reset( $post_type );
  1945. $post_type_obj = get_post_type_object( $post_type );
  1946. $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
  1947. $href = get_post_type_archive_feed_link( $post_type_obj->name );
  1948. } elseif ( is_category() ) {
  1949. $term = get_queried_object();
  1950. if ( $term ) {
  1951. $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
  1952. $href = get_category_feed_link( $term->term_id );
  1953. }
  1954. } elseif ( is_tag() ) {
  1955. $term = get_queried_object();
  1956. if ( $term ) {
  1957. $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
  1958. $href = get_tag_feed_link( $term->term_id );
  1959. }
  1960. } elseif ( is_author() ) {
  1961. $author_id = intval( get_query_var('author') );
  1962. $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
  1963. $href = get_author_feed_link( $author_id );
  1964. } elseif ( is_search() ) {
  1965. $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
  1966. $href = get_search_feed_link();
  1967. } elseif ( is_post_type_archive() ) {
  1968. $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
  1969. $post_type_obj = get_queried_object();
  1970. if ( $post_type_obj )
  1971. $href = get_post_type_archive_feed_link( $post_type_obj->name );
  1972. }
  1973. if ( isset($title) && isset($href) )
  1974. echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
  1975. }
  1976. /**
  1977. * Display the link to the Really Simple Discovery service endpoint.
  1978. *
  1979. * @link http://archipelago.phrasewise.com/rsd
  1980. * @since 2.0.0
  1981. */
  1982. function rsd_link() {
  1983. echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
  1984. }
  1985. /**
  1986. * Display the link to the Windows Live Writer manifest file.
  1987. *
  1988. * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
  1989. * @since 2.3.1
  1990. */
  1991. function wlwmanifest_link() {
  1992. echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
  1993. includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";
  1994. }
  1995. /**
  1996. * Display a noindex meta tag if required by the blog configuration.
  1997. *
  1998. * If a blog is marked as not being public then the noindex meta tag will be
  1999. * output to tell web robots not to index the page content. Add this to the wp_head action.
  2000. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
  2001. *
  2002. * @see wp_no_robots
  2003. *
  2004. * @since 2.1.0
  2005. */
  2006. function noindex() {
  2007. // If the blog is not public, tell robots to go away.
  2008. if ( '0' == get_option('blog_public') )
  2009. wp_no_robots();
  2010. }
  2011. /**
  2012. * Display a noindex meta tag.
  2013. *
  2014. * Outputs a noindex meta tag that tells web robots not to index the page content.
  2015. * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
  2016. *
  2017. * @since 3.3.0
  2018. */
  2019. function wp_no_robots() {
  2020. echo "<meta name='robots' content='noindex,follow' />\n";
  2021. }
  2022. /**
  2023. * Whether the user should have a WYSIWIG editor.
  2024. *
  2025. * Checks that the user requires a WYSIWIG editor and that the editor is
  2026. * supported in the users browser.
  2027. *
  2028. * @since 2.0.0
  2029. *
  2030. * @return bool
  2031. */
  2032. function user_can_richedit() {
  2033. global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
  2034. if ( !isset($wp_rich_edit) ) {
  2035. $wp_rich_edit = false;
  2036. if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
  2037. if ( $is_safari ) {
  2038. $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
  2039. } elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
  2040. $wp_rich_edit = true;
  2041. }
  2042. }
  2043. }
  2044. /**
  2045. * Filter whether the user can access the rich (Visual) editor.
  2046. *
  2047. * @since 2.1.0
  2048. *
  2049. * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
  2050. */
  2051. return apply_filters( 'user_can_richedit', $wp_rich_edit );
  2052. }
  2053. /**
  2054. * Find out which editor should be displayed by default.
  2055. *
  2056. * Works out which of the two editors to display as the current editor for a
  2057. * user. The 'html' setting is for the "Text" editor tab.
  2058. *
  2059. * @since 2.5.0
  2060. *
  2061. * @return string Either 'tinymce', or 'html', or 'test'
  2062. */
  2063. function wp_default_editor() {
  2064. $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
  2065. if ( wp_get_current_user() ) { // look for cookie
  2066. $ed = get_user_setting('editor', 'tinymce');
  2067. $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
  2068. }
  2069. /**
  2070. * Filter which editor should be displayed by default.
  2071. *
  2072. * @since 2.5.0
  2073. *
  2074. * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
  2075. */
  2076. return apply_filters( 'wp_default_editor', $r );
  2077. }
  2078. /**
  2079. * Renders an editor.
  2080. *
  2081. * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
  2082. * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
  2083. *
  2084. * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
  2085. * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
  2086. * On the post edit screen several actions can be used to include additional editors
  2087. * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
  2088. * See http://core.trac.wordpress.org/ticket/19173 for more information.
  2089. *
  2090. * @see wp-includes/class-wp-editor.php
  2091. * @since 3.3.0
  2092. *
  2093. * @param string $content Initial content for the editor.
  2094. * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
  2095. * @param array $settings See _WP_Editors::editor().
  2096. */
  2097. function wp_editor( $content, $editor_id, $settings = array() ) {
  2098. if ( ! class_exists( '_WP_Editors' ) )
  2099. require( ABSPATH . WPINC . '/class-wp-editor.php' );
  2100. _WP_Editors::editor($content, $editor_id, $settings);
  2101. }
  2102. /**
  2103. * Retrieve the contents of the search WordPress query variable.
  2104. *
  2105. * The search query string is passed through {@link esc_attr()}
  2106. * to ensure that it is safe for placing in an html attribute.
  2107. *
  2108. * @since 2.3.0
  2109. * @uses esc_attr()
  2110. *
  2111. * @param bool $escaped Whether the result is escaped. Default true.
  2112. * Only use when you are later escaping it. Do not use unescaped.
  2113. * @return string
  2114. */
  2115. function get_search_query( $escaped = true ) {
  2116. /**
  2117. * Filter the contents of the search query variable.
  2118. *
  2119. * @since 2.3.0
  2120. *
  2121. * @param mixed $search Contents of the search query variable.
  2122. */
  2123. $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
  2124. if ( $escaped )
  2125. $query = esc_attr( $query );
  2126. return $query;
  2127. }
  2128. /**
  2129. * Display the contents of the search query variable.
  2130. *
  2131. * The search query string is passed through {@link esc_attr()}
  2132. * to ensure that it is safe for placing in an html attribute.
  2133. *
  2134. * @uses esc_attr()
  2135. * @since 2.1.0
  2136. */
  2137. function the_search_query() {
  2138. /**
  2139. * Filter the contents of the search query variable for display.
  2140. *
  2141. * @since 2.3.0
  2142. *
  2143. * @param mixed $search Contents of the search query variable.
  2144. */
  2145. echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
  2146. }
  2147. /**
  2148. * Display the language attributes for the html tag.
  2149. *
  2150. * Builds up a set of html attributes containing the text direction and language
  2151. * information for the page.
  2152. *
  2153. * @since 2.1.0
  2154. *
  2155. * @param string $doctype The type of html document (xhtml|html).
  2156. */
  2157. function language_attributes($doctype = 'html') {
  2158. $attributes = array();
  2159. if ( function_exists( 'is_rtl' ) && is_rtl() )
  2160. $attributes[] = 'dir="rtl"';
  2161. if ( $lang = get_bloginfo('language') ) {
  2162. if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
  2163. $attributes[] = "lang=\"$lang\"";
  2164. if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
  2165. $attributes[] = "xml:lang=\"$lang\"";
  2166. }
  2167. $output = implode(' ', $attributes);
  2168. /**
  2169. * Filter the language attributes for display in the html tag.
  2170. *
  2171. * @since 2.5.0
  2172. *
  2173. * @param string $output A space-separated list of language attributes.
  2174. */
  2175. echo apply_filters( 'language_attributes', $output );
  2176. }
  2177. /**
  2178. * Retrieve paginated link for archive post pages.
  2179. *
  2180. * Technically, the function can be used to create paginated link list for any
  2181. * area. The 'base' argument is used to reference the url, which will be used to
  2182. * create the paginated links. The 'format' argument is then used for replacing
  2183. * the page number. It is however, most likely and by default, to be used on the
  2184. * archive post pages.
  2185. *
  2186. * The 'type' argument controls format of the returned value. The default is
  2187. * 'plain', which is just a string with the links separated by a newline
  2188. * character. The other possible values are either 'array' or 'list'. The
  2189. * 'array' value will return an array of the paginated link list to offer full
  2190. * control of display. The 'list' value will place all of the paginated links in
  2191. * an unordered HTML list.
  2192. *
  2193. * The 'total' argument is the total amount of pages and is an integer. The
  2194. * 'current' argument is the current page number and is also an integer.
  2195. *
  2196. * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
  2197. * and the '%_%' is required. The '%_%' will be replaced by the contents of in
  2198. * the 'format' argument. An example for the 'format' argument is "?page=%#%"
  2199. * and the '%#%' is also required. The '%#%' will be replaced with the page
  2200. * number.
  2201. *
  2202. * You can include the previous and next links in the list by setting the
  2203. * 'prev_next' argument to true, which it is by default. You can set the
  2204. * previous text, by using the 'prev_text' argument. You can set the next text
  2205. * by setting the 'next_text' argument.
  2206. *
  2207. * If the 'show_all' argument is set to true, then it will show all of the pages
  2208. * instead of a short list of the pages near the current page. By default, the
  2209. * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
  2210. * arguments. The 'end_size' argument is how many numbers on either the start
  2211. * and the end list edges, by default is 1. The 'mid_size' argument is how many
  2212. * numbers to either side of current page, but not including current page.
  2213. *
  2214. * It is possible to add query vars to the link by using the 'add_args' argument
  2215. * and see {@link add_query_arg()} for more information.
  2216. *
  2217. * The 'before_page_number' and 'after_page_number' arguments allow users to
  2218. * augment the links themselves. Typically this might be to add context to the
  2219. * numbered links so that screen reader users understand what the links are for.
  2220. * The text strings are added before and after the page number - within the
  2221. * anchor tag.
  2222. *
  2223. * @since 2.1.0
  2224. *
  2225. * @param string|array $args Optional. Override defaults.
  2226. * @return array|string String of page links or array of page links.
  2227. */
  2228. function paginate_links( $args = '' ) {
  2229. global $wp_query, $wp_rewrite;
  2230. $total = ( isset( $wp_query->max_num_pages ) ) ? $wp_query->max_num_pages : 1;
  2231. $current = ( get_query_var( 'paged' ) ) ? intval( get_query_var( 'paged' ) ) : 1;
  2232. $pagenum_link = html_entity_decode( get_pagenum_link() );
  2233. $query_args = array();
  2234. $url_parts = explode( '?', $pagenum_link );
  2235. if ( isset( $url_parts[1] ) ) {
  2236. wp_parse_str( $url_parts[1], $query_args );
  2237. }
  2238. $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  2239. $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  2240. $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  2241. $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
  2242. $defaults = array(
  2243. 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  2244. 'format' => $format, // ?page=%#% : %#% is replaced by the page number
  2245. 'total' => $total,
  2246. 'current' => $current,
  2247. 'show_all' => false,
  2248. 'prev_next' => true,
  2249. 'prev_text' => __('&laquo; Previous'),
  2250. 'next_text' => __('Next &raquo;'),
  2251. 'end_size' => 1,
  2252. 'mid_size' => 2,
  2253. 'type' => 'plain',
  2254. 'add_args' => false, // array of query args to add
  2255. 'add_fragment' => '',
  2256. 'before_page_number' => '',
  2257. 'after_page_number' => ''
  2258. );
  2259. $args = wp_parse_args( $args, $defaults );
  2260. // Who knows what else people pass in $args
  2261. $total = (int) $args['total'];
  2262. if ( $total < 2 ) {
  2263. return;
  2264. }
  2265. $current = (int) $args['current'];
  2266. $end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
  2267. if ( $end_size < 1 ) {
  2268. $end_size = 1;
  2269. }
  2270. $mid_size = (int) $args['mid_size'];
  2271. if ( $mid_size < 0 ) {
  2272. $mid_size = 2;
  2273. }
  2274. $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false;
  2275. $r = '';
  2276. $page_links = array();
  2277. $dots = false;
  2278. if ( $args['prev_next'] && $current && 1 < $current ) :
  2279. $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
  2280. $link = str_replace( '%#%', $current - 1, $link );
  2281. if ( $add_args )
  2282. $link = add_query_arg( $add_args, $link );
  2283. $link .= $args['add_fragment'];
  2284. /**
  2285. * Filter the paginated links for the given archive pages.
  2286. *
  2287. * @since 3.0.0
  2288. *
  2289. * @param string $link The paginated link URL.
  2290. */
  2291. $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
  2292. endif;
  2293. for ( $n = 1; $n <= $total; $n++ ) :
  2294. if ( $n == $current ) :
  2295. $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
  2296. $dots = true;
  2297. else :
  2298. if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
  2299. $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
  2300. $link = str_replace( '%#%', $n, $link );
  2301. if ( $add_args )
  2302. $link = add_query_arg( $add_args, $link );
  2303. $link .= $args['add_fragment'];
  2304. /** This filter is documented in wp-includes/general-template.php */
  2305. $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>";
  2306. $dots = true;
  2307. elseif ( $dots && ! $args['show_all'] ) :
  2308. $page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';
  2309. $dots = false;
  2310. endif;
  2311. endif;
  2312. endfor;
  2313. if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
  2314. $link = str_replace( '%_%', $args['format'], $args['base'] );
  2315. $link = str_replace( '%#%', $current + 1, $link );
  2316. if ( $add_args )
  2317. $link = add_query_arg( $add_args, $link );
  2318. $link .= $args['add_fragment'];
  2319. /** This filter is documented in wp-includes/general-template.php */
  2320. $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
  2321. endif;
  2322. switch ( $args['type'] ) {
  2323. case 'array' :
  2324. return $page_links;
  2325. case 'list' :
  2326. $r .= "<ul class='page-numbers'>\n\t<li>";
  2327. $r .= join("</li>\n\t<li>", $page_links);
  2328. $r .= "</li>\n</ul>\n";
  2329. break;
  2330. default :
  2331. $r = join("\n", $page_links);
  2332. break;
  2333. }
  2334. return $r;
  2335. }
  2336. /**
  2337. * Registers an admin colour scheme css file.
  2338. *
  2339. * Allows a plugin to register a new admin colour scheme. For example:
  2340. * <code>
  2341. * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
  2342. * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
  2343. * </code>
  2344. *
  2345. * @since 2.5.0
  2346. *
  2347. * @param string $key The unique key for this theme.
  2348. * @param string $name The name of the theme.
  2349. * @param string $url The url of the css file containing the colour scheme.
  2350. * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
  2351. * @param array $icons Optional An array of CSS color definitions used to color any SVG icons
  2352. */
  2353. function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
  2354. global $_wp_admin_css_colors;
  2355. if ( !isset($_wp_admin_css_colors) )
  2356. $_wp_admin_css_colors = array();
  2357. $_wp_admin_css_colors[$key] = (object) array(
  2358. 'name' => $name,
  2359. 'url' => $url,
  2360. 'colors' => $colors,
  2361. 'icon_colors' => $icons,
  2362. );
  2363. }
  2364. /**
  2365. * Registers the default Admin color schemes
  2366. *
  2367. * @since 3.0.0
  2368. */
  2369. function register_admin_color_schemes() {
  2370. $suffix = is_rtl() ? '-rtl' : '';
  2371. $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
  2372. wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
  2373. false,
  2374. array( '#222', '#333', '#0074a2', '#2ea2cc' ),
  2375. array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' )
  2376. );
  2377. // Other color schemes are not available when running out of src
  2378. if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
  2379. return;
  2380. wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
  2381. admin_url( "css/colors/light/colors$suffix.css" ),
  2382. array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
  2383. array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
  2384. );
  2385. wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
  2386. admin_url( "css/colors/blue/colors$suffix.css" ),
  2387. array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
  2388. array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
  2389. );
  2390. wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
  2391. admin_url( "css/colors/midnight/colors$suffix.css" ),
  2392. array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
  2393. array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
  2394. );
  2395. wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
  2396. admin_url( "css/colors/sunrise/colors$suffix.css" ),
  2397. array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
  2398. array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
  2399. );
  2400. wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
  2401. admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
  2402. array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
  2403. array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
  2404. );
  2405. wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
  2406. admin_url( "css/colors/ocean/colors$suffix.css" ),
  2407. array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
  2408. array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
  2409. );
  2410. wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
  2411. admin_url( "css/colors/coffee/colors$suffix.css" ),
  2412. array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
  2413. array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
  2414. );
  2415. }
  2416. /**
  2417. * Display the URL of a WordPress admin CSS file.
  2418. *
  2419. * @see WP_Styles::_css_href and its style_loader_src filter.
  2420. *
  2421. * @since 2.3.0
  2422. *
  2423. * @param string $file file relative to wp-admin/ without its ".css" extension.
  2424. */
  2425. function wp_admin_css_uri( $file = 'wp-admin' ) {
  2426. if ( defined('WP_INSTALLING') ) {
  2427. $_file = "./$file.css";
  2428. } else {
  2429. $_file = admin_url("$file.css");
  2430. }
  2431. $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
  2432. /**
  2433. * Filter the URI of a WordPress admin CSS file.
  2434. *
  2435. * @since 2.3.0
  2436. *
  2437. * @param string $_file Relative path to the file with query arguments attached.
  2438. * @param string $file Relative path to the file, minus its ".css" extension.
  2439. */
  2440. return apply_filters( 'wp_admin_css_uri', $_file, $file );
  2441. }
  2442. /**
  2443. * Enqueues or directly prints a stylesheet link to the specified CSS file.
  2444. *
  2445. * "Intelligently" decides to enqueue or to print the CSS file. If the
  2446. * 'wp_print_styles' action has *not* yet been called, the CSS file will be
  2447. * enqueued. If the wp_print_styles action *has* been called, the CSS link will
  2448. * be printed. Printing may be forced by passing true as the $force_echo
  2449. * (second) parameter.
  2450. *
  2451. * For backward compatibility with WordPress 2.3 calling method: If the $file
  2452. * (first) parameter does not correspond to a registered CSS file, we assume
  2453. * $file is a file relative to wp-admin/ without its ".css" extension. A
  2454. * stylesheet link to that generated URL is printed.
  2455. *
  2456. * @since 2.3.0
  2457. * @uses $wp_styles WordPress Styles Object
  2458. *
  2459. * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
  2460. * to wp-admin/. Defaults to 'wp-admin'.
  2461. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
  2462. */
  2463. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
  2464. global $wp_styles;
  2465. if ( !is_a($wp_styles, 'WP_Styles') )
  2466. $wp_styles = new WP_Styles();
  2467. // For backward compatibility
  2468. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
  2469. if ( $wp_styles->query( $handle ) ) {
  2470. if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
  2471. wp_print_styles( $handle );
  2472. else // Add to style queue
  2473. wp_enqueue_style( $handle );
  2474. return;
  2475. }
  2476. /**
  2477. * Filter the stylesheet link to the specified CSS file.
  2478. *
  2479. * If the site is set to display right-to-left, the RTL stylesheet link
  2480. * will be used instead.
  2481. *
  2482. * @since 2.3.0
  2483. *
  2484. * @param string $file Style handle name or filename (without ".css" extension)
  2485. * relative to wp-admin/. Defaults to 'wp-admin'.
  2486. */
  2487. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
  2488. if ( function_exists( 'is_rtl' ) && is_rtl() ) {
  2489. /** This filter is documented in wp-includes/general-template.php */
  2490. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
  2491. }
  2492. }
  2493. /**
  2494. * Enqueues the default ThickBox js and css.
  2495. *
  2496. * If any of the settings need to be changed, this can be done with another js
  2497. * file similar to media-upload.js. That file should
  2498. * require array('thickbox') to ensure it is loaded after.
  2499. *
  2500. * @since 2.5.0
  2501. */
  2502. function add_thickbox() {
  2503. wp_enqueue_script( 'thickbox' );
  2504. wp_enqueue_style( 'thickbox' );
  2505. if ( is_network_admin() )
  2506. add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
  2507. }
  2508. /**
  2509. * Display the XHTML generator that is generated on the wp_head hook.
  2510. *
  2511. * @since 2.5.0
  2512. */
  2513. function wp_generator() {
  2514. /**
  2515. * Filter the output of the XHTML generator tag.
  2516. *
  2517. * @since 2.5.0
  2518. *
  2519. * @param string $generator_type The XHTML generator.
  2520. */
  2521. the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
  2522. }
  2523. /**
  2524. * Display the generator XML or Comment for RSS, ATOM, etc.
  2525. *
  2526. * Returns the correct generator type for the requested output format. Allows
  2527. * for a plugin to filter generators overall the the_generator filter.
  2528. *
  2529. * @since 2.5.0
  2530. *
  2531. * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
  2532. */
  2533. function the_generator( $type ) {
  2534. /**
  2535. * Filter the output of the XHTML generator tag for display.
  2536. *
  2537. * @since 2.5.0
  2538. *
  2539. * @param string $generator_type The generator output.
  2540. * @param string $type The type of generator to output. Accepts 'html',
  2541. * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
  2542. */
  2543. echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
  2544. }
  2545. /**
  2546. * Creates the generator XML or Comment for RSS, ATOM, etc.
  2547. *
  2548. * Returns the correct generator type for the requested output format. Allows
  2549. * for a plugin to filter generators on an individual basis using the
  2550. * 'get_the_generator_{$type}' filter.
  2551. *
  2552. * @since 2.5.0
  2553. *
  2554. * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
  2555. * @return string The HTML content for the generator.
  2556. */
  2557. function get_the_generator( $type = '' ) {
  2558. if ( empty( $type ) ) {
  2559. $current_filter = current_filter();
  2560. if ( empty( $current_filter ) )
  2561. return;
  2562. switch ( $current_filter ) {
  2563. case 'rss2_head' :
  2564. case 'commentsrss2_head' :
  2565. $type = 'rss2';
  2566. break;
  2567. case 'rss_head' :
  2568. case 'opml_head' :
  2569. $type = 'comment';
  2570. break;
  2571. case 'rdf_header' :
  2572. $type = 'rdf';
  2573. break;
  2574. case 'atom_head' :
  2575. case 'comments_atom_head' :
  2576. case 'app_head' :
  2577. $type = 'atom';
  2578. break;
  2579. }
  2580. }
  2581. switch ( $type ) {
  2582. case 'html':
  2583. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
  2584. break;
  2585. case 'xhtml':
  2586. $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
  2587. break;
  2588. case 'atom':
  2589. $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
  2590. break;
  2591. case 'rss2':
  2592. $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
  2593. break;
  2594. case 'rdf':
  2595. $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
  2596. break;
  2597. case 'comment':
  2598. $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
  2599. break;
  2600. case 'export':
  2601. $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
  2602. break;
  2603. }
  2604. /**
  2605. * Filter the HTML for the retrieved generator type.
  2606. *
  2607. * The dynamic portion of the hook name, $type, refers to the generator type.
  2608. *
  2609. * @since 2.5.0
  2610. *
  2611. * @param string $gen The HTML markup output to 'wp_head()'.
  2612. * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
  2613. * 'rss2', 'rdf', 'comment', 'export'.
  2614. */
  2615. return apply_filters( "get_the_generator_{$type}", $gen, $type );
  2616. }
  2617. /**
  2618. * Outputs the html checked attribute.
  2619. *
  2620. * Compares the first two arguments and if identical marks as checked
  2621. *
  2622. * @since 1.0.0
  2623. *
  2624. * @param mixed $checked One of the values to compare
  2625. * @param mixed $current (true) The other value to compare if not just true
  2626. * @param bool $echo Whether to echo or just return the string
  2627. * @return string html attribute or empty string
  2628. */
  2629. function checked( $checked, $current = true, $echo = true ) {
  2630. return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  2631. }
  2632. /**
  2633. * Outputs the html selected attribute.
  2634. *
  2635. * Compares the first two arguments and if identical marks as selected
  2636. *
  2637. * @since 1.0.0
  2638. *
  2639. * @param mixed $selected One of the values to compare
  2640. * @param mixed $current (true) The other value to compare if not just true
  2641. * @param bool $echo Whether to echo or just return the string
  2642. * @return string html attribute or empty string
  2643. */
  2644. function selected( $selected, $current = true, $echo = true ) {
  2645. return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  2646. }
  2647. /**
  2648. * Outputs the html disabled attribute.
  2649. *
  2650. * Compares the first two arguments and if identical marks as disabled
  2651. *
  2652. * @since 3.0.0
  2653. *
  2654. * @param mixed $disabled One of the values to compare
  2655. * @param mixed $current (true) The other value to compare if not just true
  2656. * @param bool $echo Whether to echo or just return the string
  2657. * @return string html attribute or empty string
  2658. */
  2659. function disabled( $disabled, $current = true, $echo = true ) {
  2660. return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
  2661. }
  2662. /**
  2663. * Private helper function for checked, selected, and disabled.
  2664. *
  2665. * Compares the first two arguments and if identical marks as $type
  2666. *
  2667. * @since 2.8.0
  2668. * @access private
  2669. *
  2670. * @param mixed $helper One of the values to compare
  2671. * @param mixed $current (true) The other value to compare if not just true
  2672. * @param bool $echo Whether to echo or just return the string
  2673. * @param string $type The type of checked|selected|disabled we are doing
  2674. * @return string html attribute or empty string
  2675. */
  2676. function __checked_selected_helper( $helper, $current, $echo, $type ) {
  2677. if ( (string) $helper === (string) $current )
  2678. $result = " $type='$type'";
  2679. else
  2680. $result = '';
  2681. if ( $echo )
  2682. echo $result;
  2683. return $result;
  2684. }
  2685. /**
  2686. * Default settings for heartbeat
  2687. *
  2688. * Outputs the nonce used in the heartbeat XHR
  2689. *
  2690. * @since 3.6.0
  2691. *
  2692. * @param array $settings
  2693. * @return array $settings
  2694. */
  2695. function wp_heartbeat_settings( $settings ) {
  2696. if ( ! is_admin() )
  2697. $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
  2698. if ( is_user_logged_in() )
  2699. $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
  2700. return $settings;
  2701. }