Created
August 27, 2010 14:09
-
-
Save nb/553423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Different theme | |
Description: Use a different theme on certain conditions | |
Author: Nikolay Bachiyski | |
Version: 1.0 | |
*/ | |
class Different_Theme { | |
function __construct() { | |
add_filter( 'stylesheet', array( &$this, 'theme_stylesheet' ) ); | |
add_filter( 'option_stylesheet', array( &$this, 'theme_stylesheet' ) ); | |
add_filter( 'template', array( &$this, 'theme_template' ) ); | |
add_filter( 'option_template', array( &$this, 'theme_template' ) ); | |
} | |
/** | |
* Decides whether the use a different theme from the current one. | |
* | |
* @return string|bool Returns a the relative path to the themes directory if a different | |
* theme should be used or false if the theme should not be changed | |
*/ | |
function change_theme_to( $current_theme ) { | |
/* | |
Example: | |
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'iPhone' ) !== false ) { | |
return 'iphone-theme'; | |
} | |
*/ | |
return $current_theme; | |
} | |
function theme_template( $current_theme_template ) { | |
$new_template = $this->change_theme_to( $current_theme_template ); | |
if ( $new_template != $current_theme_template ) { | |
// use parent template in case of a child theme | |
$theme_data = get_theme_data( get_theme_root(). "/$new_template/style.css" ); | |
if ( $theme_data['Template'] ) { | |
$new_template = $theme_data['Template']; | |
} | |
} | |
return $new_template; | |
} | |
function theme_stylesheet( $current_theme_stylesheet ) { | |
return $this->change_theme_to( $current_theme_stylesheet ); | |
} | |
} | |
$wp_plugin_different_theme = new Different_Theme; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment