I'm trying to learn how to interpret results from print_r for a bridge plugin I'm developing.
Background
My first issue was setting editor capabilities receiving administrator capabilities. While working on it, I realized that only the first two capabilities in the array were being added. This is now fixed. However,
Moving Forward
I've now started to go back and look at the calls being made and inserting in wp_die, var_dump, and print_r in places to see if the results are as expected.
Now comes the question. The results are not as expected and maybe someone can explain why.
The Code
A file includes the function get_userdata( $user_id ). Within this file, there is a check for is_numeric, empty, and if !$user_id return false. Next, if !$user then to call a class which a method called fillUserData.
The fillUserData is as follows:
public static function fillUserData($visitor, $classObj, $user_id) {
if( $user_id != 0 ) {
global $XF;
$userModel = $XF->getModelFromCache('XenForo_Model_User');
$user = $userModel->getUserById($user_id, array('join' => XenForo_Model_User::FETCH_USER_FULL));
$classObj->userObj = $user;
echo '<pre>';
echo $user_id;
print_r( $classObj->userObj[username] );
echo '</pre>';
//die();
if( $user_id == $visitor->get('user_id') ) {
// doing stuff
return $classObj;
} else {
// doing stuff
return $classObj;
}
}
// return false;
echo 'This is a mess';
}
At this point I'm confused. I was expecting only one array returned. But several are returned within the theme (including default themes, etc).
This first one shows at the top left of the theme and is absolutely the one I expected. [Update: To clarify, this array is definitely for the currently logged in user]
Array
(
[user_id] => 3
[username] => Albert
[email] => albert@tuxreports.com
[gender] =>
[custom_title] =>
[language_id] => 1
[style_id] => 0
[timezone] => Europe/London
[visible] => 1
This next one is above the first post done by a different user. This totally is not what I was expecting. [Update: This array shows even when no one is logged into the site]
Array
(
[user_id] => 1
[username] => LPH
[email] => lph@tuxreports.com
[gender] =>
[custom_title] =>
[language_id] => 1
[style_id] => 0
[timezone] => Europe/London
[visible] => 1
[user_group_id] => 2
These arrays are being returned above another post done by a different user .... and not what I expected since there is a if ( $user_id != 0 )
conditional.
If I go into a single page then the print_r shows for that author of the post and not the user I'm logged in as ...
My question are:
Am I using $classObj->userObj = $user wrong? Why is the author of WordPress blog posts showing in a print_r when $user conditional suggests it should not?
Hopefully that is enough information for someone to explain to me why this is not working as expected. My knowledge is very weak (at best). Of course, if I should not be calling the class within a pluggable function then please suggest a better method.
Thank you!
$XF
object and that isn't WordPress code. You have not posted the code that links this code to WordPress, though you mentions some WordPress functions. And you have not explained what you are trying to accomplish. While you wrote quite a bit, you didn't explain much. Most everything is a black box. Right now, about all I have is that you probably replacedget_userdata
with... something.