<?php
/**
 * Plugin Name: EffortLess Multisite Language Switcher
 * Description: Adds a floating globe icon to switch languages in a WordPress multisite network.
 * Version:           1.1.9
 * Author:      domclic
 * Donate link: https://id7.dev/donate/
 * License:     GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain: effortless-multisite-language-switcher
 * Package:     ELMLS
 *
 * @package EffortLessMultisiteLanguageSwitcher
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once __DIR__ . '/includes/class-donate-notice.php';
require_once __DIR__ . '/includes/class-elmls-flag-resolver.php';
require_once __DIR__ . '/includes/class-elmls-site-data.php';
require_once __DIR__ . '/includes/class-elmls-frontend.php';
require_once __DIR__ . '/includes/class-elmls-admin.php';

/**
 * Main plugin class.
 */
class ELMLS_Plugin {
	/**
	 * Plugin version.
	 *
	 * @var string
	 */
	const VERSION = '1.1.9';

	/**
	 * Plugin directory path.
	 *
	 * @var string
	 */
	const PLUGIN_DIR = __DIR__;

	/**
	 * Plugin instance.
	 *
	 * @var ELMLS_Plugin|null
	 */
	private static $instance = null;

	/**
	 * Returns the singleton instance of the plugin.
	 *
	 * @return ELMLS_Plugin
	 */
	public static function get_instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * ELMLS_Plugin constructor.
	 */
	private function __construct() {
		if ( ! defined( 'ELMLS_PLUGIN_URL' ) ) {
			define( 'ELMLS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
		}

		$flag_resolver = new ELMLS_Flag_Resolver();
		$site_data     = new ELMLS_Site_Data( $flag_resolver );
		$frontend      = new ELMLS_Frontend( $flag_resolver, $site_data );
		$admin         = new ELMLS_Admin( $site_data, $flag_resolver );

		add_action( 'wp_enqueue_scripts', array( $frontend, 'enqueue_assets' ) );
		add_action( 'wp_footer', array( $frontend, 'render_floating_icon' ) );
		add_shortcode( 'elmls_switcher', array( $frontend, 'shortcode_switcher' ) );

		if ( is_multisite() && is_network_admin() ) {
			add_action( 'network_admin_menu', array( $admin, 'admin_menu' ) );
		}
	}
}

ELMLS_Plugin::get_instance();
new Effortless_Donate_Notice( __FILE__, array( 'settings_page_elmls-settings' ) );
