Tagged: plugin Toggle Comment Threads | Keyboard Shortcuts

  • Christopher Finke 9:26 am on October 30, 2014 Permalink | Reply
    Tags: flickr, , plugin,   

    I’ve posted a code snippet I used to sideload images from Flickr into WordPress, specifically for http://foodirl.com/ I originally stored all of my images on Flickr because I started the blog on Tumblr, knowing that I would move it later (which I did, to Crowd Fusion and then to WordPress).


    <?php
    /**
    * Retroactively sideload images referenced from Flickr.
    */
    $flickr_sideload_media_id = null;
    function flickr_sideload_get_media_id( $media_id ) {
    global $flickr_sideload_media_id;
    $flickr_sideload_media_id = $media_id;
    }
    function flickr_sideload_init() {
    global $flickr_sideload_media_id;
    if ( isset( $_GET['do_flickr_sideload'] ) ) {
    add_action( 'add_attachment', 'flickr_sideload_get_media_id' );
    require_once( ABSPATH . 'wp-admin/includes/media.php' );
    require_once( ABSPATH . 'wp-admin/includes/file.php' );
    require_once( ABSPATH . 'wp-admin/includes/image.php' );
    $offset = 0;
    $limit = 10;
    while ( $posts = get_posts( 'posts_per_page=' . $limit . '&offset=' . $offset ) ) {
    $offset += $limit;
    foreach ( $posts as $post ) {
    if ( preg_match_all( '/(?<atag><a[^>]+href="(?<href>[^"]+)"[^>]*>)\s*(?<imgtag><img[^>]+src="(?<src>[^"]+)"[^>]+>)\s*(<\/a>)?/i', $post->post_content, $images, PREG_SET_ORDER ) ) {
    $post_content = $post->post_content;
    foreach ( $images as $image ) {
    if ( strpos( $image['src'], '.flickr.com/' ) !== false ) {
    $description_matches = array();
    $description = '';
    if ( ! empty( $image['atag'] ) ) {
    preg_match_all( '/title="(?<title>[^"]+)"/i', $image['atag'], $description_matches, PREG_SET_ORDER );
    }
    if ( ! empty( $description_matches ) ) {
    $description = $description_matches[0]['title'];
    }
    else {
    preg_match_all( '/alt="(?<alt>[^"]+)"/i', $image['imgtag'], $description_matches, PREG_SET_ORDER );
    if ( ! empty( $description_matches ) ) {
    $description = $description_matches[0]['alt'];
    }
    }
    $image_html = media_sideload_image( $image['src'], $post->ID, $description );
    preg_match_all( '/width="(?<width>[0-9]+)"/', $image['imgtag'], $width_matches, PREG_SET_ORDER );
    preg_match_all( '/height="(?<height>[0-9]+)"/', $image['imgtag'], $height_matches, PREG_SET_ORDER );
    if ( ! empty( $width_matches ) && ! empty( $height_matches ) ) {
    $size = array( $width_matches[0]['width'], $height_matches[0]['height'] );
    }
    else {
    $size = 'full';
    }
    if ( ! empty( $image['atag'] ) ) {
    $image_html = wp_get_attachment_link( $flickr_sideload_media_id, $size );
    }
    else if ( $size != 'full' ) {
    $image_html = str_replace( '<img ', '<img width="' . $size[0] . '" height="' . $size[1] . '" ', $image_html );
    }
    $post_content = str_replace( $image[0], $image_html, $post_content );
    }
    }
    if ( $post_content != $post->post_content ) {
    wp_update_post( array( 'ID' => $post->ID, 'post_content' => $post_content ) );
    }
    }
    }
    }
    die;
    }
    }
    add_action( 'init', 'flickr_sideload_init' );

    Stick it in mu-plugins and then load wp-admin/?do_flickr_sideload. It doesn’t have lots of error checking, but it worked flawlessly for FoodIRL’s 160+ posts.

     
    • A. I. Sajib 5:01 pm on November 4, 2014 Permalink | Reply

      Hi,

      Thanks for your comment on my blog. I crawled back to your blog here and was curious if I could ask two questions regarding Flickr images on WordPress.

      The first question is, is there any easier way that you know of that lets authors (editors and authors, to be precise) add single Flickr image from a preset account? I found WP Flickr Embed plugin to work exactly how I want it, but I’m hitting Ajax Error repeatedly. I searched their support forum but haven’t found a solution.

      Secondly, do you know if there’s any easy way (a plugin would be handy) for us to replace all WordPress featured images (that are used as thumbnails on homepage and elsewhere on the site) by a source URL to a remote image? I store all my images to either Flickr or Google+ and link to them in order to reduce space and bandwidth on my hosting. It would make my life a lot easier if there was a way to not have to upload featured images in order for my posts to have a thumbnail image on the front page. I once worked for a publication that allowed something like this. They would add a custom field and a link to the remote image and that worked. I haven’t figured out how to do this easily.

      I understand this can be difficult and may differentiate from theme to theme. But still I’m wondering if you know of any easier solution to either of the questions above.

      Thanks for your time and answer.

      Regards.

      Like

      • Christopher Finke 6:43 pm on November 4, 2014 Permalink | Reply

        The first question is, is there any easier way that you know of that lets authors (editors and authors, to be precise) add single Flickr image from a preset account?

        I haven’t used anything that does this, but wp-flickr-press looks like it’s probably closest to what you want. Of you can just put the URL to the Flickr photo page (e.g., https://www.flickr.com/photos/cfinke/4291588352/) on its own line in your post, and WordPress will automatically embed it.

        Secondly, do you know if thereโ€™s any easy way (a plugin would be handy) for us to replace all WordPress featured images (that are used as thumbnails on homepage and elsewhere on the site) by a source URL to a remote image?

        I’m not aware of one, but if you’re ok with hosting the images yourself, you can offload bandwidth to Automattic by using Jetpack’s Photon feature: http://jetpack.me/support/photon/

        Liked by 1 person

        • A. I. Sajib 2:15 am on November 5, 2014 Permalink

          The embedding option is definitely amazing. The only problem is it doesn’t stretch to the full width of the content area. I wish there were ways to do this. I’m going to check out the plugin you linked to. Thanks for the recommendation.

          I used Photon for a while but over time the more posts I publish the number of little image files increase on my server causing some sort of issues (I’m not very technically knowledgeable on server side issues). But thanks for your help. Perhaps I can convince someone to develop a plugin for me. ๐Ÿ™‚

          Have a nice day.

          Like

        • A. I. Sajib 2:38 am on November 5, 2014 Permalink

          Hi again,

          I just wanted to say the plugin you recommended does exactly what I’m looking for. Though I needed to create an app on Flickr to get the API keys.

          I can’t thank you enough for the link. ๐Ÿ™‚

          Like

  • Christopher Finke 1:12 pm on January 20, 2014 Permalink | Reply
    Tags: keyring, plugin, reddit,   

    A new plugin and theme for Keyring users 

    I’ve posted a new plugin that works with Keyring Social Importers to allow you to import activity from Reddit and a lifestreamy theme to show off all of the data that Keyring Social Importers can transfer to WordPress. Soon, you’ll be able to back up the entire Internet to a WordPress blog.

     
  • Christopher Finke 2:30 pm on November 26, 2013 Permalink | Reply
    Tags: plugin,   

    IM-porter plugin for WordPress 

    I released a new WordPress plugin this morning: IM-porter: Import your chat transcripts into WordPress. I wanted to save some decade-old AIM logs, so I wrote an importer to convert them into posts on a private blog. While I was doing that, I found more chat and IRC logs, so I extended the importer to handle those too.

    IM-porter is extendable by other plugins too; to add support for a chat log format, just implement the abstract methods in the Chat_IMporter_Format class and add the class name to the array filtered by the chat_importer_formats filter.

     
    • julien51 2:42 pm on November 26, 2013 Permalink | Reply

      Chris, I really like your idea of making WordPress a complete “vault” for ones entire web identity. That’ very #indieweb!

      Like

      • Christopher Finke 5:12 pm on November 26, 2013 Permalink | Reply

        Thanks Julien, it’s become a passion of mine lately. Some day, I hope to have a single browseable, searchable archive of all of my online activity, and it will most likely be powered by WordPress.

        Like

  • Christopher Finke 10:30 am on October 9, 2013 Permalink | Reply
    Tags: , , plugin,   

    Improving Post Previews 

    In WordPress ticket #25546, I propose that the features of my Inline Preview plugin be included in core. Come join the discussion!

     
  • Christopher Finke 11:07 pm on July 26, 2013 Permalink | Reply
    Tags: idea, plugin   

    Idea: Chaos Monkey WordPress plugin, which would randomly cause external HTTP requests to fail, disable other plugins, simulate DB unavailability — anything bad that might happen on a WordPress site that you might want to ensure doesn’t bring your site down entirely.

    See also: The Netflix Chaos Monkey

     
  • Christopher Finke 2:52 pm on June 24, 2013 Permalink | Reply
    Tags: extend, , plugin   

    Inline Preview is now available via Extend: http://wordpress.org/plugins/inline-preview/

    The latest version has a resizeable, collapsable, auto-refreshing preview frame, and it also improves your self-esteem. Check it out now!

     
  • Christopher Finke 1:22 am on April 25, 2013 Permalink | Reply
    Tags: plugin   

    Idea a WordPress plugin that lets you easily… 

    Idea: a WordPress plugin that lets you easily generate a Chat-formatted post from any comment thread on your site. Perfect for those times when you want to promote the interesting content that arises in the discussion following a post.

     
  • Christopher Finke 12:36 pm on October 22, 2012 Permalink | Reply
    Tags: , plugin   

    This weekend, I published a long-awaited plugin called Formategory. It lets you create post templates on a per-category basis, and it’s now on Extend.

     
  • Christopher Finke 10:51 am on October 16, 2012 Permalink | Reply
    Tags: plugin   

    I wrote a quick plugin this morning to export all of a site’s posts as simple HTML files. Here’s the background on the plugin, and here’s the sourcecode. Here’s an example of the plugin in action on my main blog.

     
  • Christopher Finke 10:04 pm on October 15, 2012 Permalink | Reply
    Tags: plugin   

    I’ve updated my Feed Statistics WordPress plug-in to take advantage of all of the wonderful features added to WordPress in the last two years.

    If you use WordPress as your primary feed distribution mechanism (instead of FeedBurner or a similar service), try out the plugin and get a good idea of how many people you’re reaching. Track total subscribers, post views, and link clickthroughs.

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel