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

XF 1.5 Switching Everyone's Styles Seasonally

#1
Hello,

Sorry to pester you all, but I've been trying to make a theoretically simple add-on that switches styles based on the date/season. I have no experience dealing with XenForo add-on development, so I was hoping that this would be a good place to start. I tried to use Fuhrmann's How to create a Cron Entry to move threads (with options!) as a guide/template considering it was a similar concept except modifying a User rather than a Thread. However modifying a User's style_id doesn't seem like that would be very effective since new users or guests likely wouldn't be affected. Is there a better approach?

Thank you,
Vince
 

Attachments

Jake B.

Well-known member
#2
You can update style_id to 0 in the user table to reset all users to the new default style, and you can modify the XF default style option to the ID you want and everyone (including guests) will see the new style instead
 
#3
Sorry, but how would one go about modifying default style option through code? I would assume you would just try to find using option model's getOptions and an option_id of "defaultStyleId" and then set option_value to 0, but the xf_option table looks a bit more exotic than the xf_user one? Or does the model and datawriter handle it for me?
 

Attachments

Brogan

XenForo moderator
Staff member
#4
Quite honestly, if it's just a case of changing a column in a table, I would just run a query, rather than create an add-on.
 

Jake B.

Well-known member
#5
Sorry, but how would one go about modifying default style option through code? I would assume you would just try to find using option model's getOptions and an option_id of "defaultStyleId" and then set option_value to 0, but the xf_option table looks a bit more exotic than the xf_user one? Or does the model and datawriter handle it for me?
You won't want to set option_value to 0, you'll want to set it to the ID of whatever theme you want to use
 
#6
Setting defaultStyleId to the style ID changes the Home > Options > Appearance > Default Style setting, but doesn't seem to affect the actual default style reflected in the Appearance > Styles default style radio buttons which are the ones that seem to matter. How do I get at that?
 

Jake B.

Well-known member
#7
Setting defaultStyleId to the style ID changes the Home > Options > Appearance > Default Style setting, but doesn't seem to affect the actual default style reflected in the Appearance > Styles default style radio buttons which are the ones that seem to matter. How do I get at that?
Ah, you'll also have to update the is_default (or something similar) in xf_style. Forgot it's done there too. That said, if you update the style using the DataWriter it might automatically update the option as well
 
#8
I really appreciate all the help. It doesn't appear to be in the xf_style and the property column just seems to host all sorts of CSS and HTML. I'm still looking around, but I can't seem to find some secondary default setting/property.
xf_style.PNG
 

Jake B.

Well-known member
#9
Hm, it must get cached with the data registry, don't have it in front of me currently, but that'd be my best guess

Edit: did you edit the option with the DataWriter or just a query?
 
#10
The DataWriter works great if you don't accidentally write to the wrong option by using conditionals array for option_id with getOptions rather than getOptionById . The problem is fixed and my intelligence non-existent. Thanks for all the help.