Please help a php neophyte format this line of code!
May 4, 2008 6:58 PM   Subscribe

I am trying to get yshout (a shoutbox) working in my WordPress blog. I want the logged in members to be able to chat and have their member names used to identify their chat postings.

To do this I need to change this line of code in yshout's preferences.php:

$overrideNickname = null;

into something like this:

$overrideNickname = ?????;

where the ????? represents a php variable containing the logged in member's name.

yshout's preferences.php contains this advice:

// If you want to change the nickname, the line below is the one to modify.
// Simply set $overrideNickname to whatever variable you want to appear as the nickname,
// or leave it null to use the set nicknames.

$overrideNickname = null;

When I wasn't able to discover what to substitute for "null", I emailed yshout's creator and received the following instructions:

I'm not too familiar with Wordpress, but you need to find out how to get the
nickname of the current user into a php variable. From there, you simply set
$overrideNickname to that value, and hide the nickname input via CSS
so that people don't see it.

I tried to follow up but he doesn't appear to be available and unfortunately I'm somewhat pressed for time.

I am able to display logged in usernames elsewhere on my blog using a plugin called WP-UserOnline.

Here is my question: what variable is there in WP-UserOnline's code (below) that I can substitute for "null" (in $overrideNickname = null; ) and how must I format it?

TIA immensely!

// Print Member Name
if($members) {
$temp_member = ';
if(!function_exists('get_totalposts')) {
foreach($members as $member) {
$temp_member .= $member.$separator_members_browsingpage;
}
} else {
foreach($members as $member) {
$temp_member .= ''.
$member.'
'.$separator_members_browsingpage;
}
}
$template_browsingpage = str_replace('%USERONLINE_MEMBER_NAMES%',
substr($temp_member, 0, -strlen($separator_members_browsingpage)),
$template_browsingpage);
} else {
$template_browsingpage = str_replace('%USERONLINE_MEMBER_NAMES%',
', $template_browsingpage);
}
posted by ranebo to Computers & Internet (5 answers total)
 
This will probably do it.

(Incidentally, via first result googling "wordpress how to get username of current user")
posted by juv3nal at 11:45 PM on May 4, 2008


Response by poster: Thank you juv3nal.

I can see this is going to get me there. But there is something basic I don't understand. If I put the following code, for example, into a posting, it doesn't seem to function as php but rather just prints out as text:

<> get_currentuserinfo();

echo('Username: ' . $userdata->user_login . "\n");
echo('User level: ' . $userdata->user_level . "\n");
echo('User ID: ' . $userdata->ID . "\n");
?>
posted by ranebo at 2:01 AM on May 5, 2008


I imagine that "<>" at the beginning (instead of "<?") is just typo/transcription error..?

Otherwise, I don't know anything about wordpress, so hopefully someone more knowledgeable will come along.
posted by juv3nal at 2:32 AM on May 5, 2008


@ranebo: the likely reason that you can't put PHP code in there is that the system is actively working against that. Once you allow users to put PHP in there, they are able to do all kinds of things, including some bad ones. "Never trust user input."

Google gives these two decent-looking links among many:
some general good practices
an older LJ article, still valid

In general, the goal is to prevent the user from entering anything which will get executed by any interpreter on the system, including (but not limited to) PHP, SQL, and shell.

Good luck, and have fun learning about this!
posted by so at 5:35 AM on May 5, 2008


Response by poster: @so -- yes, I'm sure you are right. Thanks for the security perspective and resources.

@juv3nal -- thanks; I'm guessing that it was just this security factor that caused the "<>" you mention. I had cut and pasted the code exactly so it did, in fact, begin with the "<>
I appreciate both of your responses.
posted by ranebo at 5:56 AM on May 6, 2008


« Older An Encyclopedia of Exercise?   |   Ah, to be connected anywhere, anytime! Newer »
This thread is closed to new comments.