$input = ( isset( $assoc_args['post_content'] ) ) ?
$assoc_args['post_content'] : '';
- if ( $output = \WP_CLI\Utils\launch_editor_for_input( $input ) )
+ if ( $output = \WP_CLI\Utils\launch_editor_for_input( $input, 'WP-CLI: New Post' ) )
$assoc_args['post_content'] = $output;
else
$assoc_args['post_content'] = $input;
return;
}
- $r = \WP_CLI\Utils\launch_editor_for_input( $post->post_content );
+ $r = \WP_CLI\Utils\launch_editor_for_input( $post->post_content, "WP-CLI post $post_id" );
if ( !$r ) {
\WP_CLI::error( "Aborting. No change made to post.", false );
*
* @param str $content Text to edit (eg post content)
* @return str|bool Edited text, if file is saved from editor
+ * False, if no change to file
*/
-function launch_editor_for_input( $input ) {
+function launch_editor_for_input( $input, $title = 'WP-CLI' ) {
- $tmpfile = tempnam( '/tmp', 'wp-cli' );
+ $tmpfile = wp_tempnam( $title );
if ( !$tmpfile )
die( 'Error creating temporary file.' );
fwrite( $handle, $input );
fclose( $handle );
- $out = `\${EDITOR:-vi} "$tmpfile" 3>&1 1>&2 2>&3 || exit $?`;
+ \WP_CLI::launch( "\${EDITOR:-vi} '$tmpfile'" );
$handle = fopen( $tmpfile, 'r' );
$output = fread( $handle, filesize( $tmpfile ) );