Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/update success error messages to wp admin notices #85

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add WP admin notices to plugin settings page
  • Loading branch information
MaxwellGarceau committed Dec 19, 2024
commit b97dc72725848b059d7e07c8b59b363d226ee38d
111 changes: 74 additions & 37 deletions mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,44 @@ function mailchimp_sf_global_msg( $msg = null ) {
return true;
}

/**
* Display success admin notice.
*
* NOTE: WordPress localization i18n functionality should be done
* on string literals outside of this function in order to work
* correctly.
*
* For more info read here: https://salferrarello.com/why-__-needs-a-hardcoded-string-in-wordpress/
*
* @since 1.7.0
*/
function mailchimp_sf_admin_notice_success( string $msg ): void {
?>
<div class="notice notice-success is-dismissible">
<p><?php echo $msg; ?></p>
</div>
<?php
}

/**
* Display error admin notice.
*
* NOTE: WordPress localization i18n functionality should be done
* on string literals outside of this function in order to work
* correctly.
*
* For more info read here: https://salferrarello.com/why-__-needs-a-hardcoded-string-in-wordpress/
*
* @since 1.7.0
*/
function mailchimp_sf_admin_notice_error( string $msg ): void {
?>
<div class="notice notice-error">
<p><?php echo $msg; ?></p>
</div>
<?php
}

/**
* Sets the default options for the option form
*
Expand Down Expand Up @@ -486,65 +524,65 @@ function mailchimp_sf_save_general_form_settings() {
// IF NOT DEV MODE
if ( isset( $_POST['mc_use_javascript'] ) ) {
update_option( 'mc_use_javascript', 'on' );
$msg = '<p class="success_msg">' . esc_html__( 'Fancy Javascript submission turned On!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Fancy Javascript submission turned On!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
} elseif ( get_option( 'mc_use_javascript' ) !== 'off' ) {
update_option( 'mc_use_javascript', 'off' );
$msg = '<p class="success_msg">' . esc_html__( 'Fancy Javascript submission turned Off!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Fancy Javascript submission turned Off!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
}

if ( isset( $_POST['mc_use_datepicker'] ) ) {
update_option( 'mc_use_datepicker', 'on' );
$msg = '<p class="success_msg">' . esc_html__( 'Datepicker turned On!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Datepicker turned On!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
} elseif ( get_option( 'mc_use_datepicker' ) !== 'off' ) {
update_option( 'mc_use_datepicker', 'off' );
$msg = '<p class="success_msg">' . esc_html__( 'Datepicker turned Off!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Datepicker turned Off!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
}

/*Enable double optin toggle*/
if ( isset( $_POST['mc_double_optin'] ) ) {
update_option( 'mc_double_optin', true );
$msg = '<p class="success_msg">' . esc_html__( 'Double opt-in turned On!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Double opt-in turned On!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
} elseif ( get_option( 'mc_double_optin' ) !== false ) {
update_option( 'mc_double_optin', false );
$msg = '<p class="success_msg">' . esc_html__( 'Double opt-in turned Off!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Double opt-in turned Off!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
}

/* NUKE the CSS! */
if ( isset( $_POST['mc_nuke_all_styles'] ) ) {
update_option( 'mc_nuke_all_styles', true );
$msg = '<p class="success_msg">' . esc_html__( 'Mailchimp CSS turned Off!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Mailchimp CSS turned Off!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
} elseif ( get_option( 'mc_nuke_all_styles' ) !== false ) {
update_option( 'mc_nuke_all_styles', false );
$msg = '<p class="success_msg">' . esc_html__( 'Mailchimp CSS turned On!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Mailchimp CSS turned On!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
}

/* Update existing */
if ( isset( $_POST['mc_update_existing'] ) ) {
update_option( 'mc_update_existing', true );
$msg = '<p class="success_msg">' . esc_html__( 'Update existing subscribers turned On!' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Update existing subscribers turned On!' );
mailchimp_sf_admin_notice_success( $msg );
} elseif ( get_option( 'mc_update_existing' ) !== false ) {
update_option( 'mc_update_existing', false );
$msg = '<p class="success_msg">' . esc_html__( 'Update existing subscribers turned Off!' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Update existing subscribers turned Off!' );
mailchimp_sf_admin_notice_success( $msg );
}

if ( isset( $_POST['mc_use_unsub_link'] ) ) {
update_option( 'mc_use_unsub_link', 'on' );
$msg = '<p class="success_msg">' . esc_html__( 'Unsubscribe link turned On!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Unsubscribe link turned On!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
} elseif ( get_option( 'mc_use_unsub_link' ) !== 'off' ) {
update_option( 'mc_use_unsub_link', 'off' );
$msg = '<p class="success_msg">' . esc_html__( 'Unsubscribe link turned Off!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Unsubscribe link turned Off!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
}

$content = isset( $_POST['mc_header_content'] ) ? wp_kses_post( wp_unslash( $_POST['mc_header_content'] ) ) : '';
Expand Down Expand Up @@ -601,8 +639,8 @@ function mailchimp_sf_save_general_form_settings() {
}
}

$msg = '<p class="success_msg">' . esc_html__( 'Successfully Updated your List Subscribe Form Settings!', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Successfully Updated your List Subscribe Form Settings!', 'mailchimp' );
mailchimp_sf_admin_notice_success( $msg );
}

/**
Expand All @@ -614,8 +652,8 @@ function mailchimp_sf_change_list_if_necessary() {
}

if ( empty( $_POST['mc_list_id'] ) ) {
$msg = '<p class="error_msg">' . esc_html__( 'Please choose a valid list', 'mailchimp' ) . '</p>';
mailchimp_sf_global_msg( $msg );
$msg = esc_html__( 'Please choose a valid list', 'mailchimp' );
mailchimp_sf_admin_notice_error( $msg );
return;
}

Expand Down Expand Up @@ -673,16 +711,15 @@ function mailchimp_sf_change_list_if_necessary() {
$igs_text .= sprintf( esc_html__( 'and %s Sets of Interest Groups', 'mailchimp' ), count( $igs ) );
}

$msg = '<p class="success_msg">' .
sprintf(
/* translators: %s: count (number) */
__( '<b>Success!</b> Loaded and saved the info for %d Merge Variables', 'mailchimp' ) . $igs_text,
count( $mv )
) . ' ' .
esc_html__( 'from your list' ) . ' "' . $list_name . '"<br/><br/>' .
esc_html__( 'Now you should either Turn On the Mailchimp Widget or change your options below, then turn it on.', 'mailchimp' ) . '</p>';
$msg = sprintf(
/* translators: %s: count (number) */
__( '<b>Success!</b> Loaded and saved the info for %d Merge Variables', 'mailchimp' ) . $igs_text,
count( $mv )
) . ' ' .
esc_html__( 'from your list' ) . ' "' . $list_name . '"<br/><br/>' .
esc_html__( 'Now you should either Turn On the Mailchimp Widget or change your options below, then turn it on.', 'mailchimp' );

mailchimp_sf_global_msg( $msg );
mailchimp_sf_admin_notice_success( $msg );
}
}
}
Expand Down