WordPress.org

Make WordPress Core

Opened 3 years ago

#17120 new defect (bug)

Class WP_Importer references STDIN which is not available in Web Environments

Reported by: dd32 Owned by:
Milestone: Future Release Priority: low
Severity: minor Version: 3.0
Component: Import Keywords: needs-patch
Focuses: Cc:

Description

STDERR is not defined in web environments (only certain CLI environments), you can call fopen('php://stderr'); directly, however this is not delivered to browsers.

Since this is in the Multisite code, CLI imports might be more common, but it's not a given that multisite imports will not be run from the web either.

Code ref:
http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/class-wp-importer.php#L128

126	                        $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
127	                        if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
128	                                fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
129	                                exit();
130	                        }
131	                        if ( empty( $parsed['path'] ) )
132	                                $parsed['path'] = '/';
133	                        $blog = get_blog_details( array( 'domain' => $parsed['host'], 'path' => $parsed['path'] ) );
134	                        if ( !$blog ) {
135	                                fwrite( STDERR, "Error: Could not find blog\n" );
136	                                exit();
137	                        }

I'm unsure of the best way to tackle this, Ideally in a CLI environment we want the error outputs going to STDERR, but since that's not available or visible to web browsers, wp_die() would be a better choice.

One potential method would be to direct wp_die() to STDERR in CLI environments - That might cause problems with the test suite however (I'm unsure)

Change History (0)

Note: See TracTickets for help on using tickets.