Show Simplenews block only to unsubscribed users

Last modified: March 7, 2009 - 16:50

To show the Simplenews block only to unsubscribed users you have to configure the block and copy the code into the box below Page specific visibility settings. Make sure to select the last radio button (Show if the following PHP code returns TRUE).

<?php
global $user;
if (
$user->subscriptions_subscribe !=0){
    return
TRUE;
  } else {
    return
FALSE;
}
?>

UPDATE:

In the override, I just added this (using phptemplate theme):

function phptemplate_simplenews_block($block) {
$output = '';
if ($block['subscribed'] != TRUE) { ..... original function code... }
return $output;
}


Thanks to facelikebambi for this update.

For 6.0:
taroza offers:

The code below will check if the user is subscribed to anything. If you have multiple newsletters defined, you may need to tweak the query.

<?php
// Show the block only when the user is not subscribed or is anonymous
global $user;
return !(
$user->uid && simplenews_get_subscription($user)->snid)
?>

This no longer works in 5.x,

facelikebambi - May 7, 2008 - 15:12

This no longer works in 5.x, but it can still be achieved by overriding theme_simplenews_block() instead.

In the override, I just added this (using phptemplate theme):

function phptemplate_simplenews_block($block) {
$output = '';
if ($block['subscribed'] != TRUE) { ..... original function code... }
return $output;
}

The code for 6.x

taroza - July 6, 2008 - 01:21

The code bellow will check if the user is subscribed to anything. If you have multiple newsletters defined, you may need to tweak the query.

<?php
// Show the block only when the user is not subscribed or is anonymous
global $user;
return !(
$user->uid && simplenews_get_subscription($user)->snid)
?>

Evaldas
---
www.linkedin.com/in/taroza
Optaros - www.optaros.com

Where is the master copy?

doublejosh - May 12, 2009 - 00:54

Where can I find the theme function code?

This works on 5.X (assuming

JamesV33 - March 13, 2009 - 09:13

This works on 5.X (assuming only one newsletter).

<?php
global $user;
return
db_num_rows(db_query("SELECT * FROM {simplenews_subscriptions} s WHERE s.mail = '%s'", $user->mail)) ? FALSE : TRUE;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.