Make WordPress Core

Opened 10 years ago

Closed 7 years ago

#38874 closed defect (bug) (fixed)

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

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

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 10 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
10 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
10 years ago

  • Component Administration → Plugins

#2 @desrosj
8 years ago

  • Keywords has-patch needs-testing added
  • Milestone Awaiting Review → 5.3
  • Version 4.6.1 → 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
7 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → 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.