• Hi,

    I love the new wp_thumbnail_max_side_length filter, but wondering how to get access to the $file parameter sent with it. In the admin-functions.php it says:

    $max_side = apply_filters( ‘wp_thumbnail_max_side_length’, 128, $attachment_id, $file );

    So I am assuming its sending $file as a parameter with but I fail to access it in my own function:

    function custom_thumbsize( $size,$attachment_id, $file )
    {
    $th_width = 565;
    $th_height = 691;

    // figure out the longest side
    $image_attr = getimagesize( $file );
    if ( $image_attr[0] > $image_attr[1] ) {
    $th_size = $th_width;
    //width is > height
    } else if ( $image_attr[0] < $image_attr[1] ) {
    $th_size = $th_height;
    //height > width
    }
    return $th_size;

    }

    add_filter( “wp_thumbnail_max_side_length”, “custom_thumbsize” );

    Any help greatly appreciated,

    thanks

    TT

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Change this:
    add_filter( "wp_thumbnail_max_side_length", "custom_thumbsize" );

    To this:
    add_filter( 'wp_thumbnail_max_side_length', 'custom_thumbsize', 10, 3 );

    I think that’s the issue here. The extra parameters are optional. The 10 specifies the priority (10 is the default), the 3 specifies how many parameters your function can accept (1 is the default).

    Thread Starter thomastraum

    (@thomastraum)

    Woohoo, that was it, thanks so much Otto42

    Hi thomastraum,

    Have you made this into a plugin at all? I would be quite interested in it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_thumbnail_max_side_length $file parameter’ is closed to new replies.