You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

3788 lines
122 KiB

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