Skip to content

Instantly share code, notes, and snippets.

@polevaultweb
Created January 8, 2016 16:03
Show Gist options
  • Save polevaultweb/d5e2af9150e0495d078b to your computer and use it in GitHub Desktop.
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.
<?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 );
}
@janumpallykalyan
Copy link

How to add this plugin it in wordpress ?

@Qara-Penimah
Copy link

Pluginception might be an option in add a custom plugin to wordpress. https://wordpress.org/plugins/pluginception/

@BurlesonBrad
Copy link

@janumpallykalyan
All you would need to do is download the file as it is and upload it via FTP to your /plugins folder

@petertwise
Copy link

To install the plugin using only the WordPress admin:

  1. click "Download ZIP" on this github page
  2. go to Plugins > Add New in the WordPress admin
  3. click "Upload Plugin" (top of the page near the title "Add Plugins"
  4. upload the zip you downloaded to install the plugin
  5. don't forget to activate it on the Plugins page

You definitely don't need Pluginception.

@travelmassive
Copy link

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