WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 '14 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.