function jr_mt_themes_field($field_name, $theme_name, $setting, $excl_current_theme)
{
    echo "<select id='{$field_name}' name='{$setting}" . "[{$field_name}]' size='1'>";
    if (empty($theme_name)) {
        $selected = 'selected="selected"';
    } else {
        $selected = '';
    }
    echo "<option value='' {$selected}></option>";
    foreach (jr_mt_all_themes() as $folder => $theme_obj) {
        if ($excl_current_theme) {
            if (jr_mt_current_theme('stylesheet') == $theme_obj['stylesheet'] && jr_mt_current_theme('template') == $theme_obj['template']) {
                //	Skip the Current Theme
                continue;
            }
        }
        if ($theme_name === $folder) {
            $selected = 'selected="selected"';
        } else {
            $selected = '';
        }
        $name = $theme_obj->Name;
        echo "<option value='{$folder}' {$selected}>{$name}</option>";
    }
    echo '</select>' . PHP_EOL;
}
Example #2
0
function jr_mt_theme($option)
{
    /*	The hooks that (indirectly) call this function are called repeatedly by WordPress, 
    		so do the checking once and store the values in a global array.
    		$jt_mt_theme['stylesheet'] - Stylesheet Name of Theme chosen
    		$jt_mt_theme['template'] - Template Name of Theme chosen
    		
    		Very important note:
    			- get_option( 'jr_mt_settings' ) ['ids']['theme'] is the Theme Subdirectory Name,
    			as opposed to the Template or Stylesheet Name for the Theme.
    			- likewise, the variable local variable $theme
    		These three different values for each Theme must be clearly separated, as all three usually
    		match, but do not have to, e.g. - Child Themes.
    	*/
    $GLOBALS['jr_mt_cache'] = TRUE;
    global $jr_mt_theme;
    if (!isset($jr_mt_theme)) {
        $jr_mt_theme = array();
    }
    if (!isset($jr_mt_theme[$option])) {
        $theme = jr_mt_chosen();
        if ($theme === FALSE) {
            //	Get both at once, to save a repeat of this logic later:
            $jr_mt_theme['stylesheet'] = jr_mt_current_theme('stylesheet');
            $jr_mt_theme['template'] = jr_mt_current_theme('template');
        } else {
            $themes = wp_get_themes();
            $jr_mt_theme['stylesheet'] = $themes[$theme]->stylesheet;
            $jr_mt_theme['template'] = $themes[$theme]->template;
        }
    }
    $theme = $jr_mt_theme[$option];
    global $jr_mt_cache;
    if ($jr_mt_cache === FALSE) {
        unset($jr_mt_theme[$option]);
    }
    return $theme;
}
function jr_mt_theme($option)
{
    /*	The hooks that (indirectly) call this function are called repeatedly by WordPress, 
    		so do the checking once and store the values in a global array.
    		$jt_mt_theme['stylesheet'] - Stylesheet Name of Theme chosen
    		$jt_mt_theme['template'] - Template Name of Theme chosen
    		
    		Very important note:
    			- get_option( 'jr_mt_settings' ) ['ids']['theme'] is the Theme Subdirectory Name,
    			as opposed to the Template or Stylesheet Name for the Theme.
    			- likewise, the variable local variable $theme
    		These three different values for each Theme must be clearly separated, as all three usually
    		match, but do not have to, e.g. - Child Themes.
    	*/
    global $jr_mt_theme;
    if (!isset($jr_mt_theme)) {
        $jr_mt_theme = array();
    }
    if (!isset($jr_mt_theme[$option])) {
        $theme = jr_mt_chosen();
        $jr_mt_all_themes = jr_mt_all_themes();
        /*	Check to be sure that Theme is still installed.
        			If not:
        				return Everywhere theme if set and it exists,
        					otherwise, FALSE to indicate WordPress Active Theme.
        		*/
        if (FALSE !== $theme && !isset($jr_mt_all_themes[$theme])) {
            $settings = get_option('jr_mt_settings');
            $everything = $settings['current'];
            if ('' !== $everything && isset($jr_mt_all_themes[$everything])) {
                $theme = $everything;
            } else {
                $theme = FALSE;
            }
        }
        if (FALSE === $theme) {
            //	Get both at once, to save a repeat of this logic later:
            $jr_mt_theme['stylesheet'] = jr_mt_current_theme('stylesheet');
            $jr_mt_theme['template'] = jr_mt_current_theme('template');
        } else {
            $jr_mt_theme['stylesheet'] = $jr_mt_all_themes[$theme]->stylesheet;
            $jr_mt_theme['template'] = $jr_mt_all_themes[$theme]->template;
        }
        if (!is_admin()) {
            jr_mt_cookie('all', 'clean');
        }
    }
    $theme = $jr_mt_theme[$option];
    return $theme;
}
Example #4
0
/**
 * What Themes are defined to Plugin?
 *
 * @return arr - a list of Themes (folder names) defined in Settings of Plugin, plus Active WordPress Theme
 **/
function jr_mt_themes_defined()
{
    $themes = array(jr_mt_current_theme('stylesheet'), jr_mt_current_theme('template'));
    $settings = get_option('jr_mt_settings');
    foreach ($settings as $key => $value) {
        switch ($key) {
            case 'url':
            case 'url_prefix':
            case 'url_asterisk':
                foreach ($value as $arr) {
                    $themes[] = $arr['theme'];
                }
                break;
            case 'query':
                foreach ($value as $keyword => $arr1) {
                    foreach ($arr1 as $value => $theme) {
                        $themes[] = $theme;
                    }
                }
                break;
            case 'all_pages':
            case 'all_posts':
            case 'site_home':
            case 'current':
                if (!empty($value)) {
                    $themes[] = $value;
                }
                break;
        }
    }
    return array_unique($themes);
}