WC_Payment_Gateways::notify_admin_payment_gateway_enabled()
Email the site admin when a payment gateway has been enabled.
Method of the class: WC_Payment_Gateways{}
Hooks from the method
Return
true|false
. Whether the email was sent or not.
Usage
// private - for code of main (parent) class only $result = $this->notify_admin_payment_gateway_enabled( $gateway );
- $gateway(WC_Payment_Gateway) (required)
- The gateway that was enabled.
Changelog
Since 8.5.0 | Introduced. |
WC_Payment_Gateways::notify_admin_payment_gateway_enabled() WC Payment Gateways::notify admin payment gateway enabled code WC 9.4.2
private function notify_admin_payment_gateway_enabled( $gateway ) { $admin_email = get_option( 'admin_email' ); $user = get_user_by( 'email', $admin_email ); $username = $user ? $user->user_login : $admin_email; $gateway_title = $gateway->get_method_title(); $gateway_settings_url = esc_url_raw( self_admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $gateway->id ) ); $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $site_url = home_url(); /** * Allows adding to the addresses that receive payment gateway enabled notifications. * * @param array $email_addresses The array of email addresses to notify. * @param WC_Payment_Gateway $gateway The gateway that was enabled. * @return array The augmented array of email addresses to notify. * @since 8.5.0 */ $email_addresses = apply_filters( 'wc_payment_gateway_enabled_notification_email_addresses', array(), $gateway ); $email_addresses[] = $admin_email; $email_addresses = array_unique( array_filter( $email_addresses, function( $email_address ) { return filter_var( $email_address, FILTER_VALIDATE_EMAIL ); } ) ); $logger = wc_get_container()->get( LegacyProxy::class )->call_function( 'wc_get_logger' ); $logger->info( sprintf( 'Payment gateway enabled: "%s"', $gateway_title ) ); $email_text = sprintf( /* translators: Payment gateway enabled notification email. 1: Username, 2: Gateway Title, 3: Site URL, 4: Gateway Settings URL, 5: Admin Email, 6: Site Name, 7: Site URL. */ __( 'Howdy %1$s, The payment gateway "%2$s" was just enabled on this site: %3$s If this was intentional you can safely ignore and delete this email. If you did not enable this payment gateway, please log in to your site and consider disabling it here: %4$s This email has been sent to %5$s Regards, All at %6$s %7$s', 'woocommerce' ), $username, $gateway_title, $site_url, $gateway_settings_url, $admin_email, $site_name, $site_url ); if ( '' !== get_option( 'blogname' ) ) { $site_title = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); } else { $site_title = wp_parse_url( home_url(), PHP_URL_HOST ); } return wp_mail( $email_addresses, sprintf( /* translators: Payment gateway enabled notification email subject. %s1: Site title, $s2: Gateway title. */ __( '[%1$s] Payment gateway "%2$s" enabled', 'woocommerce' ), $site_title, $gateway_title ), $email_text ); }