Forked from wpmudev-sls/smush-mu-fix-image-recheck-fail-post-to-get.php
Created
November 11, 2023 23:01
-
-
Save alfredo-wpmudev/6884f100e39fa8e27cec8c1bfd2d1479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Smush Pro] Image Recheck Failure. | |
* Description: Changes async request method from POST to GET to fix image recheck failures. | |
* Jira: SLS-5197 | |
* Author: Abdoljabbar Bakhshande | |
* Author URI: https://wpmudev.com | |
* License: GPLv2 or later | |
* | |
* @package WordPress | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
add_action( 'plugins_loaded', 'smush_image_recheck_fix_post_to_get' ); | |
/** | |
* Fix image recheck failures by changing POST to GET. | |
*/ | |
function smush_image_recheck_fix_post_to_get() { | |
// Check if Smush Pro is active. | |
if ( ! class_exists( 'WP_Smush' ) ) { | |
return; | |
} | |
// File containing the async request class. | |
$file = WP_PLUGIN_DIR . '/wp-smush-pro/core/modules/background/class-async-request.php'; | |
// Check if async request file exists. | |
if ( ! file_exists( $file ) ) { | |
return; | |
} | |
// Get the file contents. | |
$content = file_get_contents( $file ); | |
// Check if we have content. | |
if ( ! $content ) { | |
return; | |
} | |
// Change POST to GET for async requests. | |
$new_content = str_replace( 'return wp_remote_post(', 'return wp_remote_get(', $content ); | |
// Update only if content changed. | |
if ( $new_content !== $content ) { | |
file_put_contents( $file, $new_content ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment