'; } public function admin_menu(){ add_options_page( 'Alternative theme switcher options', 'Alternative theme switcher', 8, 'ats_admin', array( $this, 'admin_generate_main' ) ); } public function admin_generate_main(){ include dirname(__FILE__).'/admin_main.php'; } public function admin_init() { register_setting( 'ats-options-group', 'ats_switchable_themes' ); register_setting( 'ats-options-group', 'ats_label' ); register_setting( 'ats-options-group', 'ats_default' ); add_option( 'ats_switchable_themes' ); add_option( 'ats_label' ); add_option( 'ats_default' ); } public function getThemes(){ $themeDirs = array(); // Get others themes $scanThemeDirs = scandir(get_theme_root()); foreach($scanThemeDirs as $scannedFile){ if (!preg_match("/\./", $scannedFile) && file_exists(get_theme_root().'/'.$scannedFile.'/style.css')) $themeDirs[] = $scannedFile.'/style.css'; } // Get alternative themes if (file_exists(get_theme_root().'/'.get_template().'/altThemes')){ $scanThemeDirs = scandir(get_theme_root().'/'.get_template().'/altThemes'); foreach($scanThemeDirs as $scannedFile){ if (!preg_match("/\./", $scannedFile) && file_exists(get_theme_root().'/'.get_template().'/altThemes/'.$scannedFile.'/style.css')) $themeDirs[] = get_template().'/altThemes/'.$scannedFile.'/style.css'; } } return $themeDirs; } public function render_string(){ $themes = get_option('ats_switchable_themes'); if (empty($themes) || empty($themes['theme'])) return ''; else { $string = '
'.get_option('ats_label').'
'; foreach($themes['theme'] as $pk=>$theme){ $string .= '
'; } } $string .= '
'; return $string; } public function render(){ echo $this->render_string(); } // Singleton pattern static private $instance = null; public static function getInstance(){ if (self::$instance == null) self::$instance = new altThemeSwitcher(); return self::$instance; } } altThemeSwitcher::getInstance(); ?>