function jr_mt_chosen() { if (is_admin()) { // Admin panel // return P2 theme if p2ajax= is present; current theme otherwise parse_str($_SERVER['QUERY_STRING'], $keywords); if (isset($keywords['p2ajax']) && array_key_exists('p2', wp_get_themes())) { $theme = 'p2'; } else { $theme = FALSE; // Current Theme } } else { // Non-Admin page, i.e. - Public Site, etc. extract(jr_mt_url_to_id('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'])); $settings = get_option('jr_mt_settings'); if ($home) { if (trim($settings['site_home']) != '') { return $settings['site_home']; } } $ids = $settings['ids']; if ($id === FALSE) { if (isset($ids[$page_url])) { $theme = $ids[$page_url]['theme']; } else { $theme = jr_mt_check_all($type, $rel_url, $ids); } } else { if (isset($ids[$id])) { $theme = $ids[$id]['theme']; } else { $theme = jr_mt_check_all($type, $rel_url, $ids); } } } return $theme; }
function jr_mt_validate_settings($input) { $valid = array(); foreach (array('all_pages', 'all_posts', 'site_home') as $thing) { $valid[$thing] = $input[$thing]; } $settings = get_option('jr_mt_settings'); $ids = $settings['ids']; if (isset($input['del_entry'])) { foreach ($input['del_entry'] as $del_entry) { unset($ids[$del_entry]); } } $url = trim($input['add_path_id']); if (empty($input['add_theme']) && !empty($url) || !empty($input['add_theme']) && empty($url)) { add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Both URL and Theme must be specified to add an Individual entry', 'error'); } else { if (!empty($url)) { $validate_url = jr_mt_site_url($url); if ($validate_url === TRUE) { extract(jr_mt_url_to_id($url)); if (isset($input['add_is_prefix']) && $input['add_is_prefix'] == "true") { if (parse_url($url, PHP_URL_QUERY) === NULL) { $ids[$rel_url] = array('theme' => $input['add_theme'], 'type' => 'prefix', 'id' => $id, 'page_url' => $page_url, 'rel_url' => $rel_url, 'url' => $url); } else { add_settings_error('jr_mt_settings', 'jr_mt_queryerror', '?key=val&key=val Queries are not supported in a URL Prefix', 'error'); } } else { if ($home) { add_settings_error('jr_mt_settings', 'jr_mt_homeerror', 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.', 'error'); } else { if ($type == 'admin') { add_settings_error('jr_mt_settings', 'jr_mt_adminerror', 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages.', 'error'); } else { if ($id === FALSE) { $key = $page_url; } else { $key = $id; } $ids[$key] = array('theme' => $input['add_theme'], 'type' => $type, 'id' => $id, 'page_url' => $page_url, 'rel_url' => $rel_url, 'url' => $url); } } } } else { add_settings_error('jr_mt_settings', 'jr_mt_urlerror', "Invalid URL specified for Individual page/post: '{$url}'. {$validate_url}", 'error'); } } } $errors = get_settings_errors(); if (empty($errors)) { add_settings_error('jr_mt_settings', 'jr_mt_saved', 'Settings Saved', 'updated'); } $valid['ids'] = $ids; return $valid; }