Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#33523 closed defect (bug) (wontfix)

WP_List_Table sortable header links break when list table is loaded via Ajax

Reported by: mcguive7's profile McGuive7 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Administration Keywords: close
Focuses: Cc:

Description

When using Ajax to load up a WP_List_Table with sortable columns, the column header links are broken and point to admin-ajax.php instead of the actual current URL.

This appears to be due to the following line in wp-admin/includes/class-wp-list-table.php:

$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );

Checking the $_SERVER variable returns the current request info, which is via admin-ajax.php, not the actual URL (current admin page) from which the Ajax request is made. This completely breaks column sorting for list tables loaded via Ajax, with the column header links pointing to something like: http://local.wordpress-trunk.dev/wp-admin/admin-ajax.php?orderby=version&order=asc instead of the proper URL.

Here's a screencast for clarity: http://recordit.co/DSsXlaUuka

Is there a workaround for this one? If not, it seems like a bug, right?

Change History (5)

#1 @obenland
10 years ago

  • Version trunk deleted

#2 in reply to: ↑ description @afercia
10 years ago

  • Version set to 4.3

Replying to McGuive7:

Is there a workaround for this one? If not, it seems like a bug, right?

hi @McGuive7 I'm not the best person to give an answer and I've seen you've opted for a different solution in your plugin :) just noticed that in the terms list table, where AJAX is used for some actions (for example when creating a new category or tag), a similar issue is solved this way:

$uri = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];

Wondering if this should be done for all the tables to allow plugins to play with AJAX. Any thoughts more than welcome. cc @wonderboymusic

#3 @helen
10 years ago

Would making adjustments here do anything beyond enabling Ajax-y list tables? Because if that's the only thing it'd be for, I don't like the idea of essentially explicitly saying "this is a thing you can do" because that then implies support and therefore maintaining back-compat. That's already hard enough as it is with list tables, which were always marked as private, but clearly that's disregarded so core at least tries to play nice.

#4 @afercia
10 years ago

  • Keywords close added

Sure, personally I don't have a strong opinion about this, was just trac-gardening and wondering what to do with this ticket. Seems a "close" :)

#5 @swissspidy
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Something similar is used in wp_ajax_search_plugins() for example. Developers can use the code from there if really needed.

Note: See TracTickets for help on using tickets.