/wp-includes/general-template.php

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