DKGE
Member
Hello
I would like to learn more about interacting with XF.php
But so far i am unable to find documentation of what is available.
For example once you have the user as $user what are the options you can use. (example: $user->username)
I figured some stuff out by just testing and trying different things.
But i would love to know where i need to look for these options and know exactly how to use it.
Am i just overlooking a documentation somewhere or was it never documented?
My current search is to see if the member is banned, so far no luck.
Here is my test script to find these options so far.
I would like to learn more about interacting with XF.php
But so far i am unable to find documentation of what is available.
For example once you have the user as $user what are the options you can use. (example: $user->username)
I figured some stuff out by just testing and trying different things.
But i would love to know where i need to look for these options and know exactly how to use it.
Am i just overlooking a documentation somewhere or was it never documented?
My current search is to see if the member is banned, so far no luck.
Here is my test script to find these options so far.
PHP:
<?php
$dir = '/path/to/xenforo';
require($dir . '/src/XF.php');
\XF::start($dir);
$app = \XF::setupApp('XF\Pub\App');
$app->start(); // !! Needed for $visitor !!
$session = $app->session();
$uid = $session->get('userId');
$visitor = \XF::visitor(); // !! Needed for $visitor !!
// If user is not logged in, return guest
if ($uid){
$user = $app->finder('XF:User')->where('user_id', $uid)->fetchOne();
// User Name:
print_r("Username: " . $user->username . "<br>");
// User Admin Status:
if ($user->is_admin){
print_r("User is admin<br>");
} else {
print_r("User is not admin<br>");
}
// User ID:
print_r("User ID: " . $user->user_id . "<br>");
// Print all custom fields starting with test:
foreach ($user->Profile->custom_fields as $key => $value) {
if (strpos($key, 'test') === 0){
print_r($key . " : " . $value . "<br>");
}
}
// User Last Login:
print_r("Last Login: " . date("d-m-Y H:i:s", $user->Admin->last_login) . "<br>");
// User Groups:
print_r("Primary Group: " . $user->user_group_id . "<br>");
print_r("Secondary Groups: " . implode(', ', $user->secondary_group_ids) . "<br>");
// User Avatar URL:
$avatarUrl = $visitor->getAvatarUrl('m', null, true); // s, m, l, o => avatar sizes
print_r("Avatar: " . "<a href='" . $avatarUrl . "'>" . $avatarUrl . "</a><br>");
print_r("<img src='" . $avatarUrl . "'>");
// remove value from custom field
// $user->Profile->custom_fields->set('test1', "", 'admin_edit');
// $user->Profile->save();
// Add user to group 31
// $user->set('secondary_group_ids', array_merge($user->secondary_group_ids, [31]));
// $user->save();
// remove user from secondary group 31
// $user->set('secondary_group_ids', array_diff($user->secondary_group_ids, [31]));
// $user->save();
}else{
echo 'guest';
}