@Panda @papillon121 Did this script ever work properly? Looking at it, there are two components.
- A PHP script that collects values from the page
- A JS script for processing via AJAX
This is standard behaviour for processing remote data requests via json
but Iād frankly be amazed if this ever worked properly without a user being logged in. There are functions such as the below
add_action('wp_ajax_handle_curl_request', 'handle_curl_request');
This will work if the user is logged in, but if not, then it will never return any data. The entire point of your site is for a visiting user to generate their request, see the response, then decide if they want to purchase it or not. As no data is ever returned from the json
request (because it requires an authenticated user), the visitor is likely to think it doesnāt work, and then simply move on.
Because of this, Iāve changed the above code to be as below (there are actually three of these that need fixing, but including one only for brevity. The code is commented, so you can review for yourself)
add_action('wp_ajax_handle_curl_request', 'handle_curl_request');
// Added by Phenomlab - you cannot use wp_ajax as unauthenticated user unless you specifty "nopriv"
add_action('wp_ajax_nopriv_handle_curl_request', 'handle_curl_request');
In addition, the site clearly states that it may take up to 30 seconds for any data to be returned, and yet, the timeout is hardcoded at 10 seconds!
setTimeout(function() {
$.ajax({
url: my_plugin_ajax.ajaxurl,
type: 'POST',
data: data,
dataType: 'html',
success: function(responseData) {
// Handle the response data here
jQuery('.my-plugin-container .trx_addons_loading').css({"display":"none"});
$('.my-plugin_images_columns_wrap').prepend(responseData);
},
error: function(responseData) {
console.log('AJAX Error' + responseData);
}
});
}, 10000);
This makes no sense whatsoever. The API is remote, and may well take in excess of 30 seconds to return data depending on how busy it is. I have changed this so that it waits for a minute - in my testing, itās always less than that, but the wording on the page (in the sense of the 30 secondsā¦) should also be changed as to not set expectations.
setTimeout(function() {
$.ajax({
url: my_plugin_ajax.ajaxurl,
type: 'POST',
data: data,
dataType: 'html',
success: function(responseData) {
// Handle the response data here
jQuery('.my-plugin-container .trx_addons_loading').css({"display":"none"});
$('.my-plugin_images_columns_wrap').prepend(responseData);
},
error: function(responseData) {
console.log('AJAX Error' + responseData);
}
});
}, 60000);
Clearly, this plugin has been generated in an automated fashion given the references to my-plugin...
etc, and to be honest, itās very poorly written and contains a couple of vulnerabilities where the code response could be intercepted and manipulated in some isolated cases.
I mostly do not comment on other peopleās coding work, but this is some of the worst code Iāve ever seen - mostly because of the API being exposed in the console, which Iāve removed.
Can you please test it now with both a logged in user, and guest? It should be returning data in both cases.