After testing I found that the currently accepted answer by Aryan, didn't check if the dependency was activated, only if it existed.
This solution will show an error and stop activation if the dependency is missing, and show an error notice if it is later deactivated.
This uses the built in wordpress multisite function
is_plugin_active_for_network($plugin)
but for single site wordpress installs could be substituted for
is_plugin_active($plugin)
I also post an error notice at the network level if the dependency is later deactivated. Using the hook:
network_admin_notices
For single site wordpress instead use
admin_notices
Here's the code:
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
// update to the plugin you are checking for
if ( ! is_plugin_active_for_network( 'acf-network-options-page/acf-network-options-page.php' ) ) {
function require_acf_network_plugin(){?>
<div class="notice notice-error" >
<p> Please Enable ACF Network Options Plugin before using CLN Admin Dashboard</p>
</div><?php
@trigger_error(__('Please Enable ACF Network Options Plugin before using CLN Admin Dashboard.', 'cln'), E_USER_ERROR);
}
add_action('network_admin_notices','require_acf_network_plugin');
register_activation_hook(__FILE__, 'require_acf_network_plugin');
}