• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Change user's style via PHP

#1
I'd like to change the style of all users that have got a custom preference field (nightmode) set to yes based on the time in the timezone that they are in. How would I go about doing this?

I need to get every single user ID that has nightmode enabled. Would I use XenForo connector to get all of these users or am I better directly accessing the MySQL database?
 

truonglv

Formerly Nobita.Kun
#3
This is maybe help.
PHP:
<?php
...

$db = XenForo_Application::getDb();
// style ID
$styleId = 0;
$users = $db->fetchAll('select * from xf_user where style_id = ? limit 10', $styleId);
...
 
#4
This is maybe help.
PHP:
<?php
...

$db = XenForo_Application::getDb();
// style ID
$styleId = 0;
$users = $db->fetchAll('select * from xf_user where style_id = ? limit 10', $styleId);
...
That's cool for getting the user but how do I go about updating the value without causing badly cached data to pop up?
 

Chris D

XenForo developer
Staff member
#5
PHP:
$userDw = XenForo_DataWriter::create('XenForo_DataWriter_User');
$userDw->setExistingData(123); // Replace 123 with the user ID of the user
$userDw->set('style_id', 456); // Replace 456 with the desired style ID
$userDw->save();
 
#6
PHP:
$userDw = XenForo_DataWriter::create('XenForo_DataWriter_User');
$userDw->setExistingData(123); // Replace 123 with the user ID of the user
$userDw->set('style_id', 456); // Replace 456 with the desired style ID
$userDw->save();
Thank you for responding. We're now up and running!