PageRenderTime 66ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

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