<?php
/**
 * TGM Plugin Activation
 *
 * @version 2.6.1
 * @link https://tgmpluginactivation.com/
 */

defined('ABSPATH') || exit;

if (!class_exists('TGM_Plugin_Activation')) {
  class TGM_Plugin_Activation {
    public static $instance;
    public $plugins = [];
    public $config = [];
    public $strings = [];

    public static function get_instance() {
      if (!isset(self::$instance) && !(self::$instance instanceof self)) {
        self::$instance = new self();
      }
      return self::$instance;
    }

    public function __construct() {
      do_action_ref_array('tgmpa_register', []);
      add_action('admin_menu', [$this, 'admin_menu']);
      add_action('admin_init', [$this, 'admin_init']);
    }

    public function admin_menu() {
      if (empty($this->plugins)) {
        return;
      }
      add_submenu_page(
        'themes.php',
        __('Install Plugins', 'tgmpa'),
        __('Install Plugins', 'tgmpa'),
        'manage_options',
        'tgmpa-install-plugins',
        [$this, 'install_plugins_page']
      );
    }

    public function admin_init() {
      if (empty($this->plugins)) {
        return;
      }
    }

    public function install_plugins_page() {
      echo '<div class="wrap"><h1>' . esc_html__('Install Required Plugins', 'tgmpa') . '</h1>';
      echo '<p>' . esc_html__('Please install and activate the required plugins listed below.', 'tgmpa') . '</p>';
      echo '<ul>';
      foreach ($this->plugins as $plugin) {
        $slug = isset($plugin['slug']) ? $plugin['slug'] : '';
        $name = isset($plugin['name']) ? $plugin['name'] : $slug;
        $url = self_admin_url('plugin-install.php?s=' . urlencode($slug) . '&tab=search&type=term');
        echo '<li><a href="' . esc_url($url) . '">' . esc_html($name) . '</a></li>';
      }
      echo '</ul></div>';
    }

    public function register($plugins, $config) {
      $this->plugins = $plugins;
      $this->config = $config;
    }
  }
}

if (!function_exists('tgmpa')) {
  function tgmpa($plugins, $config = []) {
    $instance = TGM_Plugin_Activation::get_instance();
    $instance->register($plugins, $config);
  }
}

TGM_Plugin_Activation::get_instance();
