Skip to content

Instantly share code, notes, and snippets.

@patrickfreitasdev
Created January 13, 2024 01:24
Show Gist options
  • Save patrickfreitasdev/1da775be2d50eaa60e1d8a20d6038c6c to your computer and use it in GitHub Desktop.
Save patrickfreitasdev/1da775be2d50eaa60e1d8a20d6038c6c to your computer and use it in GitHub Desktop.
<?php
// Under development
if (!defined('ABSPATH')) {
exit;
}
class WDEV_Smush_GrapghQL_Support
{
public function __construct()
{
add_filter('graphql_resolve_field', array($this, 'add_smush_suport_to_full_size_image'), 10, 9);
}
public function wp_smush_generate_cdn_url($src)
{
return WP_Smush::get_instance()->core()->mod->cdn->generate_cdn_url($src);
}
public function add_smush_suport_to_full_size_image($value, $source, $args, $context, $info, $type_name, $field_key)
{
if ($field_key === 'mediaItemUrl' ){
$updated_value = $this->wp_smush_generate_cdn_url($value);
return $updated_value;
}
return $value;
}
}
add_action('plugins_loaded', function () {
if (!class_exists('WP_Smush')) {
return;
}
new WDEV_Smush_GrapghQL_Support();
}, 99);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment