Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.
Notice: I'm taking a break from blogging to focus on Atari Gamer . com, check it out!

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
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.


Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

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.
comments powered by Disqus
Other posts you may like...