AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

[Solved] General question on hook triggers

3 Posts
2 Users
2 Reactions
1,096 Views
Posts: 212
 fawp
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@fawp)
Reputable Member
Joined: 7 years ago
[#51174]

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: 5774
 Sofy
Admin
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@sofy)
Support Team
Joined: 8 years ago

Yes, fawp, Everything is correct. 


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

Reputable Member
Posts: 212
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

Thanks @sofy and welcome back.


Share: