I have two versions of the same plugin - one is a free version on WordPress.org and the other is a paid upgrade. Both versions use the same function names and so can't be activated at the same time. When someone installs and activates the paid version before deactivating the free version currently a Fatal Error is displayed stating 'Fatal error: Cannot redeclare abc_function() (previously declared in ...)'.
I'm trying to add something to the register_activation_hook for the paid version which either automatically deactivates the free version or displays a wp_die notice asking them to deactivate the free version. I can get these to work, but the problem is that they don't seem to be running early enough and so I get the redeclared function fatal error. This is what I'm using:
function abc_activate() {
if ( function_exists('abc_function') ) die( "Please deactivate the free version..." );
}
register_activation_hook( __FILE__, 'abc_activate' );
I've also tried attaching the wp_die and deactivate_plugins functions to an admin_init action, but that also doesn't seem to run before the fatal error. Eg:
function abc_warning_message() {
wp_die( "Please deactivate the free version of the plugin..." );
deactivate_plugins( 'abc-plugin-name' );
}
add_action( 'admin_init', 'abc_warning_message' );
Does anyone have any idea what I might be doing wrong, or whether it's even possible to call a function before a fatal error is triggered due to the duplicate function names? Worst case scenario I can go through the plugin and rename all of the function names, but I'd love to be able to get this working.
Thanks in advance for any help!
John