' . esc_html__( 'Privacy policy', 'postaramail' ) . '' : ''; } private static function field( $where ) { if ( 'notice' === self::mode( $where ) ) { echo '

' . esc_html( self::notice_text( $where ) ) . wp_kses( self::privacy_link(), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ) ) . '

'; return; } echo '

'; } public static function reg_field() { self::field( 'reg' ); } public static function woo_field() { self::field( 'woo' ); } public static function comment_field() { echo '

'; } // ---------- Reading the visitor's choice ---------- /** The wording the person saw and agreed to (kept in PostaraMail as proof), or '' if they did not agree. */ private static function consent_for( $where ) { // phpcs:disable WordPress.Security.NonceVerification.Missing -- read-only flags on core forms that verify their own nonces. if ( 'notice' === self::mode( $where ) && ! empty( $_POST['pm_notice'] ) ) { return self::notice_text( $where ); } if ( ! empty( $_POST['pm_optin'] ) ) { return self::checkbox_label(); } // phpcs:enable return ''; } /** "notice" when the person was only told; "optin" when they ticked a box. */ private static function method_for( $where ) { return ( 'notice' === self::mode( $where ) && ! empty( $_POST['pm_notice'] ) ) ? 'notice' : 'optin'; // phpcs:ignore WordPress.Security.NonceVerification.Missing } private static function queue( $email, $first, $last, $source, $consent, $method, $country = '' ) { $geo = PostaraMail_Geo::for_request(); // captured now: the background send runs from the server, not the visitor PostaraMail_Queue::push_and_spawn( array( 'email' => $email, 'first' => $first, 'last' => $last, 'automation' => (int) get_option( 'postaramail_default_automation', 0 ), 'source' => $source, 'consent' => $consent . ' [' . $source . ']', 'method' => $method, 'country' => $country ? $country : $geo['country'], 'ip' => $country ? '' : $geo['ip'], ) ); } public static function on_register( $user_id ) { $consent = self::consent_for( 'reg' ); if ( '' === $consent ) { return; } $user = get_userdata( $user_id ); if ( ! $user || ! is_email( $user->user_email ) ) { return; } update_user_meta( $user_id, 'postaramail_optin', 'yes' ); self::queue( $user->user_email, $user->first_name ? $user->first_name : '', $user->last_name ? $user->last_name : '', 'registration', $consent, self::method_for( 'reg' ), PostaraMail_Geo::for_user( $user_id ) ); } public static function on_comment( $comment_id, $approved ) { if ( 'spam' === $approved || empty( $_POST['pm_optin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing return; } $c = get_comment( $comment_id ); if ( ! $c || ! is_email( $c->comment_author_email ) ) { return; } list( $first, $last ) = PostaraMail_Subscriber::split_name( $c->comment_author ); self::queue( $c->comment_author_email, $first, $last, 'comment', self::checkbox_label(), 'optin' ); } public static function on_order( $order_id ) { $consent = self::consent_for( 'woo' ); if ( '' === $consent || ! function_exists( 'wc_get_order' ) ) { return; } $order = wc_get_order( $order_id ); if ( ! $order || ! is_email( $order->get_billing_email() ) ) { return; } self::queue( $order->get_billing_email(), $order->get_billing_first_name(), $order->get_billing_last_name(), 'woocommerce', $consent, self::method_for( 'woo' ), strtoupper( (string) $order->get_billing_country() ) ); } }