Change user's style via PHP

LandNetwork

Member
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?
 
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);
...
 
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?
 
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();
 
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!
 
Top Bottom