properties(); if (!$list['nb']) return false; //echo "Number of files in archive : ".$list['nb']."
"; echo "Copying the files
"; $result = $unzipArchive->extract(PCLZIP_OPT_PATH, $dir); if ($result == 0) { echo 'Could not unarchive the file: ' . $unzipArchive->errorInfo(true) . '
'; return false; } else { //print_r($result); foreach ($result as $item) { if ($item['status'] != 'ok') echo $item['stored_filename'] . ' ... ' . $item['status'] . '
'; } return true; } } function themedrive_handle_theme_liberal($package) { echo "Downloading the theme from " . $package . "
"; $file = download_url($package); if (is_wp_error($file)) { echo 'Download failed: ' . $file->get_error_message(); return; } echo "Unpacking the theme
"; // Unzip theme to theme directory //theme dir $result = themedrive_unzip($file, ABSPATH . "wp-content/themes/"); // Once extracted, delete the package unlink($file); if ($result) echo "
Theme installed successfully.

"; else { echo "
Error installing the theme.

You can try installing the theme manually: $package

"; } return; } function themedrive_handle_theme_rigid($package) { global $wp_filesystem; if (!$wp_filesystem || !is_object($wp_filesystem)) WP_Filesystem($credentials); if (!is_object($wp_filesystem)) { echo 'Could not access filesystem.

'; return; } if ($wp_filesystem->errors->get_error_code()) { echo 'Filesystem error ' . $wp_filesystem->errors->get_error_message() . '

'; return; } //Get the Base folder $base = $wp_filesystem->get_base_dir(); if (empty($base)) { echo 'Unable to locate WordPress directory.

'; return; } echo "Downloading theme file from " . $package . "
"; $file = download_url($package); if (is_wp_error($file)) { echo 'Download failed : ' . $file->get_error_message() . '

'; return; } $working_dir = $base . 'wp-content/upgrade/themes'; // Clean up working directory if ($wp_filesystem->is_dir($working_dir)) $wp_filesystem->delete($working_dir, true); echo "Unpacking the theme
"; // Unzip package to theme directory $result = unzip_file($file, $working_dir); if (is_wp_error($result)) { unlink($file); $wp_filesystem->delete($working_dir, true); echo 'Unpack failed : ' . $result->get_error_message() . '

'; return; } echo "Installing the theme
"; // Copy new version of plugin into place. if (!copy_dir($working_dir, $base . "wp-content/themes")) { //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. $wp_filesystem->delete($working_dir, true); echo 'Installation failed (theme already installed?)

'; return; } //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin $filelist = array_keys($wp_filesystem->dirlist($working_dir)); // Remove working directory $wp_filesystem->delete($working_dir, true); // Once extracted, delete the package unlink($file); echo "Theme installed successfully.

"; return; } function themedrive_get_theme() { $gettheme = get_option('td_themes'); if (!empty($gettheme)) { return $gettheme; } else { return ''; } } function themedrive_get_level() { $getlevel = get_option('td_level'); if ($getlevel!='') { return 'level_' . $getlevel; } else { return 'level_10'; } } function themedrive_determine_theme() { if (!isset($_GET['theme'])) { if (!current_user_can(themedrive_get_level())) { // not admin return false; } else { $theme = themedrive_get_theme(); if ($theme == '') { // no admin-only theme defined, short-circuit out return false; } } } $all = $_GET + $_POST; if (isset($all['theme'])) { $theme = $all['theme']; } $theme_data = get_theme($theme); if (!empty($theme_data)) { // Don't let people peek at unpublished themes if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') { return false; } return $theme_data; } // perhaps they are using the theme directory instead of title $themes = get_themes(); foreach ($themes as $theme_data) { // use Stylesheet as it's unique to the theme - Template could point to another theme's templates if ($theme_data['Stylesheet'] == $theme) { // Don't let people peek at unpublished themes if (isset($theme_data['Status']) && $theme_data['Status'] != 'publish') { return false; } return $theme_data; } } return false; } function themedrive_get_template($template) { $theme = themedrive_determine_theme(); if ($theme === false) { return $template; } return $theme['Template']; } function themedrive_get_stylesheet($stylesheet) { $theme = themedrive_determine_theme(); if ($theme === false) { return $stylesheet; } return $theme['Stylesheet']; } function themedrive_switcher() { $themes = get_themes(); $default_theme = get_current_theme(); if (count($themes) > 1) { $theme_names = array_keys($themes); natcasesort($theme_names); $ts = '' . "\n\n"; $tp .= ''; } // echo $tp; echo $ts; if (themedrive_is_enabled()) { echo 'Theme Test Drive is Enabled.
'; } else { echo 'Theme Test Drive is Disabled.
'; } } add_filter('template', 'themedrive_get_template'); add_filter('stylesheet', 'themedrive_get_stylesheet'); // Admin Panel function themedrive_add_pages() { add_theme_page('Theme Test Drive Options', 'Theme Test Drive', 8, __FILE__, 'themedrive_options_page'); } function themedrive_is_enabled() { return get_option('td_themes'); } // Options Page function themedrive_options_page() { global $themedrive_localversion; global $wp_themedrive_plugin_url; $status = themedrive_getinfo(); $theVersion = $status[1]; $theMessage = $status[3]; if ((version_compare(strval($theVersion), strval($themedrive_localversion), '>') == 1)) { $msg = 'Latest version available ' . ' ' . $theVersion . '
' . $theMessage; _e('

' . $msg . '

'); } if ($_POST['button'] == 'Enable Theme Drive') { check_admin_referer('theme-drive'); $themedrive = $_POST['td_themes']; update_option('td_themes', $themedrive); $access_level = (int)$_POST['access_level']; update_option('td_level', $access_level); $msg_status = "Theme Test Drive Enabled for administrator with " . $themedrive . ' theme.'; // Show message _e('

' . $msg_status . '

'); } elseif ($_POST['button'] == 'Disable Theme Drive') { check_admin_referer('theme-drive'); // Delete the option from the DB if it's empty delete_option('td_themes'); $msg_status = "Theme Test Drive has been disabled."; // Show message _e('

' . $msg_status . '

'); } $access_level = get_option('td_level'); //if (empty($access_level)) // $access_level = '10'; $imgpath = $wp_themedrive_plugin_url . '/i'; ?>

Theme Test Drive

Theme installation'; $install_theme = !isset($_POST['install_theme']) ? '' : $_POST['install_theme']; if ($install_theme != '') { themedrive_handle_theme($install_theme); } else echo "No theme URL specified.
"; echo '

'; } ?>

Easy Theme Installation

Enter the URL to the theme zip file and click Install theme.




Usage

Select a theme to preview live on the site. Only administrator will be able to see the selected theme.

Additionally you may add "?theme=xxx" to your blog url, where xxx is the theme name you want to test.

You can specify the level of users to have access to the selected theme preview. By default it is set to 10 (admin only). Level 7 are editors, level 4 are authors and level 1 are contributors. The access level is ignored for accessing the site with ?theme=xxx paramaeter.

Access level

Disabling: If you wish to stop using Theme Test Drive, press Disable button. Alternatively, disabling this plug-in should also do the trick.

a plugin by Vladimir Prelovac

') == 1)) { $msg = 'Latest version available ' . ' ' . $theVersion . '
' . $theMessage; echo '' . $msg . ''; } else { return; } } } function themdrive_js() { echo ''; echo "\n"; echo ''; echo "\n"; } //add_action("admin_head","themdrive_js"); //$tp.= '


'; //


?>