Skip to content

Instantly share code, notes, and snippets.

@logoscreative
Created April 12, 2019 22:08
Show Gist options
  • Save logoscreative/8ba836ce4a1e9695c566f97b991957b0 to your computer and use it in GitHub Desktop.
Save logoscreative/8ba836ce4a1e9695c566f97b991957b0 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Envira CDN Fix
* Plugin URI: https://logoscreative.com
* Description: Support images on a CDN with Envira
* Version: 1.0
* Author: Logos Creative
* Author URI: https://logoscreative.com
*/
add_filter('envira_gallery_output', 'evermore_filter_envira_content', 10, 2);
add_filter('envira_gallery_link_href', 'evermore_filter_envira_link_href', 10, 5);
add_filter('envira_gallery_pre_data', 'evermore_envira_cdn_compat', 10, 2);
function evermore_filter_envira_content($gallery, $data)
{
if (isset($_GET['cliffdebug']) && $_GET['cliffdebug'] === 'sure') {
//var_dump($gallery);
//var_dump($data);
}
return apply_filters('as3cf_filter_post_local_to_s3', $gallery);
}
function evermore_filter_envira_link_href($id, $item, $data, $i, $mobile)
{
if (isset($_GET['cliffdebug']) && $_GET['cliffdebug'] === 'sure') {
var_dump($item);
var_dump($data);
}
//return apply_filters( 'as3cf_filter_post_local_to_s3', $gallery );
}
function evermore_envira_cdn_compat($data, $gallery_id)
{
$images = $data['gallery'];
foreach ($images as $attachment_id => $image) {
if ($image['src']) {
$data['gallery'][$attachment_id]['src'] = apply_filters('as3cf_filter_post_local_to_s3', $image['src']);
}
if ($image['thumb']) {
$data['gallery'][$attachment_id]['thumb'] = apply_filters('as3cf_filter_post_local_to_s3', $image['thumb']);
} else {
$data['gallery'][$attachment_id]['thumb'] = apply_filters('as3cf_filter_post_local_to_s3', wp_get_attachment_thumb_url($attachment_id));
}
}
if (isset($_GET['cliffdebug']) && $_GET['cliffdebug'] === 'sure') {
var_dump($data);
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment