Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Hacking client websites live

More often than one would like, you need to make changes to a live web site. This can be due to working with a small budget or legacy systems, when there's no separate development environment available. For us it seems this is the case often with PHP based content management systems.

To reduce the chance of things going royally south, it’s useful to make the changes in a way that they are only visible if a certain condition is met. There are quite a few ways to achieve this and in this post we have written down our most often used code snippets ready for copy pasting.

Showing content only when a "secret" url parameter exists ( e.g. site.com?secretparam=1):

<?php

if( $_GET["secretparam"] && $_GET["secretparam"] == '1' ) {
     // Add extra CSS, JS files or do something else
}

Showing content for only certain user in Wordpress:

 <?php

 $user = wp_get_current_user();
 if ( is_user_logged_in() && $user->user_login == 'myadminuser' ) {
   // Add extra CSS, JS files or do something else   
 }

Showing a different Wordpress Theme for a certain logged in user (drop into plugin folder and activate):

<?php

/*
Plugin Name: Change theme for user
Description: Display different theme to user if logged in as YOURUSER
Author: Wingmen LTD
*/

add_filter('template', 'set_theme');
add_filter('option_template', 'set_theme');
add_filter('option_stylesheet', 'set_theme');
function set_theme($theme) {
    $current_user = wp_get_current_user();
    if ( !($current_user instanceof WP_User) )
        return $theme;

    if ( $current_user->user_login == 'YOURUSER' ) {
        $theme = 'mistralv2';
    }
    return $theme;
}

Showing content for only certain user in Drupal template:

<?php

Global $user;
if( $logged_in && $user->name == 'myadminuser' {
    // Add extra CSS, JS files or do something else
}

You can find more quick and dirty tips like this under the tag note-to-self.



This post first appeared on The Wingmen Journal, please read the originial post: here

Share the post

Hacking client websites live

×

Subscribe to The Wingmen Journal

Get updates delivered right to your inbox!

Thank you for your subscription

×