WordPress: Plugin Require Another Plugin Installed

Sometimes when you write plugins, you need some other plugin installed. Yes, indeed you can copy the plugin to your folder plugin but it’s will have disadvantage that we must copied again when the plugins is updated or codes in the plugin that you copied to your folder plugin is deprecated by WordPress.

Instead we copied the plugin to your plugins then it will be better if we write some function that when user activated our plugin, show the information that other plugin that we needed for our plugins works better is must installed.

Here the codes:

<?php
/*
Plugin Name: Our Plugin
Description: The Other Plugin should be installed and active to use this plugin.
Version: 1.0.0
*/
add_action( 'admin_init', 'our_plugin' );
function our_plugin() {
    if ( is_admin() && current_user_can( 'activate_plugins' ) &&  !is_plugin_active( 'other-plugin/other-plugin.php' ) ) {
        add_action( 'admin_notices', 'no_other_plugin_installed' );

        deactivate_plugins( plugin_basename( __FILE__ ) ); 

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

function no_other_plugin_installed(){
    ?><div class="error"><p>Sorry, for better works, Our Plugin requires the other plugin to be installed and active.</p></div><?php
}

source: kosinix

Artikel terkait:   XAMPP MAC OS X Wordpress Unable to create directory

Isi Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

This site uses Akismet to reduce spam. Learn how your comment data is processed.