WordPress.org

Make WordPress Core

Ticket #13465: 13465.diff

File 13465.diff, 3.7 KB (added by ryan, 4 years ago)

Add install links to import.php, define WP_LOAD_IMPORTERS so import plugins can conditionally load

  • wp-admin/admin.php

     
    1414if ( !defined('WP_ADMIN') ) 
    1515        define('WP_ADMIN', TRUE); 
    1616 
     17if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') ) 
     18        define('WP_LOAD_IMPORTERS', true); 
     19 
    1720require_once(dirname(dirname(__FILE__)) . '/wp-load.php'); 
    1821 
    1922if ( get_option('db_upgraded') ) { 
  • wp-admin/import.php

     
    66 * @subpackage Administration 
    77 */ 
    88 
     9define('WP_LOAD_IMPORTERS', true); 
     10 
    911/** Load WordPress Bootstrap */ 
    1012require_once ('admin.php'); 
    1113 
     
    1315        wp_die(__('You do not have sufficient permissions to import content in this site.')); 
    1416 
    1517$title = __('Import'); 
     18add_thickbox(); 
    1619require_once ('admin-header.php'); 
    1720$parent_file = 'tools.php'; 
    1821?> 
     
    3942} 
    4043@closedir($imports_dir); 
    4144 
     45$popular_importers = array(); 
     46if ( current_user_can('install_plugins') ) 
     47        $popular_importers = array( 
     48                'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ), 
     49                'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJounral importer to import posts from LiveJournal using their API.' ), 'install' ), 
     50                'mt' => array( __('Movable Type and TypePad'), __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'), 'install' ), 
     51                'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ), 
     52                'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ), 
     53                'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' ) 
     54        ); 
     55 
    4256$importers = get_importers(); 
    4357 
     58// If a popular importer is not registered, create a dummy registration that links to the plugin installer. 
     59foreach ( array_keys($popular_importers) as $pop_importer ) { 
     60        if ( isset($importers[$pop_importer] ) ) 
     61                continue; 
     62 
     63        $importers[$pop_importer] = $popular_importers[$pop_importer]; 
     64} 
     65 
     66uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);')); 
     67 
    4468if (empty ($importers)) { 
    4569        echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful 
    4670} else { 
     
    5175        $style = ''; 
    5276        foreach ($importers as $id => $data) { 
    5377                $style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate'; 
    54                 $action = "<a href='admin.php?import=$id' title='".wptexturize(strip_tags($data[1]))."'>{$data[0]}</a>"; 
     78                if ( 'install' == $data[2] ) { 
     79                        $plugin_slug = $id . '-importer'; 
     80                        $action = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin_slug . 
     81                                                                        '&amp;TB_iframe=true&amp;width=600&amp;height=550') . '" class="thickbox" title="' . 
     82                                                                        esc_attr__('Install importer') . '">' . $data[0] . '</a>'; 
     83                } else { 
     84                        $action = "<a href='" . esc_url('admin.php?import=$id') . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>"; 
     85                } 
    5586 
    5687                if ($style != '') 
    5788                        $style = 'class="'.$style.'"'; 
     
    6697</table> 
    6798<?php 
    6899} 
     100 
     101if ( current_user_can('install_plugins') ) 
     102        echo '<p>' . sprintf('If the importer you need is not listed, <a href="%s">search the plugins directory</a> to see if an importer is available.', admin_url('plugin-install.php?tab=search&type=tag&s=importer') ) . '</p>'; 
    69103?> 
    70104 
    71105</div>