'emails', 'msg' => $msg, ), brai_base_url() ) ); exit; } ); /** * Settings from the form on screen (saved or not), for previews and tests. * * @param array $raw The form's values, as sent. Cleaned field by field in brai_mail_sanitize(). * @return array */ function brai_mail_from_request( $raw ) { return brai_mail_logo( wp_parse_args( brai_mail_sanitize( $raw ), brai_mail_settings() ) ); } /* Live preview while editing. */ add_action( 'wp_ajax_brai_mail_preview', function () { check_ajax_referer( 'brai_mail_prev', 'pnonce' ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error(); } $s = brai_mail_from_request( isset( $_POST['s'] ) ? wp_unslash( $_POST['s'] ) : array() ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitised field by field in brai_mail_sanitize(). $step = min( 3, max( 1, isset( $_POST['step'] ) ? (int) $_POST['step'] : 1 ) ); $r = brai_sample_row(); if ( ! empty( $_POST['anon'] ) ) { $r['name'] = ''; } list( $subj, $html, $pre ) = brai_reminder_build( $r, $step, $s ); wp_send_json( array( 'subject' => $subj, 'pre' => $pre, 'html' => $html, ) ); } ); /* Send a test of what is on screen. */ add_action( 'wp_ajax_brai_mail_test_send', function () { check_ajax_referer( 'brai_mail_prev', 'pnonce' ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error( __( 'Not allowed.', 'basketwise' ) ); } $s = brai_mail_from_request( isset( $_POST['s'] ) ? wp_unslash( $_POST['s'] ) : array() ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitised field by field in brai_mail_sanitize(). $to = isset( $_POST['to'] ) ? sanitize_email( wp_unslash( $_POST['to'] ) ) : ''; $step = isset( $_POST['tstep'] ) ? (int) $_POST['tstep'] : 0; if ( ! $to ) { wp_send_json_error( __( 'Enter the email address to send the test to.', 'basketwise' ) ); } $steps = $step ? array( min( 3, max( 1, $step ) ) ) : range( 1, (int) $s['count'] ); $r = brai_sample_row(); $ok = 0; foreach ( $steps as $n ) { $ok += brai_send_reminder( $r, $n, $to, $s ) ? 1 : 0; } if ( $ok ) { /* translators: 1: number of emails, 2: address. */ wp_send_json_success( sprintf( _n( '%1$d test email sent to %2$s.', '%1$d test emails sent to %2$s.', $ok, 'basketwise' ), $ok, $to ) ); } wp_send_json_error( __( 'The email could not be sent. Check the site\'s email (SMTP) settings.', 'basketwise' ) ); } ); /** The Email settings screen. */ function brai_mail_admin() { $s = brai_mail_settings(); $base = brai_base_url(); $live = brai_rec_live(); $me = wp_get_current_user()->user_email; $cnt = (int) $s['count']; $allow = brai_form_kses(); $nm = function ( $k, $r = '' ) { return $r ? 's[' . $r . '][' . $k . ']' : 's[' . $k . ']'; }; $val = function ( $k, $r = '' ) use ( $s ) { return $r ? $s[ $r ][ $k ] : $s[ $k ]; }; $in = function ( $k, $r = '', $type = 'text', $extra = '' ) use ( $nm, $val ) { return ''; }; $ta = function ( $k, $r = '', $rows = 3 ) use ( $nm, $val ) { return ''; }; $sw = function ( $k, $label, $r = '', $desc = '' ) use ( $nm, $val ) { return ''; }; $col = function ( $k, $label ) use ( $nm, $val ) { return '
'; }; $fld = function ( $label, $html, $hint = '' ) { return '
' . $html . ( $hint ? '

' . esc_html( $hint ) . '

' : '' ) . '
'; }; $chips = '
' . esc_html__( 'Insert:', 'basketwise' ) . ''; foreach ( array( '{first_name}' => __( 'First name', 'basketwise' ), '{site_name}' => __( 'Shop name', 'basketwise' ), '{basket_total}' => __( 'Basket total', 'basketwise' ), '{item_count}' => __( 'Item count', 'basketwise' ), '{phone}' => __( 'Phone', 'basketwise' ), '{coupon}' => __( 'Discount code', 'basketwise' ), '{discount}' => __( 'Discount amount', 'basketwise' ), '{coupon_expiry}' => __( 'Code expiry', 'basketwise' ), ) as $p => $l ) { $chips .= ''; } $chips .= '
'; $msg = sanitize_key( brai_get( 'msg' ) ); $sm = brai_site_map( true ); $pal = brai_site_palette( true ); $sl = brai_site_logo_info(); $auto = ! empty( $s['logo_auto'] ); /* What to say under the logo while the emails follow the website logo. */ if ( $sl['ok'] ) { $auto_note = __( 'Using your website logo. If you change the logo on your site, the emails follow.', 'basketwise' ); } elseif ( $sl['url'] ) { /* translators: %s: file type, such as SVG. */ $auto_note = sprintf( __( 'Your website logo is a %s file, which many email apps cannot show, so the shop name is shown as text. Choose a PNG or JPG version below.', 'basketwise' ), strtoupper( $sl['type'] ) ); } else { $auto_note = __( 'No logo was found on your website, so the shop name is shown as text. Choose one below, or add a logo to your site and it will appear here.', 'basketwise' ); } $own_note = __( 'Using the image you chose.', 'basketwise' ); $no_note = __( 'No logo: the shop name is shown as text.', 'basketwise' ); $un = count( (array) get_option( 'brai_unsub_list', array() ) ); echo '
'; brai_nav( 'emails' ); if ( 'saved' === $msg ) { echo '

' . esc_html__( 'Saved.', 'basketwise' ) . ' ' . esc_html__( 'Your email settings are live.', 'basketwise' ) . '

'; } elseif ( 'reset' === $msg ) { echo '

' . esc_html__( 'Email settings have been reset to the defaults.', 'basketwise' ) . '

'; } ?>

' : '' . esc_html__( 'No logo', 'basketwise' ) . ''; ?>

' ) . $col( 'text', __( 'Text', 'basketwise' ) ) . $col( 'link', __( 'Product names', 'basketwise' ) ) . $col( 'bg', __( 'Page background', 'basketwise' ) ) . $col( 'footer_bg', __( 'Footer background', 'basketwise' ) ) . $col( 'footer_text', __( 'Footer text', 'basketwise' ) ), $allow ); ?>

→