| 1593 | * Notify the admin about new site creation. |
| 1594 | * |
| 1595 | * Filter {@see 'wpmu_admin_notification'} to disable or bypass. |
| 1596 | * |
| 1597 | * Filter {@see 'update_admin_notification'} and {@see 'update_admin_notification_subject'} to |
| 1598 | * modify the content and subject line of the notification email. |
| 1599 | * |
| 1600 | * @param int $blog_id Site ID. |
| 1601 | * @param int $user_id User ID. |
| 1602 | * @param string $title Site title. |
| 1603 | * @return bool |
| 1604 | */ |
| 1605 | function wpmu_admin_notification( $blog_id, $user_id, $title ) { |
| 1606 | $current_network = get_network(); |
| 1607 | |
| 1608 | /** |
| 1609 | * Filters whether to bypass the admin notification email. |
| 1610 | * |
| 1611 | * Returning false disables the admin notification email. |
| 1612 | * |
| 1613 | * @param int|bool $blog_id Site ID. |
| 1614 | * @param int $user_id User ID. |
| 1615 | * @param string $title Site title. |
| 1616 | */ |
| 1617 | if ( ! apply_filters( 'wpmu_admin_notification', $blog_id, $user_id, $title ) ) { |
| 1618 | return false; |
| 1619 | } |
| 1620 | |
| 1621 | $user = get_userdata( $user_id ); |
| 1622 | |
| 1623 | $admin_notification = sprintf( |
| 1624 | /* translators: 1: user login, 2: site url, 3: site name/title */ |
| 1625 | __( |
| 1626 | 'New site created by %1$s |
| 1627 | |
| 1628 | Address: %2$s |
| 1629 | Name: %3$s' |
| 1630 | ), |
| 1631 | $user->user_login, |
| 1632 | get_site_url( $blog_id ), |
| 1633 | wp_unslash( $title ) |
| 1634 | ); |
| 1635 | |
| 1636 | /** |
| 1637 | * Filters the content of the admin notification email. |
| 1638 | * |
| 1639 | * Content should be formatted for transmission via wp_mail(). |
| 1640 | * |
| 1641 | * @param string $admin_notification Message body of the email. |
| 1642 | * @param int $blog_id Site ID. |
| 1643 | * @param int $user_id User ID. |
| 1644 | * @param string $title Site title. |
| 1645 | */ |
| 1646 | $admin_notification = apply_filters( 'update_admin_notification', $admin_notification, $blog_id, $user_id, $title ); |
| 1647 | $admin_email = get_site_option( 'admin_email' ); |
| 1648 | |
| 1649 | if ( empty( $admin_email ) ) { |
| 1650 | $admin_email = sanitize_email( 'support@' . $_SERVER['SERVER_NAME'] ); |
| 1651 | } |
| 1652 | |
| 1653 | $message_headers = sprintf( |
| 1654 | 'From: "%1$s" <%2$s>', |
| 1655 | _x( 'Site Admin', 'email "From" field' ), |
| 1656 | sanitize_email( $admin_email ) |
| 1657 | ); |
| 1658 | |
| 1659 | $message = $admin_notification; |
| 1660 | |
| 1661 | if ( empty( $current_network->site_name ) ) { |
| 1662 | $current_network->site_name = 'WordPress'; |
| 1663 | } |
| 1664 | |
| 1665 | /* translators: New site notification email subject. 1: Network name, 2: New site name */ |
| 1666 | $subject = sprintf( |
| 1667 | /* translators: %s: network name */ |
| 1668 | __( '[%s] New Site Created' ), |
| 1669 | $current_network->site_name |
| 1670 | ); |
| 1671 | |
| 1672 | /** |
| 1673 | * Filters the subject of the admin notification email. |
| 1674 | * |
| 1675 | * @param string $subject Subject of the email. |
| 1676 | */ |
| 1677 | $subject = apply_filters( 'update_admin_notification_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) ); |
| 1678 | wp_mail( $admin_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
| 1679 | |
| 1680 | return true; |
| 1681 | } |
| 1682 | |
| 1683 | /** |