コード例 #1
0
function wptouch_pro_handle_admin_command()
{
    global $wptouch_pro;
    if (isset($wptouch_pro->get['admin_command'])) {
        $admin_menu_nonce = $wptouch_pro->get['admin_menu_nonce'];
        if (wptouch_admin_menu_nonce_is_valid($admin_menu_nonce)) {
            // check user permissions
            if (current_user_can('switch_themes')) {
                switch ($wptouch_pro->get['admin_command']) {
                    case 'activate_theme':
                        WPTOUCH_DEBUG(WPTOUCH_INFO, 'Activating theme [' . $wptouch_pro->get['theme_name'] . ']');
                        wptouch_activate_theme($wptouch_pro->get['theme_name']);
                        delete_transient('wptouch_customizer_settings');
                        break;
                    case 'activate_addon':
                        WPTOUCH_DEBUG(WPTOUCH_INFO, 'Activating add-on [' . $wptouch_pro->get['addon_name'] . ']');
                        $addon_to_activate = $wptouch_pro->get['addon_name'];
                        wptouch_activate_addon($addon_to_activate);
                        delete_transient('wptouch_customizer_settings');
                        break;
                    case 'deactivate_addon':
                        WPTOUCH_DEBUG(WPTOUCH_INFO, 'Deactivating add-on [' . $wptouch_pro->get['addon_name'] . ']');
                        $addon_to_deactivate = $wptouch_pro->get['addon_name'];
                        wptouch_deactivate_addon($addon_to_deactivate);
                        break;
                    case 'copy_theme':
                        WPTOUCH_DEBUG(WPTOUCH_INFO, 'Copying theme [' . $wptouch_pro->get['theme_name'] . ']');
                        wptouch_pro_copy_theme($wptouch_pro->get['theme_name'], $wptouch_pro->get['theme_location']);
                        break;
                    case 'delete_theme':
                        WPTOUCH_DEBUG(WPTOUCH_INFO, 'Deleting theme [' . $wptouch_pro->get['theme_location'] . ']');
                        require_once WPTOUCH_DIR . '/core/file-operations.php';
                        $theme_location = WP_CONTENT_DIR . $wptouch_pro->get['theme_location'];
                        $wptouch_pro->recursive_delete($theme_location);
                        break;
                }
            }
        }
        $used_query_args = array('admin_menu_nonce', 'admin_command', 'theme_name', 'theme_location', 'addon_name', 'addon_location');
        header('Location: ' . esc_url(remove_query_arg($used_query_args)));
        die;
    }
}
コード例 #2
0
function wptouch_auto_update_themes_addons()
{
    global $wptouch_pro;
    if (!isset($wptouch_pro->post)) {
        require_once WPTOUCH_DIR . '/core/theme-hashes.php';
        $theme_hashes = wptouch_get_hashes();
        if (current_user_can('manage_options')) {
            $current_theme = $wptouch_pro->get_current_theme_info();
            $available_themes = $wptouch_pro->get_available_themes(true);
            $available_addons = $wptouch_pro->get_available_addons(true);
            $updates = 0;
            $backed_up = false;
            $errors = array();
            if (count($available_themes) > 0 || count($available_addons) > 0) {
                require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
                foreach ($available_themes as $name => $theme) {
                    $hash = false;
                    $safe_to_install_theme = false;
                    $skip_upgrade = false;
                    if (isset($theme->upgrade_available) && $theme->upgrade_available) {
                        if (!is_object($current_theme) || $name != $current_theme->name) {
                            $safe_to_install_theme = true;
                        } else {
                            if ($name == $current_theme->name && $theme->cloud_version < $theme->version) {
                                $skip_upgrade = true;
                            } else {
                                $hash = md5_dir(WP_CONTENT_DIR . $current_theme->location);
                                if (in_array($theme->version, $theme_hashes[$theme->base]) && $hash == $theme_hashes[$theme->base][$theme->version]) {
                                    // OK to upgrade the active theme (it's the same as when it shipped)
                                    $safe_to_install_theme = true;
                                }
                            }
                        }
                        // Hashes didn't match.
                        if ($safe_to_install_theme === false && $skip_upgrade === false) {
                            $copied_theme = wptouch_pro_copy_theme($theme->name, $theme->location);
                            if (is_array($copied_theme)) {
                                wptouch_pro_activate_theme($copied_theme['name'], $copied_theme['location']);
                                $backed_up = $theme->name;
                            }
                        }
                        if ($skip_upgrade === false) {
                            $installer = new WPtouchAddonThemeInstaller();
                            $installer->install($theme->base, $theme->download_url, 'themes');
                            if ($installer->had_error()) {
                                $errors[] = $installer->error_text();
                            } else {
                                $updates++;
                            }
                        }
                    }
                }
                foreach ($available_addons as $name => $addon) {
                    if (isset($addon->upgrade_available) && $addon->upgrade_available && isset($addon->download_url)) {
                        $installer = new WPtouchAddonThemeInstaller();
                        $installer->install($addon->base, $addon->download_url, 'extensions');
                        if ($installer->had_error()) {
                            $errors[] = $installer->error_text();
                        } else {
                            $updates++;
                        }
                    }
                }
                if ($backed_up) {
                    $backed_up = sprintf(__('%sYour customizations to %s have been saved as a new theme and the original reinstalled for your reference.', 'wptouch-pro'), '</p><p>', $backed_up);
                }
                if ($updates && count($errors) > 0) {
                    echo '<div id="message" class="error"><p>' . __('WPtouch Pro: Some themes or extensions could not be auto-updated. Please check the WPtouch Pro Themes &amp; Extensions page to manually update them.', 'wptouch-pro') . $backed_up . '</p></div>';
                } elseif ($updates) {
                    echo '<div id="message" class="updated"><p>' . __('WPtouch Pro: Your themes and extensions have been automatically updated. Thank you for updating WPtouch Pro!', 'wptouch-pro') . $backed_up . '</p></div>';
                }
            }
        }
    }
}