Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#38874 closed defect (bug) (fixed)

Change include of "includes/plugin-install.php" to include_once

Reported by: engelen's profile engelen Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version: 3.1
Component: Plugins Keywords: has-patch needs-testing
Focuses: administration Cc:

Description

The file wp-admin/includes/plugin-install.php, which contains only functions and does not directly execute anything, is included from 4 different files:

  1. wp-admin/includes/ajax-actions.php - using include_once
  2. wp-admin/includes/class-wp-plugin-install-list-table.php - using include
  3. wp-admin/update-core.php - using require_once
  4. wp-admin/update.php - using include_once

The second yields problems when including wp-admin/includes/plugin-install.php using custom code, as the unconditional include will then yield a fatal error ("Cannot redeclare plugins_api()").

The include should be changed to include_once.

Attachments (1)

plugin-install-include.38874.diff (620 bytes) - added by engelen 8 years ago.
Change "include" to "include-once" for including "wp-admin/includes/plugin-install.php" in "wp-admin/includes/class-wp-plugin-install-list-table.php"

Download all attachments as: .zip

Change History (4)

@engelen
8 years ago

Change "include" to "include-once" for including "wp-admin/includes/plugin-install.php" in "wp-admin/includes/class-wp-plugin-install-list-table.php"

#1 @SergeyBiryukov
8 years ago

  • Component changed from Administration to Plugins

#2 @desrosj
6 years ago

  • Keywords has-patch needs-testing added
  • Milestone changed from Awaiting Review to 5.3
  • Version changed from 4.6.1 to 3.1

Hi @engelen,

First off, sorry that it took so long or someone to get back to you on this.

I've done some digging to connect the dots on some history. For reference, here is what I found:

  • The include_once in wp-admin/includes/ajax-actions.php was introduced in [37714] for version 4.6.
  • The include in wp-admin/includes/class-wp-plugin-install-list-table.php was introduced in [15491] for version 3.1.
  • The require_once in wp-admin/update-core.php was introduced in [12157] for version 2.9.
  • The include_once in wp-admin/update.php was introduced in [11005] for version 2.8 (formatting modified in [28500]).

The patch still applies for me, and this makes sense. I am going to milestone this for the next release to get it some attention, testing, and feedback.

#3 @SergeyBiryukov
6 years ago

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

In 45751:

Plugins: Use include_once for wp-admin/includes/plugin-install.php in WP_Plugin_Install_List_Table::prepare_items().

This brings consistency with the other instances where the file is included, and allows for reusing its functions in custom code.

Props engelen, desrosj.
Fixes #38874.

Note: See TracTickets for help on using tickets.