<?php
    class Edumodo_Plugin_Dependency_Notice{
        private static $instance;

        public static function init(){
            if( null === self::$instance){
                self::$instance = new self;
            }
            return self::$instance;
        }
        public function __construct(){
            add_action('admin_notices', [$this, 'edumodo_check_dependent_plugin']);
        }
        function edumodo_check_dependent_plugin(){
            if (!current_user_can('activate_plugins')) {
                return;
            } 
            $kirki_main_file = 'kirki/kirki.php';
            if($this->edumodo_get_activated_plugin_list($kirki_main_file)){
                return;
            }

            if(! $this->edumdo_get_all_plugin_in_my_site($kirki_main_file)){
                /**
                 * if plugin not found
                 */
                $activation_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=kirki'), 'install-plugin_kirki');
                $message = sprintf(__('<strong>Edumodo</strong> requires <strong>Kirki</strong> plugin to be installed and activated for it\'s default option panel in customizer panel. Please install <strong>Kirki</strong> to continue.', 'edumodo'), '<strong>', '</strong>');
                $button_text = __('Install Kirki Now', 'edumodo');
            }else{
                /**
                 * if found
                 */
                
                $activation_url = wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $kirki_main_file . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $kirki_main_file);
                $message = __('<strong>Edumodo</strong> requires <strong>Kirki</strong> plugin to be active for it\'s default option panel in customizer panel. Please activate Kirki to continue.', 'edumodo');
                $button_text = __('Activate Kirki Now', 'edumodo');
            }
            $button = '<p><a href="' . $activation_url . '" class="button-primary">' . $button_text . '</a></p>';
            printf('<div class="error"><p>%1$s</p>%2$s</div>', __($message), $button);
        }
        public function edumdo_get_all_plugin_in_my_site($plugin_base_name){
            $installed_plugins = get_plugins();
            return isset($installed_plugins[$plugin_base_name]);
        }

        public function edumodo_get_activated_plugin_list($plugin_base_name){
            $activated_plugins = get_option('active_plugins');
            $network_activated_plugins = get_site_option('active_sitewide_plugins');
            if(is_multisite()){
                /**
                 * at first check activation status in multisite
                 * if return false then check on single site
                 */
                if(array_key_exists($plugin_base_name, $network_activated_plugins)){
                    return true;
                }elseif (in_array($plugin_base_name, $activated_plugins)) {
                    return true;
                }else{
                    return false;
                }
            }else{
                return in_array($plugin_base_name, $activated_plugins);
            }
        }
    }
?>