541 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
541 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
542 } |
542 } |
543 |
543 |
544 // Has someone already signed up for this username? |
544 // Has someone already signed up for this username? |
545 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); |
545 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); |
546 if ( null != $signup ) { |
546 if ( $signup instanceof stdClass ) { |
547 $registered_at = mysql2date( 'U', $signup->registered ); |
547 $registered_at = mysql2date( 'U', $signup->registered ); |
548 $now = time(); |
548 $now = time(); |
549 $diff = $now - $registered_at; |
549 $diff = $now - $registered_at; |
550 // If registered more than two days ago, cancel registration and let this signup go through. |
550 // If registered more than two days ago, cancel registration and let this signup go through. |
551 if ( $diff > 2 * DAY_IN_SECONDS ) { |
551 if ( $diff > 2 * DAY_IN_SECONDS ) { |
554 $errors->add( 'user_name', __( 'That username is currently reserved but may be available in a couple of days.' ) ); |
554 $errors->add( 'user_name', __( 'That username is currently reserved but may be available in a couple of days.' ) ); |
555 } |
555 } |
556 } |
556 } |
557 |
557 |
558 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); |
558 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); |
559 if ( null != $signup ) { |
559 if ( $signup instanceof stdClass ) { |
560 $diff = time() - mysql2date( 'U', $signup->registered ); |
560 $diff = time() - mysql2date( 'U', $signup->registered ); |
561 // If registered more than two days ago, cancel registration and let this signup go through. |
561 // If registered more than two days ago, cancel registration and let this signup go through. |
562 if ( $diff > 2 * DAY_IN_SECONDS ) { |
562 if ( $diff > 2 * DAY_IN_SECONDS ) { |
563 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
563 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
564 } else { |
564 } else { |
706 // Check if the domain/path has been used already. |
706 // Check if the domain/path has been used already. |
707 if ( is_subdomain_install() ) { |
707 if ( is_subdomain_install() ) { |
708 $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); |
708 $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); |
709 $path = $base; |
709 $path = $base; |
710 } else { |
710 } else { |
711 $mydomain = "$domain"; |
711 $mydomain = $domain; |
712 $path = $base . $blogname . '/'; |
712 $path = $base . $blogname . '/'; |
713 } |
713 } |
714 if ( domain_exists( $mydomain, $path, $current_network->id ) ) { |
714 if ( domain_exists( $mydomain, $path, $current_network->id ) ) { |
715 $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
715 $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
716 } |
716 } |
722 } |
722 } |
723 |
723 |
724 // Has someone already signed up for this domain? |
724 // Has someone already signed up for this domain? |
725 // TODO: Check email too? |
725 // TODO: Check email too? |
726 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); |
726 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); |
727 if ( ! empty( $signup ) ) { |
727 if ( $signup instanceof stdClass ) { |
728 $diff = time() - mysql2date( 'U', $signup->registered ); |
728 $diff = time() - mysql2date( 'U', $signup->registered ); |
729 // If registered more than two days ago, cancel registration and let this signup go through. |
729 // If registered more than two days ago, cancel registration and let this signup go through. |
730 if ( $diff > 2 * DAY_IN_SECONDS ) { |
730 if ( $diff > 2 * DAY_IN_SECONDS ) { |
731 $wpdb->delete( |
731 $wpdb->delete( |
732 $wpdb->signups, |
732 $wpdb->signups, |
926 /** |
926 /** |
927 * Filters whether to bypass the new site email notification. |
927 * Filters whether to bypass the new site email notification. |
928 * |
928 * |
929 * @since MU (3.0.0) |
929 * @since MU (3.0.0) |
930 * |
930 * |
931 * @param string|bool $domain Site domain. |
931 * @param string|false $domain Site domain, or false to prevent the email from sending. |
932 * @param string $path Site path. |
932 * @param string $path Site path. |
933 * @param string $title Site title. |
933 * @param string $title Site title. |
934 * @param string $user_login User login name. |
934 * @param string $user_login User login name. |
935 * @param string $user_email User email address. |
935 * @param string $user_email User email address. |
936 * @param string $key Activation key created in wpmu_signup_blog(). |
936 * @param string $key Activation key created in wpmu_signup_blog(). |
937 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
937 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
938 */ |
938 */ |
939 if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user_login, $user_email, $key, $meta ) ) { |
939 if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user_login, $user_email, $key, $meta ) ) { |
940 return false; |
940 return false; |
941 } |
941 } |
942 |
942 |
1573 */ |
1573 */ |
1574 return apply_filters( 'domain_exists', $result, $domain, $path, $network_id ); |
1574 return apply_filters( 'domain_exists', $result, $domain, $path, $network_id ); |
1575 } |
1575 } |
1576 |
1576 |
1577 /** |
1577 /** |
1578 * Notify a user that their blog activation has been successful. |
1578 * Notifies the site administrator that their site activation was successful. |
1579 * |
1579 * |
1580 * Filter {@see 'wpmu_welcome_notification'} to disable or bypass. |
1580 * Filter {@see 'wpmu_welcome_notification'} to disable or bypass. |
1581 * |
1581 * |
1582 * Filter {@see 'update_welcome_email'} and {@see 'update_welcome_subject'} to |
1582 * Filter {@see 'update_welcome_email'} and {@see 'update_welcome_subject'} to |
1583 * modify the content and subject line of the notification email. |
1583 * modify the content and subject line of the notification email. |
1584 * |
1584 * |
1585 * @since MU (3.0.0) |
1585 * @since MU (3.0.0) |
1586 * |
1586 * |
1587 * @param int $blog_id Blog ID. |
1587 * @param int $blog_id Site ID. |
1588 * @param int $user_id User ID. |
1588 * @param int $user_id User ID. |
1589 * @param string $password User password. |
1589 * @param string $password User password, or "N/A" if the user account is not new. |
1590 * @param string $title Site title. |
1590 * @param string $title Site title. |
1591 * @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id. |
1591 * @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id. |
1592 * @return bool |
1592 * @return bool Whether the email notification was sent. |
1593 */ |
1593 */ |
1594 function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) { |
1594 function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) { |
1595 $current_network = get_network(); |
1595 $current_network = get_network(); |
1596 |
1596 |
1597 /** |
1597 /** |
1598 * Filters whether to bypass the welcome email after site activation. |
1598 * Filters whether to bypass the welcome email sent to the site administrator after site activation. |
1599 * |
1599 * |
1600 * Returning false disables the welcome email. |
1600 * Returning false disables the welcome email. |
1601 * |
1601 * |
1602 * @since MU (3.0.0) |
1602 * @since MU (3.0.0) |
1603 * |
1603 * |
1604 * @param int|bool $blog_id Blog ID. |
1604 * @param int|false $blog_id Site ID, or false to prevent the email from sending. |
1605 * @param int $user_id User ID. |
1605 * @param int $user_id User ID of the site administrator. |
1606 * @param string $password User password. |
1606 * @param string $password User password, or "N/A" if the user account is not new. |
1607 * @param string $title Site title. |
1607 * @param string $title Site title. |
1608 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1608 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1609 */ |
1609 */ |
1610 if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) { |
1610 if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) { |
1611 return false; |
1611 return false; |
1612 } |
1612 } |
1613 |
1613 |
1643 $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email ); |
1643 $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email ); |
1644 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1644 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
1645 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
1645 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
1646 |
1646 |
1647 /** |
1647 /** |
1648 * Filters the content of the welcome email after site activation. |
1648 * Filters the content of the welcome email sent to the site administrator after site activation. |
1649 * |
1649 * |
1650 * Content should be formatted for transmission via wp_mail(). |
1650 * Content should be formatted for transmission via wp_mail(). |
1651 * |
1651 * |
1652 * @since MU (3.0.0) |
1652 * @since MU (3.0.0) |
1653 * |
1653 * |
1654 * @param string $welcome_email Message body of the email. |
1654 * @param string $welcome_email Message body of the email. |
1655 * @param int $blog_id Blog ID. |
1655 * @param int $blog_id Site ID. |
1656 * @param int $user_id User ID. |
1656 * @param int $user_id User ID of the site administrator. |
1657 * @param string $password User password. |
1657 * @param string $password User password, or "N/A" if the user account is not new. |
1658 * @param string $title Site title. |
1658 * @param string $title Site title. |
1659 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1659 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. |
1660 */ |
1660 */ |
1661 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
1661 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
1662 |
1662 |
1676 |
1676 |
1677 /* translators: New site notification email subject. 1: Network title, 2: New site title. */ |
1677 /* translators: New site notification email subject. 1: Network title, 2: New site title. */ |
1678 $subject = __( 'New %1$s Site: %2$s' ); |
1678 $subject = __( 'New %1$s Site: %2$s' ); |
1679 |
1679 |
1680 /** |
1680 /** |
1681 * Filters the subject of the welcome email after site activation. |
1681 * Filters the subject of the welcome email sent to the site administrator after site activation. |
1682 * |
1682 * |
1683 * @since MU (3.0.0) |
1683 * @since MU (3.0.0) |
1684 * |
1684 * |
1685 * @param string $subject Subject of the email. |
1685 * @param string $subject Subject of the email. |
1686 */ |
1686 */ |
1687 $subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) ); |
1687 $subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) ); |
1688 |
1688 |
1689 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
1689 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
|
1690 |
|
1691 if ( $switched_locale ) { |
|
1692 restore_previous_locale(); |
|
1693 } |
|
1694 |
|
1695 return true; |
|
1696 } |
|
1697 |
|
1698 /** |
|
1699 * Notifies the Multisite network administrator that a new site was created. |
|
1700 * |
|
1701 * Filter {@see 'send_new_site_email'} to disable or bypass. |
|
1702 * |
|
1703 * Filter {@see 'new_site_email'} to filter the contents. |
|
1704 * |
|
1705 * @since 5.6.0 |
|
1706 * |
|
1707 * @param int $site_id Site ID of the new site. |
|
1708 * @param int $user_id User ID of the administrator of the new site. |
|
1709 * @return bool Whether the email notification was sent. |
|
1710 */ |
|
1711 function wpmu_new_site_admin_notification( $site_id, $user_id ) { |
|
1712 $site = get_site( $site_id ); |
|
1713 $user = get_userdata( $user_id ); |
|
1714 $email = get_site_option( 'admin_email' ); |
|
1715 |
|
1716 if ( ! $site || ! $user || ! $email ) { |
|
1717 return false; |
|
1718 } |
|
1719 |
|
1720 /** |
|
1721 * Filters whether to send an email to the Multisite network administrator when a new site is created. |
|
1722 * |
|
1723 * Return false to disable sending the email. |
|
1724 * |
|
1725 * @since 5.6.0 |
|
1726 * |
|
1727 * @param bool $send Whether to send the email. |
|
1728 * @param WP_Site $site Site object of the new site. |
|
1729 * @param WP_User $user User object of the administrator of the new site. |
|
1730 */ |
|
1731 if ( ! apply_filters( 'send_new_site_email', true, $site, $user ) ) { |
|
1732 return false; |
|
1733 } |
|
1734 |
|
1735 $switched_locale = false; |
|
1736 $network_admin = get_user_by( 'email', $email ); |
|
1737 |
|
1738 if ( $network_admin ) { |
|
1739 // If the network admin email address corresponds to a user, switch to their locale. |
|
1740 $switched_locale = switch_to_locale( get_user_locale( $network_admin ) ); |
|
1741 } else { |
|
1742 // Otherwise switch to the locale of the current site. |
|
1743 $switched_locale = switch_to_locale( get_locale() ); |
|
1744 } |
|
1745 |
|
1746 $subject = sprintf( |
|
1747 /* translators: New site notification email subject. %s: Network title. */ |
|
1748 __( '[%s] New Site Created' ), |
|
1749 get_network()->site_name |
|
1750 ); |
|
1751 |
|
1752 $message = sprintf( |
|
1753 /* translators: New site notification email. 1: User login, 2: Site URL, 3: Site title. */ |
|
1754 __( |
|
1755 'New site created by %1$s |
|
1756 |
|
1757 Address: %2$s |
|
1758 Name: %3$s' |
|
1759 ), |
|
1760 $user->user_login, |
|
1761 get_site_url( $site->id ), |
|
1762 get_blog_option( $site->id, 'blogname' ) |
|
1763 ); |
|
1764 |
|
1765 $header = sprintf( |
|
1766 'From: "%1$s" <%2$s>', |
|
1767 _x( 'Site Admin', 'email "From" field' ), |
|
1768 $email |
|
1769 ); |
|
1770 |
|
1771 $new_site_email = array( |
|
1772 'to' => $email, |
|
1773 'subject' => $subject, |
|
1774 'message' => $message, |
|
1775 'headers' => $header, |
|
1776 ); |
|
1777 |
|
1778 /** |
|
1779 * Filters the content of the email sent to the Multisite network administrator when a new site is created. |
|
1780 * |
|
1781 * Content should be formatted for transmission via wp_mail(). |
|
1782 * |
|
1783 * @since 5.6.0 |
|
1784 * |
|
1785 * @param array $new_site_email { |
|
1786 * Used to build wp_mail(). |
|
1787 * |
|
1788 * @type string $to The email address of the recipient. |
|
1789 * @type string $subject The subject of the email. |
|
1790 * @type string $message The content of the email. |
|
1791 * @type string $headers Headers. |
|
1792 * } |
|
1793 * @param WP_Site $site Site object of the new site. |
|
1794 * @param WP_User $user User object of the administrator of the new site. |
|
1795 */ |
|
1796 $new_site_email = apply_filters( 'new_site_email', $new_site_email, $site, $user ); |
|
1797 |
|
1798 wp_mail( |
|
1799 $new_site_email['to'], |
|
1800 wp_specialchars_decode( $new_site_email['subject'] ), |
|
1801 $new_site_email['message'], |
|
1802 $new_site_email['headers'] |
|
1803 ); |
1690 |
1804 |
1691 if ( $switched_locale ) { |
1805 if ( $switched_locale ) { |
1692 restore_previous_locale(); |
1806 restore_previous_locale(); |
1693 } |
1807 } |
1694 |
1808 |
1968 $global_terms_recurse = 1; |
2082 $global_terms_recurse = 1; |
1969 } elseif ( 10 < $global_terms_recurse++ ) { |
2083 } elseif ( 10 < $global_terms_recurse++ ) { |
1970 return $term_id; |
2084 return $term_id; |
1971 } |
2085 } |
1972 |
2086 |
1973 $term_id = intval( $term_id ); |
2087 $term_id = (int) $term_id; |
1974 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); |
2088 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); |
1975 |
2089 |
1976 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); |
2090 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); |
1977 if ( null == $global_id ) { |
2091 if ( null == $global_id ) { |
1978 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); |
2092 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); |
2833 * Filters the contents of the email notification sent when the network admin email address is changed. |
2948 * Filters the contents of the email notification sent when the network admin email address is changed. |
2834 * |
2949 * |
2835 * @since 4.9.0 |
2950 * @since 4.9.0 |
2836 * |
2951 * |
2837 * @param array $email_change_email { |
2952 * @param array $email_change_email { |
2838 * Used to build wp_mail(). |
2953 * Used to build wp_mail(). |
2839 * |
2954 * |
2840 * @type string $to The intended recipient. |
2955 * @type string $to The intended recipient. |
2841 * @type string $subject The subject of the email. |
2956 * @type string $subject The subject of the email. |
2842 * @type string $message The content of the email. |
2957 * @type string $message The content of the email. |
2843 * The following strings have a special meaning and will get replaced dynamically: |
2958 * The following strings have a special meaning and will get replaced dynamically: |
2844 * - ###OLD_EMAIL### The old network admin email address. |
2959 * - ###OLD_EMAIL### The old network admin email address. |
2845 * - ###NEW_EMAIL### The new network admin email address. |
2960 * - ###NEW_EMAIL### The new network admin email address. |
2846 * - ###SITENAME### The name of the network. |
2961 * - ###SITENAME### The name of the network. |
2847 * - ###SITEURL### The URL to the site. |
2962 * - ###SITEURL### The URL to the site. |
2848 * @type string $headers Headers. |
2963 * @type string $headers Headers. |
2849 * } |
2964 * } |
2850 * @param string $old_email The old network admin email address. |
2965 * @param string $old_email The old network admin email address. |
2851 * @param string $new_email The new network admin email address. |
2966 * @param string $new_email The new network admin email address. |
2852 * @param int $network_id ID of the network. |
2967 * @param int $network_id ID of the network. |
2853 */ |
2968 */ |
2854 $email_change_email = apply_filters( 'network_admin_email_change_email', $email_change_email, $old_email, $new_email, $network_id ); |
2969 $email_change_email = apply_filters( 'network_admin_email_change_email', $email_change_email, $old_email, $new_email, $network_id ); |