[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Import WordPress Administration Screen 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 define( 'WP_LOAD_IMPORTERS', true ); 10 11 /** Load WordPress Bootstrap */ 12 require_once __DIR__ . '/admin.php'; 13 14 if ( ! current_user_can( 'import' ) ) { 15 wp_die( __( 'Sorry, you are not allowed to import content into this site.' ) ); 16 } 17 18 // Used in the HTML title tag. 19 $title = __( 'Import' ); 20 21 get_current_screen()->add_help_tab( 22 array( 23 'id' => 'overview', 24 'title' => __( 'Overview' ), 25 'content' => '<p>' . __( 'This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.' ) . '</p>' . 26 '<p>' . __( 'In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.' ) . '</p>', 27 ) 28 ); 29 30 get_current_screen()->set_help_sidebar( 31 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 32 '<p>' . __( '<a href="https://wordpress.org/documentation/article/tools-import-screen/">Documentation on Import</a>' ) . '</p>' . 33 '<p>' . __( '<a href="https://wordpress.org/support/forums">Support</a>' ) . '</p>' 34 ); 35 36 if ( current_user_can( 'install_plugins' ) ) { 37 // List of popular importer plugins from the WordPress.org API. 38 $popular_importers = wp_get_popular_importers(); 39 } else { 40 $popular_importers = array(); 41 } 42 43 // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'. 44 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { 45 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; 46 if ( $importer_id !== $_GET['invalid'] ) { // Prevent redirect loops. 47 wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) ); 48 exit; 49 } 50 unset( $importer_id ); 51 } 52 53 add_thickbox(); 54 wp_enqueue_script( 'plugin-install' ); 55 wp_enqueue_script( 'updates' ); 56 57 require_once ABSPATH . 'wp-admin/admin-header.php'; 58 $parent_file = 'tools.php'; 59 ?> 60 61 <div class="wrap"> 62 <h1><?php echo esc_html( $title ); ?></h1> 63 <?php 64 if ( ! empty( $_GET['invalid'] ) ) : 65 $importer_not_installed = '<strong>' . __( 'Error:' ) . '</strong> ' . sprintf( 66 /* translators: %s: Importer slug. */ 67 __( 'The %s importer is invalid or is not installed.' ), 68 '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' 69 ); 70 wp_admin_notice( 71 $importer_not_installed, 72 array( 73 'additional_classes' => array( 'error' ), 74 ) 75 ); 76 endif; 77 ?> 78 <p><?php _e( 'If you have posts or comments in another system, WordPress can import those into this site. To get started, choose a system to import from below:' ); ?></p> 79 80 <?php 81 // Registered (already installed) importers. They're stored in the global $wp_importers. 82 $importers = get_importers(); 83 84 // If a popular importer is not registered, create a dummy registration that links to the plugin installer. 85 foreach ( $popular_importers as $pop_importer => $pop_data ) { 86 if ( isset( $importers[ $pop_importer ] ) ) { 87 continue; 88 } 89 if ( isset( $importers[ $pop_data['importer-id'] ] ) ) { 90 continue; 91 } 92 93 // Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. 94 $importers[ $pop_data['importer-id'] ] = array( 95 $pop_data['name'], 96 $pop_data['description'], 97 'install' => $pop_data['plugin-slug'], 98 ); 99 } 100 101 if ( empty( $importers ) ) { 102 echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: Make more helpful. 103 } else { 104 uasort( $importers, '_usort_by_first_member' ); 105 ?> 106 <table class="widefat importers striped"> 107 108 <?php 109 foreach ( $importers as $importer_id => $data ) { 110 $plugin_slug = ''; 111 $action = ''; 112 $is_plugin_installed = false; 113 114 if ( isset( $data['install'] ) ) { 115 $plugin_slug = $data['install']; 116 117 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { 118 // Looks like an importer is installed, but not active. 119 $plugins = get_plugins( '/' . $plugin_slug ); 120 if ( ! empty( $plugins ) ) { 121 $keys = array_keys( $plugins ); 122 $plugin_file = $plugin_slug . '/' . $keys[0]; 123 $url = wp_nonce_url( 124 add_query_arg( 125 array( 126 'action' => 'activate', 127 'plugin' => $plugin_file, 128 'from' => 'import', 129 ), 130 admin_url( 'plugins.php' ) 131 ), 132 'activate-plugin_' . $plugin_file 133 ); 134 $action = sprintf( 135 '<a href="%s" aria-label="%s">%s</a>', 136 esc_url( $url ), 137 /* translators: %s: Importer name. */ 138 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), 139 __( 'Run Importer' ) 140 ); 141 142 $is_plugin_installed = true; 143 } 144 } 145 146 if ( empty( $action ) ) { 147 if ( is_main_site() ) { 148 $url = wp_nonce_url( 149 add_query_arg( 150 array( 151 'action' => 'install-plugin', 152 'plugin' => $plugin_slug, 153 'from' => 'import', 154 ), 155 self_admin_url( 'update.php' ) 156 ), 157 'install-plugin_' . $plugin_slug 158 ); 159 $action = sprintf( 160 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>', 161 esc_url( $url ), 162 esc_attr( $plugin_slug ), 163 esc_attr( $data[0] ), 164 /* translators: %s: Importer name. */ 165 esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $data[0] ) ), 166 _x( 'Install Now', 'plugin' ) 167 ); 168 } else { 169 $action = sprintf( 170 /* translators: %s: URL to Import screen on the main site. */ 171 __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), 172 get_admin_url( get_current_network_id(), 'import.php' ) 173 ); 174 } 175 } 176 } else { 177 $url = add_query_arg( 178 array( 179 'import' => $importer_id, 180 ), 181 self_admin_url( 'admin.php' ) 182 ); 183 $action = sprintf( 184 '<a href="%1$s" aria-label="%2$s">%3$s</a>', 185 esc_url( $url ), 186 /* translators: %s: Importer name. */ 187 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), 188 __( 'Run Importer' ) 189 ); 190 191 $is_plugin_installed = true; 192 } 193 194 if ( ! $is_plugin_installed && is_main_site() ) { 195 $url = add_query_arg( 196 array( 197 'tab' => 'plugin-information', 198 'plugin' => $plugin_slug, 199 'from' => 'import', 200 'TB_iframe' => 'true', 201 'width' => 600, 202 'height' => 550, 203 ), 204 network_admin_url( 'plugin-install.php' ) 205 ); 206 $action .= sprintf( 207 ' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>', 208 esc_url( $url ), 209 /* translators: %s: Importer name. */ 210 esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ), 211 __( 'Details' ) 212 ); 213 } 214 215 echo " 216 <tr class='importer-item'> 217 <td class='import-system'> 218 <span class='importer-title'>{$data[0]}</span> 219 <span class='importer-action'>{$action}</span> 220 </td> 221 <td class='desc'> 222 <span class='importer-desc'>{$data[1]}</span> 223 </td> 224 </tr>"; 225 } 226 ?> 227 </table> 228 <?php 229 } 230 231 if ( current_user_can( 'install_plugins' ) ) { 232 echo '<p>' . sprintf( 233 /* translators: %s: URL to Add Plugins screen. */ 234 __( 'If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.' ), 235 esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) 236 ) . '</p>'; 237 } 238 ?> 239 240 </div> 241 242 <?php 243 wp_print_request_filesystem_credentials_modal(); 244 wp_print_admin_notice_templates(); 245 246 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |