Notifications
Clear all

[Solved] General question on hook triggers

3 Posts
2 Users
2 Reactions
463 Views
Posts: 201
 fawp
Topic starter
(@fawp)
Reputable Member
Joined: 5 years ago

I have some checks (e.g. in functions.php) to ensure that if a plugin (e.g. wpForo) is disabled, any custom code related to that plugin won't break the site.

In these cases a typical function will look like this (example with wpForo-related check):

function my_custom_wpforo_function() {
	if( function_exists('WPF') ) {
	    // do something
	}
}
add_action('my_hook', 'my_custom_wpforo_function');

 

but there will be cases where the code in question is inside a specific wpForo event. For example, wpforo_loop_hook is triggered only inside a wpForo loop, so if the plugin is disabled, this event should never be triggered.

Am I right in thinking that in these types of events (that are only triggered if the plugin is active) I don't need to add a plugin check, and that I can simply leave the code as it is (example below) because it will never be executed if the plugin is disabled?

function my_custom_wpforo_event_function(){
        // do something
}
add_action( 'wpforo_loop_hook', 'my_custom_wpforo_event_function' );

 

Thank you.

2 Replies
Sofy
Posts: 4900
 Sofy
Admin
(@sofy)
Support Team
Joined: 7 years ago

Yes, fawp, Everything is correct. 

1 Reply
 fawp
(@fawp)
Joined: 5 years ago

Reputable Member
Posts: 201

Thanks @sofy and welcome back.