Opened 9 years ago
Last modified 2 months ago
#36339 new defect (bug)
Possible issue with export_wp() and undefined custom post types
Reported by: | theMikeD | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Export | Keywords: | needs-unit-tests has-patch |
Focuses: | Cc: |
Description (last modified by )
While writing the improved docblock for export_wp()
, I noticed something that may be an issue if an invalid custom post type is supplied. Here is the code:
<?php if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { $ptype = get_post_type_object( $args['content'] ); if ( ! $ptype->can_export ) $args['content'] = 'post'; $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); } else { $post_types = get_post_types( array( 'can_export' => true ) ); $esses = array_fill( 0, count($post_types), '%s' ); $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); }
The two things that occurred me are
- If a valid custom post type is supplied but its
can_export
property isfalse
,posts
will be used instead. This is unexpected behaviour. I think it should stop and not export anything. - if an invalid custom post type is supplied, every post type that has
can_export
set totrue
is used. This is also unexpected behaviour. I think it should stop and not export anything.
Am I reading this wrong? Is there a reason why it works this way?
Change History (5)
#1
@
9 years ago
- Description modified (diff)
- Summary changed from Possible issue with wp_export() and undefined custom post types to Possible issue with export_wp() and undefined custom post types
#3
@
8 years ago
- Keywords dev-feedback needs-screenshots added
It might be solved as described below.
Maybe a core committer can review the described way, so that I don't do all the work for nothing ;)
I'll write a UnitTest next week covering these scenarios:
- If a valid post type is supplied but its
can_export
property is false, no entry of this post type should be exported. - If an invalid post type is supplied then an error message should occur instead of doing the regular export with all allowed post types.
After that a mock of the error message is needed here to show what the error message will look like.
Later on I try solving this ticket.
#4
@
4 years ago
- Keywords needs-patch needs-unit-tests added; dev-feedback needs-screenshots removed
- Milestone set to Future Release
I agree. We should be throwing errors from export_wp()
instead of exporting unexpected data, even if that odd behavior is properly documented now.
The current export UI in the admin doesn't show any post types which don't have can_export
set to true
. This would only be a possible issue for other external direct calls to export_wp()
, so there wouldn't be any design work involved here.
This ticket was mentioned in PR #7527 on WordPress/wordpress-develop by @debarghyabanerjee.
2 months ago
#5
- Keywords has-patch added; needs-patch removed
Trac Ticket: Core-36339
## Overview:
- This PR enhances the export_wp function by refining the documentation and improving error handling for custom post types. The changes ensure clearer guidance for developers regarding the behavior of the function when invalid or non-exportable post types are specified.
## Changes:
- Updated the doc block for export_wp to clarify:
- The behavior when an invalid custom post type is supplied.
- The consequences of supplying a valid custom post type that is not exportable.
- Return a WP_Error for invalid or non-exportable post types.
Documentation:
Documentation updates have been made to reflect the changes in functionality and provide clear guidance for users of the export_wp
function.
Improved docblock is here FTR #36338