<?php
/*
* Plugin Name: Upload Any MIME Types
* Description: Easily upload any file type to your WordPress site, including SVG, WebP, and others. Bypass default upload restrictions and expand supported MIME types.
* Version: 1.0.4
* Author: SoftLab
* Author URI: https://softlabbd.com/
* Requires at least: 5.6
* Tested up to: 6.8
* Requires PHP: 7.0
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: upload-any-mime-types
* Domain Path: /languages
*/

// defined('ABSPATH') or die('No script kiddies please!');
if (! defined('ABSPATH')) exit;

/**
 * Summary of UAMT Main Class
 */
final class UAMT_Main_Class
{
     /**
     * Summary of instance
     * @return UAMT_Main_Class
     */
    public static function instance()
    {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }

        return self::$instance;
    }
    /**
     * Summary of version
     * @var string
     */
    public $version = '1.0.4';
    /**
     * Summary of min php
     * @var string
     */
    public $min_php = '5.6.0';
    /**
     * Summary of name
     * @var string
     */
    public $name = 'Upload Any MIME Types';
    /**
     * Summary of instance
     * @var 
     */
    protected static $instance = null;
    /**
     * Summary of __construct
     */
    public function __construct()
    {

        if ($this->check_environment()) {
            $this->define_constants();
            $this->includes();
            // $this->init_hooks();
            do_action('uamt_plugin_loaded');
        }
        add_filter('plugin_action_links',  [$this, 'uamt_settings_link'], 10, 2);

        /**
         * Summary of uamt_activation_redirect
         * @param mixed $plugin
         */
        add_action('activated_plugin', function ($plugin) {
            if (plugin_basename(UAMT_FILE) == $plugin) {
                wp_redirect(admin_url('options-general.php?page=uamt_admin_page'));
                die();
            }
        });
    }
    /**
     * Summary of check_environment
     * @return bool
     */
    public function check_environment()
    {

        $return = true;

        if (version_compare(PHP_VERSION, $this->min_php, '<=')) {
            $return = false;

            $notice = sprintf(
                /* translators: %s: Min PHP version */
                esc_html__('Unsupported PHP version Min required PHP Version: "%s"', 'upload-any-mime-types'),
                $this->min_php
            );
        }

        if (! $return) {
            // Add notice and deactivate the plugin
            add_action('admin_notices', function () use ($notice) { ?>
                <div class="notice is-dismissible notice-error">
                    <p><?php echo $notice; ?></p>
                </div>
<?php });

            if (! function_exists('deactivate_plugins')) {
                include_once(ABSPATH . 'wp-admin/includes/plugin.php');
            }

            deactivate_plugins(plugin_basename(__FILE__));
        }

        return $return;
    }
    /**
     * Summary of define_constants
     * @return void
     */
    public function define_constants()
    {
        define('UAMT_VERSION', $this->version);
        define('UAMT_FILE', __FILE__);
        define('UAMT_PATH', dirname(UAMT_FILE));
        define('UAMT_INCLUDES', UAMT_PATH . '/includes');
        define('UAMT_URL', plugins_url('', UAMT_FILE));
        define('UAMT_ASSETS', UAMT_URL . '/assets');
    }
    /**
     * Summary of includes
     * @return void
     */
    public function includes()
    {
        include_once UAMT_INCLUDES . '/functions.php';
        include_once UAMT_INCLUDES . '/class-mime-types-handler.php';
        include_once UAMT_INCLUDES . '/class-admin-menu.php';
        include_once UAMT_INCLUDES . '/class-admin-settings.php';
        include_once UAMT_INCLUDES . '/class-enqueue-script.php';
    }
    /**
     * Summary of uamt_settings_link
     * @param mixed $plugin_actions
     * @param mixed $plugin_file
     */
    public function uamt_settings_link($plugin_actions, $plugin_file)
    {
        $new_actions = array();

        if (plugin_basename(UAMT_FILE) === $plugin_file) {
            $new_actions['uamt_settings'] = sprintf('<a href="%s">%s</a>',  esc_url(admin_url('options-general.php?page=uamt_admin_page')), __('Settings', 'upload-any-mime-types'));
        }

        return array_merge($new_actions, $plugin_actions);
    }

   
}

UAMT_Main_Class::instance();
