Make WordPress Core

Opened 12 years ago

Closed 8 years ago

#17413 closed defect (bug) (fixed)

Code added by WP_List_Table::_js_vars is duplicated

Reported by: sorich87's profile sorich87 Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.2 Priority: normal
Severity: normal Version: 3.2
Component: Administration Keywords: has-patch
Focuses: administration Cc:


When a list table is 'ajax enabled' (e.g. comments list table on edit-comments.php), javascript code is added by WP_List_Table::_js_vars to the footer. If you look at the source code in your browser, you will see that code is duplicated.

Attachments (2)

17413.diff (894 bytes) - added by sorich87 12 years ago.
17413.2.diff (1.2 KB) - added by sorich87 12 years ago.
Forgot global in previous patch

Download all attachments as: .zip

Change History (8)

#1 @solarissmoke
12 years ago

  • Keywords dev-feedback added

The problem is that two instances of the List_Table class are created while loading the page, and each time the constructor hooks $this->_js_vars to admin_footer. In the case of edit-comments.php:


$wp_list_table = _get_list_table('WP_Comments_List_Table');

and then again in wp-admin/includes/template.php:337

$wp_list_table = _get_list_table('WP_Comments_List_Table');

I wonder if there isn't a fundamental problem here in that we are creating multiple list tables instances when we should be using only one. Certainly the current js stuff assumes there is only one list table.

12 years ago

#2 @sorich87
12 years ago

  • Keywords has-patch added; needs-patch removed

Attached patch fixes the issue but I am not sure if it breaks something else.

12 years ago

Forgot global in previous patch

#3 @scribu
12 years ago

The idea was that at most one list table was ajax-enabled at a time.

#5 @chriscct7
9 years ago

  • Focuses administration added

It seems this patch would be a good candidate for inclusion in core, and the patch doesn't need to be refreshed.

#6 @wonderboymusic
8 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 4.2
  • Owner sorich87 deleted
  • Status changed from new to assigned

#7 @wonderboymusic
8 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from assigned to closed

In 31019:

WP_List_Table's constructor registers an 'admin_footer' callback when AJAX is enabled. As such, if you create multiple instances of the class, you get multiple JS blobs on the page when the callbacks fire. Extra instances get made when wp_comment_reply() invokes the class constructor without checking for the existing instance via the $wp_list_table global.

We shall check the $wp_list_table global in wp_comment_reply().

Props sorich87.
Fixes #17413.

Note: See TracTickets for help on using tickets.