Created
January 8, 2016 16:03
-
-
Save polevaultweb/d5e2af9150e0495d078b to your computer and use it in GitHub Desktop.
Restores the functionality of copying of HiDPI (@2x) images during S3 offload of attachments.
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 | |
/* | |
Plugin Name: WP Offload S3 - Copy HiDPI Images | |
Description: Restores the functionality of copying of HiDPI (@2x) images during S3 offload of attachments. | |
Author: Delicious Brains | |
Version: 1.0 | |
Author URI: https://deliciousbrains.com/ | |
*/ | |
add_filter( 'as3cf_attachment_file_paths', 'wpos3_hipdi_add_hidpi_file_paths' ); | |
function wpos3_hipdi_add_hidpi_file_paths( $paths ) { | |
global $as3cf; | |
foreach ( $paths as $path ) { | |
$paths[] = $as3cf->apply_file_suffix( $path, '@2x' ); | |
} | |
return $paths; | |
} | |
add_filter( 'as3cf_find_replace_url_pairs', 'wpos3_hipdi_add_hidpi_find_replace_url_pairs', 10, 7 ); | |
function wpos3_hipdi_add_hidpi_find_replace_url_pairs( $find_replace_pairs, $file_path, $old_url, $new_url, $meta, $old_filepath, $old_meta ) { | |
global $as3cfpro; | |
$file_name = basename( $file_path ); | |
$old_filename = $file_name; | |
if ( ! is_null( $old_filepath ) ) { | |
$old_filename = basename( $old_filepath ); | |
} | |
// Replace URLs for @2x images used by most HiDPI plugins | |
$hidpi_images = array(); | |
foreach ( $find_replace_pairs as $image ) { | |
$hidpi_path = $as3cfpro->apply_file_suffix( $image['old_path'], '@2x' ); | |
$hidpi_file = basename( $hidpi_path ); | |
$old_hidpi_file = $hidpi_file; | |
if ( ! is_null( $old_filepath ) ) { | |
$existing_path = str_replace( basename( $image['new_url'] ), basename( $image['old_url'] ), $image['old_path'] ); | |
$old_hidpi_path = $as3cfpro->apply_file_suffix( $existing_path, '@2x' ); | |
$old_hidpi_file = basename( $old_hidpi_path ); | |
} | |
$hidpi_images[] = array( | |
'old_url' => str_replace( $old_filename, $old_hidpi_file, $old_url ), | |
'new_url' => str_replace( $file_name, $hidpi_file, $new_url ), | |
); | |
} | |
return array_merge( $find_replace_pairs, $hidpi_images ); | |
} |
Doesn't work for me with latest version of WP Offload S3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install the plugin using only the WordPress admin:
You definitely don't need Pluginception.