Unsubscribing from mailing list for anonymous user in simplenews I use the Simplenews module for newsletters of my site. But I don't send out mails, rather use the module for subscribing and unsubscribing. Now for the anonymous user it gets difficult to unsubscribe since the user doesn't get any mail other than the subscribe mail. I read the comment in https://drupal.org/node/337628 #6, but I don't think I have an option here.

So I want to add an unsubscribe button to my block. How can I do that?

Drupal Version - 7.22
Simplenews Version - 7.x-1.0
I needed the same thing, so I thought I'd share my solution.

In hook_form_alter():

  // Check that this is a simplenews form and the user is anonymous
  // If so, add an Unsubscribe button with a custom submit handler before the
  // default simplenews form submit handler is called
  if (strpos($form_id, 'simplenews_block_form') !== FALSE &amp;&amp; $user-&gt;uid == 0) {
    $form['unsubscribe'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Unsubscribe'),
    );

    $form['unsubscribe']['#submit'] = $form['#submit'];
    array_unshift($form['unsubscribe']['#submit'], 'custom_simplenews_form_unsubscribe');
  }


Then the custom submit handler will be something like this:

function custom_simplenews_form_unsubscribe(&amp;$form, &amp;$form_state) {
  // Change action to unsubscribe and exit so the simplenews handler will take over
  if ($form_state['clicked_button']['#value'] == 'Unsubscribe') {
    $form_state['values']['action'] = 'unsubscribe';
    $form_state['values']['submit'] = 'Unsubscribe';
  }
}


So, when control is passed to simplenews_block_form_submit() in simplenews.subscription.inc the user will be unsubscribed using the module's workflow.