: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* WordPress eXtended RSS file parser implementations
* WXR Parser that makes use of the XML Parser PHP extension.
'wp:category_description',
'wp:author_display_name',
public $wp_sub_tags = array(
'wp:comment_author_email',
function parse( $file ) {
$this->wxr_version = false;
$this->in_sub_tag = false;
$this->authors = array();
$this->category = 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 ) );
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' ) );
'authors' => $this->authors,
'categories' => $this->category,
'base_url' => $this->base_url,
'base_blog_url' => $this->base_blog_url,
'version' => $this->wxr_version,
function tag_open( $parse, $tag, $attr ) {
if ( in_array( $tag, $this->wp_tags, true ) ) {
$this->in_tag = substr( $tag, 3 );
if ( in_array( $tag, $this->wp_sub_tags, true ) ) {
$this->in_sub_tag = substr( $tag, 3 );
if ( isset( $attr['domain'], $attr['nicename'] ) ) {
if ( false === $this->sub_data ) {
$this->sub_data = array();
$this->sub_data['domain'] = $attr['domain'];
$this->sub_data['slug'] = $attr['nicename'];
$this->in_tag = 'post_title';
$this->in_tag = 'post_author';
$this->in_tag = 'post_content';
$this->in_tag = 'post_excerpt';
$this->in_sub_tag = 'key';
$this->in_sub_tag = 'value';
function cdata( $parser, $cdata ) {
if ( ! trim( $cdata ) ) {
if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
$this->cdata .= trim( $cdata );
function tag_close( $parser, $tag ) {
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['commentmeta'][] = array(
'key' => $this->sub_data['key'],
'value' => $this->sub_data['value'],
if ( ! empty( $this->sub_data ) ) {
$this->sub_data['name'] = $this->cdata;
$this->data['terms'][] = $this->sub_data;
if ( ! empty( $this->sub_data ) ) {
$this->data['postmeta'][] = $this->sub_data;
$this->posts[] = $this->data;
array_push( $this->$n, $this->data );
if ( ! empty( $this->sub_data ) ) {
$this->data['termmeta'][] = $this->sub_data;
if ( ! empty( $this->data['author_login'] ) ) {
$this->authors[ $this->data['author_login'] ] = $this->data;
$this->base_url = $this->cdata;
if ( ! isset( $this->base_blog_url ) ) {
$this->base_blog_url = $this->cdata;
$this->base_blog_url = $this->cdata;
$this->wxr_version = $this->cdata;
if ( $this->in_sub_tag ) {
if ( false === $this->sub_data ) {
$this->sub_data = array();
$this->sub_data[ $this->in_sub_tag ] = ! empty( $this->cdata ) ? $this->cdata : '';
$this->in_sub_tag = false;
} elseif ( $this->in_tag ) {
if ( false === $this->data ) {
$this->data[ $this->in_tag ] = ! empty( $this->cdata ) ? $this->cdata : '';