Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

| Views: 1270
I've been trying to make some major changes to the theme on my blog recently and doing this on the live website is not a great idea, so I started looking into the FlatPress code to see how I could dynamically change the theme that it loads by specifying a URL parameter. The changes are straight forward, but do require modification of the core files.

The change is done in the core.system.php file. Specifically, inside the system_init() function. There is a call to the user_loggedin() function that I commented out and replaced with the lines of code shown below.
function system_init() {
//user_loggedin(); // comment this out and add the following 3 lines
if (user_loggedin() && isset($_GET['theme'])) {
$GLOBALS['fp_config']['general']['theme'] = $_GET['theme'];

My code checks for whether the user is logged in, because you don't want just any visitor switching the theme on the fly. It then looks for the 'theme' URL parameter and if that's set, it modifies the loaded FlatPress configuration to the new theme. Simple.

Note: Playing around with a live system is not ideal, a test system should be set up that addresses this issue directly. However, sometimes you do want to test a theme on the live system without rolling it out for everyone to see, in that case, this kind of modification is justified.


Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...