Skip to content

Instantly share code, notes, and snippets.

@mattyza
Created August 11, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattyza/d147d9773ccfc8827a23af64efe8bd3c to your computer and use it in GitHub Desktop.
Save mattyza/d147d9773ccfc8827a23af64efe8bd3c to your computer and use it in GitHub Desktop.
Mailchimp integration connection admin notice example.
// Display an admin notice, if setup is required.
add_action( 'admin_notices', array( $this, 'maybe_display_admin_notices' ) );
/**
* Display an admin notice, if not on the integration screen and if the account isn't yet connected.
* @access public
* @since 1.0.0
* @return void
*/
public function maybe_display_admin_notices () {
if ( isset( $_GET['page'] ) && 'wc-settings' == $_GET['page'] && isset( $_GET['section'] ) && 'mailchimp' == $_GET['section'] ) return; // Don't show these notices on our admin screen.
// Find a different method of retrieving this value.
$api_key = WC()->integrations->integrations['mailchimp']->get_option( 'wc_mailchimp_api_key' );
if ( '' == $api_key ) {
$url = $this->get_settings_url();
echo '<div class="updated fade"><p>' . sprintf( __( '%sWooCommerce MailChimp is almost ready.%s To get started, %sconnect your MailChimp account%s.', 'woocommerce-mailchimp-integration' ), '<strong>', '</strong>', '<a href="' . esc_url( $url ) . '">', '</a>' ) . '</p></div>' . "\n";
}
} // End maybe_display_admin_notices()
/**
* Generate a URL to our specific settings screen.
* @access public
* @since 1.0.0
* @return string Generated URL.
*/
public function get_settings_url () {
$url = admin_url( 'admin.php' );
$url = add_query_arg( 'page', 'wc-settings', $url );
$url = add_query_arg( 'tab', 'integration', $url );
$url = add_query_arg( 'section', 'mailchimp', $url );
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment