WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#37943 closed defect (bug) (fixed)

Invalid link to the "Run importer" action while installing importer plugin from a multisite sub-site

Reported by: joelcj91 Owned by: swissspidy
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.6
Component: Import Keywords: has-screenshots has-patch commit
Focuses: javascript, administration, multisite Cc:

Description

In a WordPress multisite installation, when you try to import an XML file, from a sub-site, you will be provided with an invalid link to the "Run importer" page after the installation of the "WordPress Importer" plugin. This bug will not be there if it is not a multisite website or if the "WordPress Importer" plugin is already installed.

Steps to reproduce:

1) Create a Multisite website.
2) Go to one of your sub-sites.
3) Make sure that the "WordPress Importer" plugin is not installed already (https://wordpress.org/plugins/wordpress-importer/).
4) Go to Import section in Tools menu.
5) Click on "Install Now" under WordPress import section.
6) Now the WordPress Importer plugin will be installed though ajax request.
7) After successful installation, "Install Now" link will be replaced with "Run importer" link and also, you will be provided with a message at the top - "Importer installed successfully. Run importer".
8) Expected result is a proper, working link to the importer page., inside the current sub-site. But you can see, since the Multisite plugins are managed from network dashboard, the link returned through the ajax response is invalid, as "/network" is appended in the plugin's link.
9)

a) Expected link : mysubsite1/wp-admin/plugins.php?action=activate&plugin=wordpress-importer%2Fwordpress-importer.php&from=import&_wpnonce=123nonce

b) Current link : mysubsite1/wp-admin/network/plugins.php?action=activate&plugin=wordpress-importer%2Fwordpress-importer.php&from=import&_wpnonce=123nonce

10) This results a 404 error when we click on Run mporter.

Please see the screenshot.

Attachments (4)

Run-Importer.png (88.0 KB) - added by joelcj91 3 years ago.
Run Importer screen with invalid link
37943.patch (1.2 KB) - added by joelcj91 3 years ago.
Patch to fix this by replacing the link in installImporterSuccess function in updates.js
37943.2.patch (1.9 KB) - added by joelcj91 3 years ago.
Changed url from server side by passing pagenow
37943.diff (1.6 KB) - added by swissspidy 3 years ago.

Download all attachments as: .zip

Change History (15)

@joelcj91
3 years ago

Run Importer screen with invalid link

@joelcj91
3 years ago

Patch to fix this by replacing the link in installImporterSuccess function in updates.js

#1 @joelcj91
3 years ago

  • Keywords has-patch has-screenshots added

#2 follow-up: @netweb
3 years ago

  • Milestone changed from Awaiting Review to 4.7

@joelcj91 Welcome to Trac, thanks for a great Trac ticket, all the keywords, component, focuses, versions are perfect, detailed reproducible steps and and patch, boom, thanks :)

#3 in reply to: ↑ 2 @joelcj91
3 years ago

Thanks @netweb

Replying to netweb:

@joelcj91 Welcome to Trac, thanks for a great Trac ticket, all the keywords, component, focuses, versions are perfect, detailed reproducible steps and and patch, boom, thanks :)

#4 follow-up: @swissspidy
3 years ago

  • Keywords needs-patch added; has-patch removed

On Multisite, new plugins can only be installed via wp-admin/network/plugin-install.php, not wp-admin/plugin-install.php. That's why wp_ajax_install_plugin() uses network_admin_url(). Importers are installed on wp-admin/import.php though, so that assumption breaks.

Replacing the URL in the JavaScript is not a good idea as it only treats the symptom, not the cause.

We could solve this by passing pagenow in the Ajax request and change the URL depending on that, like we already do with wp_ajax_search_install_plugins().

#5 in reply to: ↑ 4 @joelcj91
3 years ago

Ok. I shall create another patch like you suggested.

Replying to swissspidy:

On Multisite, new plugins can only be installed via wp-admin/network/plugin-install.php, not wp-admin/plugin-install.php. That's why wp_ajax_install_plugin() uses network_admin_url(). Importers are installed on wp-admin/import.php though, so that assumption breaks.

Replacing the URL in the JavaScript is not a good idea as it only treats the symptom, not the cause.

We could solve this by passing pagenow in the Ajax request and change the URL depending on that, like we already do with wp_ajax_search_install_plugins().

@joelcj91
3 years ago

Changed url from server side by passing pagenow

#6 @joelcj91
3 years ago

  • Keywords has-patch added; needs-patch removed

@swissspidy, as per your suggestion, I have changed the url from server side. Please review the new patch.

#7 @swissspidy
3 years ago

  • Owner set to swissspidy
  • Status changed from new to reviewing

@swissspidy
3 years ago

#8 @swissspidy
3 years ago

In 37943.diff:

  • Fix indentation (tabs instead of spaces)
  • Do not activate importer network-wide after shiny install. This matches the behaviour after a page refresh.

#9 @swissspidy
3 years ago

  • Keywords commit added

#10 @swissspidy
2 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38704:

Import: Fix plugin activation link after installing an importer on multisite.

When installing the importer via Ajax, the activation link should be the same as if the page were reloaded.

Props joelcj91 for initial patch.
Fixes #37943.

#11 @joelcj91
2 years ago

Hooo! My first WordPress core contribution :) Thanks @swissspidy

Note: See TracTickets for help on using tickets.