Make WordPress Core

Opened 2 months ago

Closed 2 months ago

#64351 closed defect (bug) (duplicate)

I found an issue in WordPress version 6.9 when exporting All Content.

Reported by: mamunur105's profile mamunur105 Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.9
Component: Export Keywords:
Focuses: Cc:

Description

The export process throws an error related to the wxr_cdata() function.

The problem happens because the function is called with values that are not always strings — sometimes a meta value is null or another type. When that happens, the function breaks during export.

[

04-Dec-2025 07:13:56 UTC] PHP Fatal error:  Uncaught TypeError: wp_is_valid_utf8(): Argument #1 ($bytes) must be of type string, null given, called in /Users/radiustheme07/Local Sites/shopbuilder/app/public/wp-admin/includes/export.php on line 246 and defined in /Users/radiustheme07/Local Sites/shopbuilder/app/public/wp-includes/utf8.php:39
Stack trace:
#0 /Users/radiustheme07/Local Sites/shopbuilder/app/public/wp-admin/includes/export.php(246): wp_is_valid_utf8(NULL)
#1 /Users/radiustheme07/Local Sites/shopbuilder/app/public/wp-admin/includes/export.php(682): wxr_cdata(NULL)
#2 /Users/radiustheme07/Local Sites/shopbuilder/app/public/wp-admin/export.php(123): export_wp(Array)
#3 {main}
  thrown in /Users/radiustheme07/Local Sites/shopbuilder/app/public/wp-includes/utf8.php on line 39

To fix it, WordPress should add a simple type check before processing the value. For example:

<?php

function wxr_cdata( $str ) {
        // Make sure the value is a string before processing.
        if ( ! is_string( $str ) ) {
                return '<![CDATA[]]>'; // Fail-safe output for invalid or null values.
        }

        if ( ! wp_is_valid_utf8( $str ) ) {
                $str = utf8_encode( $str );
        }

        $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';

        return $str;
}

Change History (1)

#1 @swissspidy
2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Severity changed from major to normal
  • Status changed from new to closed

Thanks for the report, we're already tracking this in #64347

Note: See TracTickets for help on using tickets.