PageRenderTime 34ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/general-template.php

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