Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active August 18, 2023 21:14
Show Gist options
  • Save wpmudev-sls/95701b75764886e15f02337442212b6b to your computer and use it in GitHub Desktop.
Save wpmudev-sls/95701b75764886e15f02337442212b6b to your computer and use it in GitHub Desktop.
smush-mu-fix-db-version-mis-detection.php
<?php
/**
* Plugin Name: [Smush Pro] - Fix wrong detection of DB version on some DBs
* Description: [Smush Pro] - For some DB version that starts with numbers other than DB version like 5.5.5-10.4.20-MariaDB-1
* Jira: SLS-5120
* Author: Abdoljabbar Bakhshande
* Author URI: https://wpmudev.com
* License: GPLv2 or later
*
* @package WordPress
*/
if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; }
add_action( 'after_setup_theme', 'smush_mu_fix_db_version_mis_detection', 100 );
function smush_mu_fix_db_version_mis_detection() {
if ( class_exists( 'WP_Smush' ) ) {
$old_md5 = get_site_option( 'smush-mu-fix-db-version' );
$original_file = WP_PLUGIN_DIR . '/wp-smush-pro/core/class-server-utils.php';
if ( @file_exists( $original_file ) ) {
$md5 = md5_file( $original_file );
if ( $old_md5 !== $md5 ) {
$content = @file_get_contents( $original_file );
if ( ! strpos( $content, '10.4.20' ) ) {
$custom_code = base64_decode( 'cHJpdmF0ZSAkbXlzcWxfdmVyc2lvbiA9ICcxMC40LjIwJw==' );
$content = str_replace( 'private $mysql_version', $custom_code, $content );
@file_put_contents( $original_file, $content );
$md5 = md5_file( $original_file );
}
update_site_option( 'smush-mu-fix-db-version', $md5 );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment