[wp-trac] [WordPress Trac] #54973: Failed wp_insert_category() when IMPORT_DEBUG is set to true produces a fatal error.
WordPress Trac
noreply at wordpress.org
Sat Jan 29 11:10:35 UTC 2022
#54973: Failed wp_insert_category() when IMPORT_DEBUG is set to true produces a
fatal error.
-------------------------------------+----------------------------
Reporter: enshrined | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: WordPress.org
Component: Import | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-refresh | Focuses:
-------------------------------------+----------------------------
Changes (by SergeyBiryukov):
* milestone: 6.0 => WordPress.org
Comment:
Replying to [comment:3 mukesh27]:
> Hi there! thanks for the ticket and patch.
>
> Can you please add `is_wp_error` for below all occurrences so we don't
get a similar error in any other code base?
Thanks for the review! Unless I'm missing something, all of those
instances already have an `is_wp_error()` check just a few lines above, so
adding another check would be redundant.
The instance in the patch is different because it gets executed not only
if `$id` is a `WP_Error` object, but also if it's `0`:
{{{
$id = wp_insert_category( $data );
if ( ! is_wp_error( $id ) && $id > 0 ) {
...
} else {
printf( __( 'Failed to import category %s', 'wordpress-importer'
), esc_html( $cat['category_nicename'] ) );
if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
echo ': ' . $id->get_error_message(); // The instance
being patched here.
}
echo '<br />';
}
}}}
Instead of adding another `is_wp_error()` check, I think the correct fix
here would be to pass `true` as the second parameter to
`wp_insert_category()`, otherwise it can never return a `WP_Error` in the
first place.
That would also be consistent with `wp_insert_post( $postdata, true )` in
[https://github.com/WordPress/wordpress-
importer/blob/99462ec2d3390bc0de3bc5ffbe817f2160e5ef54/src/class-wp-
import.php#L746 line 746].
Moving the ticket to the WordPress.org milestone instead of 6.0, as this
code is in the WordPress importer plugin and not in WordPress core.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54973#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list