Run function on plugin activation before plugin is loaded

WordPress is not magic. If you add and action hook (register_activation_hook just add an action hook) to WordPress be able to read and run it, have to load your main plugin file, it can’t guess its content.

And if WordPress load your main plugin file, it will load all the functions defined there (or in files straight included from there) so you get the fatal error.

If you want to do that, you need to load all your functions after WordPress parsed your main plugin file, both files if both version are activated.

Main plugin file of free plugin should contain only something like this:

add_action( 'plugins_loaded', 'myplugin_require_everything_free', 100 );

function myplugin_require_everything_free() {
  // require all free plugin files here
}

and no more code. (of course on top of file you will have the plugin headers).

Main plugin file in the paid version should contain only something like this:

add_action( 'plugins_loaded', 'myplugin_require_everything_paid', 1 );

function myplugin_require_everything_paid() {

  if ( function_exists( 'myplugin_require_everything_free' ) ) {
     remove_action( 'plugins_loaded', 'myplugin_require_everything_free' );
     deactivate_plugins( 'abc-plugin-name-free' );
  }
  // require all paid plugin files here
}

Both functions run on same hook, when both file have been parsed, but the paid plugin function runs first, because has as an higher priority.

If paid version functions finds that free version is activated, it removes the action free version file added, deactivate free version plugin and only after that loads the files that contain plugin functions.

In this way no conflict may happen…