Dynamic-Image-Resize Plugin does not output anything

Ask the right guy

Which you just did, so… here’s your answer from the developer. 🙂

What does the right output tell us?

First of all, the public dynamic_image_resize() API function is just a wrapper for the singleton itself. When you take a closer look at the class, you’ll notice a __toString() method, which is the magical method that returns the output.

As you’ve seen from your var_dump(), you get back the exact object (the class name indicates that), but not the string. So the __toString() method didn’t trigger and therefore doesn’t call the output. It just called the __construct() method with your attributes, so you see the exact same thing set as the class properties, that you defined when calling the class.

How to “fix” something that isn’t broken?

The class, as stated previously, uses the __toString() method. This method – as most magical PHP methods – only trigger under a certain condition. In this case, when you echo the output.

So your solution would simply be to echo dynamic_image_resize(). Here’s it written quickly (not tested).

echo dynamic_image_resize( array(
     'src'     => array_shift( wp_get_attachment_image_src( 
         get_post_thumbnail_id( get_the_ID() )
        ,"Full"
     ) )
    ,'width'   => 60
    ,'height'  => 100
    ,'classes' => 'thumb'
) );

Leave a Comment