I created a WordPress plugin using OOP. If the plugin hasn't been activated and a method is called in a theme file, it throws the PHP fatal error "call to undefined function".
What is the correct way of doing this in the event the plugin hasn't been enabled?
Should a check be made in every file where it's used within the theme directory to see if the class exists? Or should the error just be left as is and the user will know they have to enable the plugin based on the function name?
Here's what I would like to do:
if ( mypluginname_is_event_active() ) {
echo 'it is!';
}
However, the code above triggers the PHP fatal error if the plugin hasn't been activated.
The code below prevents the error from appearing, but it seems really clunky. Especially if it has to be done in every file where it's used under themes:
// begin top of file
$is_event_live = false;
if ( class_exists( 'MyPluginName' ) ) {
$is_event_live = mypluginname_is_event_active();
}
// end top of file
if ( $is_event_live ) {
echo 'it is!';
}