Support » Plugin: Postie » Hook/feature request: One image on top, rest on bottom

  • Resolved Stevish

    (@stevish)


    Wayne,

    Thanks so much for this excellent plugin! We use it extensively!

    My current problem is that we’d like to modify the image handling slightly for our users. In the past (by customizing the plugin files directly which we refuse to do again as it was a bad idea), we had it set up that if multiple images were attached, and no image placement tags (#img1# etc) were used, the first attached image would go at the top of the post, and the rest of the images would be placed on the bottom. I am now trying to accomplish this through the hooks you have available, but can’t find a workable solution.

    So here’s my request: Could you put in a filter hook for the $pics variable in the filter_ReplaceImagePlaceHolders function? I’d think it could be inserted right after line 2505 of postie-functions.php so that lines 2505-2507 become:

            if ($autoadd_images) {
                $pics = apply_filters('postie_autoadd_images', $pics);
                if ($config['images_append']) {

    Or even better would be to build $pics as an array rather than a single string, and filter the array before imploding it. For that, starting at line 2498, it would become something like:

                        $pics[] = $imageTemplate;
                    } else {
                        DebugEcho("gallery detected, not inserting images");
                    }
                }
                $i++;
            }
            if ($autoadd_images) {
                $pics = apply_filters('postie_autoadd_images', $pics);
                $pics = implode('', $pics);
                if ($config['images_append']) {

    And up on line 2455:
    $pics = array();

    Any chance you might be willing to incorporate this or something like it? I’m willing to put it into the form of a pull request if you can point me in the direction of your VCS.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Stevish

    (@stevish)

    Oh, those apply_filters calls would need to include the $content variable so we could place the images in the content, though I could always accomplish that part through the ‘postie_post_before’ filter… but this would be a little more elegant:

    list($pics, $content) = apply_filters('postie_autoadd_images', array('pics' => $pics, 'content' => $content));

    Only a LITTLE more elegant, mind, since both parameters would need to be editable and apply_filters only passes the firs argument by reference.

    Plugin Author Wayne Allen

    (@wayneallen-1)

    I’m not sure what you are trying to capture here that is different than postie_post_before.

    If you don’t want Postie to convert the attachments to html img elements so you can do it all yourself by setting “Use custom image field for attachments” to “yes” then get all the attached media files and manipulate the content in postie_post_before.

    Thread Starter Stevish

    (@stevish)

    The reason postie_post_before won’t work for me is that the #img%# tags are already processed by then. This means I can’t differentiate between images that were placed at the top by the user on purpose, and images that were placed at the top because the user didn’t add an image tag anywhere else.

    I really do want postie to convert the images for me (I don’t want to reinvent the wheel), I just want a way to filter where the extra images (that aren’t placed explicitly with #img%# tags) are placed (specifically, the first one at the top of the post, and the rest at the bottom).

    Plugin Author Wayne Allen

    (@wayneallen-1)

    OK, I think I understand what you are trying to do. However, in order to make it more usable in the general sense how about something like:

    postie_place_media($html_fragment, $media_id) – a filter that allows you to change the html that is replacing the current #img#. Called for every placement. In your case you could keep track of which images were handled.

    postie_place_media_before, postie_place_media_after – filter that allows you to change the html for media being placed before or after the content. Called for each media file that wasn’t placed. You could keep track of which file was first and hold onto it until postie_post_before.

    Thread Starter Stevish

    (@stevish)

    Yeah, I think that would be workable!

    Plugin Author Wayne Allen

    (@wayneallen-1)

    This has been implemented in 1.8.10 available later today.

    See also http://postieplugin.com/extending/

    Thread Starter Stevish

    (@stevish)

    Shiny! Updating Postie and playing with the new features is on my list of things to do today or tomorrow.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hook/feature request: One image on top, rest on bottom’ is closed to new replies.