| | 1699 | * Notifies the network administrator that a new site was created. |
| | 1700 | * |
| | 1701 | * Filter {@see 'wpmu_new_site_admin_notification'} to disable or bypass. |
| | 1702 | * |
| | 1703 | * Filter {@see 'wp_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 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( 'wpmu_new_site_admin_notification', 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 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( 'wp_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 | ); |
| | 1804 | |
| | 1805 | if ( $switched_locale ) { |
| | 1806 | restore_previous_locale(); |
| | 1807 | } |
| | 1808 | |
| | 1809 | return true; |
| | 1810 | } |
| | 1811 | |
| | 1812 | /** |