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

Programatically change style settings


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?


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?


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')
	die('This script may only be run at the command line.');

if (!class_exists('XenForo_Autoloader', false))
	$fileDir = '/full/path/to/xenforo';

	require_once($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',

	saveStylePropertiesInStyleFromInput($styleId, $properties);

echo 'Updated specified properties.' . PHP_EOL;