From 6700577acb385663f959d396d32db40213f5ef46 Mon Sep 17 00:00:00 2001 From: robelsust Date: Mon, 28 Sep 2026 00:02:13 +0600 Subject: [PATCH] Upgrade/Install: Link to Plugins page instead of Plugin Installer after uploading a plugin. In Plugin_Installer_Skin::after(), remove the legacy branch directing plugin upload installs back to plugin-install.php. Plugin uploads now fall through to the default branch linking to plugins.php ("Go to Plugins page"), aligning behavior with Theme_Installer_Skin. Also adds dedicated unit tests for Plugin_Installer_Skin covering upload, web, import, and error handling. Props therssoftware, BusinessBloomer. Fixes #66186. --- .../includes/class-plugin-installer-skin.php | 6 - .../tests/admin/pluginInstallerSkin.php | 160 ++++++++++++++++++ 2 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 tests/phpunit/tests/admin/pluginInstallerSkin.php diff --git a/src/wp-admin/includes/class-plugin-installer-skin.php b/src/wp-admin/includes/class-plugin-installer-skin.php index ecfb1f7bd59b5..c330cfe5ebb29 100644 --- a/src/wp-admin/includes/class-plugin-installer-skin.php +++ b/src/wp-admin/includes/class-plugin-installer-skin.php @@ -152,12 +152,6 @@ public function after() { self_admin_url( 'plugin-install.php' ), __( 'Go to Plugin Installer' ) ); - } elseif ( 'upload' === $this->type && 'plugins' === $from ) { - $install_actions['plugins_page'] = sprintf( - '%s', - self_admin_url( 'plugin-install.php' ), - __( 'Go to Plugin Installer' ) - ); } else { $install_actions['plugins_page'] = sprintf( '%s', diff --git a/tests/phpunit/tests/admin/pluginInstallerSkin.php b/tests/phpunit/tests/admin/pluginInstallerSkin.php new file mode 100644 index 0000000000000..2317aaa7c1eff --- /dev/null +++ b/tests/phpunit/tests/admin/pluginInstallerSkin.php @@ -0,0 +1,160 @@ + 'upload', + ) + ); + $upgrader = new Plugin_Upgrader( $skin ); + $skin->set_upgrader( $upgrader ); + $skin->result = true; + + $captured_actions = array(); + add_filter( + 'install_plugin_complete_actions', + static function ( $actions ) use ( &$captured_actions ) { + $captured_actions = $actions; + return array(); + } + ); + + $skin->after(); + + $this->assertArrayHasKey( 'plugins_page', $captured_actions ); + $this->assertStringContainsString( 'plugins.php', $captured_actions['plugins_page'] ); + $this->assertStringContainsString( 'Go to Plugins page', $captured_actions['plugins_page'] ); + $this->assertStringNotContainsString( 'plugin-install.php', $captured_actions['plugins_page'] ); + } + + /** + * Tests that after() provides a link to the plugin installer when installed from the web. + * + * @ticket 66186 + * + * @covers Plugin_Installer_Skin::after + */ + public function test_after_should_link_to_plugin_installer_when_installed_from_web() { + $skin = new Plugin_Installer_Skin( + array( + 'type' => 'web', + ) + ); + $upgrader = new Plugin_Upgrader( $skin ); + $skin->set_upgrader( $upgrader ); + $skin->result = true; + + $captured_actions = array(); + add_filter( + 'install_plugin_complete_actions', + static function ( $actions ) use ( &$captured_actions ) { + $captured_actions = $actions; + return array(); + } + ); + + $skin->after(); + + $this->assertArrayHasKey( 'plugins_page', $captured_actions ); + $this->assertStringContainsString( 'plugin-install.php', $captured_actions['plugins_page'] ); + $this->assertStringContainsString( 'Go to Plugin Installer', $captured_actions['plugins_page'] ); + } + + /** + * Tests that after() provides an importers page link when from is import. + * + * @covers Plugin_Installer_Skin::after + */ + public function test_after_should_link_to_importers_page_when_from_is_import() { + $_GET['from'] = 'import'; + + $skin = new Plugin_Installer_Skin( + array( + 'type' => 'upload', + ) + ); + $upgrader = new Plugin_Upgrader( $skin ); + $skin->set_upgrader( $upgrader ); + $skin->result = true; + + $captured_actions = array(); + add_filter( + 'install_plugin_complete_actions', + static function ( $actions ) use ( &$captured_actions ) { + $captured_actions = $actions; + return array(); + } + ); + + $skin->after(); + + $this->assertArrayHasKey( 'importers_page', $captured_actions ); + $this->assertStringContainsString( 'import.php', $captured_actions['importers_page'] ); + $this->assertStringContainsString( 'Go to Importers', $captured_actions['importers_page'] ); + } + + /** + * Tests hide_process_failed() for folder_exists error during upload without overwrite. + * + * @covers Plugin_Installer_Skin::hide_process_failed + */ + public function test_hide_process_failed_should_return_true_on_folder_exists_for_upload() { + $skin = new Plugin_Installer_Skin( + array( + 'type' => 'upload', + 'overwrite' => '', + ) + ); + + $error = new WP_Error( 'folder_exists', 'Folder exists.' ); + $this->assertTrue( $skin->hide_process_failed( $error ) ); + + $other_error = new WP_Error( 'other_error', 'Other error.' ); + $this->assertFalse( $skin->hide_process_failed( $other_error ) ); + + $skin_web = new Plugin_Installer_Skin( + array( + 'type' => 'web', + 'overwrite' => '', + ) + ); + $this->assertFalse( $skin_web->hide_process_failed( $error ) ); + } +}