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,
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
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?
Where can I find the theme function code?
This works on 5.X (assuming
This works on 5.X (assuming only one newsletter).
<?phpglobal $user;
return db_num_rows(db_query("SELECT * FROM {simplenews_subscriptions} s WHERE s.mail = '%s'", $user->mail)) ? FALSE : TRUE;
?>