1. 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

Discussion in 'XenForo Development Discussions' started by LandNetwork, Aug 6, 2016.

  1. LandNetwork

    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?
     
  2. LandNetwork

    LandNetwork Member

    Still looking for an answer to this. Any help is appreciated :)
     
  3. Nobita.Kun

    Nobita.Kun Well-Known Member

    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);
    ...
     
    LandNetwork likes this.
  4. LandNetwork

    LandNetwork Member

    That's cool for getting the user but how do I go about updating the value without causing badly cached data to pop up?
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    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();
     
    LandNetwork likes this.
  6. LandNetwork

    LandNetwork Member

    Thank you for responding. We're now up and running!
     

Share This Page