# Needed to the function "deactivate_plugins" works
include_once(ABSPATH . 'wp-admin/includes/plugin.php');


add_action('plugins_loaded', 'check_dependent_plugin_is_activated_or_not');

function check_dependent_plugin_is_activated_or_not()
{

$dependent_plugin_path = 'wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php';

if (!is_plugin_active($dependent_plugin_path)) {

# Deactivate the current plugin
deactivate_plugins(plugin_basename(__FILE__));

# Show an error alert on the admin area
add_action('admin_notices', function () {
?>
<div class="updated error">
<p>
<?php echo __('The plugin <strong>WPGraphQL JWT Authentication Extended</strong> needs the plugin <strong>WPGraphQL JWT Authentication</strong> to be active', '');
echo '<br>';
echo __('<strong>WPGraphQL JWT Authentication Extended</strong> has been deactivated', '');
?>
</p>
</div>
<?php
if (isset($_GET['activate']))
unset($_GET['activate']);
});
}
}