When looking in WP hooks’ code, I often see hooks that call themselves.

For example, this snippet from image_downsize():

function image_downsize($id, $size="medium") {

    if ( !wp_attachment_is_image($id) )
       return false;

    if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) {
       return $out;
    }

Why doesn’t this cause recursion?

Thanks

1 Answer
1

This:

apply_filters( 'image_downsize', false, $id, $size )

doesn’t call the image_downsize function, it applies any filters hooked to the image_downsize tag, which would be a different function.

The only way that would cause recursion is if the filter you hook in turn called that function:

add_filter( 'image_downsize', 'wpd_downsize', 20, 3 );
function wpd_downsize( $return, $id, $size ){
    // collapse the universe
    return image_downsize( $id, $size );
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *