Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active April 2, 2024 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/19d7f1832c3959fa94ab4b0d1f681cef to your computer and use it in GitHub Desktop.
Save wpmudev-sls/19d7f1832c3959fa94ab4b0d1f681cef to your computer and use it in GitHub Desktop.
[Hummingbird Pro] Fix compatibility issue with wpDiscuz and Gravatar
<?php
/**
* Plugin Name: [Hummingbird Pro] Fix compatibility issue with wpDiscuz and Gravatar
* Description: Prevents Hummingbird from caching (guest) Gravatars generated by wpDiscuz infinitely, consuming disk space
* Author: Anderson Salas @ WPMUDEV
* Task: SLS-5966
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
add_action( 'plugins_loaded', function() {
if ( ! defined( 'WPHB_VERSION' ) ) {
return; // Hummingbird is not installed/enabled.
}
if ( ! defined( 'WPDISCUZ_DIR_PATH' ) ) {
return; // wpDiscuz is not installed/enabled.
}
$gravatar = \Hummingbird\WP_Hummingbird::get_instance()->core->modules['gravatar'] ?? null;
if ( null === $gravatar ) {
return; // Gravatar module not loaded.
}
$enabled = $gravatar->get_options()['enabled'] ?? null;
if ( true !== $enabled ) {
return; // Gravatar module not enabled.
}
$removed = remove_filter( 'get_avatar_data', [ $gravatar, 'get_avatar_data' ], 10, 2 );
add_filter( 'get_avatar_data', function( $args, $id_or_email ) use ( $gravatar ) {
if ( '@example.com' === substr( $id_or_email, -12 ) && 25 === strlen( $id_or_email ) ) {
return $args; // Do not cache if it's a dummy email from wpDiscuz ([UUID]@example.com)
}
return call_user_func_array( [ $gravatar, 'get_avatar_data' ], [ $args, $id_or_email ] );
}, 10, 2 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment