It seems that Simple Pages does not support current_user(). I am using Omeka 2.2.2, the Guest User plugin and this code
<?php
$newuser=current_user();
if (!$newuser) {
?>
<h2>You must be a <a href="guest-user/user/register">registered</a> user and <a href="guest-user/user/login">logged in</a> to use this site.</h2>
<h5>If you have not registered or logged in yet, please use the links in the upper right hand corner to register or login. Thanks.</h5>
<?php }; ?>
and it makes no difference if a user is logged in or not, the page displays the same.
I have embedded similar code in .php files and have not had any problems. I can only assume that I am missing something. Any ideas?
The most recent version of Simple Pages no longer supports directly inserting PHP.
You'll need to either modify the index.php
file for your theme, or write a plugin with a shortcode to insert into the page.
Thanks for pointing me in the right direction. I created a simple plugin for the shortcode [checkuser] that looks like this:
class CheckUserPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array('initialize');
public function hookInitialize()
{
add_shortcode('checkuser', array($this, 'checkusercode'));
}
public function checkusercode($args, $view)
{
$newuser=current_user();
if ($newuser) {
$html = "<meta http-equiv=refresh content=0;URL=omeka-2.2.2/>";
} else {
$html='<h2>You must be a <a href="omeka-2.2.2/guest-user/user/register">registered</a> user and <a href="omeka-2.2.2/guest-user/user/login">logged in</a> to use this site.</h2><h5>If you have not registered or logged in yet, please use the links in the upper right hand corner. Thanks.</h5>';
}
return $html;
}
}
Then I just had to embed [checkuser] in the Simple Page and then if the user is not logged in, then they see the Simple Page telling them to log in; if logged in, then they are redirected to the default home page. Thanks again.
Well done, and thanks! This makes a great example of how to convert some of the things many people were doing via PHP in SimplePages into a basic plugin. I expect it will help many others, so thanks for posting your solution.