echo not working in JomSocial plugin

45 views Asked by At

I am making a JomSocial plugin to get name of the user but when I echo the name it is not displaying the name. Here is my code

<?php
defined('_JEXEC') or die('Restricted access');
require_once JPATH_ROOT .'/components/com_community/libraries/core.php';

class plgCommunityName extends JPlugin{

    function getUserDetails(){
        $cuser = CFactory::getUser();
        $name = $cuser->username;
        echo $name;
    }
}

?>

How can I do this ?

2

There are 2 answers

0
Dennis On

Try to return $name; instead of echo $name;

0
Sulibrat On

It should be rather:

$cuser  = CFactory::getUser();
$name = $cuser->getDisplayName();
echo $name;