WordPress Plugin Activation Dependency Check

Today, We want to share with you WordPress Plugin Activation Dependency Check.In this post we will show you Correctly perform a plugin dependency check, hear for Check for dependent plugin and if false dont activate plugin we will give you demo and example for implement.In this post, we will learn about Checking for a Plugin Dependency on Activation with an example.

WordPress Plugin Activation Dependency Check

There are the Following The simple About WordPress Plugin Activation Dependency Check Full Information With Example and source code.

Read Also:  Back to Top Button using jQuery and CSS - Scroll to Top Example

As I will cover this Post with live Working example to develop wordpress theme plugin dependencies, so the wordpress plugin dependency on another plugin for this example is following below.

Check If Dependent Plugin Is Active

function my_custom_plugin_activate()
{
    add_option('Custom_Activated_Plugin', 'My-Custom-Plugin-Slug');
}

register_activation_hook(__FILE__, 'my_custom_plugin_activate');


function default_load_plugin()
{

    /* Check If Dependent Plugin Is Active */

    if (is_admin() && get_option('Custom_Activated_Plugin') == 'My-Custom-Plugin-Slug') {
        delete_option( 'Custom_Activated_Plugin' );

        if (!class_exists('WooCommerce')) {
            add_action('admin_notices', 'display_admin_notice');

            //Simple Call A Hook for Deactivate our plugin
            deactivate_plugins(plugin_basename(__FILE__));

            if (isset($_GET['activate'])) {
                unset($_GET['activate']);
            }
        }
    }
}

add_action('admin_init', 'default_load_plugin');

/**
 * Display an error message when parent plugin is missing
 */
function display_admin_notice()
{
    ?>
	<div class="error notice">
	    <p>
	        <strong>Error:</strong>
	        The <em>Your Current Plugin Name</em> plugin won't execute
	        because the following required plugin is not active:Dependent Plugin Name.
	        Please activate these <a href="plugins.php">plugin</a>.
	    </p>
	</div>
    <?php
}

Web Programming Tutorials Example with Demo

Read :

Read Also:  Post Multiple photos Stories via Facebook API with PHP SDK

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Word Press Plugin Activation Dependency Check.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.