Skip to content

Instantly share code, notes, and snippets.

@vodanh1213
Created July 17, 2015 15:19
Show Gist options
  • Save vodanh1213/e649c5d52201d1ab701c to your computer and use it in GitHub Desktop.
Save vodanh1213/e649c5d52201d1ab701c to your computer and use it in GitHub Desktop.
mailchimp ms
add_action( 'admin_menu', 'ms_mailchim_admin_menu', 99 );
function ms_mailchim_admin_menu() {
add_submenu_page( 'membership2', __( "Mailchimp Subscribe" ), __( "Mailchimp Subscribe" ), 'manage_options', 'ms-mailchimp-subsribe', 'ms_mailchim_exec' );
}
function ms_mailchim_exec() {
?>
<div class="wrap">
<form method="post">
<input type="text" name="list_id" placeholder="Mailchimp list id">
<button type="submit">Import</button>
<?php echo wp_nonce_field( 'ms_import_mailchimp' ) ?>
</form>
</div>
<?php
}
add_action( 'wp_loaded', 'do_the_ms_mail_chimp_import' );
function do_the_ms_mail_chimp_import() {
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if ( wp_verify_nonce( $_POST['_wpnonce'], 'ms_import_mailchimp' ) ) {
$list_id = isset( $_POST['list_id'] ) ? $_POST['list_id'] : 0;
if ( $list_id == 0 ) {
return;
}
$users = get_users( array(
'role' => 'subscriber'
) );
foreach ( $users as $user ) {
if ( ! MS_Addon_Mailchimp::is_user_subscribed( $user->user_email, $list_id ) ) {
$member = new MS_Model_Member( $user->ID );
$ret = MS_Addon_Mailchimp::subscribe_user( $member, $list_id );
var_dump( $ret );
}
}
die;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment