Yesterday, I received an email from Flickr with the subject line “Important updates to your Flickr account.” They wanted to inform me that they would soon be enforcing limitations on free accounts, including a limitation on the number of images. As of February 5th, 2019, they intend to delete older images from free accounts, excepting only the most recent 1000 images.
Since about 5 years ago, a friend has been uploading images to Flickr, and embedding them in their WordPress site with the WP Flickr Embed plugin. Now we’re faced with the choice of going back and manually removing those images and replacing them with locally-hosted images, which would be incredibly time-consuming and tedious task, or paying Flickr a hostage fee to continue hosting under their “Pro” service. Neither of the options suited my frugal, yet lazy personality. Thankfully, I stumbled across an excellent WordPress plugin that does a wonderful job of scraping embedded images from posts, adding them to the WordPress media library, and finally replaces the embedded image with a locally-hosted version.
Unfortunately, that plugin left behind the link to the Flickr version of the image. A quick modification of the WpAutoUpload.php file, using the magic of Regular Expressions, would help strip out the last vestiges of Flickr.
Within public function save($post)
after
$content = $post->post_content;
the following line does the dirty work of locating all instances of links to flickr and discarding them, while preserving the image source link contained within:
$content = preg_replace('/((?:<a .*)flickr.*">(<img.*>)<\/a>+)/', '$2', $content);