Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
Anonymous
ParticipantLittle late on the response, but you could add this to your functions.php file – it makes a shortcode that shows a simple unsubscribe form:
Code can be found here: http://pastie.org/10496351
add_shortcode('newsletter_unsubscribe','hos_newsletter_unsubscribe'); function hos_newsletter_unsubscribe($atts) { extract(shortcode_atts(array( 'class' => '', ), $atts)); $formcontent = '<script type="text/javascript"> //<![CDATA[ if (typeof newsletter_check !== "function") { window.newsletter_check = function (f) { var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/; if (!re.test(f.elements["ne"].value)) { alert("The email is not correct"); return false; } for (var i=1; i<20; i++) { if (f.elements["np" + i] && f.elements["np" + i].required && f.elements["np" + i].value == "") { alert(""); return false; } } if (f.elements["ny"] && !f.elements["ny"].checked) { alert("You must accept the privacy statement"); return false; } return true; } } //]]>; </script> <div class="newsletter newsletter-unsubscription"> <form method="post" action="" onsubmit="return newsletter_check(this)" _lpchecked="1"> <input type="hidden" name="form_action" value="unsubscribe"> <table cellspacing="0" cellpadding="3" border="0"> <!-- email --> <tbody><tr> <th>Email</th> <td align="left"><input class="newsletter-email" type="email" name="email_unsub" size="30" required=""></td> </tr> <tr> <td colspan="2" class="newsletter-td-submit"> <input class="newsletter-submit" type="submit" value="Unsubscribe"> </td> </tr> </tbody></table> </form> </div>'; if( "unsubscribe" == $_POST['form_action']) { global $wpdb; $email = sanitize_email($_POST['email_unsub']); $result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->newsletter WHERE /<code>email/</code> = %s ", $email ) ); if( 1 == $result ) { // Unsubscribe Message $content = '<h1>' . __('Successfully Unsubscribed','Newsletter') .'</h1>'; $content .= '<p>' . __('You have been successfully unsubscribed from our newsletter.','Newsletter') . '</p>'; } else { $content = '<h1>' . __('Unsubscribe','Newsletter') . '</h1>'; $content .= '<p class="red">' . __('That email address was not found.','Newsletter') . '</p>'; $content .= $formcontent; } } else { $content = '<h1>' . __('Unsubscribe','Newsletter') . '</h1>'; $content .= $formcontent; } return $content; }
Then where you want the unsubscription form place this shortcode:
[newsletter_unsubscribe]
The Form:
-
AuthorPosts
Viewing 1 post (of 1 total)