Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
picocodes committed Jun 4, 2024
1 parent 04727bf commit 0e04d61
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
30 changes: 16 additions & 14 deletions build/Emails/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,30 +494,32 @@ public function send() {
'name' => sprintf( '%1$s - %2$s', esc_html( $this->name ), esc_html( $suffix ) ),
'subject' => noptin_parse_email_subject_tags( $this->get_subject(), true ),
'heading' => noptin_parse_email_content_tags( $this->get( 'heading' ), true ),
'content' => noptin_parse_email_content_tags( \Noptin_Email_Generator::handle_item_lists_shortcode( $this->content ), true ),
'content' => 'visual' === $type ? noptin_parse_email_content_tags( \Noptin_Email_Generator::handle_item_lists_shortcode( $this->content ), true ) : '',
'author' => $this->author,
'preview_text' => noptin_parse_email_content_tags( $this->get( 'preview_text' ), true ),
'footer_text' => noptin_parse_email_content_tags( $this->get( 'footer_text' ), true ),
)
);

foreach ( $args as $key => $value ) {
foreach ( array_keys( get_noptin_email_types() ) as $email_type ) {
$key = 'content_' . $email_type;
if ( $type !== $email_type || ! isset( $args[ $key ] ) ) {
$args[ $key ] = '';
continue;
}

// Check if the key starts with content_.
if ( 0 === strpos( $key, 'content_' ) ) {
$value = \Noptin_Email_Generator::handle_item_lists_shortcode( $value );
$value = \Noptin_Email_Generator::handle_item_lists_shortcode( $args[ $key ] );

// Parse paragraphs.
if ( 'content_normal' === $type ) {
$value = wpautop( trim( $value ) );
}
// Parse paragraphs.
if ( 'content_normal' === $type ) {
$value = wpautop( trim( $value ) );
}

$args[ $key ] = trim( noptin_parse_email_content_tags( $value, true ) );
$args[ $key ] = trim( noptin_parse_email_content_tags( $value, true ) );

// Strip HTML.
if ( 'content_plain_text' === $type && ! empty( $args[ $key ] ) ) {
$args[ $key ] = noptin_convert_html_to_text( $args[ $key ] );
}
// Strip HTML.
if ( 'content_plain_text' === $key && ! empty( $args[ $key ] ) ) {
$args[ $key ] = noptin_convert_html_to_text( $args[ $key ] );
}
}

Expand Down
2 changes: 1 addition & 1 deletion build/Emails/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public static function set_current_email( $email ) {
*/
public static function filter_last_send_date( $date ) {

if ( ! did_action( 'noptin_prepare_email_preview' ) && ! empty( self::$current_email ) ) {
if ( ( Preview::$simulation || ! did_action( 'noptin_prepare_email_preview' ) ) && ! empty( self::$current_email ) ) {
$last_date = get_post_meta( self::$current_email->id, '_noptin_last_send', true );

if ( ! empty( $last_date ) ) {
Expand Down
18 changes: 14 additions & 4 deletions build/Emails/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Preview {
*/
public static $mode = 'preview';

/**
* Whether or not this is a simulation.
*/
public static $simulation = false;

/**
* The current campaign.
*
Expand Down Expand Up @@ -86,10 +91,11 @@ public static function admin_preview( $template ) {
}

// Prepare the preview.
self::$mode = 'preview';
self::$campaign = new Email( get_post() );
$user = wp_get_current_user();
self::$user = array(
self::$simulation = ! empty( $_GET['noptin_simulate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
self::$mode = 'preview';
self::$campaign = new Email( get_post() );
$user = wp_get_current_user();
self::$user = array(
'email' => $user->user_email,
'cid' => get_the_ID(),
);
Expand Down Expand Up @@ -132,6 +138,10 @@ private static function render() {
wp_die( esc_html( $preview->get_error_message() ) );
}

if ( self::$simulation && ! empty( $GLOBALS['noptin_email_force_skip'] ) ) {
wp_die( esc_html( $GLOBALS['noptin_email_force_skip']['message'] ) );
}

echo $preview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit;
}
Expand Down
13 changes: 6 additions & 7 deletions build/Emails/Types/Recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,11 @@ public function schedule_campaign( $campaign, $is_saving = false ) {
*/
public function maybe_send_notification( $campaign_id ) {

delete_post_meta( $campaign_id, '_bulk_email_last_error' );

// Get the campaign.
$campaign = noptin_get_email_campaign_object( $campaign_id );
$campaign = noptin_get_email_campaign_object( $campaign_id );
$campaign_id = $campaign->id;

// Ensure that the campaign is still published.
if ( ! $campaign->can_send() ) {
return;
}
delete_post_meta( $campaign_id, '_bulk_email_last_error' );

// Reschedule next send.
$campaign->options['next_send'] = '';
Expand All @@ -555,6 +551,7 @@ public function maybe_send_notification( $campaign_id ) {

// Don't send if we already sent today.
if ( ! empty( $last_send ) && gmdate( 'Ymd', $last_send ) === gmdate( 'Ymd' ) && ! defined( 'NOPTIN_RESENDING_CAMPAIGN' ) ) {
$GLOBALS['noptin_email_force_send_error'] = 'Skipped sending campaign. Reason:- Already sent today.';
return;
}

Expand All @@ -570,6 +567,8 @@ public function maybe_send_notification( $campaign_id ) {
)
);

$GLOBALS['noptin_email_force_send_error'] = 'Skipped sending campaign. Reason:- ' . $result->get_error_message();

log_noptin_message( 'Skipped sending campaign:- ' . $campaign->name . '. Reason:- ' . $result->get_error_message() );
}
}
Expand Down

0 comments on commit 0e04d61

Please sign in to comment.