Created
January 13, 2024 01:24
-
-
Save patrickfreitasdev/1da775be2d50eaa60e1d8a20d6038c6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// 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