I have a wordpress site and I am trying to get the username info and usergroup info to be called into a WP template. The purpose of this is to check if they are in X usergroup to hide certain bits of content.
I know that using the following in a template spits out the logged-in username which works, but it wipes all the WP content and just displays the username on the page.
<?php
$fileDir =$_SERVER["DOCUMENT_ROOT"];
require_once($fileDir . '/forums/src/XF.php');
\XF::start('/hc');
$app = \XF::setupApp('XF\Pub\App');
$s = $app->session();
$uid = $s->get('userId');
if ($uid){
$finder = \XF::finder('XF:User');
$user = $finder->where('user_id', $uid)->fetchOne();
print_r($user->username);
}else{
echo 'guest';
}
?>
I haven't gone any further with this until I can find out what I need to do to keep the WP content intact when this is called and also how to get the usergroups the logged in persons is in.
My PHP is not brilliant so any help here would be appreciated.
I know that using the following in a template spits out the logged-in username which works, but it wipes all the WP content and just displays the username on the page.
<?php
$fileDir =$_SERVER["DOCUMENT_ROOT"];
require_once($fileDir . '/forums/src/XF.php');
\XF::start('/hc');
$app = \XF::setupApp('XF\Pub\App');
$s = $app->session();
$uid = $s->get('userId');
if ($uid){
$finder = \XF::finder('XF:User');
$user = $finder->where('user_id', $uid)->fetchOne();
print_r($user->username);
}else{
echo 'guest';
}
?>
I haven't gone any further with this until I can find out what I need to do to keep the WP content intact when this is called and also how to get the usergroups the logged in persons is in.
My PHP is not brilliant so any help here would be appreciated.