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

Programatically change style settings

Discussion in 'Styling and Customization Questions' started by MGSteve, Oct 11, 2011.

  1. MGSteve

    MGSteve Well-Known Member

    How easy / hard would it be to change the style settings via a cron job? (i.e. a separate PHP script, not an XF cron job)

    Why I hear you ask. Well, on my site we change the key colours of the site style to key into the header image. In VB we do it by overriding the stylesheet with another one, but I'd rather update the style data directly.

    How easy / hard is it to do this in XF?
  2. MGSteve

    MGSteve Well-Known Member

    no one got any ideas about this?
  3. Kier

    Kier XenForo Developer Staff Member

    I assume you just want to change palette colours, or do you want to edit colours defined specifically within CSS style properties?
  4. Kier

    Kier XenForo Developer Staff Member

    This should do what you want. Just edit the contents of the $properties array and $styleId to suit your own purpose, then run it with PHP on the command line or via cron.

    if (PHP_SAPI != 'cli')
    'This script may only be run at the command line.');

    if (!
    $fileDir '/full/path/to/xenforo';

    $fileDir '/library/XenForo/Autoloader.php');
    setupAutoloader($fileDir '/library');

    XenForo_Application::initialize($fileDir '/library'$fileDir);

    $definitions XenForo_Application::getDb()->fetchPairs('
        SELECT property_name, property_definition_id
        FROM xf_style_property_definition

    // specify the style you want to work with
    $styleId 4;

    // specify the properties you want to update
    $properties = array(
    $definitions['pageBackground'] => 'orange',
    $definitions['dimmedTextColor'] => 'hotpink',
    $definitions['primaryDarker'] => 'rgb(0,0,128)',
    $definitions['secondaryMedium'] => '#ff99ff',
    $definitions['imagePath'] => 'styles/myOtherStyle',


    'Updated specified properties.' PHP_EOL;
    infis, Fuhrmann and Darkimmortal like this.
  5. MGSteve

    MGSteve Well-Known Member

    Kier, you're a star, thank you :)
    Kier likes this.

Share This Page