Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

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 );
}
share|improve this answer
    
Ah! I see. Thank you! –  Chris Howard Jun 26 at 10:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.