5
Do you mean $block.new_messages in modules/system/templates/blocks/system_block_user.html?
That's calculated in function b_system_user_show() in modules/system/blocks/system_blocks.php. Try this:
error_reporting(E_ALL); #*#DEBUG#
global $xoopsUser;
if (is_object($xoopsUser)) {
$pm_handler =& xoops_gethandler('privmessage');
$criteria = new CriteriaCompo(new Criteria('read_msg', 0));
$criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
$new_messages = $pm_handler->getCount($criteria);
echo "You have $new_messages new message(s).
n";
}
Since you're already checking $xoopsUser in the code you posted above, you really only need the body of the "if".