PHP 8.1.33
Preview: import.php Size: 6.48 KB
/home/jambtst2015/public_html/wp-admin/includes/import.php

<?php
/**
 * WordPress Administration Importer API.
 *
 * @package WordPress
 * @subpackage Administration
 */

/**
 * Retrieve list of importers.
 *
 * @since 2.0.0
 *
 * @global array $wp_importers
 * @return array
 */
function get_importers() {
	global $wp_importers;
	if ( is_array( $wp_importers ) ) {
		uasort( $wp_importers, '_usort_by_first_member' );
	}
	return $wp_importers;
}

/**
 * Sorts a multidimensional array by first member of each top level member
 *
 * Used by uasort() as a callback, should not be used directly.
 *
 * @since 2.9.0
 * @access private
 *
 * @param array $a
 * @param array $b
 * @return int
 */
function _usort_by_first_member( $a, $b ) {
	return strnatcasecmp( $a[0], $b[0] );
}

/**
 * Register importer for WordPress.
 *
 * @since 2.0.0
 *
 * @global array $wp_importers
 *
 * @param string   $id          Importer tag. Used to uniquely identify importer.
 * @param string   $name        Importer name and title.
 * @param string   $description Importer description.
 * @param callable $callback    Callback to run.
 * @return WP_Error Returns WP_Error when $callback is WP_Error.
 */
function register_importer( $id, $name, $description, $callback ) {
	global $wp_importers;
	if ( is_wp_error( $callback ) ) {
		return $callback;
	}
	$wp_importers[ $id ] = array( $name, $description, $callback );
}

/**
 * Cleanup importer.
 *
 * Removes attachment based on ID.
 *
 * @since 2.0.0
 *
 * @param string $id Importer ID.
 */
function wp_import_cleanup( $id ) {
	wp_delete_attachment( $id );
}

/**
 * Handle importer uploading and add attachment.
 *
 * @since 2.0.0
 *
 * @return array Uploaded file's details on success, error message on failure
 */
function wp_import_handle_upload() {
	if ( ! isset( $_FILES['import'] ) ) {
		return array(
			'error' => sprintf(
				/* translators: 1: php.ini, 2: post_max_size, 3: upload_max_filesize */
				__( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your %1$s file or by %2$s being defined as smaller than %3$s in %1$s.' ),
				'php.ini',
				'post_max_size',
				'upload_max_filesize'
			),
		);
	}

	$overrides                 = array(
		'test_form' => false,
		'test_type' => false,
	);
	$_FILES['import']['name'] .= '.txt';
	$upload                    = wp_handle_upload( $_FILES['import'], $overrides );

	if ( isset( $upload['error'] ) ) {
		return $upload;
	}

	// Construct the object array.
	$object = array(
		'post_title'     => wp_basename( $upload['file'] ),
		'post_content'   => $upload['url'],
		'post_mime_type' => $upload['type'],
		'guid'           => $upload['url'],
		'context'        => 'import',
		'post_status'    => 'private',
	);

	// Save the data.
	$id = wp_insert_attachment( $object, $upload['file'] );

	/*
	 * Schedule a cleanup for one day from now in case of failed
	 * import or missing wp_import_cleanup() call.
	 */
	wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );

	return array(
		'file' => $upload['file'],
		'id'   => $id,
	);
}

/**
 * Returns a list from WordPress.org of popular importer plugins.
 *
 * @since 3.5.0
 *
 * @return array Importers with metadata for each.
 */
function wp_get_popular_importers() {
	// Include an unmodified $wp_version.
	require ABSPATH . WPINC . '/version.php';

	$locale            = get_user_locale();
	$cache_key         = 'popular_importers_' . md5( $locale . $wp_version );
	$popular_importers = get_site_transient( $cache_key );

	if ( ! $popular_importers ) {
		$url     = add_query_arg(
			array(
				'locale'  => $locale,
				'version' => $wp_version,
			),
			'http://api.wordpress.org/core/importers/1.1/'
		);
		$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );

		if ( wp_http_supports( array( 'ssl' ) ) ) {
			$url = set_url_scheme( $url, 'https' );
		}

		$response          = wp_remote_get( $url, $options );
		$popular_importers = json_decode( wp_remote_retrieve_body( $response ), true );

		if ( is_array( $popular_importers ) ) {
			set_site_transient( $cache_key, $popular_importers, 2 * DAY_IN_SECONDS );
		} else {
			$popular_importers = false;
		}
	}

	if ( is_array( $popular_importers ) ) {
		// If the data was received as translated, return it as-is.
		if ( $popular_importers['translated'] ) {
			return $popular_importers['importers'];
		}

		foreach ( $popular_importers['importers'] as &$importer ) {
			// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
			$importer['description'] = translate( $importer['description'] );
			if ( 'WordPress' !== $importer['name'] ) {
				// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
				$importer['name'] = translate( $importer['name'] );
			}
		}
		return $popular_importers['importers'];
	}

	return array(
		// slug => name, description, plugin slug, and register_importer() slug.
		'blogger'     => array(
			'name'        => __( 'Blogger' ),
			'description' => __( 'Import posts, comments, and users from a Blogger blog.' ),
			'plugin-slug' => 'blogger-importer',
			'importer-id' => 'blogger',
		),
		'wpcat2tag'   => array(
			'name'        => __( 'Categories and Tags Converter' ),
			'description' => __( 'Convert existing categories to tags or tags to categories, selectively.' ),
			'plugin-slug' => 'wpcat2tag-importer',
			'importer-id' => 'wp-cat2tag',
		),
		'livejournal' => array(
			'name'        => __( 'LiveJournal' ),
			'description' => __( 'Import posts from LiveJournal using their API.' ),
			'plugin-slug' => 'livejournal-importer',
			'importer-id' => 'livejournal',
		),
		'movabletype' => array(
			'name'        => __( 'Movable Type and TypePad' ),
			'description' => __( 'Import posts and comments from a Movable Type or TypePad blog.' ),
			'plugin-slug' => 'movabletype-importer',
			'importer-id' => 'mt',
		),
		'rss'         => array(
			'name'        => __( 'RSS' ),
			'description' => __( 'Import posts from an RSS feed.' ),
			'plugin-slug' => 'rss-importer',
			'importer-id' => 'rss',
		),
		'tumblr'      => array(
			'name'        => __( 'Tumblr' ),
			'description' => __( 'Import posts &amp; media from Tumblr using their API.' ),
			'plugin-slug' => 'tumblr-importer',
			'importer-id' => 'tumblr',
		),
		'wordpress'   => array(
			'name'        => 'WordPress',
			'description' => __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ),
			'plugin-slug' => 'wordpress-importer',
			'importer-id' => 'wordpress',
		),
	);
}

Directory Contents

Dirs: 0 × Files: 105

Name Size Perms Modified Actions
6.52 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
3.47 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
140.67 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
9.33 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
3.15 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
2.02 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
2.06 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
5.18 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
14.33 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
20.30 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
46.79 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.08 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
5.30 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
8.28 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
26.57 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
2.33 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
14.40 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
191.43 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
11.58 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
3.20 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
20.95 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
12.16 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
3.99 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
24.03 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.28 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.97 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
11.99 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
3.40 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
47.06 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
29.53 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
18.02 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
56.00 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
22.60 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
16.21 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
19.62 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
16.45 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
21.45 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
7.36 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.43 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
7.73 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
1.05 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
39.37 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
23.19 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
19.92 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
26.56 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
13.78 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
22.65 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
42.00 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
1.44 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
56.80 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.58 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.74 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
32.32 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
11.15 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
35.97 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
13.44 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
79.16 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
6.01 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
18.59 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
15.03 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
9.95 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
6.01 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
1.44 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
35.36 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
17.35 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
5.92 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
20.26 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
5.42 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
63.42 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
39.73 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
1.40 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
23.05 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
82.32 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
35.03 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
33.72 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
6.48 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
3.15 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
111.97 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
8.94 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
61.81 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
42.95 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
1.34 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
2.96 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
33.14 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
45.45 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
24.39 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
1.06 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
4.03 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
33.72 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
83.93 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
74.52 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
31.52 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
15.55 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
40.73 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
6.20 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
7.79 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
89.80 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
6.43 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
43.22 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
8.66 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
58.53 KB lrw-r--r-- 2025-10-08 16:39:39
Edit Download
33.07 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
103.38 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
18.03 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download
10.53 KB lrw-r--r-- 2024-11-22 17:53:11
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).