WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 14 months ago

#24122 closed defect (bug) (fixed)

When opening a file in Plugin Editor, show correct plugin in the dropdown selector

Reported by: Daedalon Owned by: swissspidy
Milestone: 4.7 Priority: normal
Severity: minor Version:
Component: Plugins Keywords: has-patch commit
Focuses: administration Cc:

Description

When opening a file in Plugin Editor, the reloaded page shows the first plugin according to alphabetical order in the dropdown next to "Select plugin to edit:". It should default to the plugin the loaded file belongs to.

Steps to reproduce

  1. Open wp-admin/plugin-editor.php
  2. Select any plugin from the "Select plugin to edit:" dropdown except the alphabetically first one, eg. WordPress Beta Tester, and click Select.
  3. The page reloads and WordPress Beta Tester is shown as the default value in the dropdown, as expected.
  4. Click any file under Plugin Files, eg. wordpress-beta-tester/readme.txt

-> The page reloads and shows the file in editor. However, "Select plugin to edit:" doesn't have a value set and shows the first plugin in alphabetical order by default.

-> However, if you chose the main plugin file, eg. wordpress-beta-tester/wp-beta-tester.php, "Select plugin to edit:" shows the correct plugin as the default value.

Any clicked file should lead to its plugin used as the default value for "Select plugin to edit:".

Attachments (5)

24122.patch (553 bytes) - added by aniketpant 5 years ago.
Fixes bug by changing the way the strings were being compared
#24122_fix_logic.diff (1003 bytes) - added by jayarjo 3 years ago.
#24122_fix_logic_mt8biz.diff (1.2 KB) - added by mt8.biz 3 years ago.
fix of #24122
24122.2.patch (1.2 KB) - added by MattyRob 3 years ago.
35788.diff (5.1 KB) - added by swissspidy 15 months ago.

Download all attachments as: .zip

Change History (21)

@aniketpant
5 years ago

Fixes bug by changing the way the strings were being compared

#1 @aniketpant
5 years ago

  • Keywords has-patch added

The bug was there because when a file is selected for editing, it passes the filename to $plugin which compares $plugin with the primary file of all plugins to find which plugin the file is a part of.

Fixed the bug by exploding the two strings, and comparing the first elements.

#2 @SergeyBiryukov
5 years ago

#22634 was marked as a duplicate.

#4 @jayarjo
3 years ago

I think the root of this problem is in different place. Here is where $plugin variable gets its awkward value:

if ( $file ) {
	$plugin = $file;
} elseif ( empty( $plugin ) ) {
	$plugin = array_keys($plugins);
	$plugin = $plugin[0];
}

$plugin_files = get_plugin_files($plugin);

if ( empty($file) )
	$file = $plugin_files[0];

It seems that it is done to invoke the get_plugin_files(), even when $plugin is not set. I think the whole thing should be the other way around:

if ( empty( $plugin ) ) {
	$plugin = array_keys($plugins);
	$plugin = $plugin[0];
}

if ( empty($file) )
	$file = $plugin;

$plugin_files = get_plugin_files($file);

If $plugin is not set it will auto-resolve to the first plugin in the list. If $file is not set it will default to $plugin, which at this moment will be a path to the plugins entry file. Then to retain the logic of retrieving only a single level of files to display in the sidebar (another awkward behavior I think), we pass $file, instead of $plugin to get_plugin_files().

Last edited 3 years ago by jayarjo (previous) (diff)

#5 @mt8.biz
3 years ago

I suggest ways of judging at plugin root path.

#6 @SergeyBiryukov
3 years ago

#29486 was marked as a duplicate.

#7 follow-up: @MattyRob
3 years ago

I've tested this patch today and it needs a little adjustment.

Assume you have Aksimet and Akismet Spam Count, the main files are akismet/akismet.php and akismet_count.php respectively.

The current code evaluates both of these items as 'selected' in the drop down so when in the editor on Akismet you are selected for Aksimet Spam Count in the drop down. This can be remedied by adding a trailing slash to the path as per the attached patch.

@MattyRob
3 years ago

#8 in reply to: ↑ 7 ; follow-up: @jayarjo
3 years ago

Replying to MattyRob:

I've tested this patch today and it needs a little adjustment.

Assume you have Aksimet and Akismet Spam Count, the main files are akismet/akismet.php and akismet_count.php respectively.

Have you tried my original patch? I do not seem to encounter such problem. Not sure why it was modified any further.

#9 in reply to: ↑ 8 @MattyRob
3 years ago

  • Keywords tested commit added

Replying to jayarjo:

Have you tried my original patch? I do not seem to encounter such problem. Not sure why it was modified any further.

I have now, I just presumed that the latest patch would be the most reliable. Having tested the #24122_fix_logic.diff patch I can confirm that it works perfectly so would propose that it gets committed (if a core committer is looking).

#10 @SergeyBiryukov
3 years ago

  • Keywords tested commit removed

#24122_fix_logic.diff still doesn't work if you click the Update File button.

The patch on #17552, however, appears to resolve both tickets.

#11 @chriscct7
2 years ago

#17552 has been punted for 4.5 consideration from 4.4

#12 @swissspidy
15 months ago

#35788 was marked as a duplicate.

@swissspidy
15 months ago

#13 @swissspidy
15 months ago

  • Milestone changed from Awaiting Review to 4.7

35788.diff is an updated patch that solves this issue as well as #17552.

See #35788 for details.

#14 @desrosj
15 months ago

  • Focuses administration added

Gave @swissspidy's patch a test, fixed the issue for me.

#15 @swissspidy
15 months ago

  • Keywords commit added

Let's get this in now so we have enough time to get some feedback.

#16 @swissspidy
14 months ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 38745:

Plugins: Correctly display the current plugin in the plugin editor.

When editing a plugin file, show the correct plugin as being edited in the dropdown with the correct activation status.

Props aniketpant, dd32, DrewAPicture, jayarjo, MattyRob, mt8.biz, solarissmoke, swissspidy, WraithKenny.
Fixes #24122, #17552.

Note: See TracTickets for help on using tickets.