' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . ' ';
echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '
';
}
// use regular expressions if nothing else available or this is bad XML
$parser = new WXR_Parser_Regex;
return $parser->parse( $file );
}
}
/**
* WXR Parser that makes use of the SimpleXML PHP extension.
*/
class WXR_Parser_SimpleXML {
function parse( $file ) {
$authors = $posts = $categories = $tags = $terms = array();
$internal_errors = libxml_use_internal_errors(true);
$dom = new DOMDocument;
$old_value = null;
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 ) );
if ( ! is_null( $old_value ) && \PHP_VERSION_ID < 80000 ) {
libxml_disable_entity_loader( $old_value );
}
if ( ! $success || isset( $dom->doctype ) ) {
return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
}
$xml = simplexml_import_dom( $dom );
unset( $dom );
// halt if loading produces an error
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 )
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 ) )
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 = (string) trim( $base_url[0] );
$namespaces = $xml->getDocNamespaces();
if ( ! isset( $namespaces['wp'] ) )
$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
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,
'author_display_name' => (string) $a->author_display_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'] );
$categories[] = 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
);
}
foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) {
$t = $term_arr->children( $namespaces['wp'] );
$tags[] = 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
);
}
foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) {
$t = $term_arr->children( $namespaces['wp'] );
$terms[] = 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
);
}
// grab posts
foreach ( $xml->channel->item as $item ) {
$post = array(
'post_title' => (string) $item->title,
'guid' => (string) $item->guid,
);
$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'] );
$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;
$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['attachment_url'] = (string) $wp->attachment_url;
foreach ( $item->category as $c ) {
$att = $c->attributes();
if ( isset( $att['nicename'] ) )
$post['terms'][] = array(
'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
);
}
foreach ( $wp->comment as $comment ) {
$meta = array();
if ( isset( $comment->commentmeta ) ) {
foreach ( $comment->commentmeta as $m ) {
$meta[] = array(
'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_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,
);
}
$posts[] = $post;
}
return array(
'authors' => $authors,
'posts' => $posts,
'categories' => $categories,
'tags' => $tags,
'terms' => $terms,
'base_url' => $base_url,
'version' => $wxr_version
);
}
}
/**
* 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',
);
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',
);
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();
$xml = xml_parser_create( 'UTF-8' );
xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
xml_set_object( $xml, $this );
xml_set_character_data_handler( $xml, 'cdata' );
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_column = xml_get_current_column_number( $xml );
$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 ) )
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,
'version' => $this->wxr_version
);
}
function tag_open( $parse, $tag, $attr ) {
if ( in_array( $tag, $this->wp_tags ) ) {
$this->in_tag = substr( $tag, 3 );
return;
}
if ( in_array( $tag, $this->wp_sub_tags ) ) {
$this->in_sub_tag = substr( $tag, 3 );
return;
}
switch ( $tag ) {
case 'category':
if ( isset($attr['domain'], $attr['nicename']) ) {
$this->sub_data['domain'] = $attr['domain'];
$this->sub_data['slug'] = $attr['nicename'];
}
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 '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 ) )
return;
$this->cdata .= trim( $cdata );
}
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 ) )
$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']
);
break;
case 'category':
if ( ! empty( $this->sub_data ) ) {
$this->sub_data['name'] = $this->cdata;
$this->data['terms'][] = $this->sub_data;
}
$this->sub_data = false;
break;
case 'wp:postmeta':
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;
break;
case 'wp:category':
case 'wp:tag':
case 'wp:term':
$n = substr( $tag, 3 );
array_push( $this->$n, $this->data );
$this->data = false;
break;
case 'wp:author':
if ( ! empty($this->data['author_login']) )
$this->authors[$this->data['author_login']] = $this->data;
$this->data = false;
break;
case 'wp:base_site_url':
$this->base_url = $this->cdata;
break;
case 'wp:wxr_version':
$this->wxr_version = $this->cdata;
break;
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;
}
}
$this->cdata = false;
}
}
/**
* 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 = '';
function WXR_Parser_Regex() {
$this->__construct();
}
function __construct() {
$this->has_gzip = is_callable( 'gzopen' );
}
function parse( $file ) {
$wxr_version = $in_post = false;
$fp = $this->fopen( $file, 'r' );
if ( $fp ) {
while ( ! $this->feof( $fp ) ) {
$importline = rtrim( $this->fgets( $fp ) );
if ( ! $wxr_version && preg_match( '|(\d+\.\d+)|', $importline, $version ) )
$wxr_version = $version[1];
if ( false !== strpos( $importline, '' ) ) {
preg_match( '|(.*?)|is', $importline, $url );
$this->base_url = $url[1];
continue;
}
if ( false !== strpos( $importline, '' ) ) {
preg_match( '|(.*?)|is', $importline, $category );
$this->categories[] = $this->process_category( $category[1] );
continue;
}
if ( false !== strpos( $importline, '' ) ) {
preg_match( '|(.*?)|is', $importline, $tag );
$this->tags[] = $this->process_tag( $tag[1] );
continue;
}
if ( false !== strpos( $importline, '' ) ) {
preg_match( '|(.*?)|is', $importline, $term );
$this->terms[] = $this->process_term( $term[1] );
continue;
}
if ( false !== strpos( $importline, '' ) ) {
preg_match( '|(.*?)|is', $importline, $author );
$a = $this->process_author( $author[1] );
$this->authors[$a['author_login']] = $a;
continue;
}
if ( false !== strpos( $importline, '' ) ) {
$post = '';
$in_post = true;
continue;
}
if ( false !== strpos( $importline, '' ) ) {
$in_post = false;
$this->posts[] = $this->process_post( $post );
continue;
}
if ( $in_post ) {
$post .= $importline . "\n";
}
}
$this->fclose($fp);
}
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,
'version' => $wxr_version
);
}
function get_tag( $string, $tag ) {
preg_match( "|<$tag.*?>(.*?)$tag>|is", $string, $return );
if ( isset( $return[1] ) ) {
if ( substr( $return[1], 0, 9 ) == '' ) !== false ) {
preg_match_all( '||s', $return[1], $matches );
$return = '';
foreach( $matches[1] as $match )
$return .= $match;
} else {
$return = preg_replace( '|^$|s', '$1', $return[1] );
}
} else {
$return = $return[1];
}
} else {
$return = '';
}
return $return;
}
function process_category( $c ) {
return 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' ),
'category_description' => $this->get_tag( $c, 'wp:category_description' ),
);
}
function process_tag( $t ) {
return 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' ),
'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
);
}
function process_term( $t ) {
return 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_description' => $this->get_tag( $t, 'wp:term_description' ),
);
}
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_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' ),
);
}
function process_post( $post ) {
$post_id = $this->get_tag( $post, 'wp:post_id' );
$post_title = $this->get_tag( $post, 'title' );
$post_date = $this->get_tag( $post, 'wp:post_date' );
$post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
$comment_status = $this->get_tag( $post, 'wp:comment_status' );
$ping_status = $this->get_tag( $post, 'wp:ping_status' );
$status = $this->get_tag( $post, 'wp:status' );
$post_name = $this->get_tag( $post, 'wp:post_name' );
$post_parent = $this->get_tag( $post, 'wp:post_parent' );
$menu_order = $this->get_tag( $post, 'wp:menu_order' );
$post_type = $this->get_tag( $post, 'wp:post_type' );
$post_password = $this->get_tag( $post, 'wp:post_password' );
$is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
$guid = $this->get_tag( $post, 'guid' );
$post_author = $this->get_tag( $post, 'dc:creator' );
$post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
$post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
$post_excerpt = str_replace( ' ', ' ', $post_excerpt );
$post_excerpt = str_replace( '', '', $post_excerpt );
$post_content = $this->get_tag( $post, 'content:encoded' );
$post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
$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'
);
$attachment_url = $this->get_tag( $post, 'wp: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],
'domain' => $t[1],
'name' => str_replace( array( '' ), '', $t[3] ),
);
}
if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms;
preg_match_all( '|(.+?)|is', $post, $comments );
$comments = $comments[1];
if ( $comments ) {
foreach ( $comments as $comment ) {
preg_match_all( '|(.+?)|is', $comment, $commentmeta );
$commentmeta = $commentmeta[1];
$c_meta = array();
foreach ( $commentmeta as $m ) {
$c_meta[] = array(
'key' => $this->get_tag( $m, 'wp:meta_key' ),
'value' => $this->get_tag( $m, 'wp:meta_value' ),
);
}
$post_comments[] = array(
'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' => $c_meta,
);
}
}
if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments;
preg_match_all( '|(.+?)|is', $post, $postmeta );
$postmeta = $postmeta[1];
if ( $postmeta ) {
foreach ( $postmeta as $p ) {
$post_postmeta[] = array(
'key' => $this->get_tag( $p, 'wp:meta_key' ),
'value' => $this->get_tag( $p, 'wp:meta_value' ),
);
}
}
if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta;
return $postdata;
}
function _normalize_tag( $matches ) {
return '<' . strtolower( $matches[1] );
}
function fopen( $filename, $mode = 'r' ) {
if ( $this->has_gzip )
return gzopen( $filename, $mode );
return fopen( $filename, $mode );
}
function feof( $fp ) {
if ( $this->has_gzip )
return gzeof( $fp );
return feof( $fp );
}
function fgets( $fp, $len = 8192 ) {
if ( $this->has_gzip )
return gzgets( $fp, $len );
return fgets( $fp, $len );
}
function fclose( $fp ) {
if ( $this->has_gzip )
return gzclose( $fp );
return fclose( $fp );
}
}
PK ! 6UI? ? includes/class-logger-cli.phpnu [ level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
return;
}
printf(
'[%s] %s' . PHP_EOL,
strtoupper( $level ),
$message
);
}
public static function level_to_numeric( $level ) {
$levels = array(
'emergency' => 8,
'alert' => 7,
'critical' => 6,
'error' => 5,
'warning' => 4,
'notice' => 3,
'info' => 2,
'debug' => 1,
);
if ( ! isset( $levels[ $level ] ) ) {
return 0;
}
return $levels[ $level ];
}
}
PK ! h] includes/customizer-importer.phpnu [ download_images ) {
$data['mods'] = $this->import_images( $data['mods'] );
}
// Import custom options.
if ( isset( $data['options'] ) ) {
require dirname( __FILE__ ) . '/customizer-option.php';
foreach ( $data['options'] as $option_key => $option_value ) {
$option = new Penci_Demo_Customizer_Option( $wp_customize, $option_key, array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$option->import( $option_value );
}
}
// Loop through the mods.
foreach ( $data['mods'] as $key => $val ) {
// Save the mod.
set_theme_mod( $key, $val );
}
return true;
}
/**
* Imports images for settings saved as mods.
*
* @return array The mods array with any new import data.
*/
private function import_images( $mods ) {
foreach ( $mods as $key => $val ) {
if ( $this->is_image_url( $val ) ) {
if ( array_key_exists( $val, $this->processed_images ) ) {
$data = $this->processed_images[$val];
} else {
$data = $this->sideload_image( $val );
$this->processed_images[$val] = $data;
}
if ( ! is_wp_error( $data ) ) {
$mods[ $key ] = $data->url;
// Handle header image controls.
if ( isset( $mods[ $key . '_data' ] ) ) {
$mods[ $key . '_data' ] = $data;
update_post_meta( $data->attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
}
}
}
}
return $mods;
}
/**
* Taken from the core media_sideload_image function and
* modified to return an array of data instead of html.
*
* @param string $file The image file path.
* @return array An array of image data.
*/
private function sideload_image( $file ) {
$data = new stdClass();
if ( ! function_exists( 'media_handle_sideload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/media.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
}
if ( ! empty( $file ) ) {
// Set variables for storage, fix file filename for query strings.
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
$file_array = array();
$file_array['name'] = basename( $matches[0] );
// Download file to temp location.
$file_array['tmp_name'] = download_url( $file );
// If error storing temporarily, return the error.
if ( is_wp_error( $file_array['tmp_name'] ) ) {
return $file_array['tmp_name'];
}
// Do the validation and storage stuff.
$id = media_handle_sideload( $file_array, 0 );
// If error storing permanently, unlink.
if ( is_wp_error( $id ) ) {
@unlink( $file_array['tmp_name'] );
return $id;
}
// Build the object to return.
$meta = wp_get_attachment_metadata( $id );
$data->attachment_id = $id;
$data->url = wp_get_attachment_url( $id );
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
$data->height = $meta['height'];
$data->width = $meta['width'];
}
return $data;
}
/**
* Checks to see whether a string is an image url or not.
*
* @return bool Whether the string is an image url or not.
*/
private function is_image_url( $string = '' ) {
if ( is_string( $string ) ) {
if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
return true;
}
}
return false;
}
}
PK ! 9%S2 2 includes/class-wxr-transform.phpnu [ open( $file );
if ( ! $status ) {
return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
}
return $reader;
}
/**
* Get a stream writer for output of the transform file.
*
* @param string $file Path to the XML file.
* @return XMLReader|WP_Error Writer instance on success, error otherwise.
*/
function get_writer( $file ) {
$writer = new XMLWriter();
$this->tempnam = tempnam( dirname( $file ), 'transform' );
$status = $writer->openUri( $this->tempnam );
if ( ! $status ) {
return new WP_Error( 'wxr_importer.cannot_transform', __( 'Could not open the file for writing', 'wordpress-importer' ) );
}
$writer->setIndent( true );
$writer->setIndentString( "\t" );
return $writer;
}
/**
*
* @param XMLReader $reader
* @param XMLWriter $writer
* @param array $parent
* @return boolean
*/
function startElement( $reader, $writer, $parent ) {
if ( $this->is_wxr_namespaceURI( $reader->namespaceURI, true ) ) {
// element is from one of the old WXR namespaces
if ( in_array( $reader->localName, array( 'wxr_version', 'base_blog_url' ) ) ) {
// skip the old wp:wxr_version & base_blog_url elements
$reader->next();
return true;
}
elseif ( 'encoded' === $reader->localName ) {
// rewrite to RSS standard
$writer->startElement( 'description' );
return true;
}
$localName = $this->map_localName( $reader, $parent );
$writer->startElementNs( self::WXR_PREFIX, $localName, null );
}
elseif ( '' !== $reader->namespaceURI ) {
// element is from a "foreign" namespace, e.g., dublin core, rss_content
// or a plugin-specific namespace...just copy the start tag unchanged
$writer->startElementNs( $reader->prefix, $reader->localName, null );
}
else {
// element is from the empty namespace, i.e., standard RSS
if ( isset( $parent['localName'] ) &&
'' === $parent['namespaceURI'] && 'item' === $parent['localName'] &&
'description' === $reader->localName ) {
// skip item/description element
$reader->next();
return true;
}
$writer->startElement( $reader->localName );
if ( 'generator' === $reader->localName ) {
$wp_version = $reader->readString();
$wp_version = substr( $wp_version, stripos( $wp_version, '?v=' ) + 3 );
$writer->writeAttributeNS( 'wxr', 'wp_version', null, $wp_version );
$writer->endElement();
$reader->next();
}
if ( 'rss' === $reader->localName && 0 === $reader->depth ) {
if ( $reader->moveToAttributeNS( 'version', self::WXR_NAMESPACE_URI ) ) {
// file is already in the WXR 1.3 (or later) markup, no need to transform
return false;
}
// passing the WXR namespaceURI here will cause XMLWriter to also
// generate a namespace decl for it. After this, we always pass
// null for our namespace; otherwise, XMLWriter will generate additional
// namespace decls for it...which, while perfectly fine from a
// namespace-aware XML perspective, it results in instances that are
// much larger than they need to be.
// @link https://bugs.php.net/bug.php?id=74491
$writer->writeAttributeNS( self::WXR_PREFIX, 'version', self::WXR_NAMESPACE_URI, '1.3' );
}
}
// save whether we are currently processing an RSS category element
// so that we can rewrite @nicename
$category = '' === $reader->namespaceURI && $reader->localName;
if ( $reader->hasAttributes ) {
$this->transformAttributes( $reader, $writer, $category );
}
if ( $reader->isEmptyElement ) {
$writer->endElement();
}
return true;
}
/**
*
* @param XMLReader $reader
* @param XMLWriter $writer
* @param bool $is_rss_category
*/
function transformAttributes( $reader, $writer, $is_rss_category ) {
// save whether we are currently processing an RSS category element
// so that we can rewrite @nicename
$is_rss_category = '' === $reader->namespaceURI && $reader->localName;
while ( $reader->moveToNextAttribute() ) {
if ( '' === $reader->namespaceURI ) {
if ( $is_rss_category && 'nicename' === $reader->name ) {
// rewrite category/@nicename to category/@wxr:slug
$writer->writeAttributeNs( self::WXR_PREFIX, 'slug', null, $reader->value );
}
else {
$writer->writeAttribute( $reader->name, $reader->value );
}
}
elseif ( 'http://www.w3.org/2000/xmlns/' === $reader->namespaceURI ) {
// stupid XMLReader treats namespace decls as attributes :-(
if ( $this->is_wxr_namespaceURI( $reader->value, true ) ) {
// strip the old WXR namespace decl
continue;
}
// because of what I consider a bug in XMLWriter,
// if you write these namespace decl "attributes" via
// XMLWriter::writeAttributeNs() then it generates an
// illegal xmlns:xmlns='http://www.w3.org/2000/xmlns/'
$writer->writeAttribute( $reader->name, $reader->value );
}
else {
// namespace-qualified attribute
if ( $reader->lookupNamespace( $reader->prefix ) ) {
$writer->writeAttributeNs( $reader->prefix, $reader->localName, null, $reader->value );
}
else {
$writer->writeAttributeNs( $reader->prefix, $reader->localName, $reader->namespaceURI, $reader->value );
}
}
}
$reader->moveToElement();
}
/**
* Transform a WXR 1.0, 1.1 or 1.2 instance into the proposed 1.3 markup
*
* @param string $file ??
* @return boolean|WP_Error true if transformation performed, false if no transformation necessary,
* WP_Error on error
*/
function transform( $file ) {
$this->org_filename = $file;
$reader = $this->get_reader( $file );
if ( is_wp_error( $reader ) ) {
return $reader;
}
$writer = $this->get_writer( $file );
if ( is_wp_error( $writer ) ) {
return $writer;
}
// @todo XMLReader::read() never returns XMLReader::XML_DECLARATION
// so we just have to "guess" and hardcode the xmldecl
// I don't think it really matters because XMLReader will do any necessary
// decoding
$writer->startDocument( '1.0', 'UTF-8' );
$ancestors = array();
while ( $reader->read() ) {
switch ( $reader->nodeType ) {
case XMLReader::ELEMENT:
if ( ! $this->startElement( $reader, $writer, count( $ancestors ) > 0 ? $ancestors[0] : null ) ) {
$this->cleanup( $reader, $writer, false );
return false;
}
array_unshift( $ancestors,
array(
'namespaceURI' => $reader->namespaceURI,
'localName' => $reader->localName,
)
);
break;
case XMLReader::CDATA:
case XMLReader::TEXT:
// outputing CDATA sections when not necessary needlessly increases file size
$writer->text( $reader->value );
break;
case XMLReader::END_ELEMENT:
if ( $this->is_wxr_namespaceURI( $reader->namespaceURI, true ) ) {
if ( in_array( $reader->localName, array( 'tag', 'category' ) ) ) {
// add the appropriate before closing the
$writer->startElementNs( self::WXR_PREFIX, 'taxonomy', null );
$writer->text( 'category' === $reader->localName ? 'category' : 'post_tag' );
$writer->endElement();
}
}
$writer->endElement();
array_shift( $ancestors );
break;
case XMLReader::COMMENT:
$writer->writeComment( $reader->value );
break;
case XMLReader::PI:
// the standard exporter doesn't generate any PIs and it is unlikely a plugin
// will either, but just in case...
$writer->writePI( $reader->localName, $reader->value );
break;
}
}
$this->cleanup( $reader, $writer, true );
return true;
}
/**
* This implements the statement in the template with
* @match='*[starts-with( namespace-uri(), "http://wordpress.org/export/" )]'>
* in the XSLT transforms this class mimics.
*
* @param XMLReader $reader
* @param array $parent
* @return string
*/
function map_localName( $reader, $parent ) {
// first, start with the simple renames
if ( in_array( $reader->localName, array( 'tag', 'category' ) ) ) {
return 'term';
}
elseif ( 'author' === $reader->localName ) {
return 'user';
}
elseif ( in_array( $reader->localName, array( 'termmeta', 'postmeta', 'commentmeta' ) ) ) {
return 'meta';
}
elseif ( 'category_nicename' === $reader->localName ) {
return 'slug';
}
// // even tho this keeps the current local-name(), we have to do it here
// // rather than in or else it would get handled by
// // the "strip a leading"
// if ( 'comment_status' === $reader->localName ) {
// return $reader->localName;
// }
// store the location of the 1st '_' character. We need it several times below
// and this saves up having to call strpos() multiple times
$_underscore = strpos( $reader->localName, '_' ) + 1;
// strip leading string before "_" in SOME localName's
if ( ( in_array(
substr ( $reader->localName, 0, $_underscore ),
array( 'author_', 'post_', 'meta_', 'comment_', 'base_' ) ) &&
'comment_status' !== $reader->localName ) ||
( $this->is_wxr_namespaceURI( $parent['namespaceURI'] ) &&
in_array( $parent['localName'], array( 'tag', 'category', 'term' ) ) ) ) {
return substr( $reader->localName, $_underscore );
}
// localName is unchanged
return $reader->localName;
}
/**
* Cleanup at the end of the transform
*
* If $success is true, then rename the temporary file to the original file;
* If $success is false, then unlink the temporary file and the original file
* in tact.
*
* @param XMLReader $reader
* @param XMLWriter $writer
* @param bool $success
* @param string $file
*/
function cleanup( $reader, &$writer, $success ) {
$reader->close();
$writer->endDocument();
// set $writer to null so that it closes the file...otherwise
// the rename() will fail! The $writer parameter to this method must be
// declared 'by-reference' for this to work.
$writer = null;
if ( $success ) {
rename( $this->tempnam, $this->org_filename );
}
else {
unlink( $this->tempnam );
}
}
}PK !
tȥ includes/widgets-importer.phpnu [ true )
);
}
// Get all available widgets site supports
$available_widgets = $this->available_widgets();
// Get all existing widget instances
$widget_instances = array();
foreach ( $available_widgets as $widget_data ) {
$widget_instances[$widget_data['id_base']] = get_option( 'widget_' . $widget_data['id_base'] );
}
// Begin results
$results = array();
// Loop import data's sidebars
foreach ( $data as $sidebar_id => $widgets ) {
// Skip inactive widgets
// (should not be in export file)
if ( 'wp_inactive_widgets' == $sidebar_id ) {
continue;
}
// Check if sidebar is available on this site
// Otherwise add widgets to inactive, and say so
if ( isset( $wp_registered_sidebars[$sidebar_id] ) ) {
$sidebar_available = true;
$use_sidebar_id = $sidebar_id;
$sidebar_message_type = 'success';
$sidebar_message = '';
} else {
$sidebar_available = false;
$use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme
$sidebar_message_type = 'error';
$sidebar_message = __( 'Sidebar does not exist in theme (using Inactive)', 'claudio' );
}
// Result for sidebar
$results[$sidebar_id]['name'] = ! empty( $wp_registered_sidebars[$sidebar_id]['name'] ) ? $wp_registered_sidebars[$sidebar_id]['name'] : $sidebar_id; // sidebar name if theme supports it; otherwise ID
$results[$sidebar_id]['message_type'] = $sidebar_message_type;
$results[$sidebar_id]['message'] = $sidebar_message;
$results[$sidebar_id]['widgets'] = array();
// Loop widgets
foreach ( $widgets as $widget_instance_id => $widget ) {
$fail = false;
// Get id_base (remove -# from end) and instance ID number
$id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
$instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
// Does site support this widget?
if ( ! $fail && ! isset( $available_widgets[$id_base] ) ) {
$fail = true;
$widget_message_type = 'error';
$widget_message = __( 'Site does not support widget', 'claudio' ); // explain why widget not imported
}
// Convert multidimensional objects to multidimensional arrays
// Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays
// Without this, they are imported as objects and cause fatal error on Widgets page
// If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays
// It is probably much more likely that arrays are used than objects, however
$widget = json_decode( json_encode( $widget ), true );
// Does widget with identical settings already exist in same sidebar?
if ( ! $fail && isset( $widget_instances[$id_base] ) ) {
// Get existing widgets in this sidebar
$sidebars_widgets = get_option( 'sidebars_widgets' );
$sidebar_widgets = isset( $sidebars_widgets[$use_sidebar_id] ) ? $sidebars_widgets[$use_sidebar_id] : array(); // check Inactive if that's where will go
// Loop widgets with ID base
$single_widget_instances = ! empty( $widget_instances[$id_base] ) ? $widget_instances[$id_base] : array();
foreach ( $single_widget_instances as $check_id => $check_widget ) {
// Is widget in same sidebar and has identical settings?
if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
$fail = true;
$widget_message_type = 'warning';
$widget_message = __( 'Widget already exists', 'claudio' ); // explain why widget not imported
break;
}
}
}
// No failure
if ( ! $fail ) {
// Add widget instance
$single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time
$single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // start fresh if have to
$single_widget_instances[] = $widget; // add it
// Get the key it was given
end( $single_widget_instances );
$new_instance_id_number = key( $single_widget_instances );
// If key is 0, make it 1
// When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it)
if ( '0' === strval( $new_instance_id_number ) ) {
$new_instance_id_number = 1;
$single_widget_instances[$new_instance_id_number] = $single_widget_instances[0];
unset( $single_widget_instances[0] );
}
// Move _multiwidget to end of array for uniformity
if ( isset( $single_widget_instances['_multiwidget'] ) ) {
$multiwidget = $single_widget_instances['_multiwidget'];
unset( $single_widget_instances['_multiwidget'] );
$single_widget_instances['_multiwidget'] = $multiwidget;
}
// Update option with new widget
update_option( 'widget_' . $id_base, $single_widget_instances );
// Assign widget instance to sidebar
$sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time
$new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance
$sidebars_widgets[$use_sidebar_id][] = $new_instance_id; // add new instance to sidebar
update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data
// Success message
if ( $sidebar_available ) {
$widget_message_type = 'success';
$widget_message = __( 'Imported', 'claudio' );
} else {
$widget_message_type = 'warning';
$widget_message = __( 'Imported to Inactive', 'claudio' );
}
}
// Result for widget instance
$results[$sidebar_id]['widgets'][$new_instance_id]['name'] = isset( $available_widgets[$id_base]['name'] ) ? $available_widgets[$id_base]['name'] : $id_base; // widget name or ID if name not available (not supported by site)
$results[$sidebar_id]['widgets'][$new_instance_id]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : __( 'No Title', 'claudio' ); // show "No Title" if widget instance is untitled
$results[$sidebar_id]['widgets'][$new_instance_id]['message_type'] = $widget_message_type;
$results[$sidebar_id]['widgets'][$new_instance_id]['message'] = $widget_message;
$results[$sidebar_id]['widgets'][$new_instance_id]['id_base'] = $id_base;
}
}
// Return results
return $results;
}
/**
* Get all available widgets
*
* Gather site's widgets into array with ID base, name, etc.
* Used by export and import functions.
*
* @global array $wp_registered_widget_updates
*
* @return array Widget information
*/
public function available_widgets() {
global $wp_registered_widget_controls;
$widget_controls = $wp_registered_widget_controls;
$available_widgets = array();
foreach ( $widget_controls as $widget ) {
if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[$widget['id_base']] ) ) { // no dupes
$available_widgets[$widget['id_base']]['id_base'] = $widget['id_base'];
$available_widgets[$widget['id_base']]['name'] = $widget['name'];
}
}
return $available_widgets;
}
}
PK ! f * includes/class-logger-serversentevents.phpnu [ ` only. Default is false.)
* @var int $default_author User ID to use if author is missing or invalid. (Default is null, which leaves posts unassigned.)
* }
*/
public function __construct( $options = array() ) {
// Initialize some important variables
$empty_types = array(
'post' => array(),
'comment' => array(),
'term' => array(),
'user' => array(),
);
$this->mapping = $empty_types;
$this->mapping['user_slug'] = array();
$this->mapping['term_id'] = array();
$this->requires_remapping = $empty_types;
$this->exists = $empty_types;
$this->options = wp_parse_args( $options, array(
'prefill_existing_posts' => true,
'prefill_existing_comments' => true,
'prefill_existing_terms' => true,
'prefill_existing_links' => true,
'update_attachment_guids' => false,
'fetch_attachments' => false,
'aggressive_url_search' => false,
'default_author' => null,
) );
}
public function set_logger( $logger ) {
$this->logger = $logger;
}
/**
* Get a stream reader for the file.
*
* @param string $file Path to the XML file.
* @return XMLReader|WP_Error Reader instance on success, error otherwise.
*/
protected function get_reader( $file ) {
// Avoid loading external entities for security
$old_value = null;
$reader = new XMLReader();
$status = $reader->open( $file );
if ( ! $status ) {
return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
}
// @todo develop stategy for dealing with libxml errors
// for example, what should we do in $this->parse_post_node() if $reader->read()
// returns false because there is a non-well-formed error?
// currently it returns whatever $data it has collected to that point.
// I *think* we should punt and abort the import completely because
// every future call to $reader->read() will return false.
// libxml_use_internal_errors( true );
return $reader;
}
/**
* The main controller for the actual import stage.
*
* @param string $file Path to the WXR file for importing
*/
public function get_preliminary_information( $file ) {
// Let's run the actual importer now, woot
$reader = $this->get_reader( $file );
if ( is_wp_error( $reader ) ) {
return $reader;
}
// Start parsing!
$data = new WXR_Import_Info();
$extension_namespaces = array();
while ( $reader->read() ) {
if ( XMLReader::PI == $reader->nodeType && 'WXR_Importer' === $reader->localName ) {
if ( preg_match( "/^namespace-uri='([^']+)'\s+plugin-name='([^']+)'\s+plugin-slug='([^']+)'\s+plugin-url='([^']+)'\s+\$/", $reader->value, $matches) > 0 ) {
$data->extension_namespaces[$matches[1]][] = array( 'name' => $matches[2], 'slug' => $matches[3], 'url' => $matches[4] );
}
}
// Only deal with element opens
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
continue;
}
// note: possible bug in XMLReader: empty( $reader->namespaceURI ) always returns false
// so we have to explicitly compare against the empty string
if ( '' === $reader->namespaceURI ) {
// handle elements in the empty namespace, i.e., standard RSS elements
switch ( $reader->localName ) {
case 'rss':
$this->version = $reader->getAttributeNs( 'version', self::WXR_NAMESPACE_URI );
if ( empty( $this->version ) ) {
return new WP_Error( 'wxr_importer.unknown_version',
__( 'This does not appear to be a WXR file, missing WXR version number.', 'wordpress-importer' ) );
}
elseif ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
$this->logger->warning( sprintf(
__( 'This WXR file (version %s) is newer than the importer (version %s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
$this->version,
self::MAX_WXR_VERSION
) );
}
break;
case 'item':
$node = $reader->expand();
$parsed = $this->parse_post_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
if ( $parsed['data']['post_type'] === 'attachment' ) {
$data->media_count++;
} else {
$data->post_count++;
}
$data->comment_count += count( $parsed['comments'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'generator':
$data->generator = $reader->getAttributeNs( 'wp_version', self::WXR_NAMESPACE_URI );
$reader->next();
break;
case 'title':
$data->title = $reader->readString();
$reader->next();
break;
case 'link':
$data->home = $reader->readString();
$reader->next();
break;
}
}
elseif ( self::WXR_NAMESPACE_URI === $reader->namespaceURI ) {
switch ( $reader->localName ) {
case 'site_url':
$data->siteurl = $reader->readString();
$reader->next();
break;
case 'user':
$node = $reader->expand();
$parsed = $this->parse_user_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$data->users[] = $parsed;
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'term':
$data->term_count++;
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'link':
$data->link_count++;
// Handled everything in this node, move on to the next
$reader->next();
break;
}
}
}
$data->version = $this->version;
return $data;
}
/**
* The main controller for the actual import stage.
*
* @param string $file Path to the WXR file for importing
*/
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' ) );
$result = $this->import_start( $file );
if ( is_wp_error( $result ) ) {
return $result;
}
// Let's run the actual importer now, woot
$reader = $this->get_reader( $file );
if ( is_wp_error( $reader ) ) {
return $reader;
}
// Reset other variables
$this->base_url = '';
// Start parsing!
while ( $reader->read() ) {
// Only deal with element opens
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
continue;
}
// note: possible bug in XMLReader: empty( $reader->namespaceURI ) always returns false
// so we have to explicitly compare against the empty string
if ( '' === $reader->namespaceURI ) {
// handle elements in the empty namespace, i.e., standard RSS elements
switch ( $reader->localName ) {
case 'rss':
$this->version = $reader->getAttributeNs( 'version', self::WXR_NAMESPACE_URI );
if ( empty( $this->version ) ) {
return new WP_Error( 'wxr_importer.unknown_version',
__( 'This does not appear to be a WXR file, missing WXR version number.', 'wordpress-importer' ) );
}
elseif ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
$this->logger->warning( sprintf(
__( 'This WXR file (version %s) is newer than the importer (version %s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
$this->version,
self::MAX_WXR_VERSION
) );
}
break;
case 'item':
$node = $reader->expand();
$parsed = $this->parse_post_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$post_id = $this->process_post( $parsed['data'], $parsed['meta'], $parsed['comments'], $parsed['terms'] );
if ( is_int( $post_id ) ) {
break;
}
/**
* Post parsing completed.
*
* @param array parsed {
* @type array $data
* @type array $meta
* @type array $comments
* @type array $terms
* @type array $extension_elements
* }
* @param DOMNode $node The DOM node for the post.
*
* @todo improve this docblock
*/
do_action( 'wxr_importer.parsed.post', $post_id, $parsed, $node );
$extension_elements = $parsed['extension_elements'];
unset( $parsed['extension_elements'] ) ;
foreach ( $extension_elements as $namespaceURI => $elements ) {
/**
* Post parsing completed.
*
* The dynamic part of the hook is the namespaceURI for extension elements
*
* @param array parsed {
* @type array $data
* @type array $meta
* @type array $comments
* @type array $terms
* }
* @param DOMNode $node The DOM node for the post.
*
* @todo improve this docblock
*/
do_action( "wxr_importer.parsed.post.{$namespaceURI}", $post_id, $elements, $parsed, $node );
}
// Handled everything in this node, move on to the next
$reader->next();
break;
default:
// Skip this node, probably handled by something already
break;
}
}
elseif ( self::WXR_NAMESPACE_URI === $reader->namespaceURI ) {
switch ( $reader->localName ) {
case 'site_url':
$this->site_url = $reader->readString();
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'user':
$node = $reader->expand();
$parsed = $this->parse_user_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_user( $parsed['data'], $parsed['meta'] );
if ( is_wp_error( $status ) ) {
$this->log_error( $status );
}
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'term':
$node = $reader->expand();
$parsed = $this->parse_term_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'link':
$node = $reader->expand();
$parsed = $this->parse_link_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_link( $parsed['data'], $parsed['cats'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
default:
// Skip this node, probably handled by something already
break;
}
}
}
// Now that we've done the main processing, do any required
// post-processing and remapping.
$this->post_process();
if ( $this->options['aggressive_url_search'] ) {
$this->replace_attachment_urls_in_content();
}
// $this->remap_featured_images();
$this->import_end();
}
protected function parse_category_node( $node ) {
$data = array(
// Default taxonomy to "category", since this is a `` tag
'taxonomy' => 'category',
);
$meta = array();
if ( $node->hasAttribute( 'domain' ) ) {
$data['taxonomy'] = $node->getAttribute( 'domain' );
}
if ( $node->hasAttributeNS( self::WXR_NAMESPACE_URI, 'slug' ) ) {
$data['slug'] = $node->getAttributeNS( self::WXR_NAMESPACE_URI, 'slug' );
}
$data['name'] = $node->textContent;
if ( empty( $data['slug'] ) ) {
return null;
}
// Just for extra compatibility
if ( $data['taxonomy'] === 'tag' ) {
$data['taxonomy'] = 'post_tag';
}
return $data;
}
/**
* Parse a comment node into comment data.
*
* @param DOMElement $node Parent node of comment data (typically `wp:comment`).
* @return array Comment data array.
*/
protected function parse_comment_node( $node ) {
$data = array(
'commentmeta' => array(),
);
foreach ( $node->childNodes as $child ) {
// We only care about child elements
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
continue;
}
if ( self::WXR_NAMESPACE_URI !== $child->namespaceURI ) {
continue;
}
switch ( $child->localName ) {
case 'id':
case 'author':
case 'author_email':
case 'author_IP':
case 'author_url':
case 'user_id':
case 'date':
case 'date_gmt':
case 'content':
case 'approved':
case 'type':
case 'parent':
$data[$child->localName] = $child->textContent;
break;
case 'meta':
$meta_item = $this->parse_meta_node( $child );
if ( ! empty( $meta_item ) ) {
$data['meta'][] = $meta_item;
}
break;
}
}
// remap from XML element names to what $this->process_comments() expects
$allowed = array(
'id' => 'comment_id',
'author' => 'comment_author',
'author_email' => 'comment_author_email',
'author_IP' => 'comment_author_IP',
'author_url' => 'comment_author_url',
'user_id' => 'comment_user_id',
'date' => 'comment_date',
'date_gmt' => 'comment_date_gmt',
'content' => 'comment_content',
'approved' => 'comment_approved',
'type' => 'comment_type',
'parent' => 'comment_parent',
);
$data = $this->remap_xml_keys( $data, $allowed );
return $data;
}
/**
* Parse a meta node into meta data.
*
* @param DOMElement $node Parent node of meta data (typically `wp:postmeta` or `wp:commentmeta`).
* @return array|null Meta data array on success, or null on error.
*/
protected function parse_meta_node( $node ) {
foreach ( $node->childNodes as $child ) {
// We only care about child elements
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
continue;
}
if ( self::WXR_NAMESPACE_URI !== $child->namespaceURI ) {
continue;
}
switch ( $child->localName ) {
case 'key':
$key = $child->textContent;
break;
case 'value':
$value = $child->textContent;
break;
}
}
if ( empty( $key ) || empty( $value ) ) {
return null;
}
return compact( 'key', 'value' );
}
/**
* Parse a post node into post data.
*
* @param DOMElement $node Parent node of post data (typically `item`).
* @return array|WP_Error Post data array on success, error otherwise.
*/
protected function parse_post_node( $node ) {
$data = array();
$meta = array();
$comments = array();
$terms = array();
$extension_elements = array();
foreach ( $node->childNodes as $child ) {
// We only care about child elements
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
continue;
}
// note: in the DOM the empty namespace is represented as null,
// unlike in XMLReader, which represents it as '', so the tests below
// to find standard RSS elements are different than those in get_preliminary_information()
// and import()
if ( self::WXR_NAMESPACE_URI === $child->namespaceURI ) {
switch ( $child->localName ) {
case 'type':
case 'id':
case 'date':
case 'date_gmt':
case 'comment_status':
case 'ping_status':
case 'name':
case 'status':
case 'parent':
case 'menu_order':
case 'password':
case 'is_sticky':
case 'attachment_url':
if ( 'status' === $child->localName && 'auto-draft' === $child->textContent ) {
// Bail now
return new WP_Error(
'wxr_importer.post.cannot_import_draft',
__( 'Cannot import auto-draft posts' ),
$data
);
}
$data[$child->localName] = $child->textContent;
break;
case 'meta':
$meta_item = $this->parse_meta_node( $child );
if ( ! empty( $meta_item ) ) {
$meta[] = $meta_item;
}
break;
case 'comment':
$comment_item = $this->parse_comment_node( $child );
if ( ! empty( $comment_item ) ) {
$comments[] = $comment_item;
}
break;
}
}
elseif ( self::DUBLIN_CORE_NAMESPACE_URI === $child->namespaceURI ) {
switch ( $child->localName ) {
case 'creator':
$data["dc:{$child->localName}"] = $child->textContent;
break;
}
}
elseif ( self::RSS_CONTENT_NAMESPACE_URI === $child->namespaceURI ) {
switch ( $child->localName ) {
case 'encoded':
$data["content:{$child->localName}"] = $child->textContent;
break;
}
}
elseif ( is_null( $child->namespaceURI ) ) {
// handle elements in the empty namespace, i.e., standard RSS elements
switch ( $child->localName ) {
case 'title':
case 'guid':
case 'description':
$data[$child->localName] = $child->textContent;
break;
case 'category':
$term_item = $this->parse_category_node( $child );
if ( ! empty( $term_item ) ) {
$terms[] = $term_item;
}
break;
}
}
else {
// element in an extension namespace
if ( ! isset( $extension_elements[$child->namespaceURI] ) ) {
$extension_elements[$child->namespaceURI] = array();
}
$extension_elements[$child->namespaceURI][] = $child;
}
}
// remap from XML element names to what $this->process_post() expects
$allowed = array(
'type' => 'post_type',
'id' => 'post_id',
'title' => 'post_title',
'date' => 'post_date',
'date_gmt' => 'post_date_gmt',
'name' => 'post_name',
'status' => 'post_status',
'parent' => 'post_parent',
'password' => 'post_password',
'description' => 'post_excerpt',
'content:encoded' => 'post_content',
'dc:creator' => 'post_author',
'guid' => true,
'comment_status' => true,
'ping_status' => true,
'menu_order' => true,
'is_sticky' => true,
'attachment_url' => true,
);
$data = $this->remap_xml_keys( $data, $allowed );
return compact( 'data', 'meta', 'comments', 'terms', 'extension_elements' );
}
protected function parse_term_node( $node, $type = 'term' ) {
$data = array();
$meta = array();
foreach ( $node->childNodes as $child ) {
// We only care about child elements
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
continue;
}
if ( self::WXR_NAMESPACE_URI !== $child->namespaceURI ) {
continue;
}
switch ( $child->localName ) {
case 'id':
case 'slug':
case 'name':
case 'parent':
case 'description':
case 'taxonomy':
$data[ $child->localName ] = $child->textContent;
break;
case 'meta':
$meta_item = $this->parse_meta_node( $child );
if ( ! empty( $meta_item ) ) {
$meta[] = $meta_item;
}
}
}
if ( empty( $data['taxonomy'] ) ) {
return null;
}
// Compatibility with WXR 1.0
if ( $data['taxonomy'] === 'tag' ) {
$data['taxonomy'] = 'post_tag';
}
return compact( 'data', 'meta' );
}
protected function parse_user_node( $node ) {
$data = array();
$meta = array();
foreach ( $node->childNodes as $child ) {
// We only care about child elements
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
continue;
}
if ( self::WXR_NAMESPACE_URI !== $child->namespaceURI ) {
continue;
}
switch ( $child->localName ) {
case 'login':
case 'id':
case 'email':
case 'display_name':
case 'first_name':
case 'last_name':
$data[ $child->localName ] = $child->textContent;
break;
case 'meta':
$meta_item = $this->parse_meta_node( $child );
if ( ! empty( $meta_item ) ) {
$meta[] = $meta_item;
}
break;
}
}
// remap from XML element names to what $this->process_user() expects
$allowed = array(
'id' => 'ID',
'login' => 'user_login',
'email' => 'user_email',
'display_name' => true,
'first_name' => true,
'last_name' => true,
);
$data = $this->remap_xml_keys( $data, $allowed );
return compact( 'data', 'meta' );
}
protected function parse_link_node( $node ) {
$data = $cats = array();
foreach ( $node->childNodes as $child ) {
// We only care about child elements
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
continue;
}
if ( self::WXR_NAMESPACE_URI !== $child->namespaceURI ) {
continue;
}
switch ( $child->localName ) {
case 'id':
case 'url':
case 'name':
case 'image':
case 'target':
case 'description':
case 'visible':
case 'owner':
case 'rating':
case 'updated':
case 'rel':
case 'notes':
case 'rss':
$data[ $child->localName ] = $child->textContent;
break;
case 'category':
$cats[] = $child->textContent;
}
}
// remap from XML element names to what $this->process_post() expects
$allowed = array(
'id' => 'link_id',
'url' => 'link_url',
'name' => 'link_name',
'image' => 'link_image',
'target' => 'link_target',
'description' => 'link_description',
'visibile' => 'link_visible',
'owner' => 'link_owner',
'rating' => 'link_rating',
'updated' => 'link_updated',
'rel' => 'link_rel',
'notes' => 'link_notes',
'rss' => 'link_rss',
);
$data = $this->remap_xml_keys( $data, $allowed );
return compact( 'data', 'cats' );
}
/**
* Log an error instance to the logger.
*
* @param WP_Error $error Error instance to log.
*/
protected function log_error( WP_Error $error ) {
$this->logger->warning( $error->get_error_message() );
// Log the data as debug info too
$data = $error->get_error_data();
if ( ! empty( $data ) ) {
$this->logger->debug( var_export( $data, true ) );
}
}
/**
* Parses the WXR file and prepares us for the task of processing parsed data
*
* @param string $file Path to the WXR file for importing
*/
protected function import_start( $file ) {
if ( ! is_file( $file ) ) {
return new WP_Error( 'wxr_importer.file_missing', __( 'The file does not exist, please try again.', 'wordpress-importer' ) );
}
// Suspend bunches of stuff in WP core
wp_defer_term_counting( true );
wp_defer_comment_counting( true );
wp_suspend_cache_invalidation( true );
// Prefill exists calls if told to
if ( $this->options['prefill_existing_posts'] ) {
$this->prefill_existing_posts();
}
if ( $this->options['prefill_existing_comments'] ) {
$this->prefill_existing_comments();
}
if ( $this->options['prefill_existing_terms'] ) {
$this->prefill_existing_terms();
}
if ( $this->options['prefill_existing_links'] ) {
$this->prefill_existing_links();
}
// @todo this is redundant if we are run from within the admin UI
// but necessary when run from WP-CLI or phpunit. Figure out a single place
// where we can do the transform no matter how we are run
// possibly transform WXR 1.0, 1.1 and 1.2 instances into WXR 1.3 instances
require_once __DIR__ . '/class-wxr-transform.php';
$transform_wxr = new Transform_WXR();
if ( is_wp_error( $transform_wxr ) ) {
$this->log_error( __( 'Could not create WXR transformer.', 'wordpress-importer' ) );
return ( $transform_wxr );
}
$transform_wxr->transform( $file );
/**
* Begin the import.
*
* Fires before the import process has begun. If you need to suspend
* caching or heavy processing on hooks, do so here.
*/
do_action( 'import_start' );
}
/**
* Performs post-import cleanup of files and the cache
*/
protected function import_end() {
// Re-enable stuff in core
wp_suspend_cache_invalidation( false );
wp_cache_flush();
foreach ( get_taxonomies() as $tax ) {
delete_option( "{$tax}_children" );
_get_term_hierarchy( $tax );
}
wp_defer_term_counting( false );
wp_defer_comment_counting( false );
if( ! isset( $data_import_option ) ) {
$data_import_option = array();
}
$data_import_optionx = get_option('penci_import_demo_data');
$data_import_option_posts = isset($data_import_optionx['posts']) ? $data_import_optionx['posts'] : array();
$data_import_option_terms = isset($data_import_optionx['terms']) ? $data_import_optionx['terms'] : array();
$data_import_option['posts'] = array_merge($data_import_option_posts, $this->imported_posts);
$data_import_option['terms'] = array_merge($data_import_option_terms, $this->imported_terms);
update_option('penci_import_demo_data', $data_import_option);
/**
* Complete the import.
*
* Fires after the import process has finished. If you need to update
* your cache or re-enable processing, do so here.
*/
do_action( 'import_end' );
}
/**
* Set the user mapping.
*
* @param array $mapping List of map arrays (containing `old_slug`, `old_id`, `new_id`)
*/
public function set_user_mapping( $mapping ) {
foreach ( $mapping as $map ) {
if ( empty( $map['old_slug'] ) || empty( $map['old_id'] ) || empty( $map['new_id'] ) ) {
$this->logger->warning( __( 'Invalid author mapping', 'wordpress-importer' ) );
$this->logger->debug( var_export( $map, true ) );
continue;
}
$old_slug = $map['old_slug'];
$old_id = $map['old_id'];
$new_id = $map['new_id'];
$this->mapping['user'][ $old_id ] = $new_id;
$this->mapping['user_slug'][ $old_slug ] = $new_id;
}
}
/**
* Set the user slug overrides.
*
* Allows overriding the slug in the import with a custom/renamed version.
*
* @param string[] $overrides Map of old slug to new slug.
*/
public function set_user_slug_overrides( $overrides ) {
foreach ( $overrides as $original => $renamed ) {
$this->user_slug_override[ $original ] = $renamed;
}
}
/**
* If fetching attachments is enabled then attempt to create a new attachment
*
* @param array $post Attachment post details from WXR
* @param string $url URL to fetch attachment from
* @return int|WP_Error Post ID on success, WP_Error otherwise
*/
protected function process_attachment( $post, $meta, $remote_url ) {
// 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()
$post['upload_date'] = $post['post_date'];
foreach ( $meta as $meta_item ) {
if ( $meta_item['key'] !== '_wp_attached_file' ) {
continue;
}
if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta_item['value'], $matches ) ) {
$post['upload_date'] = $matches[0];
}
break;
}
// if the URL is absolute, but does not contain address, then upload it assuming base_site_url
if ( preg_match( '|^/[\w\W]+$|', $remote_url ) ) {
$remote_url = rtrim( $this->base_url, '/' ) . $remote_url;
}
$upload = $this->fetch_remote_file( $remote_url, $post );
if ( is_wp_error( $upload ) ) {
return $upload;
}
$info = wp_check_filetype( $upload['file'] );
if ( ! $info ) {
return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) );
}
$post['post_mime_type'] = $info['type'];
// WP really likes using the GUID for display. Allow updating it.
// See https://core.trac.wordpress.org/ticket/33386
if ( $this->options['update_attachment_guids'] ) {
$post['guid'] = $upload['url'];
}
// as per wp-admin/includes/upload.php
$post_id = wp_insert_attachment( $post, $upload['file'] );
if ( is_wp_error( $post_id ) ) {
return $post_id;
}
$attachment_metadata = wp_generate_attachment_metadata( $post_id, $upload['file'] );
wp_update_attachment_metadata( $post_id, $attachment_metadata );
// Map this image URL later if we need to
$this->url_remap[ $remote_url ] = $upload['url'];
// If we have a HTTPS URL, ensure the HTTP URL gets replaced too
if ( substr( $remote_url, 0, 8 ) === 'https://' ) {
$insecure_url = 'http' . substr( $remote_url, 5 );
$this->url_remap[ $insecure_url ] = $upload['url'];
}
if ( $this->options['aggressive_url_search'] ) {
// remap resized image URLs, works by stripping the extension and remapping the URL stub.
/*if ( preg_match( '!^image/!', $info['type'] ) ) {
$parts = pathinfo( $remote_url );
$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']}" );
$this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
}*/
}
return $post_id;
}
/**
* Process and import comment data.
*
* @param array $comments List of comment data arrays.
* @param int $post_id Post to associate with.
* @param array $post Post data.
* @return int|WP_Error Number of comments imported on success, error otherwise.
*/
protected function process_comments( $comments, $post_id, $post, $post_exists = false ) {
$comments = apply_filters( 'wp_import_post_comments', $comments, $post_id, $post );
if ( empty( $comments ) ) {
return 0;
}
$num_comments = 0;
// Sort by ID to avoid excessive remapping later
usort( $comments, array( $this, 'sort_comments_by_id' ) );
foreach ( $comments as $key => $comment ) {
/**
* Pre-process comment data
*
* @param array $comment Comment data. (Return empty to skip.)
* @param int $post_id Post the comment is attached to.
*/
$comment = apply_filters( 'wxr_importer.pre_process.comment', $comment, $post_id );
if ( empty( $comment ) ) {
return false;
}
$original_id = isset( $comment['comment_id'] ) ? (int) $comment['comment_id'] : 0;
$parent_id = isset( $comment['comment_parent'] ) ? (int) $comment['comment_parent'] : 0;
$author_id = isset( $comment['comment_user_id'] ) ? (int) $comment['comment_user_id'] : 0;
// if this is a new post we can skip the comment_exists() check
// TODO: Check comment_exists for performance
if ( $post_exists ) {
$existing = $this->comment_exists( $comment );
if ( $existing ) {
/**
* Comment processing already imported.
*
* @param array $comment Raw data imported for the comment.
*/
do_action( 'wxr_importer.process_already_imported.comment', $comment );
$this->mapping['comment'][ $original_id ] = $existing;
continue;
}
}
// Remove meta from the main array
$meta = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
unset( $comment['commentmeta'] );
// Map the parent comment, or mark it as one we need to fix
$requires_remapping = false;
if ( $parent_id ) {
if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
$comment['comment_parent'] = $this->mapping['comment'][ $parent_id ];
} else {
// Prepare for remapping later
$meta[] = array( 'key' => '_wxr_import_parent', 'value' => $parent_id );
$requires_remapping = true;
// Wipe the parent for now
$comment['comment_parent'] = 0;
}
}
// Map the author, or mark it as one we need to fix
if ( $author_id ) {
if ( isset( $this->mapping['user'][ $author_id ] ) ) {
$comment['user_id'] = $this->mapping['user'][ $author_id ];
} else {
// Prepare for remapping later
$meta[] = array( 'key' => '_wxr_import_user', 'value' => $author_id );
$requires_remapping = true;
// Wipe the user for now
$comment['user_id'] = 0;
}
}
// Run standard core filters
$comment['comment_post_ID'] = $post_id;
$comment = wp_filter_comment( $comment );
// wp_insert_comment expects slashed data
$comment_id = wp_insert_comment( wp_slash( $comment ) );
$this->mapping['comment'][ $original_id ] = $comment_id;
if ( $requires_remapping ) {
$this->requires_remapping['comment'][ $comment_id ] = true;
}
$this->mark_comment_exists( $comment, $comment_id );
/**
* Comment has been imported.
*
* @param int $comment_id New comment ID
* @param array $comment Comment inserted (`comment_id` item refers to the original ID)
* @param int $post_id Post parent of the comment
* @param array $post Post data
*/
do_action( 'wp_import_insert_comment', $comment_id, $comment, $post_id, $post );
// Process the meta items
foreach ( $meta as $meta_item ) {
$value = maybe_unserialize( $meta_item['value'] );
add_comment_meta( $comment_id, wp_slash( $meta_item['key'] ), wp_slash( $value ) );
}
/**
* Post processing completed.
*
* @param int $post_id New post ID.
* @param array $comment Raw data imported for the comment.
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
* @param array $post_id Parent post ID.
*/
do_action( 'wxr_importer.processed.comment', $comment_id, $comment, $meta, $post_id );
$num_comments++;
}
return $num_comments;
}
protected function post_process_menu_item( $post_id ) {
$menu_object_id = get_post_meta( $post_id, '_wxr_import_menu_item', true );
if ( empty( $menu_object_id ) ) {
// No processing needed!
return;
}
$menu_item_type = get_post_meta( $post_id, '_menu_item_type', true );
switch ( $menu_item_type ) {
case 'taxonomy':
if ( isset( $this->mapping['term_id'][ $menu_object_id ] ) ) {
$menu_object = $this->mapping['term_id'][ $menu_object_id ];
}
break;
case 'post_type':
if ( isset( $this->mapping['post'][ $menu_object_id ] ) ) {
$menu_object = $this->mapping['post'][ $menu_object_id ];
}
break;
default:
// Cannot handle this.
return;
}
if ( ! empty( $menu_object ) ) {
update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $menu_object ) );
} else {
$this->logger->warning( sprintf(
__( 'Could not find the menu object for "%s" (post #%d)', 'wordpress-importer' ),
get_the_title( $post_id ),
$post_id
) );
$this->logger->debug( sprintf(
__( 'Post %d was imported with object "%d" of type "%s", but could not be found', 'wordpress-importer' ),
$post_id,
$menu_object_id,
$menu_item_type
) );
}
delete_post_meta( $post_id, '_wxr_import_menu_item' );
}
/**
* Attempt to create a new menu item from import data
*
* Fails for draft, orphaned menu items and those without an associated nav_menu
* or an invalid nav_menu term. If the post type or term object which the menu item
* represents doesn't exist then the menu item will not be imported (waits until the
* end of the import to retry again before discarding).
*
* @param array $item Menu item details from WXR file
*/
protected function process_menu_item_meta( $post_id, $data, $meta ) {
$item_type = get_post_meta( $post_id, '_menu_item_type', true );
$original_object_id = get_post_meta( $post_id, '_menu_item_object_id', true );
$object_id = null;
$this->logger->debug( sprintf( 'Processing menu item %s', $item_type ) );
$requires_remapping = false;
switch ( $item_type ) {
case 'taxonomy':
if ( isset( $this->mapping['term_id'][ $original_object_id ] ) ) {
$object_id = $this->mapping['term_id'][ $original_object_id ];
} else {
add_post_meta( $post_id, '_wxr_import_menu_item', wp_slash( $original_object_id ) );
$requires_remapping = true;
}
break;
case 'post_type':
if ( isset( $this->mapping['post'][ $original_object_id ] ) ) {
$object_id = $this->mapping['post'][ $original_object_id ];
} else {
add_post_meta( $post_id, '_wxr_import_menu_item', wp_slash( $original_object_id ) );
$requires_remapping = true;
}
break;
case 'custom':
// Custom refers to itself, wonderfully easy.
$object_id = $post_id;
break;
default:
// associated object is missing or not imported yet, we'll retry later
$this->missing_menu_items[] = $item;
$this->logger->debug( 'Unknown menu item type' );
break;
}
if ( $requires_remapping ) {
$this->requires_remapping['post'][ $post_id ] = true;
}
if ( empty( $object_id ) ) {
// Nothing needed here.
return;
}
$this->logger->debug( sprintf( 'Menu item %d mapped to %d', $original_object_id, $object_id ) );
update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $object_id ) );
}
/**
* Create new posts based on import information
*
* Posts marked as having a parent which doesn't exist will become top level items.
* Doesn't create a new post if: the post type doesn't exist, the given post 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.
*/
protected function process_post( $data, $meta, $comments, $terms ) {
/**
* Pre-process post data.
*
* @param array $data Post data. (Return empty to skip.)
* @param array $meta Meta data.
* @param array $comments Comments on the post.
* @param array $terms Terms on the post.
*/
$data = apply_filters( 'wxr_importer.pre_process.post', $data, $meta, $comments, $terms );
if ( empty( $data ) ) {
return false;
}
$original_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
$parent_id = isset( $data['post_parent'] ) ? (int) $data['post_parent'] : 0;
$author_id = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
// Have we already processed this?
if ( isset( $this->mapping['post'][ $original_id ] ) ) {
return $this->mapping['post'][ $original_id ];
}
$post_type_object = get_post_type_object( $data['post_type'] );
// Is this type even valid?
if ( ! $post_type_object ) {
$this->logger->warning( sprintf(
__( 'Failed to import "%s": Invalid post type %s', 'wordpress-importer' ),
$data['post_title'],
$data['post_type']
) );
return false;
}
$post_exists = $this->post_exists( $data );
if ( $post_exists ) {
$this->logger->info( sprintf(
__( '%s "%s" already exists.', 'wordpress-importer' ),
$post_type_object->labels->singular_name,
$data['post_title']
) );
/**
* Post processing already imported.
*
* @param array $data Raw data imported for the post.
*/
do_action( 'wxr_importer.process_already_imported.post', $data );
// Even though this post already exists, new comments might need importing
$this->process_comments( $comments, $original_id, $data, $post_exists );
return $post_exists;
}
// Map the parent post, or mark it as one we need to fix
$requires_remapping = false;
if ( $parent_id ) {
if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
$data['post_parent'] = $this->mapping['post'][ $parent_id ];
} else {
$meta[] = array( 'key' => '_wxr_import_parent', 'value' => $parent_id );
$requires_remapping = true;
$data['post_parent'] = 0;
}
}
// Map the author, or mark it as one we need to fix
$author = sanitize_user( $data['post_author'], true );
if ( empty( $author ) ) {
// Missing or invalid author, use default if available.
$data['post_author'] = $this->options['default_author'];
} elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
$data['post_author'] = $this->mapping['user_slug'][ $author ];
} else {
$meta[] = array( 'key' => '_wxr_import_user_slug', 'value' => $author );
$requires_remapping = true;
$data['post_author'] = (int) get_current_user_id();
}
// Does the post look like it contains attachment images?
if ( preg_match( self::REGEX_HAS_ATTACHMENT_REFS, $data['post_content'] ) ) {
$meta[] = array( 'key' => '_wxr_import_has_attachment_refs', 'value' => true );
$requires_remapping = true;
}
// Whitelist to just the keys we allow
$postdata = array(
'import_id' => $data['post_id'],
);
$allowed = array(
'post_author' => true,
'post_date' => true,
'post_date_gmt' => true,
'post_content' => true,
'post_excerpt' => true,
'post_title' => true,
'post_status' => true,
'post_name' => true,
'comment_status' => true,
'ping_status' => true,
'guid' => true,
'post_parent' => true,
'menu_order' => true,
'post_type' => true,
'post_password' => true,
);
foreach ( $data as $key => $value ) {
if ( ! isset( $allowed[ $key ] ) ) {
continue;
}
$postdata[ $key ] = $data[ $key ];
}
$postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $data );
if ( 'attachment' === $postdata['post_type'] ) {
if ( ! $this->options['fetch_attachments'] ) {
$this->logger->notice( sprintf(
__( 'Skipping attachment "%s", fetching attachments disabled' ),
$data['post_title']
) );
/**
* Post processing skipped.
*
* @param array $data Raw data imported for the post.
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
*/
do_action( 'wxr_importer.process_skipped.post', $data, $meta );
return false;
}
$remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
$post_id = $this->process_attachment( $postdata, $meta, $remote_url );
} else {
$post_id = wp_insert_post( $postdata, true );
do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
}
if ( is_wp_error( $post_id ) ) {
$this->logger->error( sprintf(
__( 'Failed to import "%s" (%s)', 'wordpress-importer' ),
$data['post_title'],
$post_type_object->labels->singular_name
) );
$this->logger->debug( $post_id->get_error_message() );
/**
* Post processing failed.
*
* @param WP_Error $post_id Error object.
* @param array $data Raw data imported for the post.
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
* @param array $comments Raw comment data, already processed by {@see process_comments}.
* @param array $terms Raw term data, already processed.
*/
do_action( 'wxr_importer.process_failed.post', $post_id, $data, $meta, $comments, $terms );
return $post_id;
}
// Ensure stickiness is handled correctly too
if ( $data['is_sticky'] === '1' ) {
stick_post( $post_id );
}
// map pre-import ID to local ID
$this->mapping['post'][ $original_id ] = (int) $post_id;
if ( $requires_remapping ) {
$this->requires_remapping['post'][ $post_id ] = true;
}
$this->mark_post_exists( $data, $post_id );
$this->logger->info( sprintf(
__( 'Imported "%s" (%s)', 'wordpress-importer' ),
$data['post_title'],
$post_type_object->labels->singular_name
) );
$this->logger->debug( sprintf(
__( 'Post %d remapped to %d', 'wordpress-importer' ),
$original_id,
$post_id
) );
$this->imported_posts[ $data['post_type'] ][$post_id] = '';
// Handle the terms too
$terms = apply_filters( 'wp_import_post_terms', $terms, $post_id, $data );
if ( ! empty( $terms ) ) {
$term_ids = array();
foreach ( $terms as $term ) {
$taxonomy = $term['taxonomy'];
$key = sha1( $taxonomy . ':' . $term['slug'] );
if ( isset( $this->mapping['term'][ $key ] ) ) {
$term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ];
} else {
$meta[] = array( 'key' => '_wxr_import_term', 'value' => $term );
$this->requires_remapping['post'][ $post_id ] = true;
}
}
foreach ( $term_ids as $tax => $ids ) {
$tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $data );
}
}
$this->process_comments( $comments, $post_id, $data );
$this->process_post_meta( $meta, $post_id, $data );
if ( 'nav_menu_item' === $data['post_type'] ) {
$this->process_menu_item_meta( $post_id, $data, $meta );
}
/**
* Post processing completed.
*
* @param int $post_id New post ID.
* @param array $data Raw data imported for the post.
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
* @param array $comments Raw comment data, already processed by {@see process_comments}.
* @param array $terms Raw term data, already processed.
*/
do_action( 'wxr_importer.processed.post', $post_id, $data, $meta, $comments, $terms );
return $post_id;
}
/**
* Process and import post meta items.
*
* @param array $meta List of meta data arrays
* @param int $post_id Post to associate with
* @param array $post Post data
* @return int|WP_Error Number of meta items imported on success, error otherwise.
*/
protected function process_post_meta( $meta, $post_id, $post ) {
if ( empty( $meta ) ) {
return true;
}
foreach ( $meta as $meta_item ) {
/**
* Pre-process post meta data.
*
* @param array $meta_item Meta data. (Return empty to skip.)
* @param int $post_id Post the meta is attached to.
*/
$meta_item = apply_filters( 'wxr_importer.pre_process.post_meta', $meta_item, $post_id );
if ( empty( $meta_item ) ) {
return false;
}
$key = apply_filters( 'import_post_meta_key', $meta_item['key'], $post_id, $post );
$value = false;
if ( '_edit_last' === $key ) {
$value = intval( $meta_item['value'] );
if ( ! isset( $this->mapping['user'][ $value ] ) ) {
// Skip!
continue;
}
$value = $this->mapping['user'][ $value ];
}
if ( $key ) {
// export gets meta straight from the DB so could have a serialized string
if ( ! $value ) {
$value = maybe_unserialize( $meta_item['value'] );
}
add_post_meta( $post_id, $key, $value );
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;
}
}
}
return true;
}
protected function process_term( $data, $meta ) {
/**
* Pre-process term data.
*
* @param array $data Term data. (Return empty to skip.)
* @param array $meta Meta data.
*/
$data = apply_filters( 'wxr_importer.pre_process.term', $data, $meta );
if ( empty( $data ) ) {
return false;
}
$original_id = isset( $data['id'] ) ? (int) $data['id'] : 0;
$mapping_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
$existing = $this->term_exists( $data );
if ( $existing ) {
$this->logger->notice( sprintf(
__( 'Term "%s" (%s) already exists', 'wordpress-importer' ),
$data['name'],
$data['taxonomy']
) );
/**
* Term processing already imported.
*
* @param array $data Raw data imported for the term.
*/
do_action( 'wxr_importer.process_already_imported.term', $data );
$this->mapping['term'][ $mapping_key ] = $existing;
$this->mapping['term_id'][ $original_id ] = $existing;
return false;
}
// WP really likes to repeat itself in export files
if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
return false;
}
$termdata = array();
$allowed = array(
'slug' => true,
'parent' => true,
'description' => true,
);
/*
* Does this term have a parent?
* Note: $data['parent'] is the slug of the parent term.
*/
$requires_remapping = false;
if ( ! empty( $data['parent'] ) ) {
// map the parent temr, or mark it as one we need to fix.
$parent_mapping_key = sha1( $data['taxonomy'] . ':' . $data['parent'] );
// First, look in the mapping array.
if ( isset ( $this->mapping['term'][ $parent_mapping_key] ) ) {
$data['parent'] = $this->mapping['term'][ $parent_mapping_key ];
}
// Next, see if the term already exists
elseif ( $parent_id = $this->term_exists( array( 'taxonomy' => $data['taxonomy'], 'slug' => $data['parent'] ) ) ) {
$data['parent'] = $parent_id;
}
else {
// Prepare for remapping later, using the slug.
$meta[] = array( 'key' => '_wxr_import_parent', 'value' => $data['parent'] );
$requires_remapping = true;
// Wipe the parent for now
$data['parent'] = 0;
}
}
foreach ( $data as $key => $value ) {
if ( ! isset( $allowed[ $key ] ) ) {
continue;
}
$termdata[ $key ] = $data[ $key ];
}
$result = wp_insert_term( $data['name'], $data['taxonomy'], $termdata );
if ( is_wp_error( $result ) ) {
$this->logger->warning( sprintf(
__( 'Failed to import %s %s', 'wordpress-importer' ),
$data['taxonomy'],
$data['name']
) );
$this->logger->debug( $result->get_error_message() );
do_action( 'wp_import_insert_term_failed', $result, $data );
/**
* Term processing failed.
*
* @param WP_Error $result Error object.
* @param array $data Raw data imported for the term.
* @param array $meta Meta data supplied for the term.
*/
do_action( 'wxr_importer.process_failed.term', $result, $data, $meta );
return false;
}
$term_id = $result['term_id'];
// Add the new term to the mapping array.
$this->mapping['term'][ $mapping_key ] = $term_id;
$this->mapping['term_id'][ $original_id ] = $term_id;
// Add the new term to the exists array.
$this->exists['term'][ $mapping_key ] = $term_id;
$this->imported_terms[ $data['taxonomy'] ][$term_id] = '';
// Add the termmeta if necessary
if ( $requires_remapping ) {
foreach ( $meta as $insert ) {
update_term_meta( $term_id, $insert['key'], $insert['value'] );
}
$this->requires_remapping['term'][ $term_id ] = true;
}
$this->logger->info( sprintf(
__( 'Imported "%s" (%s)', 'wordpress-importer' ),
$data['name'],
$data['taxonomy']
) );
$this->logger->debug( sprintf(
__( 'Term %d remapped to %d', 'wordpress-importer' ),
$original_id,
$term_id
) );
do_action( 'wp_import_insert_term', $term_id, $data );
$this->process_term_meta( $meta, $term_id, $data );
/**
* Term processing completed.
*
* @param int $term_id New term ID.
* @param array $data Raw data imported for the term.
*/
do_action( 'wxr_importer.processed.term', $term_id, $data );
}
/**
* Process and import term meta items.
*
* @param array $meta List of meta data arrays
* @param int $post_id Post to associate with
* @param array $term Term data
* @return int|WP_Error Number of meta items imported on success, error otherwise.
*/
protected function process_term_meta( $meta, $term_id, $term ) {
if ( empty( $meta ) ) {
return true;
}
foreach ( $meta as $meta_item ) {
/**
* Pre-process post meta data.
*
* @param array $meta_item Meta data. (Return empty to skip.)
* @param int $term_id Term the meta is attached to.
*/
$meta_item = apply_filters( 'wxr_importer.pre_process.term_meta', $meta_item, $term_id );
if ( empty( $meta_item ) ) {
return false;
}
$key = apply_filters( 'import_term_meta_key', $meta_item['key'], $term_id, $term );
$value = false;
if ( $key ) {
// export gets meta straight from the DB so could have a serialized string
if ( ! $value ) {
$value = maybe_unserialize( $meta_item['value'] );
}
add_term_meta( $term_id, $key, $value );
do_action( 'import_term_meta', $term_id, $key, $value );
}
}
return true;
}
/**
* Process and import a user.
*
* @param array $data
* @param array $meta
* @return bool
*/
protected function process_user( $data, $meta ) {
/**
* Pre-process user data.
*
* @param array $data User data. (Return empty to skip.)
* @param array $meta Meta data.
*/
$data = apply_filters( 'wxr_importer.pre_process.user', $data, $meta );
if ( empty( $data ) ) {
return false;
}
// Have we already handled this user?
$original_id = isset( $data['ID'] ) ? $data['ID'] : 0;
$original_slug = $data['user_login'];
if ( isset( $this->mapping['user'][ $original_id ] ) ) {
$existing = $this->mapping['user'][ $original_id ];
// Note the slug mapping if we need to too
if ( ! isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
$this->mapping['user_slug'][ $original_slug ] = $existing;
}
$this->logger->notice( sprintf(
__( 'Skipped importing user "%s"', 'wordpress-importer' ),
$data['user_login']
) );
/**
* User processing completed.
*
* @param int $user_id New user ID.
* @param array $userdata Raw data imported for the user.
*/
do_action( 'wxr_importer.processed.user', $user_id, $userdata );
return false;
}
if ( isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
$existing = $this->mapping['user_slug'][ $original_slug ];
// Ensure we note the mapping too
$this->mapping['user'][ $original_id ] = $existing;
return false;
}
// Allow overriding the user's slug
$login = $original_slug;
if ( isset( $this->user_slug_override[ $login ] ) ) {
$login = $this->user_slug_override[ $login ];
}
$userdata = array(
'user_login' => sanitize_user( $login, true ),
'user_pass' => wp_generate_password(),
);
$allowed = array(
'user_email' => true,
'display_name' => true,
'first_name' => true,
'last_name' => true,
);
foreach ( $data as $key => $value ) {
if ( ! isset( $allowed[ $key ] ) ) {
continue;
}
$userdata[ $key ] = $data[ $key ];
}
$user_id = wp_insert_user( wp_slash( $userdata ) );
if ( is_wp_error( $user_id ) ) {
$this->logger->error( sprintf(
__( 'Failed to import user "%s"', 'wordpress-importer' ),
$userdata['user_login']
) );
$this->logger->debug( $user_id->get_error_message() );
/**
* User processing failed.
*
* @param WP_Error $user_id Error object.
* @param array $userdata Raw data imported for the user.
*/
do_action( 'wxr_importer.process_failed.user', $user_id, $userdata );
return false;
}
if ( $original_id ) {
$this->mapping['user'][ $original_id ] = $user_id;
}
$this->mapping['user_slug'][ $original_slug ] = $user_id;
$this->logger->info( sprintf(
__( 'Imported user "%s"', 'wordpress-importer' ),
$userdata['user_login']
) );
$this->logger->debug( sprintf(
__( 'User %d remapped to %d', 'wordpress-importer' ),
$original_id,
$user_id
) );
$this->process_user_meta( $meta, $user_id, $data );
/**
* User processing completed.
*
* @param int $user_id New user ID.
* @param array $userdata Raw data imported for the user.
*/
do_action( 'wxr_importer.processed.user', $user_id, $userdata );
}
/**
* Create new posts based on import information
*
* Posts marked as having a parent which doesn't exist will become top level items.
* Doesn't create a new post if: the post type doesn't exist, the given post 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.
*/
protected function process_link( $data, $link_categories ) {
/**
* Pre-process post data.
*
* @param array $data Post data. (Return empty to skip.)
* @param array $meta Meta data.
* @param array $comments Comments on the post.
* @param array $terms Terms on the post.
*/
$data = apply_filters( 'wxr_importer.pre_process.link', $data );
if ( empty( $data ) ) {
return false;
}
$original_id = isset( $data['link_id'] ) ? (int) $data['link_id'] : 0;
$author_id = isset( $data['link_owner'] ) ? (int) $data['link_owner'] : 0;
// Have we already processed this?
if ( isset( $this->mapping['link'][ $original_id ] ) ) {
return $this->mapping['link'][ $original_id ];
}
$link_exists = $this->link_exists( $data );
if ( $link_exists ) {
$this->logger->notice( sprintf(
__( 'Link "%s" already exists.', 'wordpress-importer' ),
$data['link_name']
) );
/**
* Post processing already imported.
*
* @param array $data Raw data imported for the post.
*/
do_action( 'wxr_importer.process_already_imported.link', $data );
return $link_exists;
}
// Map the parent post, or mark it as one we need to fix
$requires_remapping = false;
// Map the author, or mark it as one we need to fix
$author = sanitize_user( $data['link_owner'], true );
if ( empty( $author ) ) {
// Missing or invalid author, use default if available.
$data['link_owner'] = $this->options['default_author'];
} elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
$data['link_owner'] = $this->mapping['user_slug'][ $author ];
} else {
$requires_remapping = true;
$data['link_owner'] = (int) get_current_user_id();
}
// Whitelist to just the keys we allow
$linkdata = array(
'import_id' => $data['link_id'],
);
$allowed = array(
'link_url' => true,
'link_name' => true,
'link_image' => true,
'link_description' => true,
'link_visible' => true,
'link_owner' => true,
'link_rating' => true,
'link_updated' => true,
'link_rel' => true,
'link_notes' => true,
'link_rss' => true,
);
foreach ( $data as $key => $value ) {
if ( ! isset( $allowed[ $key ] ) ) {
continue;
}
$linkdata[ $key ] = $data[ $key ];
}
$linkdata = apply_filters( 'wp_import_link_data_processed', $linkdata, $data );
$link_id = wp_insert_link( $linkdata, true );
do_action( 'wp_import_insert_link', $link_id, $original_id, $linkdata, $data );
if ( is_wp_error( $link_id ) ) {
$this->logger->error( sprintf(
__( 'Failed to import link "%s"', 'wordpress-importer' ),
$data['link_name']
) );
$this->logger->debug( $link_id->get_error_message() );
/**
* Post processing failed.
*
* @param WP_Error $post_id Error object.
* @param array $data Raw data imported for the post.
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
* @param array $comments Raw comment data, already processed by {@see process_comments}.
* @param array $terms Raw term data, already processed.
*/
do_action( 'wxr_importer.process_failed.link', $link_id, $data );
return $link_id;
}
// map pre-import ID to local ID
$this->mapping['link'][ $original_id ] = (int) $link_id;
if ( $requires_remapping ) {
$this->requires_remapping['link'][ $link_id ] = true;
set_transient( '_wxr_import_user_slug_' . $link_id, $author );
}
$this->mark_link_exists( $data, $link_id );
$this->logger->info( sprintf(
__( 'Imported link "%s"', 'wordpress-importer' ),
$data['link_name']
) );
$this->logger->debug( sprintf(
__( 'Link %d remapped to %d', 'wordpress-importer' ),
$original_id,
$link_id
) );
// Handle the terms too
$link_categories = apply_filters( 'wp_import_link_terms', $link_categories, $link_id, $data );
if ( ! empty( $link_categories ) ) {
$term_ids = $trans = array();
foreach ( $link_categories as $term ) {
$key = sha1( 'link_category' . ':' . $term );
if ( isset( $this->mapping['term'][ $key ] ) ) {
$term_ids[] = (int) $this->mapping['term'][ $key ];
} else {
$trans[] = $term;
$this->requires_remapping['link'][ $link_id ] = true;
}
}
wp_set_link_cats( $link_id, $term_ids );
do_action( 'wp_import_set_link_cats', $term_ids, $link_id, $data );
if ( ! empty( $trans ) ) {
set_transient( '_wxr_import_term_' . $link_id, $trans );
}
}
/**
* Post processing completed.
*
* @param int $post_id New post ID.
* @param array $data Raw data imported for the post.
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
* @param array $comments Raw comment data, already processed by {@see process_comments}.
* @param array $terms Raw term data, already processed.
*/
do_action( 'wxr_importer.processed.link', $link_id, $data, $link_categories );
return $link_id;
}
/**
* Process and import a user meta.
*
* @param array $meta
* @param int $user_id
* @param array $user
* @return bool
*
*/
protected function process_user_meta( $meta, $user_id, $user ) {
/*
* @todo The standard importer has NEVER done user meta
* and I'm sure there is going to have to be remapping
* on some meta_keys. So, return without importing the
* meta until I have time to figure out the remapping strategy.
*/
return true;
if ( empty( $meta ) ) {
return true;
}
foreach ( $meta as $meta_item ) {
/**
* Pre-process yser meta data.
*
* @param array $meta_item Meta data. (Return empty to skip.)
* @param int $user_id User the meta is attached to.
*/
$meta_item = apply_filters( 'wxr_importer.pre_process.user_meta', $meta_item, $user_id );
if ( empty( $meta_item ) ) {
return false;
}
$key = apply_filters( 'import_user_meta_key', $meta_item['key'], $user_id, $user );
$value = false;
if ( ! in_array( $key, array( 'first_name', 'last_name' ) ) ) {
// export gets meta straight from the DB so could have a serialized string
if ( ! $value ) {
$value = maybe_unserialize( $meta_item['value'] );
}
add_user_meta( $user_id, $key, $value );
do_action( 'import_user_meta', $user_id, $key, $value );
}
}
return true;
}
/**
* Callback for `usort` to sort comments by ID
*
* @param array $a Comment data for the first comment
* @param array $b Comment data for the second comment
* @return int
*/
public static function sort_comments_by_id( $a, $b ) {
if ( empty( $a['comment_id'] ) ) {
return 1;
}
if ( empty( $b['comment_id'] ) ) {
return -1;
}
return $a['comment_id'] - $b['comment_id'];
}
/**
* Remap data keys from XML element name to what process_xxx() expects
*
* @param array $data Parsed XML data. key is XML element name,
* value is element's value.
* @param array $keymap Map of XML element name to processing key.
* key is XML element name, value is what that
* key maps to (or true if key should map to itself)
* @return array
*/
protected function remap_xml_keys( $data, $keymap ) {
foreach ( $data as $key => $value ) {
if ( ! isset( $keymap[ $key ] ) ) {
unset( $data[ $key ] );
continue;
}
if ( is_string( $keymap[$key] ) ) {
$data[ $keymap[$key] ] = $data[ $key ];
unset ( $data[ $key ] );
}
}
return $data;
}
/**
* Attempt to download a remote file attachment
*
* @param string $url URL of item to fetch
* @param array $post Attachment details
* @return array|WP_Error Local file location details on success, WP_Error otherwise
*/
protected function fetch_remote_file( $url, $post ) {
// extract the file name and extension from the url
$file_name = basename( $url );
// get placeholder file in the upload dir with a unique, sanitized filename
$upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
if ( $upload['error'] ) {
return new WP_Error( 'upload_dir_error', $upload['error'] );
}
// fetch the remote url and write it to the placeholder file
$response = wp_remote_get( $url, array(
'stream' => true,
'filename' => $upload['file'],
) );
// request failed
if ( is_wp_error( $response ) ) {
unlink( $upload['file'] );
return $response;
}
$code = (int) wp_remote_retrieve_response_code( $response );
// make sure the fetch was successful
if ( $code !== 200 ) {
unlink( $upload['file'] );
return new WP_Error(
'import_file_error',
sprintf(
__( 'Remote server returned %1$d %2$s for %3$s', 'wordpress-importer' ),
$code,
get_status_header_desc( $code ),
$url
)
);
}
$filesize = filesize( $upload['file'] );
$headers = wp_remote_retrieve_headers( $response );
if ( isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
unlink( $upload['file'] );
return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'wordpress-importer' ) );
}
if ( 0 === $filesize ) {
unlink( $upload['file'] );
return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) );
}
$max_size = (int) $this->max_attachment_size();
if ( ! empty( $max_size ) && $filesize > $max_size ) {
unlink( $upload['file'] );
$message = sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) );
return new WP_Error( 'import_file_error', $message );
}
return $upload;
}
protected function post_process() {
// Time to tackle any left-over bits
if ( ! empty( $this->requires_remapping['post'] ) ) {
$this->post_process_posts( $this->requires_remapping['post'] );
}
if ( ! empty( $this->requires_remapping['comment'] ) ) {
$this->post_process_comments( $this->requires_remapping['comment'] );
}
if ( ! empty( $this->requires_remapping['term'] ) ) {
$this->post_process_terms( $this->requires_remapping['term'] );
}
if ( ! empty( $this->requires_remapping['link'] ) ) {
$this->post_process_links( $this->requires_remapping['link'] );
}
}
protected function post_process_posts( $todo ) {
foreach ( $todo as $post_id => $_ ) {
$this->logger->debug( sprintf(
// Note: title intentionally not used to skip extra processing
// for when debug logging is off
__( 'Running post-processing for post %d', 'wordpress-importer' ),
$post_id
) );
$data = array();
$parent_id = get_post_meta( $post_id, '_wxr_import_parent', true );
if ( ! empty( $parent_id ) ) {
// Have we imported the parent now?
if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
$data['post_parent'] = $this->mapping['post'][ $parent_id ];
} else {
$this->logger->warning( sprintf(
__( 'Could not find the post parent for "%s" (post #%d)', 'wordpress-importer' ),
get_the_title( $post_id ),
$post_id
) );
$this->logger->debug( sprintf(
__( 'Post %d was imported with parent %d, but could not be found', 'wordpress-importer' ),
$post_id,
$parent_id
) );
}
}
$author_slug = get_post_meta( $post_id, '_wxr_import_user_slug', true );
if ( ! empty( $author_slug ) ) {
// Have we imported the user now?
if ( isset( $this->mapping['user_slug'][ $author_slug ] ) ) {
$data['post_author'] = $this->mapping['user_slug'][ $author_slug ];
} else {
$this->logger->warning( sprintf(
__( 'Could not find the author for "%s" (post #%d)', 'wordpress-importer' ),
get_the_title( $post_id ),
$post_id
) );
$this->logger->debug( sprintf(
__( 'Post %d was imported with author "%s", but could not be found', 'wordpress-importer' ),
$post_id,
$author_slug
) );
}
}
$has_attachments = get_post_meta( $post_id, '_wxr_import_has_attachment_refs', true );
if ( ! empty( $has_attachments ) ) {
$post = get_post( $post_id );
$content = $post->post_content;
// Replace all the URLs we've got
$new_content = str_replace( array_keys( $this->url_remap ), $this->url_remap, $content );
if ( $new_content !== $content ) {
$data['post_content'] = $new_content;
}
}
if ( get_post_type( $post_id ) === 'nav_menu_item' ) {
$this->post_process_menu_item( $post_id );
}
$terms = get_post_meta( $post_id, '_wxr_import_term', false );
if ( ! empty( $terms ) ) {
$term_ids = array();
foreach ( $terms as $term ) {
// Have we imported the term now?
$mapping_key = sha1( $term['taxonomy'] . ':' . $term['slug'] );
if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
$term_ids[ $term['taxonomy'] ][] = $this->mapping['term'][ $mapping_key ];
}
// Next, see if the term already exists.
elseif ( $term_id = $this->term_exists(
array( 'taxonomy' => $term['taxonomy'], 'slug' => $term['slug'] ) ) ) {
$term_ids[ $term['taxonomy'] ][] = $term_id;
}
else {
$_term = wp_insert_term( $term['name'], $term['taxonomy'],
array( 'slug' => $term['slug'] ) );
$term_id = $_term['term_id'];
$term_ids[ $term['taxonomy'] ][] = $term_id;
// Add the new term to the mapping array.
$this->mapping['term'][ $mapping_key ] = $term_id;
// Add the new term to the exists array.
$this->exists['term'][ $mapping_key ] = $term_id;
}
}
foreach ( $term_ids as $tax => $ids ) {
$tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
// @todo we don't have the $data array that is passed as the last param
// to this action in $this->process_post(). Can we reconstruct it here?
do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id );
}
}
// Do we have updates to make?
if ( empty( $data ) ) {
$this->logger->debug( sprintf(
__( 'Post %d was marked for post-processing, but none was required.', 'wordpress-importer' ),
$post_id
) );
continue;
}
// Run the update
$data['ID'] = $post_id;
$result = wp_update_post( $data, true );
if ( is_wp_error( $result ) ) {
$this->logger->warning( sprintf(
__( 'Could not update "%s" (post #%d) with mapped data', 'wordpress-importer' ),
get_the_title( $post_id ),
$post_id
) );
$this->logger->debug( $result->get_error_message() );
continue;
}
// Clear out our temporary meta keys
delete_post_meta( $post_id, '_wxr_import_parent' );
delete_post_meta( $post_id, '_wxr_import_user_slug' );
delete_post_meta( $post_id, '_wxr_import_has_attachment_refs' );
delete_post_meta( $post_id, '_wxr_import_term' );
}
}
protected function post_process_terms( $todo ) {
foreach ( $todo as $term_id => $_ ) {
$data = array();
$parent_term_slug = get_term_meta( $term_id, '_wxr_import_parent', true );
if ( ! empty( $parent_term_slug ) ) {
$term = get_term( (int) $term_id );
$parent_mapping_key = sha1( $term->taxonomy . ':' . $parent_term_slug );
// Have we imported the parent now?
if ( isset( $this->mapping['term'][ $parent_mapping_key ] ) ) {
$data['parent'] = $this->mapping['term'][ $parent_mapping_key ];
}
// Next, wee if the term already exists.
elseif ( $parent_id = $this->term_exists(
array( 'taxonomy' => $term->taxonomy, 'slug' => $parent_term_slug ) ) ) {
$data['parent'] = $parent_id;
}
else {
$this->logger->warning( sprintf( __( 'Could not find the parent for term #%d', 'wordpress-importer' ),
$term_id,
$parent_term_slug
) );
}
}
// Do we have updates to make?
if ( empty ( $data ) ) {
continue;
}
// Run the update
$result = wp_update_term( $term_id, $term->taxonomy, $data );
if ( empty( $result ) ) {
$this->logger->warning( sprintf( __( 'Cound not update term #%d with mapped data', 'wordpress-importer' ),
$term_id
) );
continue;
}
// Clear out our temporary meta keys
delete_term_meta( $term_id, '_wxr_import_parent' );
}
}
protected function post_process_comments( $todo ) {
foreach ( $todo as $comment_id => $_ ) {
$data = array();
$parent_id = get_comment_meta( $comment_id, '_wxr_import_parent', true );
if ( ! empty( $parent_id ) ) {
// Have we imported the parent now?
if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
$data['comment_parent'] = $this->mapping['comment'][ $parent_id ];
} else {
$this->logger->warning( sprintf(
__( 'Could not find the comment parent for comment #%d', 'wordpress-importer' ),
$comment_id
) );
$this->logger->debug( sprintf(
__( 'Comment %d was imported with parent %d, but could not be found', 'wordpress-importer' ),
$comment_id,
$parent_id
) );
}
}
$author_id = get_comment_meta( $comment_id, '_wxr_import_user', true );
if ( ! empty( $author_id ) ) {
// Have we imported the user now?
if ( isset( $this->mapping['user'][ $author_id ] ) ) {
$data['user_id'] = $this->mapping['user'][ $author_id ];
} else {
$this->logger->warning( sprintf(
__( 'Could not find the author for comment #%d', 'wordpress-importer' ),
$comment_id
) );
$this->logger->debug( sprintf(
__( 'Comment %d was imported with author %d, but could not be found', 'wordpress-importer' ),
$comment_id,
$author_id
) );
}
}
// Do we have updates to make?
if ( empty( $data ) ) {
continue;
}
// Run the update
$data['comment_ID'] = $comment_ID;
$result = wp_update_comment( wp_slash( $data ) );
if ( empty( $result ) ) {
$this->logger->warning( sprintf(
__( 'Could not update comment #%d with mapped data', 'wordpress-importer' ),
$comment_id
) );
continue;
}
// Clear out our temporary meta keys
delete_comment_meta( $comment_id, '_wxr_import_parent' );
delete_comment_meta( $comment_id, '_wxr_import_user' );
}
}
protected function post_process_links( $todo ) {
global $wpdb;
foreach ( $todo as $link_id => $_ ) {
$this->logger->debug( sprintf(
// Note: title intentionally not used to skip extra processing
// for when debug logging is off
__( 'Running post-processing for link %d', 'wordpress-importer' ),
$link_id
) );
$data = array();
$author_slug = get_transient( '_wxr_import_user_slug_' . $link_id );
if ( ! empty( $author_slug ) ) {
// Have we imported the user now?
if ( isset( $this->mapping['user_slug'][ $author_slug ] ) ) {
$data['link_owner'] = $this->mapping['user_slug'][ $author_slug ];
} else {
$link_name = $wpdb->get_var( $wpdb->prepare( "SELECT link_name FROM {$wpdb->links} WHERE link_id = %d", $link_id ) );
$this->logger->warning( sprintf(
__( 'Could not find the author for "%s" (link #%d)', 'wordpress-importer' ),
$link_name,
$link_id
) );
$this->logger->debug( sprintf(
__( 'Link %d was imported with author "%s", but could not be found', 'wordpress-importer' ),
$link_id,
$author_slug
) );
}
}
// Do we have updates to make?
if ( empty( $data ) ) {
$this->logger->debug( sprintf(
__( 'Link %d was marked for post-processing, but none was required.', 'wordpress-importer' ),
$link_id
) );
continue;
}
// Run the update
$data['link_id'] = $link_id;
$result = wp_update_link( $data );
if ( is_wp_error( $result ) ) {
$link_name = $wpdb->get_var( $wpdb->prepare( "SELECT link_name FROM {$wpdb->links} WHERE link_id = %d", $link_id ) );
$this->logger->warning( sprintf(
__( 'Could not update "%s" (link #%d) with mapped data', 'wordpress-importer' ),
$link_name,
$link_id
) );
$this->logger->debug( $result->get_error_message() );
continue;
}
$link_categories = get_transient( '_wxr_import_term_' . $link_id );
if ( ! empty( $link_categories ) ) {
$term_ids = array();
foreach ( $link_categories as $term ) {
// Have we imported the term now?
$mapping_key = sha1( 'link_category' . ':' . $term );
if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
$term_ids[] = $this->mapping['term'][ $mapping_key ];
}
// Next, see if the term already exists.
elseif ( $term_id = $this->term_exists(
array( 'taxonomy' => 'link_category', 'slug' => $term ) ) ) {
$term_ids = $term_id;
}
else {
$_term = wp_insert_term( $term, 'link_category' );
$term_id = $_term['term_id'];
$term_ids[] = $term_id;
// Add the new term to the mapping array.
$this->mapping['term'][ $mapping_key ] = $term_id;
// Add the new term to the exists array.
$this->exists['term'][ $mapping_key ] = $term_id;
}
}
if ( ! empty( $term_ids ) ) {
wp_set_link_cats( $link_id, $term_ids );
do_action( 'wp_import_set_link_terms', $term_ids, $link_id );
}
}
// Clear out our temporary meta keys
delete_transient( '_wxr_import_user_slug_' . $link_id );
delete_transient( '_wxr_import_term_' . $link_id );
}
}
/**
* Use stored mapping information to update old attachment URLs
*/
protected function replace_attachment_urls_in_content() {
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' ) );
foreach ( $this->url_remap as $from_url => $to_url ) {
// remap urls in post_content
$query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url );
$wpdb->query( $query );
// remap enclosure urls
$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( $query );
}
}
/**
* Update _thumbnail_id meta to new, imported attachment IDs
*/
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 ];
// only update if there's a difference
if ( $new_id !== $value ) {
update_post_meta( $post_id, '_thumbnail_id', $new_id );
}
}
}
}
/**
* Decide if the given meta key maps to information we will want to import
*
* @param string $key The meta key to check
* @return string|bool The key if we do want to import, false if not
*/
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' ) ) ) {
return false;
}
return $key;
}
/**
* Decide what the maximum file size for downloaded attachments is.
* Default is 0 (unlimited), can be filtered via import_attachment_size_limit
*
* @return int Maximum attachment file size to import
*/
protected 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
*
* @access protected
* @return int 60
*/
function bump_request_timeout($val) {
return 60;
}
// return the difference in length between two strings
function cmpr_strlen( $a, $b ) {
return strlen( $b ) - strlen( $a );
}
/**
* Prefill existing post data.
*
* This preloads all GUIDs into memory, allowing us to avoid hitting the
* database when we need to check for existence. With larger imports, this
* becomes prohibitively slow to perform SELECT queries on each.
*
* By preloading all this data into memory, it's a constant-time lookup in
* PHP instead. However, this does use a lot more memory, so for sites doing
* small imports onto a large site, it may be a better tradeoff to use
* on-the-fly checking instead.
*/
protected function prefill_existing_posts() {
global $wpdb;
$posts = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts}" );
foreach ( $posts as $item ) {
$this->exists['post'][ $item->guid ] = $item->ID;
}
}
/**
* Does the post exist?
*
* @param array $data Post data to check against.
* @return int|bool Existing post ID if it exists, false otherwise.
*/
protected function post_exists( $data ) {
// Constant-time lookup if we prefilled
$exists_key = $data['guid'];
if ( $this->options['prefill_existing_posts'] ) {
return isset( $this->exists['post'][ $exists_key ] ) ? (int) $this->exists['post'][ $exists_key ] : false;
}
// No prefilling, but might have already handled it
if ( isset( $this->exists['post'][ $exists_key ] ) ) {
return (int) $this->exists['post'][ $exists_key ];
}
// Still nothing, try post_exists, and cache it
$exists = post_exists( $data['post_title'], $data['post_content'], $data['post_date'] );
$this->exists['post'][ $exists_key ] = $exists;
return $exists;
}
/**
* Mark the post as existing.
*
* @param array $data Post data to mark as existing.
* @param int $post_id Post ID.
*/
protected function mark_post_exists( $data, $post_id ) {
$exists_key = $data['guid'];
$this->exists['post'][ $exists_key ] = $post_id;
}
/**
* Prefill existing comment data.
*
* @see self::prefill_existing_posts() for justification of why this exists.
*/
protected function prefill_existing_comments() {
global $wpdb;
$posts = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_date FROM {$wpdb->comments}" );
foreach ( $posts as $item ) {
$exists_key = sha1( $item->comment_author . ':' . $item->comment_date );
$this->exists['comment'][ $exists_key ] = $item->comment_ID;
}
}
/**
* Does the comment exist?
*
* @param array $data Comment data to check against.
* @return int|bool Existing comment ID if it exists, false otherwise.
*/
protected function comment_exists( $data ) {
$exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
// Constant-time lookup if we prefilled
if ( $this->options['prefill_existing_comments'] ) {
return isset( $this->exists['comment'][ $exists_key ] ) ? $this->exists['comment'][ $exists_key ] : false;
}
// No prefilling, but might have already handled it
if ( isset( $this->exists['comment'][ $exists_key ] ) ) {
return $this->exists['comment'][ $exists_key ];
}
// Still nothing, try comment_exists, and cache it
$exists = comment_exists( $data['comment_author'], $data['comment_date'] );
$this->exists['comment'][ $exists_key ] = $exists;
return $exists;
}
/**
* Mark the comment as existing.
*
* @param array $data Comment data to mark as existing.
* @param int $comment_id Comment ID.
*/
protected function mark_comment_exists( $data, $comment_id ) {
$exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
$this->exists['comment'][ $exists_key ] = $comment_id;
}
/**
* Does the comment exist?
*
* @param array $data Comment data to check against.
* @return int|bool Existing comment ID if it exists, false otherwise.
*/
protected function link_exists( $data ) {
$exists_key = sha1( $data['link_name'] . ':' . $data['link_url'] . ':' . $data['link_rel'] );
// Constant-time lookup if we prefilled
if ( $this->options['prefill_existing_links'] ) {
return isset( $this->exists['link'][ $exists_key ] ) ? $this->exists['link'][ $exists_key ] : false;
}
// No prefilling, but might have already handled it
if ( isset( $this->exists['link'][ $exists_key ] ) ) {
return $this->exists['link'][ $exists_key ];
}
// // Still nothing, try comment_exists, and cache it
// $exists = comment_exists( $data['comment_author'], $data['comment_date'] );
// $this->exists['comment'][ $exists_key ] = $exists;
// return $exists;
return false;
}
/**
* Mark the comment as existing.
*
* @param array $data Comment data to mark as existing.
* @param int $comment_id Comment ID.
*/
protected function mark_link_exists( $data, $link_id ) {
$exists_key = sha1( $data['link_name'] . ':' . $data['link_url'] . ':' . $data['link_rel'] );
$this->exists['link'][ $exists_key ] = $link_id;
}
/**
* Prefill existing term data.
*
* @see self::prefill_existing_posts() for justification of why this exists.
*/
protected function prefill_existing_terms() {
global $wpdb;
$query = "SELECT t.term_id, tt.taxonomy, t.slug FROM {$wpdb->terms} AS t";
$query .= " JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id";
$terms = $wpdb->get_results( $query );
foreach ( $terms as $item ) {
$exists_key = sha1( $item->taxonomy . ':' . $item->slug );
$this->exists['term'][ $exists_key ] = $item->term_id;
}
}
/**
* Does the term exist?
*
* @param array $data Term data to check against.
* @return int|bool Existing term ID if it exists, false otherwise.
*/
protected function term_exists( $data ) {
$exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
// Constant-time lookup if we prefilled
if ( $this->options['prefill_existing_terms'] ) {
return isset( $this->exists['term'][ $exists_key ] ) ? $this->exists['term'][ $exists_key ] : false;
}
// No prefilling, but might have already handled it
if ( isset( $this->exists['term'][ $exists_key ] ) ) {
return $this->exists['term'][ $exists_key ];
}
// Still nothing, try WP's term_exists, and cache it
$exists = term_exists( $data['slug'], $data['taxonomy'] );
if ( is_array( $exists ) ) {
$exists = $exists['term_id'];
}
$this->exists['term'][ $exists_key ] = $exists;
return $exists;
}
/**
* Mark the term as existing.
*
* @param array $data Term data to mark as existing.
* @param int $term_id Term ID.
*/
protected function mark_term_exists( $data, $term_id ) {
$exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
$this->exists['term'][ $exists_key ] = $term_id;
}
/**
* Prefill existing link data.
*
* @see self::prefill_existing_posts() for justification of why this exists.
*/
protected function prefill_existing_links() {
global $wpdb;
$links = $wpdb->get_results( "SELECT link_id, link_name, link_url, link_rel FROM {$wpdb->links}" );
foreach ( $links as $item ) {
$exists_key = sha1( $item->link_name . ':' . $item->link_url . ':' . $item->link_rel );
$this->exists['link'][ $exists_key ] = $item->link_id;
}
}
}
PK ! @ ( languages/penci-soledad-demo-importer.monu [ $ , 8 g 9 Project-Id-Version:
PO-Revision-Date: 2023-09-07 21:11+0700
Last-Translator:
Language-Team:
Language: en
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Plural-Forms: nplurals=2; plural=(n != 1);
X-Generator: Poedit 3.2.2
X-Poedit-Basepath: .
X-Poedit-KeywordsList: _e;__;esc_html__;esc__
X-Poedit-SearchPath-0: .
PK ! En * * ( languages/penci-soledad-demo-importer.ponu [ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2023-09-07 21:11+0700\n"
"PO-Revision-Date: 2023-09-07 21:11+0700\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.2.2\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-KeywordsList: _e;__;esc_html__;esc__\n"
"X-Poedit-SearchPath-0: .\n"
#: includes/class-wxr-importer.php:142 includes/class-wxr-transform.php:99
msgid "Could not open the file for parsing"
msgstr ""
#: includes/class-wxr-importer.php:195 includes/class-wxr-importer.php:332
msgid "This does not appear to be a WXR file, missing WXR version number."
msgstr ""
#: includes/class-wxr-importer.php:199 includes/class-wxr-importer.php:336
#, php-format
msgid ""
"This WXR file (version %s) is newer than the importer (version %s) and may "
"not be supported. Please consider updating."
msgstr ""
#: includes/class-wxr-importer.php:664
msgid "Cannot import auto-draft posts"
msgstr ""
#: includes/class-wxr-importer.php:926
msgid "The file does not exist, please try again."
msgstr ""
#: includes/class-wxr-importer.php:955
msgid "Could not create WXR transformer."
msgstr ""
#: includes/class-wxr-importer.php:1013
msgid "Invalid author mapping"
msgstr ""
#: includes/class-wxr-importer.php:1074
msgid "Invalid file type"
msgstr ""
#: includes/class-wxr-importer.php:1280
#, php-format
msgid "Could not find the menu object for \"%s\" (post #%d)"
msgstr ""
#: includes/class-wxr-importer.php:1285
#, php-format
msgid ""
"Post %d was imported with object \"%d\" of type \"%s\", but could not be "
"found"
msgstr ""
#: includes/class-wxr-importer.php:1394
#, php-format
msgid "Failed to import \"%s\": Invalid post type %s"
msgstr ""
#: includes/class-wxr-importer.php:1404
#, php-format
msgid "%s \"%s\" already exists."
msgstr ""
#: includes/class-wxr-importer.php:1489
#, php-format
msgid "Skipping attachment \"%s\", fetching attachments disabled"
msgstr ""
#: includes/class-wxr-importer.php:1510
#, php-format
msgid "Failed to import \"%s\" (%s)"
msgstr ""
#: includes/class-wxr-importer.php:1542 includes/class-wxr-importer.php:1778
#, php-format
msgid "Imported \"%s\" (%s)"
msgstr ""
#: includes/class-wxr-importer.php:1547
#, php-format
msgid "Post %d remapped to %d"
msgstr ""
#: includes/class-wxr-importer.php:1673
#, php-format
msgid "Term \"%s\" (%s) already exists"
msgstr ""
#: includes/class-wxr-importer.php:1740
#, php-format
msgid "Failed to import %s %s"
msgstr ""
#: includes/class-wxr-importer.php:1783
#, php-format
msgid "Term %d remapped to %d"
msgstr ""
#: includes/class-wxr-importer.php:1875
#, php-format
msgid "Skipped importing user \"%s\""
msgstr ""
#: includes/class-wxr-importer.php:1927
#, php-format
msgid "Failed to import user \"%s\""
msgstr ""
#: includes/class-wxr-importer.php:1948
#, php-format
msgid "Imported user \"%s\""
msgstr ""
#: includes/class-wxr-importer.php:1952
#, php-format
msgid "User %d remapped to %d"
msgstr ""
#: includes/class-wxr-importer.php:2001
#, php-format
msgid "Link \"%s\" already exists."
msgstr ""
#: includes/class-wxr-importer.php:2063
#, php-format
msgid "Failed to import link \"%s\""
msgstr ""
#: includes/class-wxr-importer.php:2091
#, php-format
msgid "Imported link \"%s\""
msgstr ""
#: includes/class-wxr-importer.php:2095
#, php-format
msgid "Link %d remapped to %d"
msgstr ""
#: includes/class-wxr-importer.php:2272 penci-demo-importer.php:1010
#, php-format
msgid "Remote server returned %1$d %2$s for %3$s"
msgstr ""
#: includes/class-wxr-importer.php:2285
msgid "Remote file is incorrect size"
msgstr ""
#: includes/class-wxr-importer.php:2290 penci-demo-importer.php:1016
msgid "Zero size file downloaded"
msgstr ""
#: includes/class-wxr-importer.php:2296
#, php-format
msgid "Remote file is too large, limit is %s"
msgstr ""
#: includes/class-wxr-importer.php:2324
#, php-format
msgid "Running post-processing for post %d"
msgstr ""
#: includes/class-wxr-importer.php:2337
#, php-format
msgid "Could not find the post parent for \"%s\" (post #%d)"
msgstr ""
#: includes/class-wxr-importer.php:2342
#, php-format
msgid "Post %d was imported with parent %d, but could not be found"
msgstr ""
#: includes/class-wxr-importer.php:2356
#, php-format
msgid "Could not find the author for \"%s\" (post #%d)"
msgstr ""
#: includes/class-wxr-importer.php:2361
#, php-format
msgid "Post %d was imported with author \"%s\", but could not be found"
msgstr ""
#: includes/class-wxr-importer.php:2423
#, php-format
msgid "Post %d was marked for post-processing, but none was required."
msgstr ""
#: includes/class-wxr-importer.php:2434
#, php-format
msgid "Could not update \"%s\" (post #%d) with mapped data"
msgstr ""
#: includes/class-wxr-importer.php:2469
#, php-format
msgid "Could not find the parent for term #%d"
msgstr ""
#: includes/class-wxr-importer.php:2484
#, php-format
msgid "Cound not update term #%d with mapped data"
msgstr ""
#: includes/class-wxr-importer.php:2506
#, php-format
msgid "Could not find the comment parent for comment #%d"
msgstr ""
#: includes/class-wxr-importer.php:2510
#, php-format
msgid "Comment %d was imported with parent %d, but could not be found"
msgstr ""
#: includes/class-wxr-importer.php:2524
#, php-format
msgid "Could not find the author for comment #%d"
msgstr ""
#: includes/class-wxr-importer.php:2528
#, php-format
msgid "Comment %d was imported with author %d, but could not be found"
msgstr ""
#: includes/class-wxr-importer.php:2545
#, php-format
msgid "Could not update comment #%d with mapped data"
msgstr ""
#: includes/class-wxr-importer.php:2564
#, php-format
msgid "Running post-processing for link %d"
msgstr ""
#: includes/class-wxr-importer.php:2578
#, php-format
msgid "Could not find the author for \"%s\" (link #%d)"
msgstr ""
#: includes/class-wxr-importer.php:2583
#, php-format
msgid "Link %d was imported with author \"%s\", but could not be found"
msgstr ""
#: includes/class-wxr-importer.php:2593
#, php-format
msgid "Link %d was marked for post-processing, but none was required."
msgstr ""
#: includes/class-wxr-importer.php:2605
#, php-format
msgid "Could not update \"%s\" (link #%d) with mapped data"
msgstr ""
#: includes/class-wxr-transform.php:117
msgid "Could not open the file for writing"
msgstr ""
#: includes/customizer-importer.php:36
msgid ""
"The customizer import file is not in a correct format. Please make sure to "
"use the correct customizer import file."
msgstr ""
#: includes/customizer-importer.php:42
msgid ""
"The customizer import file is not suitable for current theme. You can only "
"import customizer settings for the same theme or a child theme."
msgstr ""
#: includes/parsers.php:42 includes/parsers.php:72 includes/parsers.php:80
msgid "There was an error when reading this WXR file"
msgstr ""
#: includes/parsers.php:43
msgid ""
"Details are shown above. The importer will now try again with a different "
"parser..."
msgstr ""
#: includes/parsers.php:84 includes/parsers.php:89 includes/parsers.php:279
#: includes/parsers.php:468
msgid ""
"This does not appear to be a WXR file, missing/invalid WXR version number"
msgstr ""
#: includes/widgets-importer.php:29
msgid "Import data could not be read. Please try a different file."
msgstr ""
#: includes/widgets-importer.php:66
msgid "Sidebar does not exist in theme (using Inactive)"
msgstr ""
#: includes/widgets-importer.php:88
msgid "Site does not support widget"
msgstr ""
#: includes/widgets-importer.php:114
msgid "Widget already exists"
msgstr ""
#: includes/widgets-importer.php:163
msgid "Imported"
msgstr ""
#: includes/widgets-importer.php:166
msgid "Imported to Inactive"
msgstr ""
#: includes/widgets-importer.php:173
msgid "No Title"
msgstr ""
#: penci-demo-importer.php:93 penci-demo-importer.php:94
msgid "Import Demo Data"
msgstr ""
#: penci-demo-importer.php:162
msgid "Are you sure want to do this?"
msgstr ""
#: penci-demo-importer.php:162 penci-demo-importer.php:169
msgid "Please try again"
msgstr ""
#: penci-demo-importer.php:169
msgid "This import is invalid."
msgstr ""
#: penci-demo-importer.php:251 penci-demo-importer.php:264
msgid "Dismiss this notice."
msgstr ""
#: penci-demo-importer.php:261
msgid "It usally take few minutes to finish. Please be patient."
msgstr ""
#: penci-demo-importer.php:269
msgid ""
"You've installed a demo before, click button below to Uninstall that demo "
"before import a new demo:"
msgstr ""
#: penci-demo-importer.php:282
msgid "Uninstall"
msgstr ""
#: penci-demo-importer.php:283
msgid ""
"Note that: All demo data you've imported ( posts/pages/"
"media... ) before will be removed when you uninstall demo."
msgstr ""
#: penci-demo-importer.php:290
msgid "Type to search the demo"
msgstr ""
#: penci-demo-importer.php:345
msgid "Import"
msgstr ""
#: penci-demo-importer.php:448 penci-demo-importer.php:919
#: penci-demo-importer.php:1027 penci-demo-importer.php:1061
#: penci-demo-importer.php:1085 penci-demo-importer.php:1128
#: penci-demo-importer.php:1234
msgid "Verifing failed"
msgstr ""
#: penci-demo-importer.php:697
msgid "Revolution Slider plugin is not installed"
msgstr ""
#: penci-demo-importer.php:704 penci-demo-importer.php:721
msgid "There is no slider to import"
msgstr ""
#: penci-demo-importer.php:905
msgid "Default sign-up form"
msgstr ""
#: penci-demo-importer.php:936
msgid "This demo dose not need"
msgstr ""
#: penci-demo-importer.php:941
msgid "File does not exists"
msgstr ""
#: penci-demo-importer.php:974
#, php-format
msgid "Could not write file %s"
msgstr ""
#: penci-demo-importer.php:1036
msgid "Finish setting up front page and blog page."
msgstr ""
#: penci-demo-importer.php:1096
msgid "Failed to generate image ID:"
msgstr ""
#: penci-demo-importer.php:1098
#, php-format
msgid "Generated image ID %s successfully"
msgstr ""
#: penci-demo-importer.php:1135 penci-demo-importer.php:1217
msgid "Failed to install plugin: "
msgstr ""
#: penci-demo-importer.php:1148
msgid "Failed to active plugin: "
msgstr ""
#: penci-demo-importer.php:1157
#, php-format
msgid "Plugin %s actived successfully."
msgstr ""
#: penci-demo-importer.php:1227
#, php-format
msgid "Plugin %s installed successfully."
msgstr ""
#: penci-demo-importer.php:1241
msgid "Failed to uninstall demo: "
msgstr ""
#: penci-demo-importer.php:1397
#, php-format
msgid ""
"The Penci Demo Importer plugin requires PHP 5.3.2+"
"strong> to run properly. Please contact your hosting company and ask them to "
"update the PHP version of your site to at least PHP 5.3.2. Your current "
"version of PHP: %s"
msgstr ""
PK ! E#n n
import.phpnu [ 'General Blog',
'adventure-blog' => 'Adventure Blog',
'animal-news' => 'Animal News',
'architecture' => 'Architecture',
'art-artist-blog' => 'Art Artist Blog',
'art-magazine' => 'Art Magazine',
'baby' => 'Baby',
'beauty' => 'Beauty',
'beauty-blog2' => 'Beauty Blog 2',
'bitcoin-news' => 'Bitcoin News',
'book' => 'Book',
'breaking-news' => 'Breaking News',
'business-magazine' => 'Business Magazine',
'business-news' => 'Business News',
'cars' => 'Cars',
'charity' => 'Charity',
'classic' => 'Classic',
'coffee-blog' => 'Coffee Blog',
'construction' => 'Construction',
'cosmetic-blog' => 'Cosmetic Blog',
'craft-diy-blog2' => 'Craft DIY Blog 2',
'craft-diy' => 'Craft Diy',
'dark-version' => 'Dark Version',
'designers-blog' => 'Designers Blog',
'education-news' => 'Education News',
'elegant-blog' => 'Elegant Blog',
'entertainment' => 'Entertainment',
'environment-charity-blog' => 'Environment Charity Blog',
'factory-news' => 'Factory News',
'fashion-blog2' => 'Fashion Blog 2',
'fashion-lifestyle' => 'Fashion Lifestyle',
'fashion-magazine' => 'Fashion Magazine',
'fashion-magazine2' => 'Fashion Magazine 2',
'fitness' => 'Fitness',
'fitness-blog' => 'Fitness Blog',
'food' => 'Food',
'food-blog2' => 'Food Blog 2',
'food-news' => 'Food News',
'gardening-blog' => 'Gardening Blog',
'gardening-magazine' => 'Gardening Magazine',
'game' => 'Game',
'game-blog' => 'Game Blog',
'hair-stylist-blog' => 'Hair Stylist Blog',
'hair-style-magazine' => 'Hair Style Magazine',
'health-medical' => 'Health Medical',
'healthy-clean-eating-blog' => 'Healthy Clean Eating Blog',
'hipster' => 'Hipster',
'interior-design-blog' => 'Interior Design Blog',
'interior-design-magazine' => 'Interior Design Magazine',
'lawyers-blog' => 'Lawyears Blog',
'magazine' => 'Magazine',
'men-health-magazine' => 'Men Health Magazine',
'minimal-simple-magazine' => 'Minimal Simple Magazine',
'movie' => 'Movie',
'old-fashioned-blog' => 'Old Fashioned Blog',
'pet' => 'Pet',
'pet-blog' => 'Pet Blog',
'photographer' => 'Photographer',
'photography-blog' => 'Photography Blog',
'photography-magazine' => 'Photography Magazine',
'radio-blog' => 'Radio Blog',
'seo-blog' => 'SEO Blog',
'science-news' => 'Science News',
'seo-magazine' => 'Seo Magazine',
'simple' => 'Simple',
'spa-blog' => 'Spa Blog',
'sport' => 'Sport',
'sport-2' => 'Sport 2',
'stylist-blog' => 'Stylist Blog',
'tech-news' => 'Tech News',
'technology' => 'Technology',
'technology-blog2' => 'Technology Blog 2',
'time-magazine' => 'Time Magazine',
'travel' => 'Travel',
'travel-blog2' => 'Travel Blog 2',
'travel-blog3' => 'Travel Blog 3',
'travel-guide-magazine' => 'Travel Guide Magazine',
'travel-magazine' => 'Travel Magazine',
'vegan-magazine' => 'Vegan Magazine',
'video' => 'Video',
'video-dark' => 'Video Dark',
'videos-blog' => 'Videos Blog',
'vintage-blog' => 'Vintage Blog',
'viral' => 'Viral',
'wedding' => 'Wedding',
'music' => 'Music',
'beauty-blog3' => 'Beauty Blog 3',
'book-magazine' => 'Book Magazine',
'car-blog' => 'Car Blog',
'coding-blog' => 'Coding Blog',
'colorful-magazine' => 'Clorfull Magazine',
'dentist-blog' => 'Dentist Blog',
'design-magazine' => 'Design Magazine',
'fashion-blog3' => 'Fashion Blog 3',
'freelancer-blog' => 'Freelancer Blog',
'game-magazine' => 'Game Magazine',
'handmade-blog' => 'Handmade Blog',
'ios-tips-mag' => 'IOS Tips Magazine',
'motorcycle-blog' => 'Motorcycle Blog',
'musicband-blog' => 'Musicband Blog',
'painter-blog' => 'Painter Blog',
'software-tips-blog' => 'Software Tips Blog',
'transport-blog' => 'Transport Blog',
'vertical-nav' => 'Vertical Nav',
'vertical-nav-dark' => 'Vertical Nav Dark',
'video-blog2' => 'Video Blog 2',
'01-lifestyle-news-2sb' => [ 'Lifestyle News Two Sidebars', [ 'elementor' ] ],
'02-travel-news-2sb' => [ 'Travel News Two Sidebars', [ 'elementor' ] ],
'03-fashion-news-2sb' => [ 'Fashion News Two Sidebars', [ 'elementor' ] ],
'04-food-news-2sb' => [ 'Food News Two Sidebars', [ 'elementor' ] ],
'05-game-news-2sb' => [ 'Game News Two Sidebars', [ 'elementor' ] ],
'06-fitness-news-2sb' => [ 'Fitness News Two Sidebars', [ 'elementor' ] ],
'07-beauty-cosmetics-news-2sb' => [ 'Beauty & Cosmetics News', [ 'elementor' ] ],
'08-travel-agency-mul' => [ 'Travel Agency', [ 'elementor' ] ],
'09-spa-wellness-mul' => [ 'Spa & Wellness Center ', [ 'elementor' ] ],
'10-business-mul' => [ 'Business', [ 'elementor' ] ],
'11-restaurant-mul' => [ 'Restaurant', [ 'elementor' ] ],
'12-fitness-center-mul' => [ 'Fitness Center', [ 'elementor' ] ],
'13-barber-shop-mul' => [ 'Barber Shop', [ 'elementor' ] ],
'14-ceramics-art-mul' => [ 'Ceramics Art', [ 'elementor' ] ],
'15-fashion-stylist-mul' => [ 'Fashion Stylist', [ 'elementor' ] ],
'16-construction-business-mul' => [ 'Construction Business', [ 'elementor' ] ],
'17-coffee-shop-mul' => [ 'Coffee Shop', [ 'elementor' ] ],
'18-web-studio-mul' => [ 'Web Studio', [ 'elementor' ] ],
'19-wedding-studio-mul' => [ 'Wedding Studio', [ 'elementor' ] ],
'20-tailor-shop-mul' => [ 'Tailor Shop ', [ 'elementor' ] ],
'21-catering-business-mul' => [ 'Catering Business', [ 'elementor' ] ],
'22-yoga-studio-mul' => [ 'Yoga Studio', [ 'elementor' ] ],
'23-bakery-mul' => [ 'Bakery', [ 'elementor' ] ],
'24-tattoo-studio-mul' => [ 'Tattoo Studio', [ 'elementor' ] ],
'25-run-club-mutl' => [ 'Run Club', [ 'elementor' ] ],
'26-pet-clinic-mul' => [ 'Pet Clinic', [ 'elementor' ] ],
'27-honey-business-mul' => [ 'Honey Business', [ 'elementor' ] ],
'28-makeup-artist-mul' => [ 'Makeup Artist', [ 'elementor' ] ],
'29-insurance-mul' => [ 'Insurance', [ 'elementor' ] ],
'30-pizza-shop-mul' => [ 'Pizza Shop', [ 'elementor' ] ],
'31-law-firm-mul' => [ 'Law Firm', [ 'elementor' ] ],
'32-nail-salon-mul' => [ 'Nail Salon', [ 'elementor' ] ],
'33-zoo-mul' => [ 'Zoo', [ 'elementor' ] ],
'34-finance-consulting-mul' => [ 'Finance Consulting', [ 'elementor' ] ],
'35-hosting-provider-mul' => [ 'Hosting Provider', [ 'elementor' ] ],
'36-wedding-planner-mul' => [ 'Wedding Planner', [ 'elementor' ] ],
'37-garden-design-mul' => [ 'Garden Design', [ 'elementor' ] ],
'38-car-wash-business-mul' => [ 'Car Wash Business', [ 'elementor' ] ],
'39-call-center-mul' => [ 'Call Center', [ 'elementor' ] ],
'40-chocolate-business-mul' => [ 'Chocolate Business', [ 'elementor' ] ],
'41-video-production-mul' => [ 'Video Production', [ 'elementor' ] ],
'42-interior-design-mul' => [ 'Interior Design', [ 'elementor' ] ],
'43-beauty-salon-mul' => [ 'Beauty Salon', [ 'elementor' ] ],
'44-herbal-tea-mul' => [ 'Herbal Tea', [ 'elementor' ] ],
'45-logistics-business-mul' => [ 'Logistics Business', [ 'elementor' ] ],
'46-luxury-resort-mul' => [ 'Luxury Resort', [ 'elementor' ] ],
'47-kindergarten-mul' => [ 'Kindergarten', [ 'elementor' ] ],
'48-dairy-farm-mul' => [ 'Dairy Farm', [ 'elementor' ] ],
'49-burger-shop-mul' => [ 'Burger Shop', [ 'elementor' ] ],
'50-florist-mul' => [ 'Florist', [ 'elementor' ] ],
'51-clean-energy-mul' => [ 'Clean Energy', [ 'elementor' ] ],
'52-delivery-service-mul' => [ 'Delivery Service', [ 'elementor' ] ],
'53-wine-company-mul' => [ 'Wine Company', [ 'elementor' ] ],
'54-cocktail-bar-mul' => [ 'Cocktail Bar', [ 'elementor' ] ],
'55-hospital-mul' => [ 'Hospital', [ 'elementor' ] ],
'56-dental-clinic-mul' => [ 'Dental Clinic', [ 'elementor' ] ],
'57-software-development' => [ 'Software Development', [ 'elementor' ] ],
'58-craft-beer-business-mul' => [ 'Craft Beer Business', [ 'elementor' ] ],
'59-cooking-class-mul' => [ 'Cooking Class', [ 'elementor' ] ],
'60-moving-service-mul' => [ 'Moving Service', [ 'elementor' ] ],
'61-steak-house-mul' => [ 'Steak House', [ 'elementor' ] ],
'62-golf-club-mul' => [ 'Golf Club', [ 'elementor' ] ],
'63-ice-cream-mul' => [ 'Ice Cream', [ 'elementor' ] ],
'64-personal-trainer-mul' => [ 'Personal Trainer', [ 'elementor' ] ],
'65-real-estate' => [ 'Real Estate', [ 'elementor' ] ],
'66-dance-studio-mul' => [ 'Dance School', [ 'elementor' ] ],
'67-fisher-business-mul' => [ 'Fisher Business', [ 'elementor' ] ],
'68-ads-agency-mul' => [ 'Ads Agency', [ 'elementor' ] ],
'69-freelance-writer-mul' => [ 'Freelance Writer', [ 'elementor' ] ],
'70-human-resources-mul' => [ 'Human Resources', [ 'elementor' ] ],
'71-health-coach-mul' => [ 'Health Coach', [ 'elementor' ] ],
'72-cleaning-service-mul' => [ 'Cleaning Service', [ 'elementor' ] ],
'73-game-demo-mul' => [ 'Game Demo', [ 'elementor' ] ],
'74-production-house-mul' => [ 'Production House', [ 'elementor' ] ],
'75-headphones-company-mul' => [ 'Headphones Company', [ 'elementor' ] ],
'76-fashion-designer-mul' => [ 'Fashion Designer', [ 'elementor' ] ],
'77-seo-company-mul' => [ 'SEO Company', [ 'elementor' ] ],
'78-music-band-mul' => [ 'Music Band', [ 'elementor' ] ],
'79-taxi-company-mul' => [ 'Taxi Company', [ 'elementor' ] ],
'80-fitness-band-mul' => [ 'Fitness Band', [ 'elementor' ] ],
'81-psychologist-mul' => [ 'Psychologist', [ 'elementor' ] ],
'82-watch-maker-mul' => [ 'Watch Maker', [ 'elementor' ] ],
'83-smarthome-system-mul' => [ 'Smarthome System', [ 'elementor' ] ],
'84-perfume-business-mul' => [ 'Perfume Business', [ 'elementor' ] ],
'85-digital-startup-mul' => [ 'Digital Startup', [ 'elementor' ] ],
'86-wedding-catering-mul' => [ 'Wedding Catering', [ 'elementor' ] ],
'87-food-tour-travel-mul' => [ 'Food Tour Travel', [ 'elementor' ] ],
'88-market-intelligence-firm-mul' => [ 'Market Intelligence Firm', [ 'elementor' ] ],
'89-medical-consulting-business-mul' => [ 'Medical Consulting Business', [ 'elementor' ] ],
'90-food-truck-mul' => [ 'Food Truck', [ 'elementor' ] ],
'91-swimming-class-mul' => [ 'Swimming Class', [ 'elementor' ] ],
'92-loan-business-mul' => [ 'Loan Business', [ 'elementor' ] ],
'93-salad-club-business-mul' => [ 'Salad Club Business', [ 'elementor' ] ],
'94-astrology-club-mul' => [ 'Astrology Club', [ 'elementor' ] ],
'95-mechanics-business-mul' => [ 'Mechanics Shop', [ 'elementor' ] ],
'96-it-service-mul' => [ 'IT Service Business', [ 'elementor' ] ],
'97-seafood-restaurant-mul' => [ 'Seafood Restaurant', [ 'elementor' ] ],
'98-city-delivery-service-mul' => [ 'City Delivery Service', [ 'elementor' ] ],
'99-plastic-surgery-business-mul' => [ 'Plastic Surgery Business', [ 'elementor' ] ],
'100-mobile-payment-mul' => [ 'Mobile Payment', [ 'elementor' ] ],
'101-bubble-tea-shop-mul' => [ 'Bubble Tea Shop', [ 'elementor' ] ],
'102-food-photography-studio-mul' => [ 'Food Photography Studio', [ 'elementor' ] ],
'103-copywriters-business-mul' => [ 'Copywriters Business', [ 'elementor' ] ],
'104-italian-restaurant-mul' => [ 'Italian Restaurant', [ 'elementor' ] ],
'105-car-racing-mul' => [ 'Car Racing', [ 'elementor' ] ],
'106-fashion-personal-blog' => [ 'Fashion Personal Blog', [ 'elementor' ] ],
'107-massage-mul' => [ 'Massage Multipurpose', [ 'elementor' ] ],
'108-chinese-restaurant-mul' => [ 'Chinese Restaurant', [ 'elementor' ] ],
'109-online-food-delivery-mul' => [ 'Online Food Delivery', [ 'elementor' ] ],
'110-general-magazine' => [ 'General Magazine', [ 'elementor' ] ],
'111-general-shop' => [ 'General Shop', [ 'elementor', 'woocommerce' ] ],
'112-women-fashion-shop' => [ 'Women Fashion Shop', [ 'elementor', 'woocommerce' ] ],
'113-electronics-store' => [ 'Electronics Store', [ 'elementor', 'woocommerce' ] ],
'114-men-fashion-shop' => [ 'Men Fashion Shop', [ 'elementor', 'woocommerce' ] ],
'115-personal-blog-and-shop' => [ 'Personal Blog & Shop', [ 'elementor', 'woocommerce' ] ],
'116-watch-store' => [ 'Watch Store', [ 'elementor', 'woocommerce' ] ],
'117-glasses-store' => [ 'Glasses Store', [ 'elementor', 'woocommerce' ] ],
'118-electronic-accessories-store' => [ 'Electronic Accessories Store', [ 'elementor', 'woocommerce' ] ],
'119-fashion-accessories-store' => [ 'Fashion Accessories Store', [ 'elementor', 'woocommerce' ] ],
'120-minimal-shop' => [ 'Minimal Shop', [ 'elementor', 'woocommerce' ] ],
'127-personal-skincare-blog-and-shop' => [ 'Skincare Blog & Shop', [ 'elementor', 'woocommerce' ] ],
'128-personal-food-blog' => [ 'Personal Food Blog', [ 'elementor' ] ],
'129-home-decor-design-magazine' => [ 'Home Decor Design Magazine', [ 'elementor' ] ],
'130-times-magazine' => [ 'Times Magazine', [ 'elementor' ] ],
'131-modern-news-magazine' => [ 'Modern News', [ 'elementor' ] ],
'132-daily-news' => [ 'Daily News', [ 'elementor' ] ],
'134-graph-newspaper' => [ 'Graph Newspaper', [ 'elementor' ] ],
'135-citylight-magazine' => [ 'Citylight Magazine', [ 'elementor' ] ],
'136-central-news' => [ 'Central News', [ 'elementor' ] ],
'137-news-station' => [ 'News Station', [ 'elementor' ] ],
'138-new-modern-tech' => [ 'New Modern Tech', [ 'elementor' ] ],
'139-pop-news' => [ 'Pop News', [ 'elementor' ] ],
'140-elegance-news' => [ 'Elegance News', [ 'elementor' ] ],
'141-world-wide-news' => [ 'World Wide News', [ 'elementor' ] ],
'142-live-news' => [ 'Live News', [ 'elementor' ] ],
'143-news-hub' => [ 'News Hub', [ 'elementor' ] ],
'144-24h-news-magazine' => [ '24h News Magazine', [ 'elementor' ] ],
'145-world-express-news' => [ 'World Express News', [ 'elementor' ] ],
'146-kitchen-shop-and-blog' => [ 'Kitchen Blog & Shop', [ 'elementor', 'woocommerce' ] ],
'147-photography-blog-and-shop' => [ 'Photography Blog & Shop', [ 'elementor', 'woocommerce' ] ],
'148-coffee-blog-and-shop' => [ 'Coffee Blog & Shop', [ 'elementor', 'woocommerce' ] ],
'149-crypto-nft-personal-blog' => [ 'Crypto NFT Blog', [ 'elementor' ] ],
'150-art-personal-blog' => [ 'Art Personal Blog', [ 'elementor' ] ],
'151-zero-waste-personal' => [ 'Zero Waste Personal', [ 'elementor' ] ],
'152-interior-design-personal' => [ 'Interior Design Personal', [ 'elementor' ] ],
'153-pet-care-personal' => [ 'Pet Care', [ 'elementor' ] ],
'154-general-magazine-rtl' => [ 'General Magazine RTL', [ 'elementor' ] ],
'155-24h-news-magazine-rtl' => [ '24h News Magazine RTL', [ 'elementor' ] ],
'156-travel-magazine2' => [ 'Travel Magazine 2', [ 'elementor' ] ],
'157-game-magazine2' => [ 'Game Magazine 2', [ 'elementor' ] ],
);
asort( $demo_listing );
$new_demo_listing = penci_soledad_get_list_new_demo();
$demo_configs = array();
foreach ( $demo_listing as $key => $label ) {
if ( in_array( $key, $new_demo_listing ) ) {
$demo_configs[] = array(
'id_demo' => $key,
'name' => is_array( $label ) ? $label[0] : $label,
'content' => 'https://soledad-new-data.s3.amazonaws.com/' . $key . '/demo-content.xml',
'widgets' => 'https://soledad-new-data.s3.amazonaws.com/' . $key . '/widgets.wie',
'preview' => 'https://soledad-new-data.s3.amazonaws.com/' . $key . '/preview.jpg',
'customizer' => 'https://soledad-new-data.s3.amazonaws.com/' . $key . '/customizer.dat',
'menus' => array( 'main-menu' => 'menu', 'topbar-menu' => 'top-bar-menu' ),
'plugins' => is_array( $label ) ? $label[1] : false,
'pages' => array(
'front_page' => 'Soledad_Home',
'blog' => '',
'shop' => 'Shop',
'cart' => 'Cart',
'checkout' => 'Checkout',
'my_account' => 'My Account',
'portfolio' => 'Masonry 3 Columns',
)
);
continue;
}
$config = array(
'id_demo' => $key,
'name' => is_array( $label ) ? $label[0] : $label,
'content' => 'https://soledad-datas.s3.amazonaws.com/' . $key . '/demo-content.xml',
'widgets' => 'https://soledad-datas.s3.amazonaws.com/' . $key . '/widgets.wie',
'preview' => 'https://soledad-datas.s3.amazonaws.com/' . $key . '/preview.jpg',
'customizer' => 'https://soledad-datas.s3.amazonaws.com/' . $key . '/customizer.dat',
'menus' => array( 'main-menu' => 'menu-1' ),
'plugins' => is_array( $label ) ? $label[1] : false,
);
if ( $key == 'default' ) {
$config['pages'] = array(
'front_page' => '',
'blog' => '',
'shop' => 'Shop',
'cart' => 'Cart',
'checkout' => 'Checkout',
'my_account' => 'My Account',
'portfolio' => 'Masonry 3 Columns',
);
$config['options'] = array(
'shop_catalog_image_size' => array(
'width' => 600,
'height' => 732,
'crop' => 1,
),
'shop_single_image_size' => array(
'width' => 600,
'height' => 732,
'crop' => 1,
),
'shop_thumbnail_image_size' => array(
'width' => 150,
'height' => 183,
'crop' => 1,
),
);
} else {
$config['pages'] = array(
'front_page' => '',
'blog' => '',
);
$config['options'] = array();
}
// Add menu
if ( $key == 'magazine' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'sport' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'video' ) {
$config['menus']['topbar-menu'] = 'topbar-menu';
} elseif ( $key == 'game' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'music' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'health-medical' ) {
$config['menus']['topbar-menu'] = 'topbar-menu';
} elseif ( $key == 'cars' ) {
$config['menus']['footer-menu'] = 'footer-menu';
} elseif ( $key == 'wedding' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'simple' ) {
$config['menus']['topbar-menu'] = 'topbar-menu';
} elseif ( $key == 'tech-news' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'business-news' ) {
$config['menus']['footer-menu'] = 'footer-menu';
} elseif ( $key == 'fashion-magazine' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
} elseif ( $key == 'charity' ) {
$config['menus']['topbar-menu'] = 'top-bar-menu';
}
$demo_configs[] = $config;
}
return $demo_configs;
}
if ( ! function_exists( 'penci_soledad_get_list_new_demo' ) ):
function penci_soledad_get_list_new_demo() {
$new_demo_listing = array(
'01-lifestyle-news-2sb',
'02-travel-news-2sb',
'03-fashion-news-2sb',
'04-food-news-2sb',
'05-game-news-2sb',
'06-fitness-news-2sb',
'07-beauty-cosmetics-news-2sb',
'08-travel-agency-mul',
'09-spa-wellness-mul',
'10-business-mul',
'11-restaurant-mul',
'12-fitness-center-mul',
'13-barber-shop-mul',
'14-ceramics-art-mul',
'15-fashion-stylist-mul',
'16-construction-business-mul',
'17-coffee-shop-mul',
'18-web-studio-mul',
'19-wedding-studio-mul',
'20-tailor-shop-mul',
'21-catering-business-mul',
'22-yoga-studio-mul',
'23-bakery-mul',
'24-tattoo-studio-mul',
'25-run-club-mutl',
'26-pet-clinic-mul',
'27-honey-business-mul',
'28-makeup-artist-mul',
'29-insurance-mul',
'30-pizza-shop-mul',
'31-law-firm-mul',
'32-nail-salon-mul',
'33-zoo-mul',
'34-finance-consulting-mul',
'35-hosting-provider-mul',
'36-wedding-planner-mul',
'37-garden-design-mul',
'38-car-wash-business-mul',
'39-call-center-mul',
'40-chocolate-business-mul',
'41-video-production-mul',
'42-interior-design-mul',
'43-beauty-salon-mul',
'44-herbal-tea-mul',
'45-logistics-business-mul',
'46-luxury-resort-mul',
'47-kindergarten-mul',
'48-dairy-farm-mul',
'49-burger-shop-mul',
'50-florist-mul',
'51-clean-energy-mul',
'52-delivery-service-mul',
'53-wine-company-mul',
'54-cocktail-bar-mul',
'55-hospital-mul',
'56-dental-clinic-mul',
'57-software-development',
'58-craft-beer-business-mul',
'59-cooking-class-mul',
'60-moving-service-mul',
'61-steak-house-mul',
'62-golf-club-mul',
'63-ice-cream-mul',
'64-personal-trainer-mul',
'65-real-estate',
'66-dance-studio-mul',
'67-fisher-business-mul',
'68-ads-agency-mul',
'69-freelance-writer-mul',
'70-human-resources-mul',
'71-health-coach-mul',
'72-cleaning-service-mul',
'73-game-demo-mul',
'74-production-house-mul',
'75-headphones-company-mul',
'76-fashion-designer-mul',
'77-seo-company-mul',
'78-music-band-mul',
'79-taxi-company-mul',
'80-fitness-band-mul',
'81-psychologist-mul',
'82-watch-maker-mul',
'83-smarthome-system-mul',
'84-perfume-business-mul',
'85-digital-startup-mul',
'86-wedding-catering-mul',
'87-food-tour-travel-mul',
'88-market-intelligence-firm-mul',
'89-medical-consulting-business-mul',
'90-food-truck-mul',
'91-swimming-class-mul',
'92-loan-business-mul',
'93-salad-club-business-mul',
'94-astrology-club-mul',
'95-mechanics-business-mul',
'96-it-service-mul',
'97-seafood-restaurant-mul',
'98-city-delivery-service-mul',
'99-plastic-surgery-business-mul',
'100-mobile-payment-mul',
'101-bubble-tea-shop-mul',
'102-food-photography-studio-mul',
'103-copywriters-business-mul',
'104-italian-restaurant-mul',
'105-car-racing-mul',
'106-fashion-personal-blog',
'107-massage-mul',
'108-chinese-restaurant-mul',
'109-online-food-delivery-mul',
'110-general-magazine',
'111-general-shop',
'112-women-fashion-shop',
'113-electronics-store',
'114-men-fashion-shop',
'115-personal-blog-and-shop',
'116-watch-store',
'117-glasses-store',
'118-electronic-accessories-store',
'119-fashion-accessories-store',
'120-minimal-shop',
'127-personal-skincare-blog-and-shop',
'128-personal-food-blog',
'129-home-decor-design-magazine',
'130-times-magazine',
'131-modern-news-magazine',
'132-daily-news',
'134-graph-newspaper',
'135-citylight-magazine',
'136-central-news',
'137-news-station',
'138-new-modern-tech',
'139-pop-news',
'140-elegance-news',
'141-world-wide-news',
'142-live-news',
'143-news-hub',
'144-24h-news-magazine',
'145-world-express-news',
'146-kitchen-shop-and-blog',
'147-photography-blog-and-shop',
'148-coffee-blog-and-shop',
'149-crypto-nft-personal-blog',
'150-art-personal-blog',
'151-zero-waste-personal',
'152-interior-design-personal',
'153-pet-care-personal',
'154-general-magazine-rtl',
'155-24h-news-magazine-rtl',
'156-travel-magazine2',
'157-game-magazine2',
);
return $new_demo_listing;
}
endif;
add_filter( 'penci_soledad_plugins_required', 'penci_soledad_plugins_required_register' );
if ( ! function_exists( 'penci_soledad_plugins_required_register' ) ) {
function penci_soledad_plugins_required_register() {
return array(
'vafpress-post-formats-ui-develop',
'penci-shortcodes',
'penci-soledad-slider',
'penci-portfolio',
'penci-recipe',
'penci-review',
'penci-soledad-demo-importer',
'instagram-slider-widget',
'oauth-twitter-feed-for-developers',
'contact-form-7',
'mailchimp-for-wp',
);
}
}
add_action( 'penci_soledaddi_after_setup_pages', 'penci_soledad_addons_import_order_tracking' );
/**
* Update more page options
*
* @param $pages
*/
function penci_soledad_addons_import_order_tracking( $pages ) {
if ( isset( $pages['order_tracking'] ) ) {
$order = penci_get_page_by_title( $pages['order_tracking'] );
if ( $order ) {
update_option( 'penci_soledad_order_tracking_page_id', $order->ID );
}
}
if ( isset( $pages['portfolio'] ) ) {
$portfolio = penci_get_page_by_title( $pages['portfolio'] );
if ( $portfolio ) {
update_option( 'penci_soledad_portfolio_page_id', $portfolio->ID );
}
}
}
add_action( 'penci_soledaddi_before_import_content', 'penci_soledad_addons_import_product_attributes' );
/**
* Prepare product attributes before import demo content
*
* @param $file
*/
function penci_soledad_addons_import_product_attributes( $file ) {
global $wpdb;
if ( ! class_exists( 'WXR_Parser' ) ) {
require_once WP_PLUGIN_DIR . '/penci-soledad-demo-importer/includes/parsers.php';
}
if ( ! function_exists( 'wc_sanitize_taxonomy_name' ) || ! function_exists( 'wc_get_attribute_taxonomies' ) ) {
return;
}
$parser = new WXR_Parser();
$import_data = $parser->parse( $file );
if ( isset( $import_data['posts'] ) ) {
$posts = $import_data['posts'];
if ( $posts && sizeof( $posts ) > 0 ) {
foreach ( $posts as $post ) {
if ( 'product' === $post['post_type'] ) {
if ( ! empty( $post['terms'] ) ) {
foreach ( $post['terms'] as $term ) {
if ( strstr( $term['domain'], 'pa_' ) ) {
if ( ! taxonomy_exists( $term['domain'] ) ) {
$attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $term['domain'] ) );
// Create the taxonomy
if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies() ) ) {
$attribute = array(
'attribute_label' => $attribute_name,
'attribute_name' => $attribute_name,
'attribute_type' => 'select',
'attribute_orderby' => 'menu_order',
'attribute_public' => 0
);
$wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
delete_transient( 'wc_attribute_taxonomies' );
}
// Register the taxonomy now so that the import works!
register_taxonomy( $term['domain'], apply_filters( 'woocommerce_taxonomy_objects_' . $term['domain'], array( 'product' ) ), apply_filters( 'woocommerce_taxonomy_args_' . $term['domain'], array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
) ) );
}
}
}
}
}
}
}
}
}
PK ! sV V penci-demo-importer.phpnu [ data = apply_filters( 'penci_soledad_demo_packages', array() );
$this->plugins_required = apply_filters( 'penci_soledad_plugins_required', array() );
add_action( 'admin_menu', array( $this, 'menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
add_filter(
'http_request_args',
function ( $r, $url ) {
$r['headers']['Accept-Encoding'] = 'identity';
return $r;
},
10,
2
);
add_action(
'plugins_loaded',
function () {
load_plugin_textdomain( 'penci-soledad-demo-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
);
add_action( 'wp_ajax_penci_soledad_install_plugin', array( $this, 'ajax_install_plugin' ) );
add_action( 'wp_ajax_penci_soledad_download_file', array( $this, 'ajax_download_file' ) );
add_action( 'wp_ajax_penci_soledad_import', array( $this, 'ajax_import' ) );
add_action( 'wp_ajax_penci_soledad_config_theme', array( $this, 'ajax_config_theme' ) );
add_action( 'wp_ajax_penci_soledad_get_images', array( $this, 'ajax_get_images' ) );
add_action( 'wp_ajax_penci_soledad_generate_image', array( $this, 'ajax_generate_image' ) );
add_action( 'wp_ajax_penci_soledad_unintall_demo', array( $this, 'ajax_unintall_demo' ) );
if ( class_exists( 'TGM_Plugin_Activation' ) ) {
do_action( 'tgmpa_register' );
$this->tgm_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
}
}
/**
* Add new menu under Appearance menu
*/
public function menu() {
if ( empty( $this->data ) ) {
return;
}
add_theme_page(
esc_html__( 'Import Demo Data', 'penci_soledad' ),
esc_html__( 'Import Demo Data', 'penci_soledad' ),
'edit_theme_options',
'import-demo-content',
array(
$this,
'page',
)
);
}
/**
* Load scripts
*/
public function scripts( $hook ) {
if ( 'appearance_page_import-demo-content' != $hook ) {
return;
}
wp_enqueue_style( 'penci-soledad-import', plugins_url( 'assets/css/penci-import.css', __FILE__ ) );
wp_enqueue_script( 'penci-soledad-import', plugins_url( 'assets/js/penci-import.js', __FILE__ ), array( 'jquery' ), '3.6', true );
wp_enqueue_script( 'penci-soledad-demo-search', plugins_url( 'assets/js/penci-demo-search.js', __FILE__ ), array( 'jquery' ), '3.6', true );
wp_localize_script(
'penci-soledad-import',
'PenciObject',
array(
'plugins_required' => $this->plugins_required,
)
);
}
/**
* Admin page for importing demo content
*/
public function page() {
if ( isset( $_GET['action'] ) && isset( $_GET['step'] ) ) {
$this->uninstall_demo_page();
} elseif ( isset( $_GET['step'] ) ) {
$this->import_demo_page();
} else {
$this->select_demo_page();
}
}
private function uninstall_demo_page() {
?>
1
If your website is new and doesn't have any old posts or pages, you can do a full import by
selecting "Import Demo Style" and "Import Demo Content" as
normal.
However, if your website is already established and has existing posts or pages, it is
recommended to only import the demo style and leave the "Import Demo Content"
option unchecked. This will prevent any potential conflicts with your existing content and
ensure that the demo style is imported properly.
2
After importing a demo, if you encounter any issues with the menu, you can follow these steps to
fix it:
Go to "Appearance" > "Menus"
Create a new menu or select an existing one to use as your main navigation
Scroll down to the bottom of the page and check the box next to "Primary Menu"
Save your changes and refresh your website to see if the menu is now working properly.
3
If you have already finished importing the demo and no longer need to use the "Penci Soledad
Demo Importer" plugin, you can deactivate it. This will not affect any functionality of your
website as the plugin is only used for demo import purposes. To deactivate the plugin, simply go
to "Plugins" > "Installed Plugins" and click on the "Deactivate" button next to "Penci Soledad
Demo Importer".
Note that: All demo data you\'ve imported ( posts/pages/media... ) before will be removed when you uninstall demo.', 'soledad' ); ?>