Skip to content

Instantly share code, notes, and snippets.

@simonrcodrington
Last active March 22, 2018 06:06
Show Gist options
  • Select an option

  • Save simonrcodrington/be60b6daae0b966a559878c4ba16d9d0 to your computer and use it in GitHub Desktop.

Select an option

Save simonrcodrington/be60b6daae0b966a559878c4ba16d9d0 to your computer and use it in GitHub Desktop.
Missing GD PHP Module warning in WordPress Media Settings page
<?php
/**
* Adds a notice to the Media Settings page inside of WP if the GB library is missing
*
* Used to warn the user that no images will be re-sized automatically on upload without the GD library
*/
class WPMissingGDNotice
{
private static $instance = null;
private function __construct()
{
add_action('admin_notices', [$this, 'displayAdminNotice']);
}
/**
* Display an admin notice warning about the missing GD library
*/
public function displayAdminNotice()
{
//trigger only if gd is not enabled
if (!extension_loaded('gd')) {
//trigger only for media settimngs page
$currentScreen = get_current_screen();
if ($currentScreen->base == 'options-media') {
?>
<div class="notice notice-error">
<p>
<?php _e('The PHP GD image library is missing from your server. WordPress will not create multiple re-sized image sizes for uploaded images.',
'sample-text-domain'); ?>
</p>
</div>
<?php
}
}
}
/**
* Get / set instance
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
}
$WPMissingGDNotice = WPMissingGDNotice::getInstance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment