Skip to content

Instantly share code, notes, and snippets.

@tomjn
Last active August 10, 2020 17:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomjn/a7036d369d6f8082dd1eb256c651696e to your computer and use it in GitHub Desktop.
Save tomjn/a7036d369d6f8082dd1eb256c651696e to your computer and use it in GitHub Desktop.
Turns off the Unsplash CDN hotlinking when using the Unsplash plugin ( for paranoid people )
<?php
/**
* Plugin Name: Splish Splosh
* Version: 1.0.1
* Author: Tom J Nowell
* Author URI: https://tomjn.com/
* Description: Turns off the Unsplash CDN when using the Unsplash plugin
* Requires PHP: 5.6
* Requires at least: 4.9
* License: GPLv2+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
**/
add_action(
'plugins_loaded',
function () {
$plugin = \Unsplash\get_plugin_instance();
$hotlink = $plugin->hotlink;
remove_filter( 'content_save_pre', [ $hotlink, 'wp_get_attachment_url' ], 10 );
remove_filter( 'image_downsize', [ $hotlink, 'image_downsize' ], 10 );
remove_filter( 'the_content', [ $hotlink, 'hotlink_images_in_content' ], 99 );
remove_filter( 'wp_calculate_image_srcset', [ $hotlink, 'wp_calculate_image_srcset' ], 99 );
remove_filter( 'wp_get_attachment_image_src', [ $hotlink, 'wp_get_attachment_image_src' ], 10 );
},
1000,
0
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment