Skip to content

Commit

Permalink
Update WordPress Importer plugin from 0.8.2 to 0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpoke-bot committed Oct 23, 2024
1 parent 732c7b6 commit f68050a
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 94 deletions.
104 changes: 52 additions & 52 deletions wp-content/plugins/wordpress-importer/class-wp-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@
* WordPress importer class.
*/
class WP_Import extends WP_Importer {
var $max_wxr_version = 1.2; // max. supported WXR version
public $max_wxr_version = 1.2; // max. supported WXR version

var $id; // WXR attachment ID
public $id; // WXR attachment ID

// information to import from WXR file
var $version;
var $authors = array();
var $posts = array();
var $terms = array();
var $categories = array();
var $tags = array();
var $base_url = '';
public $version;
public $authors = array();
public $posts = array();
public $terms = array();
public $categories = array();
public $tags = array();
public $base_url = '';

// mappings from old information to new
var $processed_authors = array();
var $author_mapping = array();
var $processed_terms = array();
var $processed_posts = array();
var $post_orphans = array();
var $processed_menu_items = array();
var $menu_item_orphans = array();
var $missing_menu_items = array();

var $fetch_attachments = false;
var $url_remap = array();
var $featured_images = array();
public $processed_authors = array();
public $author_mapping = array();
public $processed_terms = array();
public $processed_posts = array();
public $post_orphans = array();
public $processed_menu_items = array();
public $menu_item_orphans = array();
public $missing_menu_items = array();

public $fetch_attachments = false;
public $url_remap = array();
public $featured_images = array();

/**
* Registered callback function for the WordPress Importer
*
* Manages the three separate stages of the WXR import process
*/
function dispatch() {
public function dispatch() {
$this->header();

$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
Expand Down Expand Up @@ -74,7 +74,7 @@ function dispatch() {
*
* @param string $file Path to the WXR file for importing
*/
function import( $file ) {
public function import( $file ) {
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );

Expand Down Expand Up @@ -102,7 +102,7 @@ function import( $file ) {
*
* @param string $file Path to the WXR file for importing
*/
function import_start( $file ) {
public function import_start( $file ) {
if ( ! is_file( $file ) ) {
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
echo __( 'The file does not exist, please try again.', 'wordpress-importer' ) . '</p>';
Expand Down Expand Up @@ -136,7 +136,7 @@ function import_start( $file ) {
/**
* Performs post-import cleanup of files and the cache
*/
function import_end() {
public function import_end() {
wp_import_cleanup( $this->id );

wp_cache_flush();
Expand All @@ -160,7 +160,7 @@ function import_end() {
*
* @return bool False if error uploading or invalid file, true otherwise
*/
function handle_upload() {
public function handle_upload() {
$file = wp_import_handle_upload();

if ( isset( $file['error'] ) ) {
Expand Down Expand Up @@ -202,7 +202,7 @@ function handle_upload() {
*
* @param array $import_data Data returned by a WXR parser
*/
function get_authors_from_import( $import_data ) {
public function get_authors_from_import( $import_data ) {
if ( ! empty( $import_data['authors'] ) ) {
$this->authors = $import_data['authors'];
// no author information, grab it from the posts
Expand All @@ -229,7 +229,7 @@ function get_authors_from_import( $import_data ) {
* Display pre-import options, author importing/mapping and option to
* fetch attachments
*/
function import_options() {
public function import_options() {
$j = 0;
// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
?>
Expand Down Expand Up @@ -271,7 +271,7 @@ function import_options() {
* @param int $n Index for each author in the form
* @param array $author Author information, e.g. login, display name, email
*/
function author_select( $n, $author ) {
public function author_select( $n, $author ) {
_e( 'Import author:', 'wordpress-importer' );
echo ' <strong>' . esc_html( $author['author_display_name'] );
if ( '1.0' != $this->version ) {
Expand Down Expand Up @@ -329,7 +329,7 @@ function author_select( $n, $author ) {
* in import options form. Can map to an existing user, create a new user
* or falls back to the current user in case of error with either of the previous
*/
function get_author_mapping() {
public function get_author_mapping() {
if ( ! isset( $_POST['imported_authors'] ) ) {
return;
}
Expand Down Expand Up @@ -393,7 +393,7 @@ function get_author_mapping() {
*
* Doesn't create a new category if its slug already exists
*/
function process_categories() {
public function process_categories() {
$this->categories = apply_filters( 'wp_import_categories', $this->categories );

if ( empty( $this->categories ) ) {
Expand Down Expand Up @@ -448,7 +448,7 @@ function process_categories() {
*
* Doesn't create a tag if its slug already exists
*/
function process_tags() {
public function process_tags() {
$this->tags = apply_filters( 'wp_import_tags', $this->tags );

if ( empty( $this->tags ) ) {
Expand Down Expand Up @@ -499,7 +499,7 @@ function process_tags() {
*
* Doesn't create a term its slug already exists
*/
function process_terms() {
public function process_terms() {
$this->terms = apply_filters( 'wp_import_terms', $this->terms );

if ( empty( $this->terms ) ) {
Expand Down Expand Up @@ -624,7 +624,7 @@ protected function process_termmeta( $term, $term_id ) {
* is already noted as imported or a post with the same title and date already exists.
* Note that new/updated terms, comments and meta are imported for the last of the above.
*/
function process_posts() {
public function process_posts() {
$this->posts = apply_filters( 'wp_import_posts', $this->posts );

foreach ( $this->posts as $post ) {
Expand Down Expand Up @@ -656,7 +656,7 @@ function process_posts() {

$post_type_object = get_post_type_object( $post['post_type'] );

$post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
$post_exists = post_exists( $post['post_title'], '', $post['post_date'], $post['post_type'] );

/**
* Filter ID of the existing post corresponding to post currently importing.
Expand Down Expand Up @@ -859,7 +859,7 @@ function process_posts() {
add_comment_meta( $inserted_comments[ $key ], wp_slash( $meta['key'] ), wp_slash_strings_only( $value ) );
}

$num_comments++;
++$num_comments;
}
}
unset( $newcomments, $inserted_comments, $post['comments'] );
Expand Down Expand Up @@ -917,7 +917,7 @@ function process_posts() {
*
* @param array $item Menu item details from WXR file
*/
function process_menu_item( $item ) {
public function process_menu_item( $item ) {
// skip draft, orphaned menu items
if ( 'draft' == $item['status'] ) {
return;
Expand Down Expand Up @@ -1006,7 +1006,7 @@ function process_menu_item( $item ) {
* @param string $url URL to fetch attachment from
* @return int|WP_Error Post ID on success, WP_Error otherwise
*/
function process_attachment( $post, $url ) {
public function process_attachment( $post, $url ) {
if ( ! $this->fetch_attachments ) {
return new WP_Error(
'attachment_processing_error',
Expand Down Expand Up @@ -1058,7 +1058,7 @@ function process_attachment( $post, $url ) {
* @param array $post Attachment details
* @return array|WP_Error Local file location details on success, WP_Error otherwise
*/
function fetch_remote_file( $url, $post ) {
public function fetch_remote_file( $url, $post ) {
// Extract the file name from the URL.
$path = parse_url( $url, PHP_URL_PATH );
$file_name = '';
Expand Down Expand Up @@ -1220,7 +1220,7 @@ function fetch_remote_file( $url, $post ) {
* so try again. Similarly for child menu items and menu items which were missing
* the object (e.g. post) they represent in the menu
*/
function backfill_parents() {
public function backfill_parents() {
global $wpdb;

// find parents for post orphans
Expand Down Expand Up @@ -1266,7 +1266,7 @@ function backfill_parents() {
/**
* Use stored mapping information to update old attachment URLs
*/
function backfill_attachment_urls() {
public function backfill_attachment_urls() {
global $wpdb;
// make sure we do the longest urls first, in case one is a substring of another
uksort( $this->url_remap, array( &$this, 'cmpr_strlen' ) );
Expand All @@ -1282,7 +1282,7 @@ function backfill_attachment_urls() {
/**
* Update _thumbnail_id meta to new, imported attachment IDs
*/
function remap_featured_images() {
public function remap_featured_images() {
// cycle through posts that have a featured image
foreach ( $this->featured_images as $post_id => $value ) {
if ( isset( $this->processed_posts[ $value ] ) ) {
Expand All @@ -1301,13 +1301,13 @@ function remap_featured_images() {
* @param string $file Path to WXR file for parsing
* @return array Information gathered from the WXR file
*/
function parse( $file ) {
public function parse( $file ) {
$parser = new WXR_Parser();
return $parser->parse( $file );
}

// Display import page title
function header() {
public function header() {
echo '<div class="wrap">';
echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>';

Expand All @@ -1322,14 +1322,14 @@ function header() {
}

// Close div.wrap
function footer() {
public function footer() {
echo '</div>';
}

/**
* Display introductory text and file upload form
*/
function greet() {
public function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ) . '</p>';
echo '<p>' . __( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ) . '</p>';
Expand All @@ -1343,7 +1343,7 @@ function greet() {
* @param string $key The meta key to check
* @return string|bool The key if we do want to import, false if not
*/
function is_valid_meta_key( $key ) {
public function is_valid_meta_key( $key ) {
// skip attachment metadata since we'll regenerate it from scratch
// skip _edit_lock as not relevant for import
if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ), true ) ) {
Expand All @@ -1358,7 +1358,7 @@ function is_valid_meta_key( $key ) {
*
* @return bool True if creating users is allowed
*/
function allow_create_users() {
public function allow_create_users() {
return apply_filters( 'import_allow_create_users', true );
}

Expand All @@ -1369,7 +1369,7 @@ function allow_create_users() {
*
* @return bool True if downloading attachments is allowed
*/
function allow_fetch_attachments() {
public function allow_fetch_attachments() {
return apply_filters( 'import_allow_fetch_attachments', true );
}

Expand All @@ -1379,20 +1379,20 @@ function allow_fetch_attachments() {
*
* @return int Maximum attachment file size to import
*/
function max_attachment_size() {
public function max_attachment_size() {
return apply_filters( 'import_attachment_size_limit', 0 );
}

/**
* Added to http_request_timeout filter to force timeout at 60 seconds during import
* @return int 60
*/
function bump_request_timeout( $val ) {
public function bump_request_timeout( $val ) {
return 60;
}

// return the difference in length between two strings
function cmpr_strlen( $a, $b ) {
public function cmpr_strlen( $a, $b ) {
return strlen( $b ) - strlen( $a );
}

Expand Down
8 changes: 4 additions & 4 deletions wp-content/plugins/wordpress-importer/parsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
_deprecated_file( basename( __FILE__ ), '0.7.0' );

/** WXR_Parser class */
require_once dirname( __FILE__ ) . '/parsers/class-wxr-parser.php';
require_once __DIR__ . '/parsers/class-wxr-parser.php';

/** WXR_Parser_SimpleXML class */
require_once dirname( __FILE__ ) . '/parsers/class-wxr-parser-simplexml.php';
require_once __DIR__ . '/parsers/class-wxr-parser-simplexml.php';

/** WXR_Parser_XML class */
require_once dirname( __FILE__ ) . '/parsers/class-wxr-parser-xml.php';
require_once __DIR__ . '/parsers/class-wxr-parser-xml.php';

/** WXR_Parser_Regex class */
require_once dirname( __FILE__ ) . '/parsers/class-wxr-parser-regex.php';
require_once __DIR__ . '/parsers/class-wxr-parser-regex.php';
Loading

0 comments on commit f68050a

Please sign in to comment.