From 94487bb9eaac4826884732454a5b58075cf5f7bf Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 27 May 2010 11:04:08 +0000 Subject: [PATCH] Add Importer support to Plugin Install workflow, Offers to Activate Plugin & Run installer, and returning to Imports upon successful Importer Plugin Installation. See #13566 git-svn-id: https://develop.svn.wordpress.org/trunk@14985 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/import.php | 31 ++++++++++++++----------- wp-admin/includes/class-wp-upgrader.php | 15 ++++++++---- wp-admin/includes/plugin-install.php | 2 ++ wp-admin/plugins.php | 11 +++++---- wp-admin/update.php | 3 +++ 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/wp-admin/import.php b/wp-admin/import.php index 525140626e..5a82f12b37 100644 --- a/wp-admin/import.php +++ b/wp-admin/import.php @@ -23,6 +23,23 @@ add_contextual_help($current_screen, '

' . __('This screen lists links to plug '

' . sprintf(__('Support Forums'), 'http://wordpress.org/support/') . '

' ); +$popular_importers = array(); +if ( current_user_can('install_plugins') ) + $popular_importers = array( + 'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ), + 'wpcat2tag' => array(__('Categories and Tags Converter'), __('Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.'), 'install', 'wp-cat2tag' ), + 'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'install' ), + 'movabletype' => array( __('Movable Type and TypePad'), __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'), 'install', 'mt' ), + 'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ), + 'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ), + 'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' ) + ); + +if ( ! empty( $_GET['invalid'] ) && !empty($popular_importers[$_GET['invalid']][3]) ) { + wp_redirect("import.php?import=" . $popular_importers[$_GET['invalid']][3]); + exit; +} + add_thickbox(); require_once ('admin-header.php'); $parent_file = 'tools.php'; @@ -53,18 +70,6 @@ if ($imports_dir) { } @closedir($imports_dir); -$popular_importers = array(); -if ( current_user_can('install_plugins') ) - $popular_importers = array( - 'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ), - 'wpcat2tag' => array(__('Categories and Tags Converter'), __('Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.'), 'install', 'wp-cat2tag' ), - 'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'install' ), - 'movabletype' => array( __('Movable Type and TypePad'), __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'), 'install', 'mt' ), - 'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ), - 'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ), - 'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' ) - ); - $importers = get_importers(); // If a popular importer is not registered, create a dummy registration that links to the plugin installer. @@ -92,7 +97,7 @@ if (empty ($importers)) { if ( 'install' == $data[2] ) { $plugin_slug = $id . '-importer'; $action = '' . $data[0] . ''; } else { $action = "{$data[0]}"; diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 37e5456c6d..adfef20499 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -1261,14 +1261,21 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { $plugin_file = $this->upgrader->plugin_info(); - $install_actions = array( - 'activate_plugin' => '' . __('Activate Plugin') . '', - ); + $install_actions = array(); + + $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins'; + + if ( 'import' == $from ) + $install_actions['activate_plugin'] = '' . __('Activate Plugin & Run Importer') . ''; + else + $install_actions['activate_plugin'] = '' . __('Activate Plugin') . ''; if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) $install_actions['network_activate'] = '' . __('Network Activate') . ''; - if ( $this->type == 'web' ) + if ( 'import' == $from ) + $install_actions['importers_page'] = '' . __('Return to Importers') . ''; + else if ( $this->type == 'web' ) $install_actions['plugins_page'] = '' . __('Return to Plugin Installer') . ''; else $install_actions['plugins_page'] = '' . __('Return to Plugins page') . ''; diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php index 39c7f7400d..f348e609e5 100644 --- a/wp-admin/includes/plugin-install.php +++ b/wp-admin/includes/plugin-install.php @@ -473,6 +473,8 @@ function install_plugin_install_status($api, $loop = false) { $url = wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); } } + if ( isset($_GET['from']) ) + $url .= '&from=' . urlencode(stripslashes($_GET['from'])); return compact('status', 'url', 'version'); } diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index dbeb7f761a..41d93af570 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -51,7 +51,7 @@ if ( !empty($action) ) { $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide); if ( is_wp_error( $result ) ) { - if ('unexpected_output' == $result->get_error_code()) { + if ( 'unexpected_output' == $result->get_error_code() ) { $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin; wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); exit; @@ -65,8 +65,11 @@ if ( !empty($action) ) { unset($recent[ $plugin ]); update_option('recently_activated', $recent); } - - wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above + if ( isset($_GET['from']) && 'import' == $_GET['from'] ) { + wp_redirect("import.php?import=" . str_replace('-importer', '', dirname($plugin)) ); // overrides the ?error=true one above and redirects to the Imports page, striping the -importer suffix + } else { + wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above + } exit; break; case 'activate-selected': @@ -437,7 +440,7 @@ $total_network_plugins = count($network_plugins); $total_mustuse_plugins = count($mustuse_plugins); $total_dropins_plugins = count($dropins_plugins); -//Searching. +// Searching. if ( !empty($_GET['s']) ) { function _search_plugins_filter_callback($plugin) { static $term; diff --git a/wp-admin/update.php b/wp-admin/update.php index 39175ed149..0664ac8f36 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -110,6 +110,9 @@ if ( isset($_GET['action']) ) { $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ); $nonce = 'install-plugin_' . $plugin; $url = 'update.php?action=install-plugin&plugin=' . $plugin; + if ( isset($_GET['from']) ) + $url .= '&from=' . urlencode(stripslashes($_GET['from'])); + $type = 'web'; //Install plugin type, From Web or an Upload. $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );