Created
August 11, 2016 06:09
-
-
Save mattyza/d147d9773ccfc8827a23af64efe8bd3c to your computer and use it in GitHub Desktop.
Mailchimp integration connection admin notice example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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