From 53a7b244e751322face3cd208fac64a20740fc77 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Tue, 12 Sep 2023 02:22:37 +0300 Subject: [PATCH] chore: update wordpress-importer to 0.8.1 --- wordpress-importer/class-wp-import.php | 605 ++++++++++-------- wordpress-importer/compat.php | 30 - .../parsers/class-wxr-parser-regex.php | 170 +++-- .../parsers/class-wxr-parser-simplexml.php | 198 +++--- .../parsers/class-wxr-parser-xml.php | 198 ++++-- .../parsers/class-wxr-parser.php | 15 +- wordpress-importer/readme.txt | 251 ++++---- wordpress-importer/wordpress-importer.php | 29 +- 8 files changed, 857 insertions(+), 639 deletions(-) diff --git a/wordpress-importer/class-wp-import.php b/wordpress-importer/class-wp-import.php index ac3a3920ad..e1cb0940e2 100644 --- a/wordpress-importer/class-wp-import.php +++ b/wordpress-importer/class-wp-import.php @@ -16,26 +16,26 @@ class WP_Import extends WP_Importer { // information to import from WXR file var $version; - var $authors = array(); - var $posts = array(); - var $terms = array(); + var $authors = array(); + var $posts = array(); + var $terms = array(); var $categories = array(); - var $tags = array(); - var $base_url = ''; + var $tags = array(); + var $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_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 $menu_item_orphans = array(); + var $missing_menu_items = array(); var $fetch_attachments = false; - var $url_remap = array(); - var $featured_images = array(); + var $url_remap = array(); + var $featured_images = array(); /** * Registered callback function for the WordPress Importer @@ -52,15 +52,16 @@ function dispatch() { break; case 1: check_admin_referer( 'import-upload' ); - if ( $this->handle_upload() ) + if ( $this->handle_upload() ) { $this->import_options(); + } break; case 2: check_admin_referer( 'import-wordpress' ); $this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() ); - $this->id = (int) $_POST['import_id']; - $file = get_attached_file( $this->id ); - set_time_limit(0); + $this->id = (int) $_POST['import_id']; + $file = get_attached_file( $this->id ); + set_time_limit( 0 ); $this->import( $file ); break; } @@ -102,7 +103,7 @@ function import( $file ) { * @param string $file Path to the WXR file for importing */ function import_start( $file ) { - if ( ! is_file($file) ) { + if ( ! is_file( $file ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; echo __( 'The file does not exist, please try again.', 'wordpress-importer' ) . '

'; $this->footer(); @@ -120,11 +121,11 @@ function import_start( $file ) { $this->version = $import_data['version']; $this->get_authors_from_import( $import_data ); - $this->posts = $import_data['posts']; - $this->terms = $import_data['terms']; + $this->posts = $import_data['posts']; + $this->terms = $import_data['terms']; $this->categories = $import_data['categories']; - $this->tags = $import_data['tags']; - $this->base_url = esc_url( $import_data['base_url'] ); + $this->tags = $import_data['tags']; + $this->base_url = esc_url( $import_data['base_url'] ); wp_defer_term_counting( true ); wp_defer_comment_counting( true ); @@ -166,14 +167,14 @@ function handle_upload() { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; echo esc_html( $file['error'] ) . '

'; return false; - } else if ( ! file_exists( $file['file'] ) ) { + } elseif ( ! file_exists( $file['file'] ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; printf( __( 'The export file could not be found at %s. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file['file'] ) ); echo '

'; return false; } - $this->id = (int) $file['id']; + $this->id = (int) $file['id']; $import_data = $this->parse( $file['file'] ); if ( is_wp_error( $import_data ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; @@ -184,7 +185,7 @@ function handle_upload() { $this->version = $import_data['version']; if ( $this->version > $this->max_wxr_version ) { echo '

'; - printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html($import_data['version']) ); + printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html( $import_data['version'] ) ); echo '

'; } @@ -204,7 +205,7 @@ function handle_upload() { 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 + // no author information, grab it from the posts } else { foreach ( $import_data['posts'] as $post ) { $login = sanitize_user( $post['post_author'], true ); @@ -214,11 +215,12 @@ function get_authors_from_import( $import_data ) { continue; } - if ( ! isset($this->authors[$login]) ) - $this->authors[$login] = array( - 'author_login' => $login, - 'author_display_name' => $post['post_author'] + if ( ! isset( $this->authors[ $login ] ) ) { + $this->authors[ $login ] = array( + 'author_login' => $login, + 'author_display_name' => $post['post_author'], ); + } } } } @@ -229,7 +231,8 @@ function get_authors_from_import( $import_data ) { */ function import_options() { $j = 0; -?> + // phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect + ?>
@@ -238,7 +241,7 @@ function import_options() {

allow_create_users() ) : ?> -

+

    authors as $author ) : ?> @@ -257,7 +260,8 @@ function import_options() {

    -' . esc_html( $author['author_display_name'] ); - if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')'; + if ( '1.0' != $this->version ) { + echo ' (' . esc_html( $author['author_login'] ) . ')'; + } echo '
    '; - if ( $this->version != '1.0' ) + if ( '1.0' != $this->version ) { echo '
    '; + } $create_users = $this->allow_create_users(); if ( $create_users ) { - echo '
    '; + } } /** @@ -320,55 +330,60 @@ function author_select( $n, $author ) { * or falls back to the current user in case of error with either of the previous */ function get_author_mapping() { - if ( ! isset( $_POST['imported_authors'] ) ) + if ( ! isset( $_POST['imported_authors'] ) ) { return; + } $create_users = $this->allow_create_users(); foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) { // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts. $santized_old_login = sanitize_user( $old_login, true ); - $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false; + $old_id = isset( $this->authors[ $old_login ]['author_id'] ) ? intval( $this->authors[ $old_login ]['author_id'] ) : false; - if ( ! empty( $_POST['user_map'][$i] ) ) { - $user = get_userdata( intval($_POST['user_map'][$i]) ); + if ( ! empty( $_POST['user_map'][ $i ] ) ) { + $user = get_userdata( intval( $_POST['user_map'][ $i ] ) ); if ( isset( $user->ID ) ) { - if ( $old_id ) - $this->processed_authors[$old_id] = $user->ID; - $this->author_mapping[$santized_old_login] = $user->ID; + if ( $old_id ) { + $this->processed_authors[ $old_id ] = $user->ID; + } + $this->author_mapping[ $santized_old_login ] = $user->ID; } - } else if ( $create_users ) { - if ( ! empty($_POST['user_new'][$i]) ) { - $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() ); - } else if ( $this->version != '1.0' ) { + } elseif ( $create_users ) { + if ( ! empty( $_POST['user_new'][ $i ] ) ) { + $user_id = wp_create_user( $_POST['user_new'][ $i ], wp_generate_password() ); + } elseif ( '1.0' != $this->version ) { $user_data = array( - 'user_login' => $old_login, - 'user_pass' => wp_generate_password(), - 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '', - 'display_name' => $this->authors[$old_login]['author_display_name'], - 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '', - 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '', + 'user_login' => $old_login, + 'user_pass' => wp_generate_password(), + 'user_email' => isset( $this->authors[ $old_login ]['author_email'] ) ? $this->authors[ $old_login ]['author_email'] : '', + 'display_name' => $this->authors[ $old_login ]['author_display_name'], + 'first_name' => isset( $this->authors[ $old_login ]['author_first_name'] ) ? $this->authors[ $old_login ]['author_first_name'] : '', + 'last_name' => isset( $this->authors[ $old_login ]['author_last_name'] ) ? $this->authors[ $old_login ]['author_last_name'] : '', ); - $user_id = wp_insert_user( $user_data ); + $user_id = wp_insert_user( $user_data ); } if ( ! is_wp_error( $user_id ) ) { - if ( $old_id ) - $this->processed_authors[$old_id] = $user_id; - $this->author_mapping[$santized_old_login] = $user_id; + if ( $old_id ) { + $this->processed_authors[ $old_id ] = $user_id; + } + $this->author_mapping[ $santized_old_login ] = $user_id; } else { - printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html($this->authors[$old_login]['author_display_name']) ); - if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) + printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $this->authors[ $old_login ]['author_display_name'] ) ); + if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo ' ' . $user_id->get_error_message(); + } echo '
    '; } } // failsafe: if the user_id was invalid, default to the current user - if ( ! isset( $this->author_mapping[$santized_old_login] ) ) { - if ( $old_id ) - $this->processed_authors[$old_id] = (int) get_current_user_id(); - $this->author_mapping[$santized_old_login] = (int) get_current_user_id(); + if ( ! isset( $this->author_mapping[ $santized_old_login ] ) ) { + if ( $old_id ) { + $this->processed_authors[ $old_id ] = (int) get_current_user_id(); + } + $this->author_mapping[ $santized_old_login ] = (int) get_current_user_id(); } } } @@ -381,16 +396,20 @@ function get_author_mapping() { function process_categories() { $this->categories = apply_filters( 'wp_import_categories', $this->categories ); - if ( empty( $this->categories ) ) + if ( empty( $this->categories ) ) { return; + } foreach ( $this->categories as $cat ) { // if the category already exists leave it alone $term_id = term_exists( $cat['category_nicename'], 'category' ); if ( $term_id ) { - if ( is_array($term_id) ) $term_id = $term_id['term_id']; - if ( isset($cat['term_id']) ) - $this->processed_terms[intval($cat['term_id'])] = (int) $term_id; + if ( is_array( $term_id ) ) { + $term_id = $term_id['term_id']; + } + if ( isset( $cat['term_id'] ) ) { + $this->processed_terms[ intval( $cat['term_id'] ) ] = (int) $term_id; + } continue; } @@ -404,14 +423,16 @@ function process_categories() { 'category_description' => wp_slash( $description ), ); - $id = wp_insert_category( $data ); + $id = wp_insert_category( $data, true ); if ( ! is_wp_error( $id ) && $id > 0 ) { - if ( isset($cat['term_id']) ) - $this->processed_terms[intval($cat['term_id'])] = $id; + if ( isset( $cat['term_id'] ) ) { + $this->processed_terms[ intval( $cat['term_id'] ) ] = $id; + } } else { - printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) ); - if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) + printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html( $cat['category_nicename'] ) ); + if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo ': ' . $id->get_error_message(); + } echo '
    '; continue; } @@ -430,16 +451,20 @@ function process_categories() { function process_tags() { $this->tags = apply_filters( 'wp_import_tags', $this->tags ); - if ( empty( $this->tags ) ) + if ( empty( $this->tags ) ) { return; + } foreach ( $this->tags as $tag ) { // if the tag already exists leave it alone $term_id = term_exists( $tag['tag_slug'], 'post_tag' ); if ( $term_id ) { - if ( is_array($term_id) ) $term_id = $term_id['term_id']; - if ( isset($tag['term_id']) ) - $this->processed_terms[intval($tag['term_id'])] = (int) $term_id; + if ( is_array( $term_id ) ) { + $term_id = $term_id['term_id']; + } + if ( isset( $tag['term_id'] ) ) { + $this->processed_terms[ intval( $tag['term_id'] ) ] = (int) $term_id; + } continue; } @@ -451,12 +476,14 @@ function process_tags() { $id = wp_insert_term( wp_slash( $tag['tag_name'] ), 'post_tag', $args ); if ( ! is_wp_error( $id ) ) { - if ( isset($tag['term_id']) ) - $this->processed_terms[intval($tag['term_id'])] = $id['term_id']; + if ( isset( $tag['term_id'] ) ) { + $this->processed_terms[ intval( $tag['term_id'] ) ] = $id['term_id']; + } } else { - printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) ); - if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) + printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html( $tag['tag_name'] ) ); + if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo ': ' . $id->get_error_message(); + } echo '
    '; continue; } @@ -475,16 +502,20 @@ function process_tags() { function process_terms() { $this->terms = apply_filters( 'wp_import_terms', $this->terms ); - if ( empty( $this->terms ) ) + if ( empty( $this->terms ) ) { return; + } foreach ( $this->terms as $term ) { // if the term already exists in the correct taxonomy leave it alone $term_id = term_exists( $term['slug'], $term['term_taxonomy'] ); if ( $term_id ) { - if ( is_array($term_id) ) $term_id = $term_id['term_id']; - if ( isset($term['term_id']) ) - $this->processed_terms[intval($term['term_id'])] = (int) $term_id; + if ( is_array( $term_id ) ) { + $term_id = $term_id['term_id']; + } + if ( isset( $term['term_id'] ) ) { + $this->processed_terms[ intval( $term['term_id'] ) ] = (int) $term_id; + } continue; } @@ -501,17 +532,19 @@ function process_terms() { $args = array( 'slug' => $term['slug'], 'description' => wp_slash( $description ), - 'parent' => (int) $parent + 'parent' => (int) $parent, ); $id = wp_insert_term( wp_slash( $term['term_name'] ), $term['term_taxonomy'], $args ); if ( ! is_wp_error( $id ) ) { - if ( isset($term['term_id']) ) - $this->processed_terms[intval($term['term_id'])] = $id['term_id']; + if ( isset( $term['term_id'] ) ) { + $this->processed_terms[ intval( $term['term_id'] ) ] = $id['term_id']; + } } else { - printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) ); - if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) + printf( __( 'Failed to import %1$s %2$s', 'wordpress-importer' ), esc_html( $term['term_taxonomy'] ), esc_html( $term['term_name'] ) ); + if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo ': ' . $id->get_error_message(); + } echo '
    '; continue; } @@ -531,10 +564,6 @@ function process_terms() { * @param int $term_id ID of the newly created term. */ protected function process_termmeta( $term, $term_id ) { - if ( ! function_exists( 'add_term_meta' ) ) { - return; - } - if ( ! isset( $term['termmeta'] ) ) { $term['termmeta'] = array(); } @@ -602,18 +631,23 @@ function process_posts() { $post = apply_filters( 'wp_import_post_data_raw', $post ); if ( ! post_type_exists( $post['post_type'] ) ) { - printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), - esc_html($post['post_title']), esc_html($post['post_type']) ); + printf( + __( 'Failed to import “%1$s”: Invalid post type %2$s', 'wordpress-importer' ), + esc_html( $post['post_title'] ), + esc_html( $post['post_type'] ) + ); echo '
    '; do_action( 'wp_import_post_exists', $post ); continue; } - if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) ) + if ( isset( $this->processed_posts[ $post['post_id'] ] ) && ! empty( $post['post_id'] ) ) { continue; + } - if ( $post['status'] == 'auto-draft' ) + if ( 'auto-draft' == $post['status'] ) { continue; + } if ( 'nav_menu_item' == $post['post_type'] ) { $this->process_menu_item( $post ); @@ -639,85 +673,105 @@ function process_posts() { $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post ); if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) { - printf( __('%s “%s” already exists.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) ); + printf( __( '%1$s “%2$s” already exists.', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html( $post['post_title'] ) ); echo '
    '; - $comment_post_ID = $post_id = $post_exists; + $comment_post_id = $post_exists; + $post_id = $post_exists; $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists ); } else { $post_parent = (int) $post['post_parent']; if ( $post_parent ) { // if we already know the parent, map it to the new local ID - if ( isset( $this->processed_posts[$post_parent] ) ) { - $post_parent = $this->processed_posts[$post_parent]; - // otherwise record the parent for later + if ( isset( $this->processed_posts[ $post_parent ] ) ) { + $post_parent = $this->processed_posts[ $post_parent ]; + // otherwise record the parent for later } else { - $this->post_orphans[intval($post['post_id'])] = $post_parent; - $post_parent = 0; + $this->post_orphans[ intval( $post['post_id'] ) ] = $post_parent; + $post_parent = 0; } } // map the post author $author = sanitize_user( $post['post_author'], true ); - if ( isset( $this->author_mapping[$author] ) ) - $author = $this->author_mapping[$author]; - else + if ( isset( $this->author_mapping[ $author ] ) ) { + $author = $this->author_mapping[ $author ]; + } else { $author = (int) get_current_user_id(); + } $postdata = array( - 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], - 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], - 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], - 'post_status' => $post['status'], 'post_name' => $post['post_name'], - 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], - 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], - 'post_type' => $post['post_type'], 'post_password' => $post['post_password'] + 'import_id' => $post['post_id'], + 'post_author' => $author, + 'post_date' => $post['post_date'], + 'post_date_gmt' => $post['post_date_gmt'], + 'post_content' => $post['post_content'], + 'post_excerpt' => $post['post_excerpt'], + 'post_title' => $post['post_title'], + 'post_status' => $post['status'], + 'post_name' => $post['post_name'], + 'comment_status' => $post['comment_status'], + 'ping_status' => $post['ping_status'], + 'guid' => $post['guid'], + 'post_parent' => $post_parent, + 'menu_order' => $post['menu_order'], + 'post_type' => $post['post_type'], + 'post_password' => $post['post_password'], ); - $original_post_ID = $post['post_id']; - $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post ); + $original_post_id = $post['post_id']; + $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post ); $postdata = wp_slash( $postdata ); if ( 'attachment' == $postdata['post_type'] ) { - $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']; + $remote_url = ! empty( $post['attachment_url'] ) ? $post['attachment_url'] : $post['guid']; // try to use _wp_attached file for upload folder placement to ensure the same location as the export site // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload() $postdata['upload_date'] = $post['post_date']; if ( isset( $post['postmeta'] ) ) { - foreach( $post['postmeta'] as $meta ) { - if ( $meta['key'] == '_wp_attached_file' ) { - if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) ) + foreach ( $post['postmeta'] as $meta ) { + if ( '_wp_attached_file' == $meta['key'] ) { + if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) ) { $postdata['upload_date'] = $matches[0]; + } break; } } } - $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url ); + $comment_post_id = $this->process_attachment( $postdata, $remote_url ); + $post_id = $comment_post_id; } else { - $comment_post_ID = $post_id = wp_insert_post( $postdata, true ); - do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post ); + $comment_post_id = wp_insert_post( $postdata, true ); + $post_id = $comment_post_id; + do_action( 'wp_import_insert_post', $post_id, $original_post_id, $postdata, $post ); } if ( is_wp_error( $post_id ) ) { - printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), - $post_type_object->labels->singular_name, esc_html($post['post_title']) ); - if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) + printf( + __( 'Failed to import %1$s “%2$s”', 'wordpress-importer' ), + $post_type_object->labels->singular_name, + esc_html( $post['post_title'] ) + ); + if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo ': ' . $post_id->get_error_message(); + } echo '
    '; continue; } - if ( $post['is_sticky'] == 1 ) + if ( 1 == $post['is_sticky'] ) { stick_post( $post_id ); + } } // map pre-import ID to local ID - $this->processed_posts[intval($post['post_id'])] = (int) $post_id; + $this->processed_posts[ intval( $post['post_id'] ) ] = (int) $post_id; - if ( ! isset( $post['terms'] ) ) + if ( ! isset( $post['terms'] ) ) { $post['terms'] = array(); + } $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post ); @@ -726,24 +780,25 @@ function process_posts() { $terms_to_set = array(); foreach ( $post['terms'] as $term ) { // back compat with WXR 1.0 map 'tag' to 'post_tag' - $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain']; + $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain']; $term_exists = term_exists( $term['slug'], $taxonomy ); - $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; + $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; if ( ! $term_id ) { $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) ); if ( ! is_wp_error( $t ) ) { $term_id = $t['term_id']; do_action( 'wp_import_insert_term', $t, $term, $post_id, $post ); } else { - printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) ); - if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) + printf( __( 'Failed to import %1$s %2$s', 'wordpress-importer' ), esc_html( $taxonomy ), esc_html( $term['name'] ) ); + if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo ': ' . $t->get_error_message(); + } echo '
    '; do_action( 'wp_import_insert_term_failed', $t, $term, $post_id, $post ); continue; } } - $terms_to_set[$taxonomy][] = intval( $term_id ); + $terms_to_set[ $taxonomy ][] = intval( $term_id ); } foreach ( $terms_to_set as $tax => $ids ) { @@ -753,38 +808,40 @@ function process_posts() { unset( $post['terms'], $terms_to_set ); } - if ( ! isset( $post['comments'] ) ) + if ( ! isset( $post['comments'] ) ) { $post['comments'] = array(); + } $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post ); // add/update comments if ( ! empty( $post['comments'] ) ) { - $num_comments = 0; + $num_comments = 0; $inserted_comments = array(); foreach ( $post['comments'] as $comment ) { - $comment_id = $comment['comment_id']; - $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; - $newcomments[$comment_id]['comment_author'] = $comment['comment_author']; - $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email']; - $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP']; - $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url']; - $newcomments[$comment_id]['comment_date'] = $comment['comment_date']; - $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; - $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; - $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; - $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; - $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; - $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array(); - if ( isset( $this->processed_authors[$comment['comment_user_id']] ) ) - $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']]; + $comment_id = $comment['comment_id']; + $newcomments[ $comment_id ]['comment_post_ID'] = $comment_post_id; + $newcomments[ $comment_id ]['comment_author'] = $comment['comment_author']; + $newcomments[ $comment_id ]['comment_author_email'] = $comment['comment_author_email']; + $newcomments[ $comment_id ]['comment_author_IP'] = $comment['comment_author_IP']; + $newcomments[ $comment_id ]['comment_author_url'] = $comment['comment_author_url']; + $newcomments[ $comment_id ]['comment_date'] = $comment['comment_date']; + $newcomments[ $comment_id ]['comment_date_gmt'] = $comment['comment_date_gmt']; + $newcomments[ $comment_id ]['comment_content'] = $comment['comment_content']; + $newcomments[ $comment_id ]['comment_approved'] = $comment['comment_approved']; + $newcomments[ $comment_id ]['comment_type'] = $comment['comment_type']; + $newcomments[ $comment_id ]['comment_parent'] = $comment['comment_parent']; + $newcomments[ $comment_id ]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array(); + if ( isset( $this->processed_authors[ $comment['comment_user_id'] ] ) ) { + $newcomments[ $comment_id ]['user_id'] = $this->processed_authors[ $comment['comment_user_id'] ]; + } } ksort( $newcomments ); foreach ( $newcomments as $key => $comment ) { // if this is a new post we can skip the comment_exists() check if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) { - if ( isset( $inserted_comments[$comment['comment_parent']] ) ) { + if ( isset( $inserted_comments[ $comment['comment_parent'] ] ) ) { $comment['comment_parent'] = $inserted_comments[ $comment['comment_parent'] ]; } @@ -794,9 +851,9 @@ function process_posts() { $inserted_comments[ $key ] = wp_insert_comment( $comment_data ); - do_action( 'wp_import_insert_comment', $inserted_comments[ $key ], $comment, $comment_post_ID, $post ); + do_action( 'wp_import_insert_comment', $inserted_comments[ $key ], $comment, $comment_post_id, $post ); - foreach( $comment['commentmeta'] as $meta ) { + foreach ( $comment['commentmeta'] as $meta ) { $value = maybe_unserialize( $meta['value'] ); add_comment_meta( $inserted_comments[ $key ], wp_slash( $meta['key'] ), wp_slash_strings_only( $value ) ); @@ -808,22 +865,24 @@ function process_posts() { unset( $newcomments, $inserted_comments, $post['comments'] ); } - if ( ! isset( $post['postmeta'] ) ) + if ( ! isset( $post['postmeta'] ) ) { $post['postmeta'] = array(); + } $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post ); // add/update post meta if ( ! empty( $post['postmeta'] ) ) { foreach ( $post['postmeta'] as $meta ) { - $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post ); + $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post ); $value = false; if ( '_edit_last' == $key ) { - if ( isset( $this->processed_authors[intval($meta['value'])] ) ) - $value = $this->processed_authors[intval($meta['value'])]; - else + if ( isset( $this->processed_authors[ intval( $meta['value'] ) ] ) ) { + $value = $this->processed_authors[ intval( $meta['value'] ) ]; + } else { $key = false; + } } if ( $key ) { @@ -837,8 +896,9 @@ function process_posts() { do_action( 'import_post_meta', $post_id, $key, $value ); // if the post has a featured image, take note of this in case of remap - if ( '_thumbnail_id' == $key ) - $this->featured_images[$post_id] = (int) $value; + if ( '_thumbnail_id' == $key ) { + $this->featured_images[ $post_id ] = (int) $value; + } } } } @@ -859,11 +919,12 @@ function process_posts() { */ function process_menu_item( $item ) { // skip draft, orphaned menu items - if ( 'draft' == $item['status'] ) + if ( 'draft' == $item['status'] ) { return; + } $menu_slug = false; - if ( isset($item['terms']) ) { + if ( isset( $item['terms'] ) ) { // loop through terms, assume first nav_menu term is correct menu foreach ( $item['terms'] as $term ) { if ( 'nav_menu' == $term['domain'] ) { @@ -889,50 +950,53 @@ function process_menu_item( $item ) { $menu_id = is_array( $menu_id ) ? $menu_id['term_id'] : $menu_id; } - foreach ( $item['postmeta'] as $meta ) + foreach ( $item['postmeta'] as $meta ) { ${$meta['key']} = $meta['value']; + } - if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) { - $_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)]; - } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[intval($_menu_item_object_id)] ) ) { - $_menu_item_object_id = $this->processed_posts[intval($_menu_item_object_id)]; - } else if ( 'custom' != $_menu_item_type ) { + if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[ intval( $_menu_item_object_id ) ] ) ) { + $_menu_item_object_id = $this->processed_terms[ intval( $_menu_item_object_id ) ]; + } elseif ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[ intval( $_menu_item_object_id ) ] ) ) { + $_menu_item_object_id = $this->processed_posts[ intval( $_menu_item_object_id ) ]; + } elseif ( 'custom' != $_menu_item_type ) { // associated object is missing or not imported yet, we'll retry later $this->missing_menu_items[] = $item; return; } - if ( isset( $this->processed_menu_items[intval($_menu_item_menu_item_parent)] ) ) { - $_menu_item_menu_item_parent = $this->processed_menu_items[intval($_menu_item_menu_item_parent)]; - } else if ( $_menu_item_menu_item_parent ) { - $this->menu_item_orphans[intval($item['post_id'])] = (int) $_menu_item_menu_item_parent; - $_menu_item_menu_item_parent = 0; + if ( isset( $this->processed_menu_items[ intval( $_menu_item_menu_item_parent ) ] ) ) { + $_menu_item_menu_item_parent = $this->processed_menu_items[ intval( $_menu_item_menu_item_parent ) ]; + } elseif ( $_menu_item_menu_item_parent ) { + $this->menu_item_orphans[ intval( $item['post_id'] ) ] = (int) $_menu_item_menu_item_parent; + $_menu_item_menu_item_parent = 0; } // wp_update_nav_menu_item expects CSS classes as a space separated string $_menu_item_classes = maybe_unserialize( $_menu_item_classes ); - if ( is_array( $_menu_item_classes ) ) + if ( is_array( $_menu_item_classes ) ) { $_menu_item_classes = implode( ' ', $_menu_item_classes ); + } $args = array( - 'menu-item-object-id' => $_menu_item_object_id, - 'menu-item-object' => $_menu_item_object, - 'menu-item-parent-id' => $_menu_item_menu_item_parent, - 'menu-item-position' => intval( $item['menu_order'] ), - 'menu-item-type' => $_menu_item_type, - 'menu-item-title' => $item['post_title'], - 'menu-item-url' => $_menu_item_url, + 'menu-item-object-id' => $_menu_item_object_id, + 'menu-item-object' => $_menu_item_object, + 'menu-item-parent-id' => $_menu_item_menu_item_parent, + 'menu-item-position' => intval( $item['menu_order'] ), + 'menu-item-type' => $_menu_item_type, + 'menu-item-title' => $item['post_title'], + 'menu-item-url' => $_menu_item_url, 'menu-item-description' => $item['post_content'], - 'menu-item-attr-title' => $item['post_excerpt'], - 'menu-item-target' => $_menu_item_target, - 'menu-item-classes' => $_menu_item_classes, - 'menu-item-xfn' => $_menu_item_xfn, - 'menu-item-status' => $item['status'] + 'menu-item-attr-title' => $item['post_excerpt'], + 'menu-item-target' => $_menu_item_target, + 'menu-item-classes' => $_menu_item_classes, + 'menu-item-xfn' => $_menu_item_xfn, + 'menu-item-status' => $item['status'], ); $id = wp_update_nav_menu_item( $menu_id, 0, $args ); - if ( $id && ! is_wp_error( $id ) ) - $this->processed_menu_items[intval($item['post_id'])] = (int) $id; + if ( $id && ! is_wp_error( $id ) ) { + $this->processed_menu_items[ intval( $item['post_id'] ) ] = (int) $id; + } } /** @@ -943,22 +1007,29 @@ function process_menu_item( $item ) { * @return int|WP_Error Post ID on success, WP_Error otherwise */ function process_attachment( $post, $url ) { - if ( ! $this->fetch_attachments ) - return new WP_Error( 'attachment_processing_error', - __( 'Fetching attachments is not enabled', 'wordpress-importer' ) ); + if ( ! $this->fetch_attachments ) { + return new WP_Error( + 'attachment_processing_error', + __( 'Fetching attachments is not enabled', 'wordpress-importer' ) + ); + } // if the URL is absolute, but does not contain address, then upload it assuming base_site_url - if ( preg_match( '|^/[\w\W]+$|', $url ) ) + if ( preg_match( '|^/[\w\W]+$|', $url ) ) { $url = rtrim( $this->base_url, '/' ) . $url; + } $upload = $this->fetch_remote_file( $url, $post ); - if ( is_wp_error( $upload ) ) + if ( is_wp_error( $upload ) ) { return $upload; + } - if ( $info = wp_check_filetype( $upload['file'] ) ) + $info = wp_check_filetype( $upload['file'] ); + if ( $info ) { $post['post_mime_type'] = $info['type']; - else - return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') ); + } else { + return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) ); + } $post['guid'] = $upload['url']; @@ -969,12 +1040,12 @@ function process_attachment( $post, $url ) { // remap resized image URLs, works by stripping the extension and remapping the URL stub. if ( preg_match( '!^image/!', $info['type'] ) ) { $parts = pathinfo( $url ); - $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2 + $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2 $parts_new = pathinfo( $upload['url'] ); - $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); + $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); - $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new; + $this->url_remap[ $parts['dirname'] . '/' . $name ] = $parts_new['dirname'] . '/' . $name_new; } return $post_id; @@ -989,7 +1060,11 @@ function process_attachment( $post, $url ) { */ function fetch_remote_file( $url, $post ) { // Extract the file name from the URL. - $file_name = basename( parse_url( $url, PHP_URL_PATH ) ); + $path = parse_url( $url, PHP_URL_PATH ); + $file_name = ''; + if ( is_string( $path ) ) { + $file_name = basename( $path ); + } if ( ! $file_name ) { $file_name = md5( $url ); @@ -1001,14 +1076,17 @@ function fetch_remote_file( $url, $post ) { } // Fetch the remote URL and write it to the placeholder file. - $remote_response = wp_safe_remote_get( $url, array( - 'timeout' => 300, - 'stream' => true, - 'filename' => $tmp_file_name, - 'headers' => array( - 'Accept-Encoding' => 'identity', - ), - ) ); + $remote_response = wp_safe_remote_get( + $url, + array( + 'timeout' => 300, + 'stream' => true, + 'filename' => $tmp_file_name, + 'headers' => array( + 'Accept-Encoding' => 'identity', + ), + ) + ); if ( is_wp_error( $remote_response ) ) { @unlink( $tmp_file_name ); @@ -1044,25 +1122,25 @@ function fetch_remote_file( $url, $post ) { // Request failed. if ( ! $headers ) { @unlink( $tmp_file_name ); - return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') ); + return new WP_Error( 'import_file_error', __( 'Remote server did not respond', 'wordpress-importer' ) ); } $filesize = (int) filesize( $tmp_file_name ); if ( 0 === $filesize ) { @unlink( $tmp_file_name ); - return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wordpress-importer') ); + return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) ); } if ( ! isset( $headers['content-encoding'] ) && isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) { @unlink( $tmp_file_name ); - return new WP_Error( 'import_file_error', __('Downloaded file has incorrect size', 'wordpress-importer' ) ); + return new WP_Error( 'import_file_error', __( 'Downloaded file has incorrect size', 'wordpress-importer' ) ); } $max_size = (int) $this->max_attachment_size(); if ( ! empty( $max_size ) && $filesize > $max_size ) { @unlink( $tmp_file_name ); - return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer' ), size_format($max_size) ) ); + return new WP_Error( 'import_file_error', sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) ) ); } // Override file name with Content-Disposition header value. @@ -1125,11 +1203,12 @@ function fetch_remote_file( $url, $post ) { ); // keep track of the old and new urls so we can substitute them later - $this->url_remap[$url] = $upload['url']; - $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed? + $this->url_remap[ $url ] = $upload['url']; + $this->url_remap[ $post['guid'] ] = $upload['url']; // r13735, really needed? // keep track of the destination if the remote url is redirected somewhere else - if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url ) - $this->url_remap[$headers['x-final-location']] = $upload['url']; + if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) { + $this->url_remap[ $headers['x-final-location'] ] = $upload['url']; + } return $upload; } @@ -1146,11 +1225,14 @@ function backfill_parents() { // find parents for post orphans foreach ( $this->post_orphans as $child_id => $parent_id ) { - $local_child_id = $local_parent_id = false; - if ( isset( $this->processed_posts[$child_id] ) ) - $local_child_id = $this->processed_posts[$child_id]; - if ( isset( $this->processed_posts[$parent_id] ) ) - $local_parent_id = $this->processed_posts[$parent_id]; + $local_child_id = false; + $local_parent_id = false; + if ( isset( $this->processed_posts[ $child_id ] ) ) { + $local_child_id = $this->processed_posts[ $child_id ]; + } + if ( isset( $this->processed_posts[ $parent_id ] ) ) { + $local_parent_id = $this->processed_posts[ $parent_id ]; + } if ( $local_child_id && $local_parent_id ) { $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' ); @@ -1160,19 +1242,24 @@ function backfill_parents() { // all other posts/terms are imported, retry menu items with missing associated object $missing_menu_items = $this->missing_menu_items; - foreach ( $missing_menu_items as $item ) + foreach ( $missing_menu_items as $item ) { $this->process_menu_item( $item ); + } // find parents for menu item orphans foreach ( $this->menu_item_orphans as $child_id => $parent_id ) { - $local_child_id = $local_parent_id = 0; - if ( isset( $this->processed_menu_items[$child_id] ) ) - $local_child_id = $this->processed_menu_items[$child_id]; - if ( isset( $this->processed_menu_items[$parent_id] ) ) - $local_parent_id = $this->processed_menu_items[$parent_id]; + $local_child_id = 0; + $local_parent_id = 0; + if ( isset( $this->processed_menu_items[ $child_id ] ) ) { + $local_child_id = $this->processed_menu_items[ $child_id ]; + } + if ( isset( $this->processed_menu_items[ $parent_id ] ) ) { + $local_parent_id = $this->processed_menu_items[ $parent_id ]; + } - if ( $local_child_id && $local_parent_id ) + if ( $local_child_id && $local_parent_id ) { update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id ); + } } } @@ -1182,13 +1269,13 @@ function backfill_parents() { 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') ); + uksort( $this->url_remap, array( &$this, 'cmpr_strlen' ) ); foreach ( $this->url_remap as $from_url => $to_url ) { // remap urls in post_content - $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) ); + $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url ) ); // remap enclosure urls - $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) ); + $result = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url ) ); } } @@ -1198,11 +1285,12 @@ function backfill_attachment_urls() { 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] ) ) { - $new_id = $this->processed_posts[$value]; + if ( isset( $this->processed_posts[ $value ] ) ) { + $new_id = $this->processed_posts[ $value ]; // only update if there's a difference - if ( $new_id != $value ) + if ( $new_id != $value ) { update_post_meta( $post_id, '_thumbnail_id', $new_id ); + } } } } @@ -1223,10 +1311,10 @@ function header() { echo '
    '; echo '

    ' . __( 'Import WordPress', 'wordpress-importer' ) . '

    '; - $updates = get_plugin_updates(); - $basename = plugin_basename(__FILE__); - if ( isset( $updates[$basename] ) ) { - $update = $updates[$basename]; + $updates = get_plugin_updates(); + $basename = plugin_basename( __FILE__ ); + if ( isset( $updates[ $basename ] ) ) { + $update = $updates[ $basename ]; echo '

    '; printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version ); echo '

    '; @@ -1243,8 +1331,8 @@ function footer() { */ function greet() { echo '
    '; - echo '

    '.__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ).'

    '; - echo '

    '.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ).'

    '; + echo '

    ' . __( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ) . '

    '; + echo '

    ' . __( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ) . '

    '; wp_import_upload_form( 'admin.php?import=wordpress&step=1' ); echo '
    '; } @@ -1258,8 +1346,9 @@ function greet() { 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' ) ) ) + if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ), true ) ) { return false; + } return $key; } @@ -1304,7 +1393,7 @@ function bump_request_timeout( $val ) { // return the difference in length between two strings function cmpr_strlen( $a, $b ) { - return strlen($b) - strlen($a); + return strlen( $b ) - strlen( $a ); } /** diff --git a/wordpress-importer/compat.php b/wordpress-importer/compat.php index 22ebc4ed7b..590439ddcd 100644 --- a/wordpress-importer/compat.php +++ b/wordpress-importer/compat.php @@ -37,33 +37,3 @@ function addslashes_strings_only( $value ) { return is_string( $value ) ? addslashes( $value ) : $value; } } - -if ( ! function_exists( 'map_deep' ) ) { - /** - * Maps a function to all non-iterable elements of an array or an object. - * - * Compat for WordPress < 4.4.0. - * - * @since 0.7.0 - * - * @param mixed $value The array, object, or scalar. - * @param callable $callback The function to map onto $value. - * @return mixed The value with the callback applied to all non-arrays and non-objects inside it. - */ - function map_deep( $value, $callback ) { - if ( is_array( $value ) ) { - foreach ( $value as $index => $item ) { - $value[ $index ] = map_deep( $item, $callback ); - } - } elseif ( is_object( $value ) ) { - $object_vars = get_object_vars( $value ); - foreach ( $object_vars as $property_name => $property_value ) { - $value->$property_name = map_deep( $property_value, $callback ); - } - } else { - $value = call_user_func( $callback, $value ); - } - - return $value; - } -} diff --git a/wordpress-importer/parsers/class-wxr-parser-regex.php b/wordpress-importer/parsers/class-wxr-parser-regex.php index a68d287492..45baf6f9fa 100644 --- a/wordpress-importer/parsers/class-wxr-parser-regex.php +++ b/wordpress-importer/parsers/class-wxr-parser-regex.php @@ -10,20 +10,22 @@ * WXR Parser that uses regular expressions. Fallback for installs without an XML parser. */ class WXR_Parser_Regex { - var $authors = array(); - var $posts = array(); - var $categories = array(); - var $tags = array(); - var $terms = array(); - var $base_url = ''; - var $base_blog_url = ''; + public $authors = array(); + public $posts = array(); + public $categories = array(); + public $tags = array(); + public $terms = array(); + public $base_url = ''; + public $base_blog_url = ''; + public $has_gzip; function __construct() { $this->has_gzip = is_callable( 'gzopen' ); } function parse( $file ) { - $wxr_version = $in_multiline = false; + $wxr_version = false; + $in_multiline = false; $multiline_content = ''; @@ -37,10 +39,12 @@ function parse( $file ) { $fp = $this->fopen( $file, 'r' ); if ( $fp ) { while ( ! $this->feof( $fp ) ) { - $importline = rtrim( $this->fgets( $fp ) ); + $is_tag_line = false; + $importline = rtrim( $this->fgets( $fp ) ); - if ( ! $wxr_version && preg_match( '|(\d+\.\d+)|', $importline, $version ) ) + if ( ! $wxr_version && preg_match( '|(\d+\.\d+)|', $importline, $version ) ) { $wxr_version = $version[1]; + } if ( false !== strpos( $importline, '' ) ) { preg_match( '|(.*?)|is', $importline, $url ); @@ -52,58 +56,61 @@ function parse( $file ) { preg_match( '|(.*?)|is', $importline, $blog_url ); $this->base_blog_url = $blog_url[1]; continue; - } else { + } elseif ( empty( $this->base_blog_url ) ) { $this->base_blog_url = $this->base_url; } if ( false !== strpos( $importline, '' ) ) { preg_match( '|(.*?)|is', $importline, $author ); - $a = $this->process_author( $author[1] ); - $this->authors[$a['author_login']] = $a; + $a = $this->process_author( $author[1] ); + $this->authors[ $a['author_login'] ] = $a; continue; } foreach ( $multiline_tags as $tag => $handler ) { // Handle multi-line tags on a singular line + $pos = strpos( $importline, "<$tag>" ); + $pos_closing = strpos( $importline, "" ); if ( preg_match( '|<' . $tag . '>(.*?)|is', $importline, $matches ) ) { $this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] ); - } elseif ( false !== ( $pos = strpos( $importline, "<$tag>" ) ) ) { + } elseif ( false !== $pos ) { // Take note of any content after the opening tag $multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) ); // We don't want to have this line added to `$is_multiline` below. - $importline = ''; - $in_multiline = $tag; + $in_multiline = $tag; + $is_tag_line = true; - } elseif ( false !== ( $pos = strpos( $importline, "" ) ) ) { - $in_multiline = false; - $multiline_content .= trim( substr( $importline, 0, $pos ) ); + } elseif ( false !== $pos_closing ) { + $in_multiline = false; + $multiline_content .= trim( substr( $importline, 0, $pos_closing ) ); $this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content ); } } - if ( $in_multiline && $importline ) { + if ( $in_multiline && ! $is_tag_line ) { $multiline_content .= $importline . "\n"; } } - $this->fclose($fp); + $this->fclose( $fp ); } - if ( ! $wxr_version ) + if ( ! $wxr_version ) { return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); + } return array( - 'authors' => $this->authors, - 'posts' => $this->posts, - 'categories' => $this->categories, - 'tags' => $this->tags, - 'terms' => $this->terms, - 'base_url' => $this->base_url, + 'authors' => $this->authors, + 'posts' => $this->posts, + 'categories' => $this->categories, + 'tags' => $this->tags, + 'terms' => $this->terms, + 'base_url' => $this->base_url, 'base_blog_url' => $this->base_blog_url, - 'version' => $wxr_version + 'version' => $wxr_version, ); } @@ -114,8 +121,9 @@ function get_tag( $string, $tag ) { if ( strpos( $return[1], ']]]]>' ) !== false ) { preg_match_all( '||s', $return[1], $matches ); $return = ''; - foreach( $matches[1] as $match ) + foreach ( $matches[1] as $match ) { $return .= $match; + } } else { $return = preg_replace( '|^$|s', '$1', $return[1] ); } @@ -130,10 +138,10 @@ function get_tag( $string, $tag ) { function process_category( $c ) { $term = array( - 'term_id' => $this->get_tag( $c, 'wp:term_id' ), - 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ), - 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ), - 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ), + 'term_id' => $this->get_tag( $c, 'wp:term_id' ), + 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ), + 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ), + 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ), 'category_description' => $this->get_tag( $c, 'wp:category_description' ), ); @@ -147,9 +155,9 @@ function process_category( $c ) { function process_tag( $t ) { $term = array( - 'term_id' => $this->get_tag( $t, 'wp:term_id' ), - 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ), - 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ), + 'term_id' => $this->get_tag( $t, 'wp:term_id' ), + 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ), + 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ), 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ), ); @@ -163,11 +171,11 @@ function process_tag( $t ) { function process_term( $t ) { $term = array( - 'term_id' => $this->get_tag( $t, 'wp:term_id' ), - 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ), - 'slug' => $this->get_tag( $t, 'wp:term_slug' ), - 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ), - 'term_name' => $this->get_tag( $t, 'wp:term_name' ), + 'term_id' => $this->get_tag( $t, 'wp:term_id' ), + 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ), + 'slug' => $this->get_tag( $t, 'wp:term_slug' ), + 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ), + 'term_name' => $this->get_tag( $t, 'wp:term_name' ), 'term_description' => $this->get_tag( $t, 'wp:term_description' ), ); @@ -200,12 +208,12 @@ function process_meta( $string, $tag ) { function process_author( $a ) { return array( - 'author_id' => $this->get_tag( $a, 'wp:author_id' ), - 'author_login' => $this->get_tag( $a, 'wp:author_login' ), - 'author_email' => $this->get_tag( $a, 'wp:author_email' ), + 'author_id' => $this->get_tag( $a, 'wp:author_id' ), + 'author_login' => $this->get_tag( $a, 'wp:author_login' ), + 'author_email' => $this->get_tag( $a, 'wp:author_email' ), 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ), - 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ), - 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ), + 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ), + 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ), ); } @@ -236,43 +244,61 @@ function process_post( $post ) { $post_content = str_replace( '
    ', '
    ', $post_content ); $post_content = str_replace( '
    ', '
    ', $post_content ); - $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', - 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', - 'menu_order', 'post_type', 'post_password', 'is_sticky' + $postdata = compact( + 'post_id', + 'post_author', + 'post_date', + 'post_date_gmt', + 'post_content', + 'post_excerpt', + 'post_title', + 'status', + 'post_name', + 'comment_status', + 'ping_status', + 'guid', + 'post_parent', + 'menu_order', + 'post_type', + 'post_password', + 'is_sticky' ); $attachment_url = $this->get_tag( $post, 'wp:attachment_url' ); - if ( $attachment_url ) + if ( $attachment_url ) { $postdata['attachment_url'] = $attachment_url; + } preg_match_all( '|(.+?)|is', $post, $terms, PREG_SET_ORDER ); foreach ( $terms as $t ) { $post_terms[] = array( - 'slug' => $t[2], + 'slug' => $t[2], 'domain' => $t[1], - 'name' => str_replace( array( '' ), '', $t[3] ), + 'name' => str_replace( array( '' ), '', $t[3] ), ); } - if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms; + if ( ! empty( $post_terms ) ) { + $postdata['terms'] = $post_terms; + } preg_match_all( '|(.+?)|is', $post, $comments ); $comments = $comments[1]; if ( $comments ) { foreach ( $comments as $comment ) { $post_comments[] = array( - 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ), - 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ), + 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ), + 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ), 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ), - 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ), - 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ), - 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ), - 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ), - 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ), - 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ), - 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ), - 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ), - 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ), - 'commentmeta' => $this->process_meta( $comment, 'wp:commentmeta' ), + 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ), + 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ), + 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ), + 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ), + 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ), + 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ), + 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ), + 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ), + 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ), + 'commentmeta' => $this->process_meta( $comment, 'wp:commentmeta' ), ); } } @@ -293,26 +319,30 @@ function _normalize_tag( $matches ) { } function fopen( $filename, $mode = 'r' ) { - if ( $this->has_gzip ) + if ( $this->has_gzip ) { return gzopen( $filename, $mode ); + } return fopen( $filename, $mode ); } function feof( $fp ) { - if ( $this->has_gzip ) + if ( $this->has_gzip ) { return gzeof( $fp ); + } return feof( $fp ); } function fgets( $fp, $len = 8192 ) { - if ( $this->has_gzip ) + if ( $this->has_gzip ) { return gzgets( $fp, $len ); + } return fgets( $fp, $len ); } function fclose( $fp ) { - if ( $this->has_gzip ) + if ( $this->has_gzip ) { return gzclose( $fp ); + } return fclose( $fp ); } } diff --git a/wordpress-importer/parsers/class-wxr-parser-simplexml.php b/wordpress-importer/parsers/class-wxr-parser-simplexml.php index 0a57ef5cff..00dd110e22 100644 --- a/wordpress-importer/parsers/class-wxr-parser-simplexml.php +++ b/wordpress-importer/parsers/class-wxr-parser-simplexml.php @@ -11,13 +11,17 @@ */ class WXR_Parser_SimpleXML { function parse( $file ) { - $authors = $posts = $categories = $tags = $terms = array(); + $authors = array(); + $posts = array(); + $categories = array(); + $tags = array(); + $terms = array(); - $internal_errors = libxml_use_internal_errors(true); + $internal_errors = libxml_use_internal_errors( true ); - $dom = new DOMDocument; + $dom = new DOMDocument; $old_value = null; - if ( function_exists( 'libxml_disable_entity_loader' ) ) { + if ( function_exists( 'libxml_disable_entity_loader' ) && PHP_VERSION_ID < 80000 ) { $old_value = libxml_disable_entity_loader( true ); } $success = $dom->loadXML( file_get_contents( $file ) ); @@ -33,23 +37,25 @@ function parse( $file ) { unset( $dom ); // halt if loading produces an error - if ( ! $xml ) + if ( ! $xml ) { return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); + } - $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version'); - if ( ! $wxr_version ) + $wxr_version = $xml->xpath( '/rss/channel/wp:wxr_version' ); + if ( ! $wxr_version ) { return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); + } $wxr_version = (string) trim( $wxr_version[0] ); // confirm that we are dealing with the correct file format - if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) + if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) { return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); + } - $base_url = $xml->xpath('/rss/channel/wp:base_site_url'); + $base_url = $xml->xpath( '/rss/channel/wp:base_site_url' ); $base_url = (string) trim( isset( $base_url[0] ) ? $base_url[0] : '' ); - - $base_blog_url = $xml->xpath('/rss/channel/wp:base_blog_url'); + $base_blog_url = $xml->xpath( '/rss/channel/wp:base_blog_url' ); if ( $base_blog_url ) { $base_blog_url = (string) trim( $base_blog_url[0] ); } else { @@ -57,80 +63,82 @@ function parse( $file ) { } $namespaces = $xml->getDocNamespaces(); - if ( ! isset( $namespaces['wp'] ) ) + if ( ! isset( $namespaces['wp'] ) ) { $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; - if ( ! isset( $namespaces['excerpt'] ) ) + } + if ( ! isset( $namespaces['excerpt'] ) ) { $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; + } // grab authors - foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) { - $a = $author_arr->children( $namespaces['wp'] ); - $login = (string) $a->author_login; - $authors[$login] = array( - 'author_id' => (int) $a->author_id, - 'author_login' => $login, - 'author_email' => (string) $a->author_email, + foreach ( $xml->xpath( '/rss/channel/wp:author' ) as $author_arr ) { + $a = $author_arr->children( $namespaces['wp'] ); + $login = (string) $a->author_login; + $authors[ $login ] = array( + 'author_id' => (int) $a->author_id, + 'author_login' => $login, + 'author_email' => (string) $a->author_email, 'author_display_name' => (string) $a->author_display_name, - 'author_first_name' => (string) $a->author_first_name, - 'author_last_name' => (string) $a->author_last_name + 'author_first_name' => (string) $a->author_first_name, + 'author_last_name' => (string) $a->author_last_name, ); } // grab cats, tags and terms - foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) { - $t = $term_arr->children( $namespaces['wp'] ); + foreach ( $xml->xpath( '/rss/channel/wp:category' ) as $term_arr ) { + $t = $term_arr->children( $namespaces['wp'] ); $category = array( - 'term_id' => (int) $t->term_id, - 'category_nicename' => (string) $t->category_nicename, - 'category_parent' => (string) $t->category_parent, - 'cat_name' => (string) $t->cat_name, - 'category_description' => (string) $t->category_description + 'term_id' => (int) $t->term_id, + 'category_nicename' => (string) $t->category_nicename, + 'category_parent' => (string) $t->category_parent, + 'cat_name' => (string) $t->cat_name, + 'category_description' => (string) $t->category_description, ); foreach ( $t->termmeta as $meta ) { $category['termmeta'][] = array( - 'key' => (string) $meta->meta_key, - 'value' => (string) $meta->meta_value + 'key' => (string) $meta->meta_key, + 'value' => (string) $meta->meta_value, ); } $categories[] = $category; } - foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) { - $t = $term_arr->children( $namespaces['wp'] ); + foreach ( $xml->xpath( '/rss/channel/wp:tag' ) as $term_arr ) { + $t = $term_arr->children( $namespaces['wp'] ); $tag = array( - 'term_id' => (int) $t->term_id, - 'tag_slug' => (string) $t->tag_slug, - 'tag_name' => (string) $t->tag_name, - 'tag_description' => (string) $t->tag_description + 'term_id' => (int) $t->term_id, + 'tag_slug' => (string) $t->tag_slug, + 'tag_name' => (string) $t->tag_name, + 'tag_description' => (string) $t->tag_description, ); foreach ( $t->termmeta as $meta ) { $tag['termmeta'][] = array( - 'key' => (string) $meta->meta_key, - 'value' => (string) $meta->meta_value + 'key' => (string) $meta->meta_key, + 'value' => (string) $meta->meta_value, ); } $tags[] = $tag; } - foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) { - $t = $term_arr->children( $namespaces['wp'] ); + foreach ( $xml->xpath( '/rss/channel/wp:term' ) as $term_arr ) { + $t = $term_arr->children( $namespaces['wp'] ); $term = array( - 'term_id' => (int) $t->term_id, - 'term_taxonomy' => (string) $t->term_taxonomy, - 'slug' => (string) $t->term_slug, - 'term_parent' => (string) $t->term_parent, - 'term_name' => (string) $t->term_name, - 'term_description' => (string) $t->term_description + 'term_id' => (int) $t->term_id, + 'term_taxonomy' => (string) $t->term_taxonomy, + 'slug' => (string) $t->term_slug, + 'term_parent' => (string) $t->term_parent, + 'term_name' => (string) $t->term_name, + 'term_description' => (string) $t->term_description, ); foreach ( $t->termmeta as $meta ) { $term['termmeta'][] = array( - 'key' => (string) $meta->meta_key, - 'value' => (string) $meta->meta_value + 'key' => (string) $meta->meta_key, + 'value' => (string) $meta->meta_value, ); } @@ -141,48 +149,50 @@ function parse( $file ) { foreach ( $xml->channel->item as $item ) { $post = array( 'post_title' => (string) $item->title, - 'guid' => (string) $item->guid, + 'guid' => (string) $item->guid, ); - $dc = $item->children( 'http://purl.org/dc/elements/1.1/' ); + $dc = $item->children( 'http://purl.org/dc/elements/1.1/' ); $post['post_author'] = (string) $dc->creator; - $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' ); - $excerpt = $item->children( $namespaces['excerpt'] ); + $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' ); + $excerpt = $item->children( $namespaces['excerpt'] ); $post['post_content'] = (string) $content->encoded; $post['post_excerpt'] = (string) $excerpt->encoded; - $wp = $item->children( $namespaces['wp'] ); - $post['post_id'] = (int) $wp->post_id; - $post['post_date'] = (string) $wp->post_date; - $post['post_date_gmt'] = (string) $wp->post_date_gmt; + $wp = $item->children( $namespaces['wp'] ); + $post['post_id'] = (int) $wp->post_id; + $post['post_date'] = (string) $wp->post_date; + $post['post_date_gmt'] = (string) $wp->post_date_gmt; $post['comment_status'] = (string) $wp->comment_status; - $post['ping_status'] = (string) $wp->ping_status; - $post['post_name'] = (string) $wp->post_name; - $post['status'] = (string) $wp->status; - $post['post_parent'] = (int) $wp->post_parent; - $post['menu_order'] = (int) $wp->menu_order; - $post['post_type'] = (string) $wp->post_type; - $post['post_password'] = (string) $wp->post_password; - $post['is_sticky'] = (int) $wp->is_sticky; - - if ( isset($wp->attachment_url) ) + $post['ping_status'] = (string) $wp->ping_status; + $post['post_name'] = (string) $wp->post_name; + $post['status'] = (string) $wp->status; + $post['post_parent'] = (int) $wp->post_parent; + $post['menu_order'] = (int) $wp->menu_order; + $post['post_type'] = (string) $wp->post_type; + $post['post_password'] = (string) $wp->post_password; + $post['is_sticky'] = (int) $wp->is_sticky; + + if ( isset( $wp->attachment_url ) ) { $post['attachment_url'] = (string) $wp->attachment_url; + } foreach ( $item->category as $c ) { $att = $c->attributes(); - if ( isset( $att['nicename'] ) ) + if ( isset( $att['nicename'] ) ) { $post['terms'][] = array( - 'name' => (string) $c, - 'slug' => (string) $att['nicename'], - 'domain' => (string) $att['domain'] + 'name' => (string) $c, + 'slug' => (string) $att['nicename'], + 'domain' => (string) $att['domain'], ); + } } foreach ( $wp->postmeta as $meta ) { $post['postmeta'][] = array( - 'key' => (string) $meta->meta_key, - 'value' => (string) $meta->meta_value + 'key' => (string) $meta->meta_key, + 'value' => (string) $meta->meta_value, ); } @@ -191,26 +201,26 @@ function parse( $file ) { if ( isset( $comment->commentmeta ) ) { foreach ( $comment->commentmeta as $m ) { $meta[] = array( - 'key' => (string) $m->meta_key, - 'value' => (string) $m->meta_value + 'key' => (string) $m->meta_key, + 'value' => (string) $m->meta_value, ); } } $post['comments'][] = array( - 'comment_id' => (int) $comment->comment_id, - 'comment_author' => (string) $comment->comment_author, + 'comment_id' => (int) $comment->comment_id, + 'comment_author' => (string) $comment->comment_author, 'comment_author_email' => (string) $comment->comment_author_email, - 'comment_author_IP' => (string) $comment->comment_author_IP, - 'comment_author_url' => (string) $comment->comment_author_url, - 'comment_date' => (string) $comment->comment_date, - 'comment_date_gmt' => (string) $comment->comment_date_gmt, - 'comment_content' => (string) $comment->comment_content, - 'comment_approved' => (string) $comment->comment_approved, - 'comment_type' => (string) $comment->comment_type, - 'comment_parent' => (string) $comment->comment_parent, - 'comment_user_id' => (int) $comment->comment_user_id, - 'commentmeta' => $meta, + 'comment_author_IP' => (string) $comment->comment_author_IP, + 'comment_author_url' => (string) $comment->comment_author_url, + 'comment_date' => (string) $comment->comment_date, + 'comment_date_gmt' => (string) $comment->comment_date_gmt, + 'comment_content' => (string) $comment->comment_content, + 'comment_approved' => (string) $comment->comment_approved, + 'comment_type' => (string) $comment->comment_type, + 'comment_parent' => (string) $comment->comment_parent, + 'comment_user_id' => (int) $comment->comment_user_id, + 'commentmeta' => $meta, ); } @@ -218,14 +228,14 @@ function parse( $file ) { } return array( - 'authors' => $authors, - 'posts' => $posts, - 'categories' => $categories, - 'tags' => $tags, - 'terms' => $terms, - 'base_url' => $base_url, + 'authors' => $authors, + 'posts' => $posts, + 'categories' => $categories, + 'tags' => $tags, + 'terms' => $terms, + 'base_url' => $base_url, 'base_blog_url' => $base_blog_url, - 'version' => $wxr_version + 'version' => $wxr_version, ); } } diff --git a/wordpress-importer/parsers/class-wxr-parser-xml.php b/wordpress-importer/parsers/class-wxr-parser-xml.php index 981a5a7f23..e144c23507 100644 --- a/wordpress-importer/parsers/class-wxr-parser-xml.php +++ b/wordpress-importer/parsers/class-wxr-parser-xml.php @@ -10,23 +10,82 @@ * WXR Parser that makes use of the XML Parser PHP extension. */ class WXR_Parser_XML { - var $wp_tags = array( - 'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url', - 'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password', - 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description', - 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent', - 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name', - 'wp:author_first_name', 'wp:author_last_name', + public $wp_tags = array( + 'wp:post_id', + 'wp:post_date', + 'wp:post_date_gmt', + 'wp:comment_status', + 'wp:ping_status', + 'wp:attachment_url', + 'wp:status', + 'wp:post_name', + 'wp:post_parent', + 'wp:menu_order', + 'wp:post_type', + 'wp:post_password', + 'wp:is_sticky', + 'wp:term_id', + 'wp:category_nicename', + 'wp:category_parent', + 'wp:cat_name', + 'wp:category_description', + 'wp:tag_slug', + 'wp:tag_name', + 'wp:tag_description', + 'wp:term_taxonomy', + 'wp:term_parent', + 'wp:term_name', + 'wp:term_description', + 'wp:author_id', + 'wp:author_login', + 'wp:author_email', + 'wp:author_display_name', + 'wp:author_first_name', + 'wp:author_last_name', ); - var $wp_sub_tags = array( - 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url', - 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content', - 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id', + public $wp_sub_tags = array( + 'wp:comment_id', + 'wp:comment_author', + 'wp:comment_author_email', + 'wp:comment_author_url', + 'wp:comment_author_IP', + 'wp:comment_date', + 'wp:comment_date_gmt', + 'wp:comment_content', + 'wp:comment_approved', + 'wp:comment_type', + 'wp:comment_parent', + 'wp:comment_user_id', ); + public $wxr_version; + public $in_post; + public $cdata; + public $data; + public $sub_data; + public $in_tag; + public $in_sub_tag; + public $authors; + public $posts; + public $term; + public $category; + public $tag; + public $base_url; + public $base_blog_url; + function parse( $file ) { - $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; - $this->authors = $this->posts = $this->term = $this->category = $this->tag = array(); + $this->wxr_version = false; + $this->in_post = false; + $this->cdata = false; + $this->data = false; + $this->sub_data = false; + $this->in_tag = false; + $this->in_sub_tag = false; + $this->authors = array(); + $this->posts = array(); + $this->term = array(); + $this->category = array(); + $this->tag = array(); $xml = xml_parser_create( 'UTF-8' ); xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 ); @@ -36,63 +95,89 @@ function parse( $file ) { xml_set_element_handler( $xml, 'tag_open', 'tag_close' ); if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) { - $current_line = xml_get_current_line_number( $xml ); + $current_line = xml_get_current_line_number( $xml ); $current_column = xml_get_current_column_number( $xml ); - $error_code = xml_get_error_code( $xml ); - $error_string = xml_error_string( $error_code ); + $error_code = xml_get_error_code( $xml ); + $error_string = xml_error_string( $error_code ); return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) ); } xml_parser_free( $xml ); - if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) + if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) { return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); + } return array( - 'authors' => $this->authors, - 'posts' => $this->posts, - 'categories' => $this->category, - 'tags' => $this->tag, - 'terms' => $this->term, - 'base_url' => $this->base_url, + 'authors' => $this->authors, + 'posts' => $this->posts, + 'categories' => $this->category, + 'tags' => $this->tag, + 'terms' => $this->term, + 'base_url' => $this->base_url, 'base_blog_url' => $this->base_blog_url, - 'version' => $this->wxr_version + 'version' => $this->wxr_version, ); } function tag_open( $parse, $tag, $attr ) { - if ( in_array( $tag, $this->wp_tags ) ) { + if ( in_array( $tag, $this->wp_tags, true ) ) { $this->in_tag = substr( $tag, 3 ); return; } - if ( in_array( $tag, $this->wp_sub_tags ) ) { + if ( in_array( $tag, $this->wp_sub_tags, true ) ) { $this->in_sub_tag = substr( $tag, 3 ); return; } switch ( $tag ) { case 'category': - if ( isset($attr['domain'], $attr['nicename']) ) { + if ( isset( $attr['domain'], $attr['nicename'] ) ) { + if ( false === $this->sub_data ) { + $this->sub_data = array(); + } + $this->sub_data['domain'] = $attr['domain']; - $this->sub_data['slug'] = $attr['nicename']; + $this->sub_data['slug'] = $attr['nicename']; + } + break; + case 'item': + $this->in_post = true; + break; + case 'title': + if ( $this->in_post ) { + $this->in_tag = 'post_title'; } break; - case 'item': $this->in_post = true; - case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break; - case 'guid': $this->in_tag = 'guid'; break; - case 'dc:creator': $this->in_tag = 'post_author'; break; - case 'content:encoded': $this->in_tag = 'post_content'; break; - case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break; + case 'guid': + $this->in_tag = 'guid'; + break; + case 'dc:creator': + $this->in_tag = 'post_author'; + break; + case 'content:encoded': + $this->in_tag = 'post_content'; + break; + case 'excerpt:encoded': + $this->in_tag = 'post_excerpt'; + break; - case 'wp:term_slug': $this->in_tag = 'slug'; break; - case 'wp:meta_key': $this->in_sub_tag = 'key'; break; - case 'wp:meta_value': $this->in_sub_tag = 'value'; break; + case 'wp:term_slug': + $this->in_tag = 'slug'; + break; + case 'wp:meta_key': + $this->in_sub_tag = 'key'; + break; + case 'wp:meta_value': + $this->in_sub_tag = 'value'; + break; } } function cdata( $parser, $cdata ) { - if ( ! trim( $cdata ) ) + if ( ! trim( $cdata ) ) { return; + } if ( false !== $this->in_tag || false !== $this->in_sub_tag ) { $this->cdata .= $cdata; @@ -105,31 +190,33 @@ function tag_close( $parser, $tag ) { switch ( $tag ) { case 'wp:comment': unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data - if ( ! empty( $this->sub_data ) ) + if ( ! empty( $this->sub_data ) ) { $this->data['comments'][] = $this->sub_data; + } $this->sub_data = false; break; case 'wp:commentmeta': $this->sub_data['commentmeta'][] = array( - 'key' => $this->sub_data['key'], - 'value' => $this->sub_data['value'] + 'key' => $this->sub_data['key'], + 'value' => $this->sub_data['value'], ); break; case 'category': if ( ! empty( $this->sub_data ) ) { $this->sub_data['name'] = $this->cdata; - $this->data['terms'][] = $this->sub_data; + $this->data['terms'][] = $this->sub_data; } $this->sub_data = false; break; case 'wp:postmeta': - if ( ! empty( $this->sub_data ) ) + if ( ! empty( $this->sub_data ) ) { $this->data['postmeta'][] = $this->sub_data; + } $this->sub_data = false; break; case 'item': $this->posts[] = $this->data; - $this->data = false; + $this->data = false; break; case 'wp:category': case 'wp:tag': @@ -145,8 +232,9 @@ function tag_close( $parser, $tag ) { $this->sub_data = false; break; case 'wp:author': - if ( ! empty($this->data['author_login']) ) - $this->authors[$this->data['author_login']] = $this->data; + if ( ! empty( $this->data['author_login'] ) ) { + $this->authors[ $this->data['author_login'] ] = $this->data; + } $this->data = false; break; case 'wp:base_site_url': @@ -164,11 +252,19 @@ function tag_close( $parser, $tag ) { default: if ( $this->in_sub_tag ) { - $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : ''; - $this->in_sub_tag = false; - } else if ( $this->in_tag ) { - $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : ''; - $this->in_tag = false; + if ( false === $this->sub_data ) { + $this->sub_data = array(); + } + + $this->sub_data[ $this->in_sub_tag ] = ! empty( $this->cdata ) ? $this->cdata : ''; + $this->in_sub_tag = false; + } elseif ( $this->in_tag ) { + if ( false === $this->data ) { + $this->data = array(); + } + + $this->data[ $this->in_tag ] = ! empty( $this->cdata ) ? $this->cdata : ''; + $this->in_tag = false; } } diff --git a/wordpress-importer/parsers/class-wxr-parser.php b/wordpress-importer/parsers/class-wxr-parser.php index dc7cce8fe8..057bf9ebf2 100644 --- a/wordpress-importer/parsers/class-wxr-parser.php +++ b/wordpress-importer/parsers/class-wxr-parser.php @@ -17,24 +17,27 @@ function parse( $file ) { $result = $parser->parse( $file ); // If SimpleXML succeeds or this is an invalid WXR file then return the results - if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) + if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) { return $result; - } else if ( extension_loaded( 'xml' ) ) { + } + } elseif ( extension_loaded( 'xml' ) ) { $parser = new WXR_Parser_XML; $result = $parser->parse( $file ); // If XMLParser succeeds or this is an invalid WXR file then return the results - if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) + if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) { return $result; + } } // We have a malformed XML file, so display the error and fallthrough to regex - if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) { + if ( isset( $result ) && defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) { echo '
    ';
     			if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
    -				foreach  ( $result->get_error_data() as $error )
    +				foreach ( $result->get_error_data() as $error ) {
     					echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
    -			} else if ( 'XML_parse_error' == $result->get_error_code() ) {
    +				}
    +			} elseif ( 'XML_parse_error' == $result->get_error_code() ) {
     				$error = $result->get_error_data();
     				echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
     			}
    diff --git a/wordpress-importer/readme.txt b/wordpress-importer/readme.txt
    index 4edf74db71..f729f52728 100644
    --- a/wordpress-importer/readme.txt
    +++ b/wordpress-importer/readme.txt
    @@ -1,118 +1,133 @@
    -=== WordPress Importer ===
    -Contributors: wordpressdotorg
    -Donate link: https://wordpressfoundation.org/donate/
    -Tags: importer, wordpress
    -Requires at least: 3.7
    -Tested up to: 5.4
    -Stable tag: 0.7
    -License: GPLv2 or later
    -License URI: https://www.gnu.org/licenses/gpl-2.0.html
    -
    -Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
    -
    -== Description ==
    -
    -The WordPress Importer will import the following content from a WordPress export file:
    -
    -* Posts, pages and other custom post types
    -* Comments and comment meta
    -* Custom fields and post meta
    -* Categories, tags and terms from custom taxonomies and term meta
    -* Authors
    -
    -For further information and instructions please see the [documention on Importing Content](https://wordpress.org/support/article/importing-content/#wordpress).
    -
    -== Installation ==
    -
    -The quickest method for installing the importer is:
    -
    -1. Visit Tools -> Import in the WordPress dashboard
    -1. Click on the WordPress link in the list of importers
    -1. Click "Install Now"
    -1. Finally click "Activate Plugin & Run Importer"
    -
    -If you would prefer to do things manually then follow these instructions:
    -
    -1. Upload the `wordpress-importer` folder to the `/wp-content/plugins/` directory
    -1. Activate the plugin through the 'Plugins' menu in WordPress
    -1. Go to the Tools -> Import screen, click on WordPress
    -
    -== Changelog ==
    -
    -= 0.7 =
    -* Update minimum WordPress requirement to 3.7 and ensure compatibility with PHP 7.4.
    -* Fix bug that caused not importing term meta.
    -* Fix bug that caused slashes to be stripped from imported meta data.
    -* Fix bug that prevented import of serialized meta data.
    -* Fix file size check after download of remote files with HTTP compression enabled.
    -* Improve accessibility of form fields by adding missing labels.
    -* Improve imports for remote file URLs without name and/or extension.
    -* Add support for `wp:base_blog_url` field to allow importing multiple files with WP-CLI.
    -* Add support for term meta parsing when using the regular expressions or XML parser.
    -* Developers: All PHP classes have been moved into their own files.
    -* Developers: Allow to change `IMPORT_DEBUG` via `wp-config.php` and change default value to the value of `WP_DEBUG`.
    -
    -= 0.6.4 =
    -* Improve PHP7 compatibility.
    -* Fix bug that caused slashes to be stripped from imported comments.
    -* Fix for various deprecation notices including `wp_get_http()` and `screen_icon()`.
    -* Fix for importing export files with multiline term meta data.
    -
    -= 0.6.3 =
    -* Add support for import term metadata.
    -* Fix bug that caused slashes to be stripped from imported content.
    -* Fix bug that caused characters to be stripped inside of CDATA in some cases.
    -* Fix PHP notices.
    -
    -= 0.6.2 =
    -* Add `wp_import_existing_post` filter, see [Trac ticket #33721](https://core.trac.wordpress.org/ticket/33721).
    -
    -= 0.6 =
    -* Support for WXR 1.2 and multiple CDATA sections
    -* Post aren't duplicates if their post_type's are different
    -
    -= 0.5.2 =
    -* Double check that the uploaded export file exists before processing it. This prevents incorrect error messages when
    -an export file is uploaded to a server with bad permissions and WordPress 3.3 or 3.3.1 is being used.
    -
    -= 0.5 =
    -* Import comment meta (requires export from WordPress 3.2)
    -* Minor bugfixes and enhancements
    -
    -= 0.4 =
    -* Map comment user_id where possible
    -* Import attachments from `wp:attachment_url`
    -* Upload attachments to correct directory
    -* Remap resized image URLs correctly
    -
    -= 0.3 =
    -* Use an XML Parser if possible
    -* Proper import support for nav menus
    -* ... and much more, see [Trac ticket #15197](https://core.trac.wordpress.org/ticket/15197)
    -
    -= 0.1 =
    -* Initial release
    -
    -== Frequently Asked Questions ==
    -
    -= Help! I'm getting out of memory errors or a blank screen. =
    -If your exported file is very large, the import script may run into your host's configured memory limit for PHP.
    -
    -A message like "Fatal error: Allowed memory size of 8388608 bytes exhausted" indicates that the script can't successfully import your XML file under the current PHP memory limit. If you have access to the php.ini file, you can manually increase the limit; if you do not (your WordPress installation is hosted on a shared server, for instance), you might have to break your exported XML file into several smaller pieces and run the import script one at a time.
    -
    -For those with shared hosting, the best alternative may be to consult hosting support to determine the safest approach for running the import. A host may be willing to temporarily lift the memory limit and/or run the process directly from their end.
    -
    --- [Support Article: Importing Content](https://wordpress.org/support/article/importing-content/#before-importing)
    -
    -== Filters ==
    -
    -The importer has a couple of filters to allow you to completely enable/block certain features:
    -
    -* `import_allow_create_users`: return false if you only want to allow mapping to existing users
    -* `import_allow_fetch_attachments`: return false if you do not wish to allow importing and downloading of attachments
    -* `import_attachment_size_limit`: return an integer value for the maximum file size in bytes to save (default is 0, which is unlimited)
    -
    -There are also a few actions available to hook into:
    -
    -* `import_start`: occurs after the export file has been uploaded and author import settings have been chosen
    -* `import_end`: called after the last output from the importer
    +=== WordPress Importer ===
    +Contributors: wordpressdotorg
    +Donate link: https://wordpressfoundation.org/donate/
    +Tags: importer, wordpress
    +Requires at least: 5.2
    +Tested up to: 6.2
    +Requires PHP: 5.6
    +Stable tag: 0.8.1
    +License: GPLv2 or later
    +License URI: https://www.gnu.org/licenses/gpl-2.0.html
    +
    +Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
    +
    +== Description ==
    +
    +The WordPress Importer will import the following content from a WordPress export file:
    +
    +* Posts, pages and other custom post types
    +* Comments and comment meta
    +* Custom fields and post meta
    +* Categories, tags and terms from custom taxonomies and term meta
    +* Authors
    +
    +For further information and instructions please see the [documention on Importing Content](https://wordpress.org/support/article/importing-content/#wordpress).
    +
    +== Installation ==
    +
    +The quickest method for installing the importer is:
    +
    +1. Visit Tools -> Import in the WordPress dashboard
    +1. Click on the WordPress link in the list of importers
    +1. Click "Install Now"
    +1. Finally click "Activate Plugin & Run Importer"
    +
    +If you would prefer to do things manually then follow these instructions:
    +
    +1. Upload the `wordpress-importer` folder to the `/wp-content/plugins/` directory
    +1. Activate the plugin through the 'Plugins' menu in WordPress
    +1. Go to the Tools -> Import screen, click on WordPress
    +
    +== Changelog ==
    +
    += 0.8.1 =
    +
    +* Update compatibility tested-up-to to WordPress 6.2.
    +* Update paths to build status badges.
    +
    += 0.8 =
    +* Update minimum WordPress requirement to 5.2.
    +* Update minimum PHP requirement to 5.6.
    +* Update compatibility tested-up-to to WordPress 6.1.
    +* PHP 8.0, 8.1, and 8.2 compatibility fixes.
    +* Fix a bug causing blank lines in content to be ignored when using the Regex Parser.
    +* Fix a bug resulting in a PHP fatal error when IMPORT_DEBUG is enabled and a category creation error occurs.
    +* Improved Unit testing & automated testing.
    +
    += 0.7 =
    +* Update minimum WordPress requirement to 3.7 and ensure compatibility with PHP 7.4.
    +* Fix bug that caused not importing term meta.
    +* Fix bug that caused slashes to be stripped from imported meta data.
    +* Fix bug that prevented import of serialized meta data.
    +* Fix file size check after download of remote files with HTTP compression enabled.
    +* Improve accessibility of form fields by adding missing labels.
    +* Improve imports for remote file URLs without name and/or extension.
    +* Add support for `wp:base_blog_url` field to allow importing multiple files with WP-CLI.
    +* Add support for term meta parsing when using the regular expressions or XML parser.
    +* Developers: All PHP classes have been moved into their own files.
    +* Developers: Allow to change `IMPORT_DEBUG` via `wp-config.php` and change default value to the value of `WP_DEBUG`.
    +
    += 0.6.4 =
    +* Improve PHP7 compatibility.
    +* Fix bug that caused slashes to be stripped from imported comments.
    +* Fix for various deprecation notices including `wp_get_http()` and `screen_icon()`.
    +* Fix for importing export files with multiline term meta data.
    +
    += 0.6.3 =
    +* Add support for import term metadata.
    +* Fix bug that caused slashes to be stripped from imported content.
    +* Fix bug that caused characters to be stripped inside of CDATA in some cases.
    +* Fix PHP notices.
    +
    += 0.6.2 =
    +* Add `wp_import_existing_post` filter, see [Trac ticket #33721](https://core.trac.wordpress.org/ticket/33721).
    +
    += 0.6 =
    +* Support for WXR 1.2 and multiple CDATA sections
    +* Post aren't duplicates if their post_type's are different
    +
    += 0.5.2 =
    +* Double check that the uploaded export file exists before processing it. This prevents incorrect error messages when
    +an export file is uploaded to a server with bad permissions and WordPress 3.3 or 3.3.1 is being used.
    +
    += 0.5 =
    +* Import comment meta (requires export from WordPress 3.2)
    +* Minor bugfixes and enhancements
    +
    += 0.4 =
    +* Map comment user_id where possible
    +* Import attachments from `wp:attachment_url`
    +* Upload attachments to correct directory
    +* Remap resized image URLs correctly
    +
    += 0.3 =
    +* Use an XML Parser if possible
    +* Proper import support for nav menus
    +* ... and much more, see [Trac ticket #15197](https://core.trac.wordpress.org/ticket/15197)
    +
    += 0.1 =
    +* Initial release
    +
    +== Frequently Asked Questions ==
    +
    += Help! I'm getting out of memory errors or a blank screen. =
    +If your exported file is very large, the import script may run into your host's configured memory limit for PHP.
    +
    +A message like "Fatal error: Allowed memory size of 8388608 bytes exhausted" indicates that the script can't successfully import your XML file under the current PHP memory limit. If you have access to the php.ini file, you can manually increase the limit; if you do not (your WordPress installation is hosted on a shared server, for instance), you might have to break your exported XML file into several smaller pieces and run the import script one at a time.
    +
    +For those with shared hosting, the best alternative may be to consult hosting support to determine the safest approach for running the import. A host may be willing to temporarily lift the memory limit and/or run the process directly from their end.
    +
    +-- [Support Article: Importing Content](https://wordpress.org/support/article/importing-content/#before-importing)
    +
    +== Filters ==
    +
    +The importer has a couple of filters to allow you to completely enable/block certain features:
    +
    +* `import_allow_create_users`: return false if you only want to allow mapping to existing users
    +* `import_allow_fetch_attachments`: return false if you do not wish to allow importing and downloading of attachments
    +* `import_attachment_size_limit`: return an integer value for the maximum file size in bytes to save (default is 0, which is unlimited)
    +
    +There are also a few actions available to hook into:
    +
    +* `import_start`: occurs after the export file has been uploaded and author import settings have been chosen
    +* `import_end`: called after the last output from the importer
    diff --git a/wordpress-importer/wordpress-importer.php b/wordpress-importer/wordpress-importer.php
    index bdea4c460e..b0e9feecf3 100644
    --- a/wordpress-importer/wordpress-importer.php
    +++ b/wordpress-importer/wordpress-importer.php
    @@ -1,15 +1,18 @@
     posts, pages, comments, custom fields, categories, and tags from a WordPress export file.', 'wordpress-importer'), array( $GLOBALS['wp_import'], 'dispatch' ) );
    +	// phpcs:ignore WordPress.WP.CapitalPDangit
    +	register_importer( 'wordpress', 'WordPress', __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.', 'wordpress-importer' ), array( $GLOBALS['wp_import'], 'dispatch' ) );
     }
     add_action( 'admin_init', 'wordpress_importer_init' );