]+)>/', $one, $m ) ) { $one = $m[1]; } $one = sanitize_email( trim( $one ) ); if ( is_email( $one ) ) { $to[] = strtolower( $one ); } } } $subject = mb_substr( trim( wp_strip_all_tags( html_entity_decode( (string) ( $mail['subject'] ?? '' ), ENT_QUOTES, 'UTF-8' ) ) ), 0, 200 ); foreach ( array_unique( $to ) as $email ) { $c = Nodebook_Contacts::find_by_email( $email ); if ( ! $c ) { continue; } // Mail to the team about the contact (new order notices) is not mail to the contact. $u = get_user_by( 'email', $email ); if ( $u && user_can( $u, Nodebook_Admin::cap() ) ) { continue; } $label = self::label( $source ); Nodebook_Activities::add( (int) $c['id'], 'email_out', /* translators: %s: email subject */ sprintf( __( 'Email sent: %s', 'nodebook' ), '' !== $subject ? $subject : __( '(no subject)', 'nodebook' ) ), array( 'user_id' => 0, 'data' => array_filter( array( 'source' => $label ) ), ) ); } } /** Which plugin is sending: its folder name, 'nodebook', or '' (WordPress itself or a theme). */ private static function source() { $plugins = wp_normalize_path( WP_PLUGIN_DIR ) . '/'; $mu = wp_normalize_path( WPMU_PLUGIN_DIR ) . '/'; $self = wp_normalize_path( dirname( NODEBOOK_FILE ) ) . '/'; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- finding the sending plugin. $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 50 ); // Only who called wp_mail() counts, not this listener. $from = 0; foreach ( $trace as $i => $f ) { if ( isset( $f['function'] ) && 'wp_mail' === $f['function'] && empty( $f['class'] ) ) { $from = $i; } } foreach ( array_slice( $trace, $from ) as $f ) { $file = isset( $f['file'] ) ? wp_normalize_path( $f['file'] ) : ''; if ( '' === $file || 0 === strpos( $file, $mu ) ) { continue; } if ( 0 === strpos( $file, $self ) ) { return 'nodebook'; } if ( 0 === strpos( $file, $plugins ) ) { $slug = strtok( substr( $file, strlen( $plugins ) ), '/' ); // Mail plugins (SMTP) only carry the mail: keep looking for who wrote it. if ( preg_match( '/smtp|mail-?log|postman|fluent-?smtp|sendgrid|mailgun|brevo|sendinblue|easy-wp-smtp|check-email/i', (string) $slug ) ) { continue; } return (string) $slug; } } return ''; } /** A plugin folder as people know it. */ private static function label( $slug ) { if ( '' === $slug ) { return __( 'WordPress', 'nodebook' ); } $known = array( 'woocommerce' => 'WooCommerce', 'ameliabooking' => 'Amelia', 'latepoint' => 'LatePoint', 'simply-schedule-appointments' => 'Simply Schedule Appointments', 'motopress-hotel-booking-lite' => 'MotoPress Hotel Booking', 'motopress-hotel-booking' => 'MotoPress Hotel Booking', 'contact-form-7' => 'Contact Form 7', 'wpforms-lite' => 'WPForms', 'wpforms' => 'WPForms', 'gravityforms' => 'Gravity Forms', 'ninja-forms' => 'Ninja Forms', 'fluentform' => 'Fluent Forms', 'formidable' => 'Formidable Forms', 'elementor-pro' => 'Elementor', 'mailpoet' => 'MailPoet', 'fluent-crm' => 'FluentCRM', 'easy-digital-downloads' => 'Easy Digital Downloads', 'bookly-responsive-appointment-booking-tool' => 'Bookly', ); if ( isset( $known[ $slug ] ) ) { return $known[ $slug ]; } if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } foreach ( get_plugins( '/' . $slug ) as $data ) { if ( ! empty( $data['Name'] ) ) { return wp_strip_all_tags( $data['Name'] ); } } return ucwords( str_replace( array( '-', '_' ), ' ', $slug ) ); } }