Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active February 12, 2025 04:29
Show Gist options
  • Save wpmudev-sls/3020def900dc79c58db50b1298fb9edd to your computer and use it in GitHub Desktop.
Save wpmudev-sls/3020def900dc79c58db50b1298fb9edd to your computer and use it in GitHub Desktop.
[SmartCrawl Pro] SEO Health Check timeout fix
<?php
/**
* Plugin Name: [SmartCrawl Pro] SEO Health Check timeout fix
* Description: Use this snippet to fix the SEO Health Check timeout issue under certain conditions.
* Author: Anderson Salas @ WPMUDEV
* Task: SLS-6826
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*
* @package WPMUDEV_Alternative_SEO_Health_Check
*/
add_action(
'init',
function () {
if ( ! defined( 'SMARTCRAWL_VERSION' ) ) {
return;
}
if ( get_transient( 'wds-lighthouse-seo-report-temp' ) ) {
$current_report = get_option( 'wds-lighthouse-seo-last-report', array() );
if ( isset( $current_report['error'] )
&& true === $current_report['error']
&& isset( $current_report['code'] )
&& 'timeout' === $current_report['code']
) {
$report = get_transient( 'wds-lighthouse-seo-report-temp' );
update_option( 'wds-lighthouse-seo-last-report', (array) $report );
delete_transient( 'wds-lighthouse-seo-report-temp' );
}
}
add_filter(
'http_request_args',
function ( $parsed_args, $url ) {
if ( false !== strpos( $url, 'seo-result/latest' ) ) {
$parsed_args['timeout'] = 30;
}
add_filter(
'http_response',
function ( $response, $parsed_args, $url ) {
if ( false === strpos( $url, 'seo-result/latest' ) ) {
return false;
}
$response_json = json_decode( $response['body'], true );
if ( isset( $response_json['error'] )
&& false === $response_json['error']
&& ! empty( $response_json['code'] )
&& 200 === $response_json['code']
) {
// We need to save the response in a transient if the SEO Report is successful.
set_transient( 'wds-lighthouse-seo-report-temp', $response_json, HOUR_IN_SECONDS );
}
return $response;
},
10,
3
);
return $parsed_args;
},
10,
2
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment