<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[14985] trunk/wp-admin: Add Importer support to Plugin Install workflow,
Offers to Activate Plugin & Run installer,
and returning to Imports upon successful Importer Plugin Installation.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14985">14985</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-05-27 11:04:08 +0000 (Thu, 27 May 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add Importer support to Plugin Install workflow, Offers to Activate Plugin & Run installer, and returning to Imports upon successful Importer Plugin Installation. See <a href="http://trac.wordpress.org/ticket/13566">#13566</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminimportphp">trunk/wp-admin/import.php</a></li>
<li><a href="#trunkwpadminincludesclasswpupgraderphp">trunk/wp-admin/includes/class-wp-upgrader.php</a></li>
<li><a href="#trunkwpadminincludesplugininstallphp">trunk/wp-admin/includes/plugin-install.php</a></li>
<li><a href="#trunkwpadminpluginsphp">trunk/wp-admin/plugins.php</a></li>
<li><a href="#trunkwpadminupdatephp">trunk/wp-admin/update.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminimportphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import.php (14984 => 14985)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import.php        2010-05-27 09:49:38 UTC (rev 14984)
+++ trunk/wp-admin/import.php        2010-05-27 11:04:08 UTC (rev 14985)
</span><span class="lines">@@ -23,6 +23,23 @@
</span><span class="cx">         '<p>' . sprintf(__('<a href="%s">Support Forums</a>'), 'http://wordpress.org/support/') . '</p>'
</span><span class="cx"> );
</span><span class="cx">
</span><ins>+$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;
+}
+
</ins><span class="cx"> add_thickbox();
</span><span class="cx"> require_once ('admin-header.php');
</span><span class="cx"> $parent_file = 'tools.php';
</span><span class="lines">@@ -53,18 +70,6 @@
</span><span class="cx"> }
</span><span class="cx"> @closedir($imports_dir);
</span><span class="cx">
</span><del>-$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' )
-        );
-
</del><span class="cx"> $importers = get_importers();
</span><span class="cx">
</span><span class="cx"> // If a popular importer is not registered, create a dummy registration that links to the plugin installer.
</span><span class="lines">@@ -92,7 +97,7 @@
</span><span class="cx">                 if ( 'install' == $data[2] ) {
</span><span class="cx">                         $plugin_slug = $id . '-importer';
</span><span class="cx">                         $action = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin_slug .
</span><del>-                                                                        '&amp;TB_iframe=true&amp;width=600&amp;height=550') . '" class="thickbox" title="' .
</del><ins>+                                                                        '&amp;from=import&amp;TB_iframe=true&amp;width=600&amp;height=550') . '" class="thickbox" title="' .
</ins><span class="cx">                                                                         esc_attr__('Install importer') . '">' . $data[0] . '</a>';
</span><span class="cx">                 } else {
</span><span class="cx">                         $action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-upgrader.php (14984 => 14985)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-upgrader.php        2010-05-27 09:49:38 UTC (rev 14984)
+++ trunk/wp-admin/includes/class-wp-upgrader.php        2010-05-27 11:04:08 UTC (rev 14985)
</span><span class="lines">@@ -1261,14 +1261,21 @@
</span><span class="cx">
</span><span class="cx">                 $plugin_file = $this->upgrader->plugin_info();
</span><span class="cx">
</span><del>-                $install_actions = array(
-                        'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
-                                                        );
</del><ins>+                $install_actions = array();
</ins><span class="cx">
</span><ins>+                $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
+
+                if ( 'import' == $from )
+                        $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;from=import&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin &amp; Run Importer') . '</a>';
+                else
+                        $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
+
</ins><span class="cx">                 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) )
</span><span class="cx">                         $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
</span><span class="cx">
</span><del>-                if ( $this->type == 'web' )
</del><ins>+                if ( 'import' == $from )
+                        $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
+                else if ( $this->type == 'web' )
</ins><span class="cx">                         $install_actions['plugins_page'] = '<a href="' . admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>';
</span><span class="cx">                 else
</span><span class="cx">                         $install_actions['plugins_page'] = '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
</span></span></pre></div>
<a id="trunkwpadminincludesplugininstallphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/plugin-install.php (14984 => 14985)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/plugin-install.php        2010-05-27 09:49:38 UTC (rev 14984)
+++ trunk/wp-admin/includes/plugin-install.php        2010-05-27 11:04:08 UTC (rev 14985)
</span><span class="lines">@@ -473,6 +473,8 @@
</span><span class="cx">                                 $url = wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
</span><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+        if ( isset($_GET['from']) )
+                $url .= '&amp;from=' . urlencode(stripslashes($_GET['from']));
</ins><span class="cx">
</span><span class="cx">         return compact('status', 'url', 'version');
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminpluginsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/plugins.php (14984 => 14985)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/plugins.php        2010-05-27 09:49:38 UTC (rev 14984)
+++ trunk/wp-admin/plugins.php        2010-05-27 11:04:08 UTC (rev 14985)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx">
</span><span class="cx">                         $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
</span><span class="cx">                         if ( is_wp_error( $result ) ) {
</span><del>-                                if ('unexpected_output' == $result->get_error_code()) {
</del><ins>+                                if ( 'unexpected_output' == $result->get_error_code() ) {
</ins><span class="cx">                                         $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
</span><span class="cx">                                         wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
</span><span class="cx">                                         exit;
</span><span class="lines">@@ -65,8 +65,11 @@
</span><span class="cx">                                 unset($recent[ $plugin ]);
</span><span class="cx">                                 update_option('recently_activated', $recent);
</span><span class="cx">                         }
</span><del>-
-                        wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above
</del><ins>+                        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
+                        }
</ins><span class="cx">                         exit;
</span><span class="cx">                         break;
</span><span class="cx">                 case 'activate-selected':
</span><span class="lines">@@ -437,7 +440,7 @@
</span><span class="cx"> $total_mustuse_plugins = count($mustuse_plugins);
</span><span class="cx"> $total_dropins_plugins = count($dropins_plugins);
</span><span class="cx">
</span><del>-//Searching.
</del><ins>+// Searching.
</ins><span class="cx"> if ( !empty($_GET['s']) ) {
</span><span class="cx">         function _search_plugins_filter_callback($plugin) {
</span><span class="cx">                 static $term;
</span></span></pre></div>
<a id="trunkwpadminupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/update.php (14984 => 14985)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/update.php        2010-05-27 09:49:38 UTC (rev 14984)
+++ trunk/wp-admin/update.php        2010-05-27 11:04:08 UTC (rev 14985)
</span><span class="lines">@@ -110,6 +110,9 @@
</span><span class="cx">                 $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
</span><span class="cx">                 $nonce = 'install-plugin_' . $plugin;
</span><span class="cx">                 $url = 'update.php?action=install-plugin&plugin=' . $plugin;
</span><ins>+                if ( isset($_GET['from']) )
+                        $url .= '&from=' . urlencode(stripslashes($_GET['from']));
+
</ins><span class="cx">                 $type = 'web'; //Install plugin type, From Web or an Upload.
</span><span class="cx">
</span><span class="cx">                 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
</span></span></pre>
</div>
</div>
</body>
</html>