I'm learning WordPress plugin development using OOP approach. In most resources before declaring a class there is usually a check if class exists class_exists()
.
Is it a good approach to check this or can it be omitted?
Also, I was wondering if it's a good approach to check in one block if none of plugin's classes exist. Even if one class already exists, the whole plugin can't work correctly as it can't re-declare a class. So, instead having class_exists()
through the code, I was wondering if it's better to have it in one block when activating a plugin, something like:
if ( class_exists( 'Class_Name_One' )
|| class_exists( 'Class_Name_Two' )
|| class_exists( 'Class_Name_Three' )
|| class_exists( 'Class_Name_Four' ) ) {
exit;
}
Any advice and feedback is hugely appreciated.
EDIT If there is a conflict with another plugin that declares the same class names, I want to deactivate my plugin and display admin notice.