Much simpler this way. Also does away with the need to check for empty
output, although now we have to check the return value of
`launch_editor_for_input` strictly against false, since its possible for
it to return an empty string now (editing a post and deleting all the
content).
$r = \WP_CLI\Utils\launch_editor_for_input( $post->post_content, "WP-CLI post $post_id" );
- if ( !$r ) {
+ if ( $r === false ) {
\WP_CLI::error( "Aborting. No change made to post.", false );
return;
}
if ( !$tmpfile )
die( 'Error creating temporary file.' );
- $handle = fopen( $tmpfile, 'w+t' );
- fwrite( $handle, $input );
- fclose( $handle );
+ file_put_contents( $tmpfile, $input );
\WP_CLI::launch( "\${EDITOR:-vi} '$tmpfile'" );
- $filesize = filesize( $tmpfile );
+ $output = file_get_contents( $tmpfile );
- if ( $filesize === 0 )
- return false;
-
- $handle = fopen( $tmpfile, 'r' );
- $output = fread( $handle, $filesize );
- fclose( $handle );
unlink( $tmpfile );
if ( $output === $input )