admin-ajax.php + load-scripts.php hanging for minutes
My issue is that when I do a simple Admin Dashboard change, like updating a post or page, I sometimes wait up to 10 minutes for the request to finish. I have tried restarting the process and my server many times; the only way it works is if I wait all 10 minutes or so for the request to finish. Here is a screen shot of what the error looks like:
That error will loop 5-10 times, making it take forever to post anything. It looks like jQuery UI is causing all these issues when it is loaded via admin-ajax.php and load-scripts.php.
My setup is a bit convoluted because I'm trying to create a re-usable code-base for my projects. First of all, I am running it locally using Gulp and the connect-php server, but I also have MAMP Pro running for the database, which is doing MySQL replication to a BlueHost server for back-up.
I am using Timber and Advanced Custom Fields Pro for my custom theme. Then, I'm trying to strip as much Javascript that I don't need from WordPress as possible and I wire dependencies automatically with gulp, so my functions.php contains the following code:
add_filter( 'emoji_svg_url', '__return_false' );
function disable_wp_emojicons() {
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
// filter to remove TinyMCE emojis
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );
function disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
add_action('init', 'disable_emojicons_tinymce');
function kp_deregister_scripts(){
wp_deregister_script('wp-embed');
wp_dequeue_script('jquery');
}
add_action('wp_footer', 'kp_deregister_scripts');
add_action('wp_header', 'kp_deregister_scripts');
show_admin_bar(false);
function bower_enqueue_assets() {
// bower:js
wp_enqueue_script('jquery-js', get_stylesheet_directory_uri() . '/bower_components/jquery/dist/jquery.js');
wp_enqueue_script('tether-js', get_stylesheet_directory_uri() . '/bower_components/tether/dist/js/tether.js');
wp_enqueue_script('bootstrap-js', get_stylesheet_directory_uri() . '/bower_components/bootstrap/dist/js/bootstrap.js');
wp_enqueue_script('ResizeSensor-min.js', get_stylesheet_directory_uri() . '/bower_components/resize-sensor/ResizeSensor.min.js');
wp_enqueue_script('slick-js', get_stylesheet_directory_uri() . '/bower_components/slick-carousel/slick/slick.js');
wp_enqueue_script('jquery-form-validator.min.js', get_stylesheet_directory_uri() . '/bower_components/jquery-form-validator/form-validator/jquery.form-validator.min.js');
// endbower
}
add_action('wp_enqueue_scripts', 'bower_enqueue_assets');
function enqueue_recaptcha() {
// Enqueue recaptcha script from Google
wp_enqueue_script('recaptcha', 'https://www.google.com/recaptcha/api.js');
}
add_action('wp_enqueue_scripts', 'enqueue_recaptcha');
function contact_mailer() {
// Custom mailer code here using PHPMailer
}
}
add_action('wp_ajax_contactmailer', 'contact_mailer');
add_action('wp_ajax_nopriv_contactmailer', 'contact_mailer');
function mailchimp_subscribe() {
// Custom MailChimp subscription that just uses cURL
}
add_action('wp_ajax_mailchimpsignup', 'mailchimp_subscribe');
add_action('wp_ajax_nopriv_mailchimpsignup', 'mailchimp_subscribe');
On top of that, I have my own in-theme MailChimp and contact form mailer (using PHPMailer) code built-in.
I have also tried to use HeartBeat Control and I've set it up to only run on editing posts and slow it down to 60 seconds. That has intermittently worked in that this only happens one out of five or six posts now.
Anyways, I will try on a live server soon enough, but for now, this is really slowing things up on the development side and I'd like to get to a point where this isn't an issue. Anything else I can try?
Topic heartbeat-api ajax functions theme-development Wordpress optimization
Category Web