WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Auto Post Thumbnail] Not working on my posts (1 post)

  1. rbredow
    Member
    Posted 3 years ago #

    I love the idea of this plugin--but for some reason I haven't been able to get it working for my blog. I've added some logging to the plugin and I think I've found a bug in the regex that is trying to put the images from the posts's body. If I've diagnosed it correctly, I'm not sure how it works for everyone else (perhaps they are not trying to make it work with images managed by Wordress' media library).

    Here's what I've learned so far. This line:

    // Get all images from post's body
        preg_match_all('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i', $post[0]->post_content, $matches);

    With post bodies that have image tags that like this:

    <img src="/images/2007/06/113813951_78111f7a1b_m.jpg" alt="Ansel Adams Photograph LA" title="Ansel Adams Photograph LA" width="233" height="240" class="alignleft size-full wp-image-44" />

    Leaves the $match variable with a list of matches that looks like this:

    <img src="/images/2007/06/113813951_78111f7a1b_m.jpg
    <img src="/images/2009/04/market-st-470x312.jpg

    And then the subsequent code in the plugin searches those matches to look for tags like wp-image-#### to hook up the thumbnails automatically. Since the initial regex is not capturing all the image tags, the rest of the plugin doesn't work and none of my thumbnails get hooked up properly.

    I was going to try to fix that expression but I know enough about regex to know that I wouldn't get it right.

    Am I the only one? Is there a fix to the regex that would make this work?

    Thanks in advance for your help and for a great plugin.

    Rob

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags