I was working on some php functions and I got confused with php syntax.
Here is the function.
Is this correct? to use add_filter inside function_exists check
if ( ! function_exists( 'disable_password_reset' ) ) :
function disable_password_reset() {
return false;
}
add_filter ( 'allow_password_reset', 'disable_password_reset' );
endif;
or this one is correct, to use add_filter outside function_exists check
if ( ! function_exists( 'disable_password_reset' ) ) :
function disable_password_reset() {
return false;
}
endif;
add_filter ( 'allow_password_reset', 'disable_password_reset' );
I was working on WordPress if that matters.
What you are trying to do is:
disable_password_reset()exists, and if not, create it.disable_password_reset()to a WordPress filter.If you do this:
then
add_filter ( 'allow_password_reset', 'disable_password_reset' );will not be executed ifdisable_password_reset()already exists. If you don’t want that, then you should calladd_filter()outside theifblock, as in your second example.