PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/pluggable.php

https://bitbucket.org/aukhanev/xdn-wordpress31
PHP | 1774 lines | 957 code | 250 blank | 567 comment | 315 complexity | 0dab7882287246275349a56196715e9a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * These functions can be replaced via plugins. If plugins do not redefine these
  4. * functions, then these will be used instead.
  5. *
  6. * @package WordPress
  7. */
  8. if ( !function_exists('wp_set_current_user') ) :
  9. /**
  10. * Changes the current user by ID or name.
  11. *
  12. * Set $id to null and specify a name if you do not know a user's ID.
  13. *
  14. * Some WordPress functionality is based on the current user and not based on
  15. * the signed in user. Therefore, it opens the ability to edit and perform
  16. * actions on users who aren't signed in.
  17. *
  18. * @since 2.0.3
  19. * @global object $current_user The current user object which holds the user data.
  20. * @uses do_action() Calls 'set_current_user' hook after setting the current user.
  21. *
  22. * @param int $id User ID
  23. * @param string $name User's username
  24. * @return WP_User Current user User object
  25. */
  26. function wp_set_current_user($id, $name = '') {
  27. global $current_user;
  28. if ( isset($current_user) && ($id == $current_user->ID) )
  29. return $current_user;
  30. $current_user = new WP_User($id, $name);
  31. setup_userdata($current_user->ID);
  32. do_action('set_current_user');
  33. return $current_user;
  34. }
  35. endif;
  36. if ( !function_exists('wp_get_current_user') ) :
  37. /**
  38. * Retrieve the current user object.
  39. *
  40. * @since 2.0.3
  41. *
  42. * @return WP_User Current user WP_User object
  43. */
  44. function wp_get_current_user() {
  45. global $current_user;
  46. get_currentuserinfo();
  47. return $current_user;
  48. }
  49. endif;
  50. if ( !function_exists('get_currentuserinfo') ) :
  51. /**
  52. * Populate global variables with information about the currently logged in user.
  53. *
  54. * Will set the current user, if the current user is not set. The current user
  55. * will be set to the logged in person. If no user is logged in, then it will
  56. * set the current user to 0, which is invalid and won't have any permissions.
  57. *
  58. * @since 0.71
  59. * @uses $current_user Checks if the current user is set
  60. * @uses wp_validate_auth_cookie() Retrieves current logged in user.
  61. *
  62. * @return bool|null False on XMLRPC Request and invalid auth cookie. Null when current user set
  63. */
  64. function get_currentuserinfo() {
  65. global $current_user;
  66. if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
  67. return false;
  68. if ( ! empty($current_user) )
  69. return;
  70. if ( ! $user = wp_validate_auth_cookie() ) {
  71. if ( is_blog_admin() || is_network_admin() || empty($_COOKIE[LOGGED_IN_COOKIE]) || !$user = wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in') ) {
  72. wp_set_current_user(0);
  73. return false;
  74. }
  75. }
  76. wp_set_current_user($user);
  77. }
  78. endif;
  79. if ( !function_exists('get_userdata') ) :
  80. /**
  81. * Retrieve user info by user ID.
  82. *
  83. * @since 0.71
  84. *
  85. * @param int $user_id User ID
  86. * @return bool|object False on failure, User DB row object
  87. */
  88. function get_userdata( $user_id ) {
  89. global $wpdb;
  90. if ( ! is_numeric( $user_id ) )
  91. return false;
  92. $user_id = absint( $user_id );
  93. if ( ! $user_id )
  94. return false;
  95. $user = wp_cache_get( $user_id, 'users' );
  96. if ( $user )
  97. return $user;
  98. if ( ! $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ) )
  99. return false;
  100. _fill_user( $user );
  101. return $user;
  102. }
  103. endif;
  104. if ( !function_exists('cache_users') ) :
  105. /**
  106. * Retrieve info for user lists to prevent multiple queries by get_userdata()
  107. *
  108. * @since 3.0.0
  109. *
  110. * @param array $users User ID numbers list
  111. */
  112. function cache_users( $users ) {
  113. global $wpdb;
  114. $clean = array();
  115. foreach($users as $id) {
  116. $id = (int) $id;
  117. if (wp_cache_get($id, 'users')) {
  118. // seems to be cached already
  119. } else {
  120. $clean[] = $id;
  121. }
  122. }
  123. if ( 0 == count($clean) )
  124. return;
  125. $list = implode(',', $clean);
  126. $results = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID IN ($list)");
  127. _fill_many_users($results);
  128. }
  129. endif;
  130. if ( !function_exists('get_user_by') ) :
  131. /**
  132. * Retrieve user info by a given field
  133. *
  134. * @since 2.8.0
  135. *
  136. * @param string $field The field to retrieve the user with. id | slug | email | login
  137. * @param int|string $value A value for $field. A user ID, slug, email address, or login name.
  138. * @return bool|object False on failure, User DB row object
  139. */
  140. function get_user_by($field, $value) {
  141. global $wpdb;
  142. switch ($field) {
  143. case 'id':
  144. return get_userdata($value);
  145. break;
  146. case 'slug':
  147. $user_id = wp_cache_get($value, 'userslugs');
  148. $field = 'user_nicename';
  149. break;
  150. case 'email':
  151. $user_id = wp_cache_get($value, 'useremail');
  152. $field = 'user_email';
  153. break;
  154. case 'login':
  155. $value = sanitize_user( $value );
  156. $user_id = wp_cache_get($value, 'userlogins');
  157. $field = 'user_login';
  158. break;
  159. default:
  160. return false;
  161. }
  162. if ( false !== $user_id )
  163. return get_userdata($user_id);
  164. if ( !$user = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->users WHERE $field = %s", $value) ) )
  165. return false;
  166. _fill_user($user);
  167. return $user;
  168. }
  169. endif;
  170. if ( !function_exists('get_userdatabylogin') ) :
  171. /**
  172. * Retrieve user info by login name.
  173. *
  174. * @since 0.71
  175. *
  176. * @param string $user_login User's username
  177. * @return bool|object False on failure, User DB row object
  178. */
  179. function get_userdatabylogin($user_login) {
  180. return get_user_by('login', $user_login);
  181. }
  182. endif;
  183. if ( !function_exists('get_user_by_email') ) :
  184. /**
  185. * Retrieve user info by email.
  186. *
  187. * @since 2.5
  188. *
  189. * @param string $email User's email address
  190. * @return bool|object False on failure, User DB row object
  191. */
  192. function get_user_by_email($email) {
  193. return get_user_by('email', $email);
  194. }
  195. endif;
  196. if ( !function_exists( 'wp_mail' ) ) :
  197. /**
  198. * Send mail, similar to PHP's mail
  199. *
  200. * A true return value does not automatically mean that the user received the
  201. * email successfully. It just only means that the method used was able to
  202. * process the request without any errors.
  203. *
  204. * Using the two 'wp_mail_from' and 'wp_mail_from_name' hooks allow from
  205. * creating a from address like 'Name <email@address.com>' when both are set. If
  206. * just 'wp_mail_from' is set, then just the email address will be used with no
  207. * name.
  208. *
  209. * The default content type is 'text/plain' which does not allow using HTML.
  210. * However, you can set the content type of the email by using the
  211. * 'wp_mail_content_type' filter.
  212. *
  213. * The default charset is based on the charset used on the blog. The charset can
  214. * be set using the 'wp_mail_charset' filter.
  215. *
  216. * @since 1.2.1
  217. * @uses apply_filters() Calls 'wp_mail' hook on an array of all of the parameters.
  218. * @uses apply_filters() Calls 'wp_mail_from' hook to get the from email address.
  219. * @uses apply_filters() Calls 'wp_mail_from_name' hook to get the from address name.
  220. * @uses apply_filters() Calls 'wp_mail_content_type' hook to get the email content type.
  221. * @uses apply_filters() Calls 'wp_mail_charset' hook to get the email charset
  222. * @uses do_action_ref_array() Calls 'phpmailer_init' hook on the reference to
  223. * phpmailer object.
  224. * @uses PHPMailer
  225. * @
  226. *
  227. * @param string|array $to Array or comma-separated list of email addresses to send message.
  228. * @param string $subject Email subject
  229. * @param string $message Message contents
  230. * @param string|array $headers Optional. Additional headers.
  231. * @param string|array $attachments Optional. Files to attach.
  232. * @return bool Whether the email contents were sent successfully.
  233. */
  234. function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
  235. // Compact the input, apply the filters, and extract them back out
  236. extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
  237. if ( !is_array($attachments) )
  238. $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
  239. global $phpmailer;
  240. // (Re)create it, if it's gone missing
  241. if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
  242. require_once ABSPATH . WPINC . '/class-phpmailer.php';
  243. require_once ABSPATH . WPINC . '/class-smtp.php';
  244. $phpmailer = new PHPMailer();
  245. }
  246. // Headers
  247. if ( empty( $headers ) ) {
  248. $headers = array();
  249. } else {
  250. if ( !is_array( $headers ) ) {
  251. // Explode the headers out, so this function can take both
  252. // string headers and an array of headers.
  253. $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
  254. } else {
  255. $tempheaders = $headers;
  256. }
  257. $headers = array();
  258. // If it's actually got contents
  259. if ( !empty( $tempheaders ) ) {
  260. // Iterate through the raw headers
  261. foreach ( (array) $tempheaders as $header ) {
  262. if ( strpos($header, ':') === false ) {
  263. if ( false !== stripos( $header, 'boundary=' ) ) {
  264. $parts = preg_split('/boundary=/i', trim( $header ) );
  265. $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
  266. }
  267. continue;
  268. }
  269. // Explode them out
  270. list( $name, $content ) = explode( ':', trim( $header ), 2 );
  271. // Cleanup crew
  272. $name = trim( $name );
  273. $content = trim( $content );
  274. switch ( strtolower( $name ) ) {
  275. // Mainly for legacy -- process a From: header if it's there
  276. case 'from':
  277. if ( strpos($content, '<' ) !== false ) {
  278. // So... making my life hard again?
  279. $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
  280. $from_name = str_replace( '"', '', $from_name );
  281. $from_name = trim( $from_name );
  282. $from_email = substr( $content, strpos( $content, '<' ) + 1 );
  283. $from_email = str_replace( '>', '', $from_email );
  284. $from_email = trim( $from_email );
  285. } else {
  286. $from_email = trim( $content );
  287. }
  288. break;
  289. case 'content-type':
  290. if ( strpos( $content, ';' ) !== false ) {
  291. list( $type, $charset ) = explode( ';', $content );
  292. $content_type = trim( $type );
  293. if ( false !== stripos( $charset, 'charset=' ) ) {
  294. $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
  295. } elseif ( false !== stripos( $charset, 'boundary=' ) ) {
  296. $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset ) );
  297. $charset = '';
  298. }
  299. } else {
  300. $content_type = trim( $content );
  301. }
  302. break;
  303. case 'cc':
  304. $cc = array_merge( (array) $cc, explode( ',', $content ) );
  305. break;
  306. case 'bcc':
  307. $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
  308. break;
  309. default:
  310. // Add it to our grand headers array
  311. $headers[trim( $name )] = trim( $content );
  312. break;
  313. }
  314. }
  315. }
  316. }
  317. // Empty out the values that may be set
  318. $phpmailer->ClearAddresses();
  319. $phpmailer->ClearAllRecipients();
  320. $phpmailer->ClearAttachments();
  321. $phpmailer->ClearBCCs();
  322. $phpmailer->ClearCCs();
  323. $phpmailer->ClearCustomHeaders();
  324. $phpmailer->ClearReplyTos();
  325. // From email and name
  326. // If we don't have a name from the input headers
  327. if ( !isset( $from_name ) )
  328. $from_name = 'WordPress';
  329. /* If we don't have an email from the input headers default to wordpress@$sitename
  330. * Some hosts will block outgoing mail from this address if it doesn't exist but
  331. * there's no easy alternative. Defaulting to admin_email might appear to be another
  332. * option but some hosts may refuse to relay mail from an unknown domain. See
  333. * http://trac.wordpress.org/ticket/5007.
  334. */
  335. if ( !isset( $from_email ) ) {
  336. // Get the site domain and get rid of www.
  337. $sitename = strtolower( $_SERVER['SERVER_NAME'] );
  338. if ( substr( $sitename, 0, 4 ) == 'www.' ) {
  339. $sitename = substr( $sitename, 4 );
  340. }
  341. $from_email = 'wordpress@' . $sitename;
  342. }
  343. // Plugin authors can override the potentially troublesome default
  344. $phpmailer->From = apply_filters( 'wp_mail_from' , $from_email );
  345. $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name );
  346. // Set destination addresses
  347. if ( !is_array( $to ) )
  348. $to = explode( ',', $to );
  349. foreach ( (array) $to as $recipient ) {
  350. $phpmailer->AddAddress( trim( $recipient ) );
  351. }
  352. // Set mail's subject and body
  353. $phpmailer->Subject = $subject;
  354. $phpmailer->Body = $message;
  355. // Add any CC and BCC recipients
  356. if ( !empty( $cc ) ) {
  357. foreach ( (array) $cc as $recipient ) {
  358. $phpmailer->AddCc( trim($recipient) );
  359. }
  360. }
  361. if ( !empty( $bcc ) ) {
  362. foreach ( (array) $bcc as $recipient) {
  363. $phpmailer->AddBcc( trim($recipient) );
  364. }
  365. }
  366. // Set to use PHP's mail()
  367. $phpmailer->IsMail();
  368. // Set Content-Type and charset
  369. // If we don't have a content-type from the input headers
  370. if ( !isset( $content_type ) )
  371. $content_type = 'text/plain';
  372. $content_type = apply_filters( 'wp_mail_content_type', $content_type );
  373. $phpmailer->ContentType = $content_type;
  374. // Set whether it's plaintext, depending on $content_type
  375. if ( 'text/html' == $content_type )
  376. $phpmailer->IsHTML( true );
  377. // If we don't have a charset from the input headers
  378. if ( !isset( $charset ) )
  379. $charset = get_bloginfo( 'charset' );
  380. // Set the content-type and charset
  381. $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
  382. // Set custom headers
  383. if ( !empty( $headers ) ) {
  384. foreach( (array) $headers as $name => $content ) {
  385. $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
  386. }
  387. if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) )
  388. $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
  389. }
  390. if ( !empty( $attachments ) ) {
  391. foreach ( $attachments as $attachment ) {
  392. $phpmailer->AddAttachment($attachment);
  393. }
  394. }
  395. do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
  396. // Send!
  397. $result = @$phpmailer->Send();
  398. return $result;
  399. }
  400. endif;
  401. if ( !function_exists('wp_authenticate') ) :
  402. /**
  403. * Checks a user's login information and logs them in if it checks out.
  404. *
  405. * @since 2.5.0
  406. *
  407. * @param string $username User's username
  408. * @param string $password User's password
  409. * @return WP_Error|WP_User WP_User object if login successful, otherwise WP_Error object.
  410. */
  411. function wp_authenticate($username, $password) {
  412. $username = sanitize_user($username);
  413. $password = trim($password);
  414. $user = apply_filters('authenticate', null, $username, $password);
  415. if ( $user == null ) {
  416. // TODO what should the error message be? (Or would these even happen?)
  417. // Only needed if all authentication handlers fail to return anything.
  418. $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));
  419. }
  420. $ignore_codes = array('empty_username', 'empty_password');
  421. if (is_wp_error($user) && !in_array($user->get_error_code(), $ignore_codes) ) {
  422. do_action('wp_login_failed', $username);
  423. }
  424. return $user;
  425. }
  426. endif;
  427. if ( !function_exists('wp_logout') ) :
  428. /**
  429. * Log the current user out.
  430. *
  431. * @since 2.5.0
  432. */
  433. function wp_logout() {
  434. wp_clear_auth_cookie();
  435. do_action('wp_logout');
  436. }
  437. endif;
  438. if ( !function_exists('wp_validate_auth_cookie') ) :
  439. /**
  440. * Validates authentication cookie.
  441. *
  442. * The checks include making sure that the authentication cookie is set and
  443. * pulling in the contents (if $cookie is not used).
  444. *
  445. * Makes sure the cookie is not expired. Verifies the hash in cookie is what is
  446. * should be and compares the two.
  447. *
  448. * @since 2.5
  449. *
  450. * @param string $cookie Optional. If used, will validate contents instead of cookie's
  451. * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
  452. * @return bool|int False if invalid cookie, User ID if valid.
  453. */
  454. function wp_validate_auth_cookie($cookie = '', $scheme = '') {
  455. if ( ! $cookie_elements = wp_parse_auth_cookie($cookie, $scheme) ) {
  456. do_action('auth_cookie_malformed', $cookie, $scheme);
  457. return false;
  458. }
  459. extract($cookie_elements, EXTR_OVERWRITE);
  460. $expired = $expiration;
  461. // Allow a grace period for POST and AJAX requests
  462. if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] )
  463. $expired += 3600;
  464. // Quick check to see if an honest cookie has expired
  465. if ( $expired < time() ) {
  466. do_action('auth_cookie_expired', $cookie_elements);
  467. return false;
  468. }
  469. $user = get_userdatabylogin($username);
  470. if ( ! $user ) {
  471. do_action('auth_cookie_bad_username', $cookie_elements);
  472. return false;
  473. }
  474. $pass_frag = substr($user->user_pass, 8, 4);
  475. $key = wp_hash($username . $pass_frag . '|' . $expiration, $scheme);
  476. $hash = hash_hmac('md5', $username . '|' . $expiration, $key);
  477. if ( $hmac != $hash ) {
  478. do_action('auth_cookie_bad_hash', $cookie_elements);
  479. return false;
  480. }
  481. if ( $expiration < time() ) // AJAX/POST grace period set above
  482. $GLOBALS['login_grace_period'] = 1;
  483. do_action('auth_cookie_valid', $cookie_elements, $user);
  484. return $user->ID;
  485. }
  486. endif;
  487. if ( !function_exists('wp_generate_auth_cookie') ) :
  488. /**
  489. * Generate authentication cookie contents.
  490. *
  491. * @since 2.5
  492. * @uses apply_filters() Calls 'auth_cookie' hook on $cookie contents, User ID
  493. * and expiration of cookie.
  494. *
  495. * @param int $user_id User ID
  496. * @param int $expiration Cookie expiration in seconds
  497. * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
  498. * @return string Authentication cookie contents
  499. */
  500. function wp_generate_auth_cookie($user_id, $expiration, $scheme = 'auth') {
  501. $user = get_userdata($user_id);
  502. $pass_frag = substr($user->user_pass, 8, 4);
  503. $key = wp_hash($user->user_login . $pass_frag . '|' . $expiration, $scheme);
  504. $hash = hash_hmac('md5', $user->user_login . '|' . $expiration, $key);
  505. $cookie = $user->user_login . '|' . $expiration . '|' . $hash;
  506. return apply_filters('auth_cookie', $cookie, $user_id, $expiration, $scheme);
  507. }
  508. endif;
  509. if ( !function_exists('wp_parse_auth_cookie') ) :
  510. /**
  511. * Parse a cookie into its components
  512. *
  513. * @since 2.7
  514. *
  515. * @param string $cookie
  516. * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
  517. * @return array Authentication cookie components
  518. */
  519. function wp_parse_auth_cookie($cookie = '', $scheme = '') {
  520. if ( empty($cookie) ) {
  521. switch ($scheme){
  522. case 'auth':
  523. $cookie_name = AUTH_COOKIE;
  524. break;
  525. case 'secure_auth':
  526. $cookie_name = SECURE_AUTH_COOKIE;
  527. break;
  528. case "logged_in":
  529. $cookie_name = LOGGED_IN_COOKIE;
  530. break;
  531. default:
  532. if ( is_ssl() ) {
  533. $cookie_name = SECURE_AUTH_COOKIE;
  534. $scheme = 'secure_auth';
  535. } else {
  536. $cookie_name = AUTH_COOKIE;
  537. $scheme = 'auth';
  538. }
  539. }
  540. if ( empty($_COOKIE[$cookie_name]) )
  541. return false;
  542. $cookie = $_COOKIE[$cookie_name];
  543. }
  544. $cookie_elements = explode('|', $cookie);
  545. if ( count($cookie_elements) != 3 )
  546. return false;
  547. list($username, $expiration, $hmac) = $cookie_elements;
  548. return compact('username', 'expiration', 'hmac', 'scheme');
  549. }
  550. endif;
  551. if ( !function_exists('wp_set_auth_cookie') ) :
  552. /**
  553. * Sets the authentication cookies based User ID.
  554. *
  555. * The $remember parameter increases the time that the cookie will be kept. The
  556. * default the cookie is kept without remembering is two days. When $remember is
  557. * set, the cookies will be kept for 14 days or two weeks.
  558. *
  559. * @since 2.5
  560. *
  561. * @param int $user_id User ID
  562. * @param bool $remember Whether to remember the user
  563. */
  564. function wp_set_auth_cookie($user_id, $remember = false, $secure = '') {
  565. if ( $remember ) {
  566. $expiration = $expire = time() + apply_filters('auth_cookie_expiration', 1209600, $user_id, $remember);
  567. } else {
  568. $expiration = time() + apply_filters('auth_cookie_expiration', 172800, $user_id, $remember);
  569. $expire = 0;
  570. }
  571. if ( '' === $secure )
  572. $secure = is_ssl();
  573. $secure = apply_filters('secure_auth_cookie', $secure, $user_id);
  574. $secure_logged_in_cookie = apply_filters('secure_logged_in_cookie', false, $user_id, $secure);
  575. if ( $secure ) {
  576. $auth_cookie_name = SECURE_AUTH_COOKIE;
  577. $scheme = 'secure_auth';
  578. } else {
  579. $auth_cookie_name = AUTH_COOKIE;
  580. $scheme = 'auth';
  581. }
  582. $auth_cookie = wp_generate_auth_cookie($user_id, $expiration, $scheme);
  583. $logged_in_cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in');
  584. do_action('set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme);
  585. do_action('set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in');
  586. // Set httponly if the php version is >= 5.2.0
  587. if ( version_compare(phpversion(), '5.2.0', 'ge') ) {
  588. setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
  589. setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
  590. setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);
  591. if ( COOKIEPATH != SITECOOKIEPATH )
  592. setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true);
  593. } else {
  594. $cookie_domain = COOKIE_DOMAIN;
  595. if ( !empty($cookie_domain) )
  596. $cookie_domain .= '; HttpOnly';
  597. setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, $cookie_domain, $secure);
  598. setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, $cookie_domain, $secure);
  599. setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, $cookie_domain, $secure_logged_in_cookie);
  600. if ( COOKIEPATH != SITECOOKIEPATH )
  601. setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, $cookie_domain, $secure_logged_in_cookie);
  602. }
  603. }
  604. endif;
  605. if ( !function_exists('wp_clear_auth_cookie') ) :
  606. /**
  607. * Removes all of the cookies associated with authentication.
  608. *
  609. * @since 2.5
  610. */
  611. function wp_clear_auth_cookie() {
  612. do_action('clear_auth_cookie');
  613. setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
  614. setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
  615. setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
  616. setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
  617. setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
  618. setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
  619. // Old cookies
  620. setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
  621. setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
  622. setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
  623. setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
  624. // Even older cookies
  625. setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
  626. setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
  627. setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
  628. setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
  629. }
  630. endif;
  631. if ( !function_exists('is_user_logged_in') ) :
  632. /**
  633. * Checks if the current visitor is a logged in user.
  634. *
  635. * @since 2.0.0
  636. *
  637. * @return bool True if user is logged in, false if not logged in.
  638. */
  639. function is_user_logged_in() {
  640. $user = wp_get_current_user();
  641. if ( $user->id == 0 )
  642. return false;
  643. return true;
  644. }
  645. endif;
  646. if ( !function_exists('auth_redirect') ) :
  647. /**
  648. * Checks if a user is logged in, if not it redirects them to the login page.
  649. *
  650. * @since 1.5
  651. */
  652. function auth_redirect() {
  653. // Checks if a user is logged in, if not redirects them to the login page
  654. $secure = ( is_ssl() || force_ssl_admin() );
  655. $secure = apply_filters('secure_auth_redirect', $secure);
  656. // If https is required and request is http, redirect
  657. if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
  658. if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
  659. wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
  660. exit();
  661. } else {
  662. wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  663. exit();
  664. }
  665. }
  666. if ( is_user_admin() )
  667. $scheme = 'logged_in';
  668. else
  669. $scheme = apply_filters( 'auth_redirect_scheme', '' );
  670. if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) {
  671. do_action('auth_redirect', $user_id);
  672. // If the user wants ssl but the session is not ssl, redirect.
  673. if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
  674. if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
  675. wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
  676. exit();
  677. } else {
  678. wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  679. exit();
  680. }
  681. }
  682. return; // The cookie is good so we're done
  683. }
  684. // The cookie is no good so force login
  685. nocache_headers();
  686. if ( is_ssl() )
  687. $proto = 'https://';
  688. else
  689. $proto = 'http://';
  690. $redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  691. $login_url = wp_login_url($redirect, true);
  692. wp_redirect($login_url);
  693. exit();
  694. }
  695. endif;
  696. if ( !function_exists('check_admin_referer') ) :
  697. /**
  698. * Makes sure that a user was referred from another admin page.
  699. *
  700. * To avoid security exploits.
  701. *
  702. * @since 1.2.0
  703. * @uses do_action() Calls 'check_admin_referer' on $action.
  704. *
  705. * @param string $action Action nonce
  706. * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
  707. */
  708. function check_admin_referer($action = -1, $query_arg = '_wpnonce') {
  709. $adminurl = strtolower(admin_url());
  710. $referer = strtolower(wp_get_referer());
  711. $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce($_REQUEST[$query_arg], $action) : false;
  712. if ( !$result && !(-1 == $action && strpos($referer, $adminurl) === 0) ) {
  713. wp_nonce_ays($action);
  714. die();
  715. }
  716. do_action('check_admin_referer', $action, $result);
  717. return $result;
  718. }endif;
  719. if ( !function_exists('check_ajax_referer') ) :
  720. /**
  721. * Verifies the AJAX request to prevent processing requests external of the blog.
  722. *
  723. * @since 2.0.3
  724. *
  725. * @param string $action Action nonce
  726. * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
  727. */
  728. function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
  729. if ( $query_arg )
  730. $nonce = $_REQUEST[$query_arg];
  731. else
  732. $nonce = isset($_REQUEST['_ajax_nonce']) ? $_REQUEST['_ajax_nonce'] : $_REQUEST['_wpnonce'];
  733. $result = wp_verify_nonce( $nonce, $action );
  734. if ( $die && false == $result )
  735. die('-1');
  736. do_action('check_ajax_referer', $action, $result);
  737. return $result;
  738. }
  739. endif;
  740. if ( !function_exists('wp_redirect') ) :
  741. /**
  742. * Redirects to another page.
  743. *
  744. * @since 1.5.1
  745. * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
  746. *
  747. * @param string $location The path to redirect to
  748. * @param int $status Status code to use
  749. * @return bool False if $location is not set
  750. */
  751. function wp_redirect($location, $status = 302) {
  752. global $is_IIS;
  753. $location = apply_filters('wp_redirect', $location, $status);
  754. $status = apply_filters('wp_redirect_status', $status, $location);
  755. if ( !$location ) // allows the wp_redirect filter to cancel a redirect
  756. return false;
  757. $location = wp_sanitize_redirect($location);
  758. if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
  759. status_header($status); // This causes problems on IIS and some FastCGI setups
  760. header("Location: $location", true, $status);
  761. }
  762. endif;
  763. if ( !function_exists('wp_sanitize_redirect') ) :
  764. /**
  765. * Sanitizes a URL for use in a redirect.
  766. *
  767. * @since 2.3
  768. *
  769. * @return string redirect-sanitized URL
  770. **/
  771. function wp_sanitize_redirect($location) {
  772. $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location);
  773. $location = wp_kses_no_null($location);
  774. // remove %0d and %0a from location
  775. $strip = array('%0d', '%0a', '%0D', '%0A');
  776. $location = _deep_replace($strip, $location);
  777. return $location;
  778. }
  779. endif;
  780. if ( !function_exists('wp_safe_redirect') ) :
  781. /**
  782. * Performs a safe (local) redirect, using wp_redirect().
  783. *
  784. * Checks whether the $location is using an allowed host, if it has an absolute
  785. * path. A plugin can therefore set or remove allowed host(s) to or from the
  786. * list.
  787. *
  788. * If the host is not allowed, then the redirect is to wp-admin on the siteurl
  789. * instead. This prevents malicious redirects which redirect to another host,
  790. * but only used in a few places.
  791. *
  792. * @since 2.3
  793. * @uses wp_validate_redirect() To validate the redirect is to an allowed host.
  794. *
  795. * @return void Does not return anything
  796. **/
  797. function wp_safe_redirect($location, $status = 302) {
  798. // Need to look at the URL the way it will end up in wp_redirect()
  799. $location = wp_sanitize_redirect($location);
  800. $location = wp_validate_redirect($location, admin_url());
  801. wp_redirect($location, $status);
  802. }
  803. endif;
  804. if ( !function_exists('wp_validate_redirect') ) :
  805. /**
  806. * Validates a URL for use in a redirect.
  807. *
  808. * Checks whether the $location is using an allowed host, if it has an absolute
  809. * path. A plugin can therefore set or remove allowed host(s) to or from the
  810. * list.
  811. *
  812. * If the host is not allowed, then the redirect is to $default supplied
  813. *
  814. * @since 2.8.1
  815. * @uses apply_filters() Calls 'allowed_redirect_hosts' on an array containing
  816. * WordPress host string and $location host string.
  817. *
  818. * @param string $location The redirect to validate
  819. * @param string $default The value to return is $location is not allowed
  820. * @return string redirect-sanitized URL
  821. **/
  822. function wp_validate_redirect($location, $default = '') {
  823. // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
  824. if ( substr($location, 0, 2) == '//' )
  825. $location = 'http:' . $location;
  826. // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
  827. $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
  828. $lp = parse_url($test);
  829. // Give up if malformed URL
  830. if ( false === $lp )
  831. return $default;
  832. // Allow only http and https schemes. No data:, etc.
  833. if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) )
  834. return $default;
  835. // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
  836. if ( isset($lp['scheme']) && !isset($lp['host']) )
  837. return $default;
  838. $wpp = parse_url(home_url());
  839. $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
  840. if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
  841. $location = $default;
  842. return $location;
  843. }
  844. endif;
  845. if ( ! function_exists('wp_notify_postauthor') ) :
  846. /**
  847. * Notify an author of a comment/trackback/pingback to one of their posts.
  848. *
  849. * @since 1.0.0
  850. *
  851. * @param int $comment_id Comment ID
  852. * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback'
  853. * @return bool False if user email does not exist. True on completion.
  854. */
  855. function wp_notify_postauthor( $comment_id, $comment_type = '' ) {
  856. $comment = get_comment( $comment_id );
  857. $post = get_post( $comment->comment_post_ID );
  858. $author = get_userdata( $post->post_author );
  859. // The comment was left by the author
  860. if ( $comment->user_id == $post->post_author )
  861. return false;
  862. // The author moderated a comment on his own post
  863. if ( $post->post_author == get_current_user_id() )
  864. return false;
  865. // If there's no email to send the comment to
  866. if ( '' == $author->user_email )
  867. return false;
  868. $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
  869. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  870. // we want to reverse this for the plain text arena of emails.
  871. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  872. if ( empty( $comment_type ) ) $comment_type = 'comment';
  873. if ('comment' == $comment_type) {
  874. $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
  875. /* translators: 1: comment author, 2: author IP, 3: author domain */
  876. $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
  877. $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
  878. $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
  879. $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
  880. $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
  881. $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
  882. /* translators: 1: blog name, 2: post title */
  883. $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
  884. } elseif ('trackback' == $comment_type) {
  885. $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
  886. /* translators: 1: website name, 2: author IP, 3: author domain */
  887. $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
  888. $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
  889. $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
  890. $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
  891. /* translators: 1: blog name, 2: post title */
  892. $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
  893. } elseif ('pingback' == $comment_type) {
  894. $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
  895. /* translators: 1: comment author, 2: author IP, 3: author domain */
  896. $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
  897. $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
  898. $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
  899. $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
  900. /* translators: 1: blog name, 2: post title */
  901. $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
  902. }
  903. $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
  904. $notify_message .= sprintf( __('Permalink: %s'), get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ) . "\r\n";
  905. if ( EMPTY_TRASH_DAYS )
  906. $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
  907. else
  908. $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
  909. $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
  910. $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
  911. if ( '' == $comment->comment_author ) {
  912. $from = "From: \"$blogname\" <$wp_email>";
  913. if ( '' != $comment->comment_author_email )
  914. $reply_to = "Reply-To: $comment->comment_author_email";
  915. } else {
  916. $from = "From: \"$comment->comment_author\" <$wp_email>";
  917. if ( '' != $comment->comment_author_email )
  918. $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
  919. }
  920. $message_headers = "$from\n"
  921. . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
  922. if ( isset($reply_to) )
  923. $message_headers .= $reply_to . "\n";
  924. $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
  925. $subject = apply_filters('comment_notification_subject', $subject, $comment_id);
  926. $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
  927. @wp_mail( $author->user_email, $subject, $notify_message, $message_headers );
  928. return true;
  929. }
  930. endif;
  931. if ( !function_exists('wp_notify_moderator') ) :
  932. /**
  933. * Notifies the moderator of the blog about a new comment that is awaiting approval.
  934. *
  935. * @since 1.0
  936. * @uses $wpdb
  937. *
  938. * @param int $comment_id Comment ID
  939. * @return bool Always returns true
  940. */
  941. function wp_notify_moderator($comment_id) {
  942. global $wpdb;
  943. if ( 0 == get_option( 'moderation_notify' ) )
  944. return true;
  945. $comment = get_comment($comment_id);
  946. $post = get_post($comment->comment_post_ID);
  947. $user = get_userdata( $post->post_author );
  948. // Send to the administation and to the post author if the author can modify the comment.
  949. $email_to = array( get_option('admin_email') );
  950. if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) )
  951. $email_to[] = $user->user_email;
  952. $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
  953. $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
  954. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  955. // we want to reverse this for the plain text arena of emails.
  956. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  957. switch ($comment->comment_type)
  958. {
  959. case 'trackback':
  960. $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
  961. $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
  962. $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
  963. $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
  964. $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
  965. break;
  966. case 'pingback':
  967. $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
  968. $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
  969. $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
  970. $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
  971. $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
  972. break;
  973. default: //Comments
  974. $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n";
  975. $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
  976. $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
  977. $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
  978. $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n";
  979. $notify_message .= sprintf( __('Whois : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n";
  980. $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
  981. break;
  982. }
  983. $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n";
  984. if ( EMPTY_TRASH_DAYS )
  985. $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
  986. else
  987. $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
  988. $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
  989. $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:',
  990. 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n";
  991. $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n";
  992. $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title );
  993. $message_headers = '';
  994. $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id);
  995. $subject = apply_filters('comment_moderation_subject', $subject, $comment_id);
  996. $message_headers = apply_filters('comment_moderation_headers', $message_headers);
  997. foreach ( $email_to as $email )
  998. @wp_mail($email, $subject, $notify_message, $message_headers);
  999. return true;
  1000. }
  1001. endif;
  1002. if ( !function_exists('wp_password_change_notification') ) :
  1003. /**
  1004. * Notify the blog admin of a user changing password, normally via email.
  1005. *
  1006. * @since 2.7
  1007. *
  1008. * @param object $user User Object
  1009. */
  1010. function wp_password_change_notification(&$user) {
  1011. // send a copy of password change notification to the admin
  1012. // but check to see if it's the admin whose password we're changing, and skip this
  1013. if ( $user->user_email != get_option('admin_email') ) {
  1014. $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
  1015. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  1016. // we want to reverse this for the plain text arena of emails.
  1017. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  1018. wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), $blogname), $message);
  1019. }
  1020. }
  1021. endif;
  1022. if ( !function_exists('wp_new_user_notification') ) :
  1023. /**
  1024. * Notify the blog admin of a new user, normally via email.
  1025. *
  1026. * @since 2.0
  1027. *
  1028. * @param int $user_id User ID
  1029. * @param string $plaintext_pass Optional. The user's plaintext password
  1030. */
  1031. function wp_new_user_notification($user_id, $plaintext_pass = '') {
  1032. $user = new WP_User($user_id);
  1033. $user_login = stripslashes($user->user_login);
  1034. $user_email = stripslashes($user->user_email);
  1035. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  1036. // we want to reverse this for the plain text arena of emails.
  1037. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  1038. $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
  1039. $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
  1040. $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
  1041. @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
  1042. if ( empty($plaintext_pass) )
  1043. return;
  1044. $message = sprintf(__('Username: %s'), $user_login) . "\r\n";
  1045. $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
  1046. $message .= wp_login_url() . "\r\n";
  1047. wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
  1048. }
  1049. endif;
  1050. if ( !function_exists('wp_nonce_tick') ) :
  1051. /**
  1052. * Get the time-dependent variable for nonce creation.
  1053. *
  1054. * A nonce has a lifespan of two ticks. Nonces in their second tick may be
  1055. * updated, e.g. by autosave.
  1056. *
  1057. * @since 2.5
  1058. *
  1059. * @return int
  1060. */
  1061. function wp_nonce_tick() {
  1062. $nonce_life = apply_filters('nonce_life', 86400);
  1063. return ceil(time() / ( $nonce_life / 2 ));
  1064. }
  1065. endif;
  1066. if ( !function_exists('wp_verify_nonce') ) :
  1067. /**
  1068. * Verify that correct nonce was used with time limit.
  1069. *
  1070. * The user is given an amount of time to use the token, so therefore, since the
  1071. * UID and $action remain the same, the independent variable is the time.
  1072. *
  1073. * @since 2.0.3
  1074. *
  1075. * @param string $nonce Nonce that was used in the form to verify
  1076. * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
  1077. * @return bool Whether the nonce check passed or failed.
  1078. */
  1079. function wp_verify_nonce($nonce, $action = -1) {
  1080. $user = wp_get_current_user();
  1081. $uid = (int) $user->id;
  1082. $i = wp_nonce_tick();
  1083. // Nonce generated 0-12 hours ago
  1084. if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce )
  1085. return 1;
  1086. // Nonce generated 12-24 hours ago
  1087. if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) == $nonce )
  1088. return 2;
  1089. // Invalid nonce
  1090. return false;
  1091. }
  1092. endif;
  1093. if ( !function_exists('wp_create_nonce') ) :
  1094. /**
  1095. * Creates a random, one time use token.
  1096. *
  1097. * @since 2.0.3
  1098. *
  1099. * @param string|int $action Scalar value to add context to the nonce.
  1100. * @return string The one use form token
  1101. */
  1102. function wp_create_nonce($action = -1) {
  1103. $user = wp_get_current_user();
  1104. $uid = (int) $user->id;
  1105. $i = wp_nonce_tick();
  1106. return substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10);
  1107. }
  1108. endif;
  1109. if ( !function_exists('wp_salt') ) :
  1110. /**
  1111. * Get salt to add to hashes to help prevent attacks.
  1112. *
  1113. * The secret key is located in two places: the database in case the secret key
  1114. * isn't defined in the second place, which is in the wp-config.php file. If you
  1115. * are going to set the secret key, then you must do so in the wp-config.php
  1116. * file.
  1117. *
  1118. * The secret key in the database is randomly generated and will be appended to
  1119. * the secret key that is in wp-config.php file in some instances. It is
  1120. * important to have the secret key defined or changed in wp-config.php.
  1121. *
  1122. * If you have installed WordPress 2.5 or later, then you will have the
  1123. * SECRET_KEY defined in the wp-config.php already. You will want to change the
  1124. * value in it because hackers will know what it is. If you have upgraded to
  1125. * WordPress 2.5 or later version from a version before WordPress 2.5, then you
  1126. * should add the constant to your wp-config.php file.
  1127. *
  1128. * Below is an example of how the SECRET_KEY constant is defined with a value.
  1129. * You must not copy the below example and paste into your wp-config.php. If you
  1130. * need an example, then you can have a
  1131. * {@link https://api.wordpress.org/secret-key/1.1/ secret key created} for you.
  1132. *
  1133. * <code>
  1134. * define('SECRET_KEY', 'mAry1HadA15|\/|b17w55w1t3asSn09w');
  1135. * </code>
  1136. *
  1137. * Salting passwords helps against tools which has stored hashed values of
  1138. * common dictionary strings. The added values makes it harder to crack if given
  1139. * salt string is not weak.
  1140. *
  1141. * @since 2.5
  1142. * @link https://api.wordpress.org/secret-key/1.1/ Create a Secret Key for wp-config.php
  1143. *
  1144. * @param string $scheme Authentication scheme
  1145. * @return string Salt value
  1146. */
  1147. function wp_salt($scheme = 'auth') {
  1148. global $wp_default_secret_key;
  1149. $secret_key = '';
  1150. if ( defined('SECRET_KEY') && ('' != SECRET_KEY) && ( $wp_default_secret_key != SECRET_KEY) )
  1151. $secret_key = SECRET_KEY;
  1152. if ( 'auth' == $scheme ) {
  1153. if ( defined('AUTH_KEY') && ('' != AUTH_KEY) && ( $wp_default_secret_key != AUTH_KEY) )
  1154. $secret_key = AUTH_KEY;
  1155. if ( defined('AUTH_SALT') && ('' != AUTH_SALT) && ( $wp_default_secret_key != AUTH_SALT) ) {
  1156. $salt = AUTH_SALT;
  1157. } elseif ( defined('SECRET_SALT') && ('' != SECRET_SALT) && ( $wp_default_secret_key != SECRET_SALT) ) {
  1158. $salt = SECRET_SALT;
  1159. } else {
  1160. $salt = get_site_option('auth_salt');
  1161. if ( empty($salt) ) {
  1162. $salt = wp_generate_password( 64, true, true );
  1163. update_site_option('auth_salt', $salt);
  1164. }
  1165. }
  1166. } elseif ( 'secure_auth' == $scheme ) {
  1167. if ( defined('SECURE_AUTH_KEY') && ('' != SECURE_AUTH_KEY) && ( $wp_default_secret_key != SECURE_AUTH_KEY) )
  1168. $secret_key = SECURE_AUTH_KEY;
  1169. if ( defined('SECURE_AUTH_SALT') && ('' != SECURE_AUTH_SALT) && ( $wp_default_secret_key != SECURE_AUTH_SALT) ) {
  1170. $salt = SECURE_AUTH_SALT;
  1171. } else {
  1172. $salt = get_site_option('secure_auth_salt');
  1173. if ( empty($salt) ) {
  1174. $salt = wp_generate_password( 64, true, true );
  1175. update_site_option('secure_auth_salt', $salt);
  1176. }
  1177. }
  1178. } elseif ( 'logged_in' == $scheme ) {
  1179. if ( defined('LOGGED_IN_KEY') && ('' != LOGGED_IN_KEY) && ( $wp_default_secret_key != LOGGED_IN_KEY) )
  1180. $secret_key = LOGGED_IN_KEY;
  1181. if ( defined('LOGGED_IN_SALT') && ('' != LOGGED_IN_SALT) && ( $wp_default_secret_key != LOGGED_IN_SALT) ) {
  1182. $salt = LOGGED_IN_SALT;
  1183. } else {
  1184. $salt = get_site_option('logged_in_salt');
  1185. if ( empty($salt) ) {
  1186. $salt = wp_generate_password( 64, true, true );
  1187. update_site_option('logged_in_salt', $salt);
  1188. }
  1189. }
  1190. } elseif ( 'nonce' == $scheme ) {
  1191. if ( defined('NONCE_KEY') && ('' != NONCE_KEY) && ( $wp_default_secret_key != NONCE_KEY) )
  1192. $secret_key = NONCE_KEY;
  1193. if ( defined('NONCE_SALT') && ('' != NONCE_SALT) && ( $wp_default_secret_key != NONCE_SALT) ) {
  1194. $salt = NONCE_SALT;
  1195. } else {
  1196. $salt = get_site_option('nonce_salt');
  1197. if ( empty($salt) ) {
  1198. $salt = wp_generate_password( 64, true, true );
  1199. update_site_option('nonce_salt', $salt);
  1200. }
  1201. }
  1202. } else {
  1203. // ensure each auth scheme has its own unique salt
  1204. $salt = hash_hmac('md5', $scheme, $secret_key);
  1205. }
  1206. return apply_filters('salt', $secret_key . $salt, $scheme);
  1207. }
  1208. endif;
  1209. if ( !function_exists('wp_hash') ) :
  1210. /**
  1211. * Get hash of given string.
  1212. *
  1213. * @since 2.0.3
  1214. * @uses wp_salt() Get WordPress salt
  1215. *
  1216. * @param string $data Plain text to hash
  1217. * @return string Hash of $data
  1218. */
  1219. function wp_hash($data, $scheme = 'auth') {
  1220. $salt = wp_salt($scheme);
  1221. return hash_hmac('md5', $data, $salt);
  1222. }
  1223. endif;
  1224. if ( !function_exists('wp_hash_password') ) :
  1225. /**
  1226. * Create a hash (encrypt) of a plain text password.
  1227. *
  1228. * For integration with other applications, this function can be overwritten to
  1229. * instead use the other package password checking algorithm.
  1230. *
  1231. * @since 2.5
  1232. * @global object $wp_hasher PHPass object
  1233. * @uses PasswordHash::HashPassword
  1234. *
  1235. * @param string $password Plain text user password to hash
  1236. * @return string The hash string of the password
  1237. */
  1238. function wp_hash_password($password) {
  1239. global $wp_hasher;
  1240. if ( empty($wp_hasher) ) {
  1241. require_once( ABSPATH . 'wp-includes/class-phpass.php');
  1242. // By default, use the portable hash from phpass
  1243. $wp_hasher = new PasswordHash(8, TRUE);
  1244. }
  1245. return $wp_hasher->HashPassword($password);
  1246. }
  1247. endif;
  1248. if ( !function_exists('wp_check_password') ) :
  1249. /**
  1250. * Checks the plaintext password against the encrypted Password.
  1251. *
  1252. * Maintains compatibility between old version and the new cookie authentication
  1253. * protocol using PHPass library. The $hash parameter is the encrypted password
  1254. * and the function compares the plain text password when encypted similarly
  1255. * against the already encrypted password to see if they match.
  1256. *
  1257. * For …

Large files files are truncated, but you can click here to view the full file