protected function _edit( $content, $title ) {
$content = apply_filters( 'the_editor_content', $content );
- $os = strpos( $_SERVER['OS'], 'indows' )===false ? 'linux' : 'windows';
- $output = \WP_CLI\Utils\launch_editor_for_input( $content, $title, $os );
+ $output = \WP_CLI\Utils\launch_editor_for_input( $content, $title );
return ( is_string( $output ) ) ?
apply_filters( 'content_save_pre', $output ) : $output;
}
* @return str|bool Edited text, if file is saved from editor
* False, if no change to file
*/
-function launch_editor_for_input( $input, $title = 'WP-CLI', $os='linux' ) {
+function launch_editor_for_input( $input, $title = 'WP-CLI' ) {
$tmpfile = wp_tempnam( $title );
$output = '';
file_put_contents( $tmpfile, $input );
- if( $os==='linux' )
- \WP_CLI::launch( "\${EDITOR:-vi} '$tmpfile'" );
- else
- exec("notepad $tmpfile" );
+ $editor = getenv( 'EDITOR' );
+ if ( !$editor ) {
+ if ( isset( $_SERVER['OS'] ) && false !== strpos( $_SERVER['OS'], 'indows' ) )
+ $editor = 'notepad';
+ else
+ $editor = 'vi';
+ }
+
+ \WP_CLI::launch( \WP_CLI\Utils\esc_cmd( "$editor %s", $tmpfile ) );
$output = file_get_contents( $tmpfile );