18 * |
18 * |
19 * @since 2.0.3 |
19 * @since 2.0.3 |
20 * |
20 * |
21 * @global WP_User $current_user The current user object which holds the user data. |
21 * @global WP_User $current_user The current user object which holds the user data. |
22 * |
22 * |
23 * @param int $id User ID |
23 * @param int|null $id User ID. |
24 * @param string $name User's username |
24 * @param string $name User's username. |
25 * @return WP_User Current user User object |
25 * @return WP_User Current user User object. |
26 */ |
26 */ |
27 function wp_set_current_user( $id, $name = '' ) { |
27 function wp_set_current_user( $id, $name = '' ) { |
28 global $current_user; |
28 global $current_user; |
29 |
29 |
30 // If `$id` matches the current user, there is nothing to do. |
30 // If `$id` matches the current user, there is nothing to do. |
376 * another option, but some hosts may refuse to relay mail from an unknown domain. |
376 * another option, but some hosts may refuse to relay mail from an unknown domain. |
377 * See https://core.trac.wordpress.org/ticket/5007. |
377 * See https://core.trac.wordpress.org/ticket/5007. |
378 */ |
378 */ |
379 if ( ! isset( $from_email ) ) { |
379 if ( ! isset( $from_email ) ) { |
380 // Get the site domain and get rid of www. |
380 // Get the site domain and get rid of www. |
381 $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST ); |
381 $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST ); |
382 if ( 'www.' === substr( $sitename, 0, 4 ) ) { |
382 $from_email = 'wordpress@'; |
383 $sitename = substr( $sitename, 4 ); |
383 |
|
384 if ( null !== $sitename ) { |
|
385 if ( 'www.' === substr( $sitename, 0, 4 ) ) { |
|
386 $sitename = substr( $sitename, 4 ); |
|
387 } |
|
388 |
|
389 $from_email .= $sitename; |
384 } |
390 } |
385 |
|
386 $from_email = 'wordpress@' . $sitename; |
|
387 } |
391 } |
388 |
392 |
389 /** |
393 /** |
390 * Filters the email address to send from. |
394 * Filters the email address to send from. |
391 * |
395 * |
535 * |
539 * |
536 * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). |
540 * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). |
537 */ |
541 */ |
538 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
542 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
539 |
543 |
|
544 $mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); |
|
545 |
540 // Send! |
546 // Send! |
541 try { |
547 try { |
542 return $phpmailer->send(); |
548 $send = $phpmailer->send(); |
|
549 |
|
550 /** |
|
551 * Fires after PHPMailer has successfully sent an email. |
|
552 * |
|
553 * The firing of this action does not necessarily mean that the recipient(s) received the |
|
554 * email successfully. It only means that the `send` method above was able to |
|
555 * process the request without any errors. |
|
556 * |
|
557 * @since 5.9.0 |
|
558 * |
|
559 * @param array $mail_data { |
|
560 * An array containing the email recipient(s), subject, message, headers, and attachments. |
|
561 * |
|
562 * @type string[] $to Email addresses to send message. |
|
563 * @type string $subject Email subject. |
|
564 * @type string $message Message contents. |
|
565 * @type string[] $headers Additional headers. |
|
566 * @type string[] $attachments Paths to files to attach. |
|
567 * } |
|
568 */ |
|
569 do_action( 'wp_mail_succeeded', $mail_data ); |
|
570 |
|
571 return $send; |
543 } catch ( PHPMailer\PHPMailer\Exception $e ) { |
572 } catch ( PHPMailer\PHPMailer\Exception $e ) { |
544 |
573 $mail_data['phpmailer_exception_code'] = $e->getCode(); |
545 $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' ); |
|
546 $mail_error_data['phpmailer_exception_code'] = $e->getCode(); |
|
547 |
574 |
548 /** |
575 /** |
549 * Fires after a PHPMailer\PHPMailer\Exception is caught. |
576 * Fires after a PHPMailer\PHPMailer\Exception is caught. |
550 * |
577 * |
551 * @since 4.4.0 |
578 * @since 4.4.0 |
552 * |
579 * |
553 * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array |
580 * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array |
554 * containing the mail recipient, subject, message, headers, and attachments. |
581 * containing the mail recipient, subject, message, headers, and attachments. |
555 */ |
582 */ |
556 do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) ); |
583 do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) ); |
557 |
584 |
558 return false; |
585 return false; |
559 } |
586 } |
560 } |
587 } |
561 endif; |
588 endif; |
696 /** |
723 /** |
697 * Fires once an authentication cookie has expired. |
724 * Fires once an authentication cookie has expired. |
698 * |
725 * |
699 * @since 2.7.0 |
726 * @since 2.7.0 |
700 * |
727 * |
701 * @param string[] $cookie_elements An array of data for the authentication cookie. |
728 * @param string[] $cookie_elements { |
|
729 * Authentication cookie components. None of the components should be assumed |
|
730 * to be valid as they come directly from a client-provided cookie value. |
|
731 * |
|
732 * @type string $username User's username. |
|
733 * @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
734 * @type string $token User's session token used. |
|
735 * @type string $hmac The security hash for the cookie. |
|
736 * @type string $scheme The cookie scheme to use. |
|
737 * } |
702 */ |
738 */ |
703 do_action( 'auth_cookie_expired', $cookie_elements ); |
739 do_action( 'auth_cookie_expired', $cookie_elements ); |
704 return false; |
740 return false; |
705 } |
741 } |
706 |
742 |
709 /** |
745 /** |
710 * Fires if a bad username is entered in the user authentication process. |
746 * Fires if a bad username is entered in the user authentication process. |
711 * |
747 * |
712 * @since 2.7.0 |
748 * @since 2.7.0 |
713 * |
749 * |
714 * @param string[] $cookie_elements An array of data for the authentication cookie. |
750 * @param string[] $cookie_elements { |
|
751 * Authentication cookie components. None of the components should be assumed |
|
752 * to be valid as they come directly from a client-provided cookie value. |
|
753 * |
|
754 * @type string $username User's username. |
|
755 * @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
756 * @type string $token User's session token used. |
|
757 * @type string $hmac The security hash for the cookie. |
|
758 * @type string $scheme The cookie scheme to use. |
|
759 * } |
715 */ |
760 */ |
716 do_action( 'auth_cookie_bad_username', $cookie_elements ); |
761 do_action( 'auth_cookie_bad_username', $cookie_elements ); |
717 return false; |
762 return false; |
718 } |
763 } |
719 |
764 |
729 /** |
774 /** |
730 * Fires if a bad authentication cookie hash is encountered. |
775 * Fires if a bad authentication cookie hash is encountered. |
731 * |
776 * |
732 * @since 2.7.0 |
777 * @since 2.7.0 |
733 * |
778 * |
734 * @param string[] $cookie_elements An array of data for the authentication cookie. |
779 * @param string[] $cookie_elements { |
|
780 * Authentication cookie components. None of the components should be assumed |
|
781 * to be valid as they come directly from a client-provided cookie value. |
|
782 * |
|
783 * @type string $username User's username. |
|
784 * @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
785 * @type string $token User's session token used. |
|
786 * @type string $hmac The security hash for the cookie. |
|
787 * @type string $scheme The cookie scheme to use. |
|
788 * } |
735 */ |
789 */ |
736 do_action( 'auth_cookie_bad_hash', $cookie_elements ); |
790 do_action( 'auth_cookie_bad_hash', $cookie_elements ); |
737 return false; |
791 return false; |
738 } |
792 } |
739 |
793 |
742 /** |
796 /** |
743 * Fires if a bad session token is encountered. |
797 * Fires if a bad session token is encountered. |
744 * |
798 * |
745 * @since 4.0.0 |
799 * @since 4.0.0 |
746 * |
800 * |
747 * @param string[] $cookie_elements An array of data for the authentication cookie. |
801 * @param string[] $cookie_elements { |
|
802 * Authentication cookie components. None of the components should be assumed |
|
803 * to be valid as they come directly from a client-provided cookie value. |
|
804 * |
|
805 * @type string $username User's username. |
|
806 * @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
807 * @type string $token User's session token used. |
|
808 * @type string $hmac The security hash for the cookie. |
|
809 * @type string $scheme The cookie scheme to use. |
|
810 * } |
748 */ |
811 */ |
749 do_action( 'auth_cookie_bad_session_token', $cookie_elements ); |
812 do_action( 'auth_cookie_bad_session_token', $cookie_elements ); |
750 return false; |
813 return false; |
751 } |
814 } |
752 |
815 |
758 /** |
821 /** |
759 * Fires once an authentication cookie has been validated. |
822 * Fires once an authentication cookie has been validated. |
760 * |
823 * |
761 * @since 2.7.0 |
824 * @since 2.7.0 |
762 * |
825 * |
763 * @param string[] $cookie_elements An array of data for the authentication cookie. |
826 * @param string[] $cookie_elements { |
|
827 * Authentication cookie components. |
|
828 * |
|
829 * @type string $username User's username. |
|
830 * @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
831 * @type string $token User's session token used. |
|
832 * @type string $hmac The security hash for the cookie. |
|
833 * @type string $scheme The cookie scheme to use. |
|
834 * } |
764 * @param WP_User $user User object. |
835 * @param WP_User $user User object. |
765 */ |
836 */ |
766 do_action( 'auth_cookie_valid', $cookie_elements, $user ); |
837 do_action( 'auth_cookie_valid', $cookie_elements, $user ); |
767 |
838 |
768 return $user->ID; |
839 return $user->ID; |
826 * |
897 * |
827 * @since 2.7.0 |
898 * @since 2.7.0 |
828 * |
899 * |
829 * @param string $cookie Authentication cookie. |
900 * @param string $cookie Authentication cookie. |
830 * @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'. |
901 * @param string $scheme Optional. The cookie scheme to use: 'auth', 'secure_auth', or 'logged_in'. |
831 * @return string[]|false Authentication cookie components. |
902 * @return string[]|false { |
|
903 * Authentication cookie components. None of the components should be assumed |
|
904 * to be valid as they come directly from a client-provided cookie value. If |
|
905 * the cookie value is malformed, false is returned. |
|
906 * |
|
907 * @type string $username User's username. |
|
908 * @type string $expiration The time the cookie expires as a UNIX timestamp. |
|
909 * @type string $token User's session token used. |
|
910 * @type string $hmac The security hash for the cookie. |
|
911 * @type string $scheme The cookie scheme to use. |
|
912 * } |
832 */ |
913 */ |
833 function wp_parse_auth_cookie( $cookie = '', $scheme = '' ) { |
914 function wp_parse_auth_cookie( $cookie = '', $scheme = '' ) { |
834 if ( empty( $cookie ) ) { |
915 if ( empty( $cookie ) ) { |
835 switch ( $scheme ) { |
916 switch ( $scheme ) { |
836 case 'auth': |
917 case 'auth': |
1567 * others to be added. |
1648 * others to be added. |
1568 * |
1649 * |
1569 * @since 3.7.0 |
1650 * @since 3.7.0 |
1570 * |
1651 * |
1571 * @param string[] $emails An array of email addresses to receive a comment notification. |
1652 * @param string[] $emails An array of email addresses to receive a comment notification. |
1572 * @param int $comment_id The comment ID. |
1653 * @param string $comment_id The comment ID as a numeric string. |
1573 */ |
1654 */ |
1574 $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); |
1655 $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); |
1575 $emails = array_filter( $emails ); |
1656 $emails = array_filter( $emails ); |
1576 |
1657 |
1577 // If there are no addresses to send the comment to, bail. |
1658 // If there are no addresses to send the comment to, bail. |
1588 * By default, comment authors aren't notified of their comments on their own |
1669 * By default, comment authors aren't notified of their comments on their own |
1589 * posts. This filter allows you to override that. |
1670 * posts. This filter allows you to override that. |
1590 * |
1671 * |
1591 * @since 3.8.0 |
1672 * @since 3.8.0 |
1592 * |
1673 * |
1593 * @param bool $notify Whether to notify the post author of their own comment. |
1674 * @param bool $notify Whether to notify the post author of their own comment. |
1594 * Default false. |
1675 * Default false. |
1595 * @param int $comment_id The comment ID. |
1676 * @param string $comment_id The comment ID as a numeric string. |
1596 */ |
1677 */ |
1597 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); |
1678 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); |
1598 |
1679 |
1599 // The comment was left by the author. |
1680 // The comment was left by the author. |
1600 if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { |
1681 if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { |
1723 * Filters the comment notification email text. |
1804 * Filters the comment notification email text. |
1724 * |
1805 * |
1725 * @since 1.5.2 |
1806 * @since 1.5.2 |
1726 * |
1807 * |
1727 * @param string $notify_message The comment notification email text. |
1808 * @param string $notify_message The comment notification email text. |
1728 * @param int $comment_id Comment ID. |
1809 * @param string $comment_id Comment ID as a numeric string. |
1729 */ |
1810 */ |
1730 $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); |
1811 $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); |
1731 |
1812 |
1732 /** |
1813 /** |
1733 * Filters the comment notification email subject. |
1814 * Filters the comment notification email subject. |
1734 * |
1815 * |
1735 * @since 1.5.2 |
1816 * @since 1.5.2 |
1736 * |
1817 * |
1737 * @param string $subject The comment notification email subject. |
1818 * @param string $subject The comment notification email subject. |
1738 * @param int $comment_id Comment ID. |
1819 * @param string $comment_id Comment ID as a numeric string. |
1739 */ |
1820 */ |
1740 $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); |
1821 $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); |
1741 |
1822 |
1742 /** |
1823 /** |
1743 * Filters the comment notification email headers. |
1824 * Filters the comment notification email headers. |
1744 * |
1825 * |
1745 * @since 1.5.2 |
1826 * @since 1.5.2 |
1746 * |
1827 * |
1747 * @param string $message_headers Headers for the comment notification email. |
1828 * @param string $message_headers Headers for the comment notification email. |
1748 * @param int $comment_id Comment ID. |
1829 * @param string $comment_id Comment ID as a numeric string. |
1749 */ |
1830 */ |
1750 $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); |
1831 $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); |
1751 |
1832 |
1752 foreach ( $emails as $email ) { |
1833 foreach ( $emails as $email ) { |
1753 wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
1834 wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
2783 * @param mixed $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash, |
2864 * @param mixed $id_or_email The avatar to retrieve. Accepts a user_id, Gravatar MD5 hash, |
2784 * user email, WP_User object, WP_Post object, or WP_Comment object. |
2865 * user email, WP_User object, WP_Post object, or WP_Comment object. |
2785 * @param int $size Square avatar width and height in pixels to retrieve. |
2866 * @param int $size Square avatar width and height in pixels to retrieve. |
2786 * @param string $default URL for the default image or a default type. Accepts '404', 'retro', 'monsterid', |
2867 * @param string $default URL for the default image or a default type. Accepts '404', 'retro', 'monsterid', |
2787 * 'wavatar', 'indenticon', 'mystery', 'mm', 'mysteryman', 'blank', or 'gravatar_default'. |
2868 * 'wavatar', 'indenticon', 'mystery', 'mm', 'mysteryman', 'blank', or 'gravatar_default'. |
2788 * Default is the value of the 'avatar_default' option, with a fallback of 'mystery'. |
2869 * @param string $alt Alternative text to use in the avatar image tag. |
2789 * @param string $alt Alternative text to use in the avatar image tag. Default empty. |
|
2790 * @param array $args Arguments passed to get_avatar_data(), after processing. |
2870 * @param array $args Arguments passed to get_avatar_data(), after processing. |
2791 */ |
2871 */ |
2792 return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); |
2872 return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); |
2793 } |
2873 } |
2794 endif; |
2874 endif; |