From 1fd64cdd3c5e71bc9be3fae161302dc2a48b66a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:18:21 +0000 Subject: [PATCH 1/3] Initial plan From ce89c0d99f90c0452b542da12131002152aae754 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:21:06 +0000 Subject: [PATCH 2/3] Add SSH connection detection and fallback URL output Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- admin-command.php | 27 ++++++++++++++++++++++++++- features/admin-command.feature | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 features/admin-command.feature diff --git a/admin-command.php b/admin-command.php index b96329b..60e2f14 100644 --- a/admin-command.php +++ b/admin-command.php @@ -8,6 +8,21 @@ * Open /wp-admin/ in a browser. */ function wp_cli_admin_command() { + $admin_url = admin_url(); + + // Detect if running over SSH connection + $is_ssh = ! empty( $_SERVER['SSH_CONNECTION'] ) + || ! empty( $_SERVER['SSH_CLIENT'] ) + || ! empty( $_SERVER['SSH_TTY'] ); + + // If SSH connection detected, output the URL instead of trying to open browser + if ( $is_ssh ) { + WP_CLI::log( 'Detected SSH connection. Please open this URL in your local browser:' ); + WP_CLI::log( $admin_url ); + return; + } + + // Determine the command to open browser based on OS switch ( strtoupper( substr( PHP_OS, 0, 3 ) ) ) { case 'DAR': $exec = 'open'; @@ -18,6 +33,16 @@ function wp_cli_admin_command() { default: $exec = 'xdg-open'; } - passthru( $exec . ' ' . escapeshellarg( admin_url() ) ); + + // Try to open the URL in the browser + $output = ''; + $return_var = 0; + exec( $exec . ' ' . escapeshellarg( $admin_url ) . ' 2>&1', $output, $return_var ); + + // If the command fails (e.g., xdg-open not found), fallback to printing the URL + if ( 0 !== $return_var ) { + WP_CLI::log( 'Unable to open browser automatically. Please open this URL:' ); + WP_CLI::log( $admin_url ); + } } WP_CLI::add_command( 'admin', 'wp_cli_admin_command' ); diff --git a/features/admin-command.feature b/features/admin-command.feature new file mode 100644 index 0000000..ce19c84 --- /dev/null +++ b/features/admin-command.feature @@ -0,0 +1,23 @@ +Feature: Open /wp-admin/ in a browser + + Scenario: Admin command outputs URL when SSH connection detected + Given a WP install + + When I try `wp admin` + Then the return code should be 0 + And STDOUT should contain: + """ + http:// + """ + + Scenario: Admin command works with custom site URL + Given a WP install + And I run `wp option update siteurl 'http://example.com'` + And I run `wp option update home 'http://example.com'` + + When I try `wp admin` + Then the return code should be 0 + And STDOUT should contain: + """ + http://example.com/wp-admin/ + """ From 22a1892e69613f1737e434452fc23e56b61ebc9e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Feb 2026 17:22:45 +0000 Subject: [PATCH 3/3] Update documentation and finalize SSH remote connection support Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- admin-command.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/admin-command.php b/admin-command.php index 60e2f14..d49db9b 100644 --- a/admin-command.php +++ b/admin-command.php @@ -6,6 +6,8 @@ /** * Open /wp-admin/ in a browser. + * + * When running over SSH, outputs the URL instead of trying to open it. */ function wp_cli_admin_command() { $admin_url = admin_url();