wp-list-table-example icon indicating copy to clipboard operation
wp-list-table-example copied to clipboard

"Request-URI Too Long" error

Open columbian-chris opened this issue 7 years ago • 5 comments

After testing my bulk actions, I received this error from Apache:

Request-URI Too Long The requested URL's length exceeds the capacity limit for this server.

Then I noticed every time I was checking items, selecting a bulk action, then clicking "Apply", it was just adding onto to the URL parameters that were already there and using the new ones, so the URL was getting longer and longer every time and eventually reached the maximum length the server would accept. How do I clear the URL parameters every time I want to make another bulk action request?

columbian-chris avatar Oct 12 '17 16:10 columbian-chris

@columbian-chris would you be able to share your code so I could see what it is. It sounds like you just need to generate the bulk actions url with a base of wp-admin.php and not the current url.

jonathanbossenger avatar Oct 13 '17 13:10 jonathanbossenger

Hey @jonathanbossenger, thanks for the reply. :)

So it's any of my bulk actions. I'll use the delete bulk action because that one is very standard. Here what's I have for it (simplified to improve readability and to prevent unnecessary explanation of non-related functionality):

My get_bulk_actions() method:

protected function get_bulk_actions() {
	$actions = array(
		'delete' => _x( 'Delete', 'List table bulk action', 'domain-wp-list-table' ),
	);
	return $actions;
}

My process_bulk_action() method:

protected function process_bulk_action() {
	if ( 'delete' === $this->current_action() ) {
		global $wpdb;
		$query = "DELETE FROM `$this->source` WHERE `$this->key_col` IN( ".implode(',',$ids)." )";
		$results = $wpdb->query( $wpdb->prepare($query, $_REQUEST[$this->_args['singular']]) );
	}
}

Nothing too crazy here. Notice how my URL's increase in size with every attempt to delete multiple entries:

URL on first call: {my site}/wp-admin/admin.php?s&page=homes-realtors&_wpnonce=ed93ec22e2&_wp_http_referer=%2Frealestate%2Fwp-admin%2Fadmin.php%3Fpage%3Dhomes-realtors&action=delete&paged=1&item%5B0%5D=30299LAU++&item%5B1%5D=3091++++++&action2=-1

Second call: {my site}/wp-admin/admin.php?s&page=homes-realtors&_wpnonce=ed93ec22e2&_wp_http_referer=%2Frealestate%2Fwp-admin%2Fadmin.php%3Fs%3D%26page%3Dhomes-realtors%26_wpnonce%3Ded93ec22e2%26_wp_http_referer%3D%252Frealestate%252Fwp-admin%252Fadmin.php%253Fpage%253Dhomes-realtors%26action%3Ddelete%26paged%3D1%26item%255B%255D%3D30299LAU%2B%2B%26item%255B%255D%3D3091%2B%2B%2B%2B%2B%2B%26action2%3D-1&action=delete&paged=1&item%5B0%5D=32968+++++&item%5B1%5D=3379++++++&action2=-1

Third call: {my site}/wp-admin/admin.php?s&page=homes-realtors&_wpnonce=ed93ec22e2&_wp_http_referer=%2Frealestate%2Fwp-admin%2Fadmin.php%3Fs%3D%26page%3Dhomes-realtors%26_wpnonce%3Ded93ec22e2%26_wp_http_referer%3D%252Frealestate%252Fwp-admin%252Fadmin.php%253Fs%253D%2526page%253Dhomes-realtors%2526_wpnonce%253Ded93ec22e2%2526_wp_http_referer%253D%25252Frealestate%25252Fwp-admin%25252Fadmin.php%25253Fpage%25253Dhomes-realtors%2526action%253Ddelete%2526paged%253D1%2526item%25255B%25255D%253D30299LAU%252B%252B%2526item%25255B%25255D%253D3091%252B%252B%252B%252B%252B%252B%2526action2%253D-1%26action%3Ddelete%26paged%3D1%26item%255B%255D%3D32968%2B%2B%2B%2B%2B%26item%255B%255D%3D3379%2B%2B%2B%2B%2B%2B%26action2%3D-1&action=delete&paged=1&item%5B0%5D=3321++++++&item%5B1%5D=3460++++++&action2=-1


My hypothesis is going to be that it should be processing URL's without using encoded characters, but I don't even know where the bulk actions are creating those. Your help is greatly appreciated!

columbian-chris avatar Oct 13 '17 16:10 columbian-chris

Okay, so it looks like the only URL parameter that is increasing in size with every bulk action call is the _wp_http_referer. I have a bit of a rough hack to fix this. If you put an empty hidden tag for it at the bottom of the <form>, it'll just overwrite the first one in the HTML with a blank one.

Use case: after you call $your_instance_name->display() in your PHP, throw in <input type="hidden" name="_wp_http_referer" value=""> and make sure it's still within your form tag (before the closing </form>).

columbian-chris avatar Jan 24 '18 21:01 columbian-chris

@columbian-chris interesting. You should also be able to set the _wp_http_referer in the plugin itself when the url is being generated. I'll try and see if I can figure out where this needs to go in the next few days and submit a pull request.

jonathanbossenger avatar Feb 01 '18 06:02 jonathanbossenger

@columbian-chris It sure does work well to prevent the url too long errors! Thanks a ton!!!!

oooorgle avatar Sep 25 '22 19:09 oooorgle