Try this out, it’s commented, so that should help you understand it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php /* Plugin Name: Child Plugin Description: Parent Plugin should be installed and active to use this plugin. Version: 1.0.0 */ register_activation_hook( __FILE__, 'child_plugin_activate' ); function child_plugin_activate(){ // Require parent plugin if ( ! is_plugin_active( 'parent-plugin/parent-plugin.php' ) and current_user_can( 'activate_plugins' ) ) { // Stop activation redirect and show error wp_die('Sorry, but this plugin requires the Parent Plugin to be installed and active. <br><a href="' . admin_url( 'plugins.php' ) . '">« Return to Plugins</a>'); } } |
Notice that I’m not using deactivate_plugins( $plugin ); as for some reason it does not work. So I used wp_die to cancel the activation redirection and inform the user.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.