Support » Plugin: Email Users » Shortcode For Unsubscribe Check Boxes

  • Hi All,

    For those who are using Email Users and need to provide their subscribers with an option to unsubscribe, here is a code for a shortcode that can be used to create an unsubscribe link anywhere on the website. First, copy and paste the code below in your functions.php or a blank plugin, then place the shortcode [subscription] anywhere on the site (such as a new page and preferably a password protected section) you want the check boxes to appear. Remember to provide a link to the page in the footer of your mass emails and newsletters!

    function email_users_opt_in_out(){
    	$id = get_current_user_id();
    	$notif = get_user_meta( $id, 'email_users_accept_notifications', true );
    	$mass = get_user_meta( $id, 'email_users_accept_mass_emails', true );
    	//This section for testin purposes
    	echo '<p>'.$notif.'</p>';
    	echo '<p>'.$mass.'</p>';
    	if($notif == "true"){
    		$notifications = "checked";	
    		$notifications = "";
    	//This section for testing purposes
    	echo "<p>Notifications:</p>";
    	echo "<p>".$notifications."</p>";
    	if($mass == "true"){
    		$mass_emails = "checked";
    		$mass_emails = "";
    	//This section for testing purposes
    	echo "<p>Mass Emails:</p>";
    	echo "<p>".$mass_emails."</p>";
    <div class="opt-form-container">
    <form id="new_post" name="new_post" method="post">
    			<h3>Email Preferences</h3>
    	<table class="form-table">
                	<input type="hidden" id="user_id_number" name="user_id_number" value=<?php echo $id; ?>></input>
    				<input type="checkbox"
    						<?php echo $notifications;?> ></input>
    				Accept to receive post or page notification emails<br/>
    				<input type="checkbox"
    						<?php echo $mass_emails;?> ></input>
    				Accept to receive emails sent to multiple recipients (but still accept emails sent only to me)			</td>
        <?php //wp_nonce_field( 'wps-frontend-post' ); ?>
        <p align="right"><input type="submit" value="Save Changes" tabindex="6" id="submit" name="submit" /></p>
    </div><!-- end of .opt-form-container -->
    add_shortcode( 'subscription', 'email_users_opt_in_out' );
    function save_post_if_submitted() {
        if ( isset($_POST['email_users_accept_notifications']) ) {
    		update_user_meta( $_POST['user_id_number'], 'email_users_accept_notifications', 'true' );
    		update_user_meta( $_POST['user_id_number'], 'email_users_accept_notifications', 'false' );
        if ( isset($_POST['email_users_accept_mass_emails']) ) {
    		update_user_meta( $_POST['user_id_number'], 'email_users_accept_mass_emails', 'true' );
    		update_user_meta( $_POST['user_id_number'], 'email_users_accept_mass_emails', 'false' );
  • The topic ‘Shortcode For Unsubscribe Check Boxes’ is closed to new replies.