If you follow official guide, you will always include TGM Plugin Activation file. Most of the times you won’t need this additional 94 KB. In this case, you can use conditional loading very simply.
First, make function for registration as suggested and hook it to specific TGM Plugin Activation action. Then, create a new function (or put code inside existing one) that should be loaded before init with priority 10 (you can even hook it to init with higher priority).
In this example, we require plugin Posts 2 Posts and TGM Plugin Activation file is placed inside child inc
directory. You only need to check if your requested plugin is loaded, for example, Posts 2 Posts uses function _p2p_load()
in its main file.
So the code is:
function md_tgmpa_init() {
// Load TGM Plugin Activation
if ( ! function_exists( '_p2p_load' ) ) {
require_once dirname( __FILE__ ) . '/inc/class-tgm-plugin-activation.php';
}
}
add_action( 'init', 'md_tgmpa_init', 7 );