{"id":310,"date":"2018-11-07T01:13:01","date_gmt":"2018-11-07T06:13:01","guid":{"rendered":"http:\/\/www.oostdyk.com\/randy\/blog\/?p=310"},"modified":"2018-11-07T01:30:43","modified_gmt":"2018-11-07T06:30:43","slug":"removing-embedded-flickr-images-from-wordpress","status":"publish","type":"post","link":"https:\/\/www.oostdyk.com\/randy\/blog\/2018\/11\/07\/removing-embedded-flickr-images-from-wordpress\/","title":{"rendered":"Removing embedded Flickr images from WordPress"},"content":{"rendered":"<p>Yesterday, I received an email from Flickr with the subject line &#8220;Important updates to your Flickr account.&#8221; 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.<\/p>\n<p>Since about 5 years ago, a friend has been uploading images to Flickr, and embedding them in their WordPress site with the <a href=\"https:\/\/github.com\/hiddentao\/wp-flickr-embed\">WP Flickr Embed plugin<\/a>. Now we&#8217;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 &#8220;Pro&#8221; service. Neither of the options suited my frugal, yet lazy personality. Thankfully, I <a href=\"https:\/\/www.wpbeginner.com\/plugins\/how-to-import-external-images-in-wordpress\/\">stumbled across<\/a> an <a href=\"https:\/\/wordpress.org\/plugins\/auto-upload-images\/\">excellent WordPress plugin<\/a> 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.<!--more--><\/p>\n<p>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.<\/p>\n<p>Within <code>public function save($post)<\/code><\/p>\n<p>after<br \/>\n<code>$content = $post->post_content;<\/code><\/p>\n<p>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:<br \/>\n<code><br \/>\n$content = preg_replace('\/((?:&lt;a .*)flickr.*&quot;&gt;(&lt;img.*&gt;)&lt;\\\/a&gt;+)\/', '$2', $content);<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday, I received an email from Flickr with the subject line &#8220;Important updates to your Flickr account.&#8221; 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 &hellip; <a href=\"https:\/\/www.oostdyk.com\/randy\/blog\/2018\/11\/07\/removing-embedded-flickr-images-from-wordpress\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Removing embedded Flickr images from WordPress<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-310","post","type-post","status-publish","format-standard","hentry","category-announce"],"_links":{"self":[{"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/posts\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":5,"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/posts\/310\/revisions\/315"}],"wp:attachment":[{"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oostdyk.com\/randy\/blog\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}