Created
April 6, 2011 20:22
-
-
Save dashr/906440 to your computer and use it in GitHub Desktop.
simple drupal6 paywall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determine if this is a premium user with special access to content | |
* | |
* @param $user | |
* Bring in the user object to test its roles | |
* @return boolean | |
* True if this is a premium user | |
*/ | |
function is_Premium($user) { | |
// let the super user have access | |
if ($user->uid == 1) { | |
return true; | |
} | |
//allowed roles | |
$valid_roles = array ( | |
'Basic Member', | |
'Contributing Member' | |
); | |
// match against user's roles | |
if ( array_intersect($valid_roles, $user->roles) ) { | |
return true; | |
} | |
return false; | |
} | |
/* Usage: node-article.tpl.php | |
<?php if (!is_Premium($user)) : ?> | |
<?php echo $node->field_article_introduction[0]["view"]; ?> | |
<p><a href="/user/login?destination=<?php print urlencode($node->path) ?>">Login</a> or <a href="member signup form">Become a Member</a> to register.</p> | |
<?php else: ?> | |
<div class="content"> | |
<?php print $content ?> | |
</div> | |
<?php endif; ?> | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment