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

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.
 fp-includes/core/core.system.php
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.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.