Reputation: 302
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.
Upvotes: 0
Views: 157
Reputation: 6345
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:
if ( ! function_exists( 'disable_password_reset' ) ) :
function disable_password_reset() {
return false;
}
add_filter ( 'allow_password_reset', 'disable_password_reset' );
endif;
then add_filter ( 'allow_password_reset', 'disable_password_reset' );
will not be executed if disable_password_reset()
already exists. If you don't want that, then you should call add_filter()
outside the if
block, as in your second example.
Upvotes: 3