recipient(); if ( ! is_email( $to ) ) { return [ 'ok' => false, 'message' => __( 'No notification address is set for email capture.', 'trueplayer' ), ]; } $video_id = (int) ( $data['video_id'] ?? 0 ); $title = $video_id ? get_the_title( $video_id ) : ''; $email = (string) ( $data['email'] ?? '' ); $name = (string) ( $data['name'] ?? '' ); $subject = sprintf( /* translators: %s: video title. */ __( 'New subscriber from %s', 'trueplayer' ), $title !== '' ? $title : __( 'your video', 'trueplayer' ) ); $lines = [ sprintf( /* translators: %s: email address. */ __( 'Email: %s', 'trueplayer' ), $email ), ]; if ( '' !== $name ) { $lines[] = sprintf( /* translators: %s: subscriber name. */ __( 'Name: %s', 'trueplayer' ), $name ); } if ( $video_id ) { $lines[] = sprintf( /* translators: 1: video title, 2: video id. */ __( 'Video: %1$s (#%2$d)', 'trueplayer' ), $title, $video_id ); } $lines[] = sprintf( /* translators: %s: site name. */ __( 'Site: %s', 'trueplayer' ), get_bloginfo( 'name' ) ); $sent = wp_mail( $to, $subject, implode( "\n", $lines ) ); // A viewer must never be told their address was rejected because the // site's own mail transport is down — the capture itself succeeded, and // `subscriber.added` still carries it to any webhook that is listening. if ( ! $sent ) { // Mail transport failed; the capture itself still succeeded. unset( $sent ); } return [ 'ok' => true ]; } }