WP Ajax Callback being fired twice

Question

I noticed the problem when I was setting up an Ajax action which creates a file with a random name. It always created 2 files with random names.

This is a clean install.

I went ahead and started debugging the core files and realized that everything is called twice. For example, try echoing “ok” in the wp() function in wp-includes/functions.php – it will output “okok” in the front-end.

Is this by design or is there something wrong with the current version of WP?
Is there something I should do to avoid this?

Here are the steps to reproduce:

1 – Add this function to the theme functions.php:

function test() {
  fopen("/var/www/html/yourpath/test." . random_int(0, 100000), "w");
  die();
}
add_action('wp_ajax_test', 'test');

2 – Access the URL: /wp-admin/admin-ajax.php?action=test

3 – Check your directory to see 2 different files were created

Thank you!

0
Luciano 1 year 2020-07-12T20:10:43-05:00 0 Answers 56 views 0

Leave an answer

Browse
Browse