<?php
/**
 * Plugin Name:       SuiteMkt3k
 * Plugin URI:        https://www.31416k.com/suitemkt3k/
 * Description:       Marketing suite for WooCommerce: scheduled coupons, newsletter, abandoned cart recovery, subscriber management, analytics and built-in SMTP.
 * Version:           1.1.4
 * Requires at least: 6.2
 * Requires PHP:      8.0
 * Author:            31416k
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       suitemkt3k
 * Domain Path:       /languages
 *
 * @package SuiteMkt3k
 */

defined( 'ABSPATH' ) || exit;

if ( defined( 'SUITEMKT3K_VERSION' ) ) {
	return;
}

define( 'SUITEMKT3K_VERSION', '1.1.4' );

define( 'SUITEMKT3K_DB_VERSION', '1.1.2' );

define( 'SUITEMKT3K_FILE', __FILE__ );

define( 'SUITEMKT3K_PATH', plugin_dir_path( __FILE__ ) );

define( 'SUITEMKT3K_URL', plugin_dir_url( __FILE__ ) );

define( 'SUITEMKT3K_BASENAME', plugin_basename( __FILE__ ) );

define( 'SUITEMKT3K_SLUG', 'suitemkt3k' );

define( 'SUITEMKT3K_PREFIX', 'wmk_' );

define( 'SUITEMKT3K_REST_NAMESPACE', 'suitemkt3k/v1' );

define( 'SUITEMKT3K_MIN_PHP', '8.0' );

define( 'SUITEMKT3K_MIN_WP', '6.2' );

require_once SUITEMKT3K_PATH . 'includes/class-autoloader.php';

\SuiteMkt3k\Autoloader::register();

\SuiteMkt3k\Utils\I18n::register();

register_activation_hook( SUITEMKT3K_FILE, array( 'SuiteMkt3k\Activator', 'activate' ) );

register_deactivation_hook( SUITEMKT3K_FILE, array( 'SuiteMkt3k\Deactivator', 'deactivate' ) );

add_filter(
	'cron_schedules',
	static function ( $schedules ) {
		$schedules['suitemkt3k_5min']  = array(
			'interval' => 5 * MINUTE_IN_SECONDS,
			'display'  => __( 'Every 5 minutes (SuiteMkt3k)', 'suitemkt3k' ),
		);
		$schedules['suitemkt3k_15min'] = array(
			'interval' => 15 * MINUTE_IN_SECONDS,
			'display'  => __( 'Every 15 minutes (SuiteMkt3k)', 'suitemkt3k' ),
		);
		return $schedules;
	}
);

add_action(
	'activated_plugin',
	static function ( $plugin ) {
		if ( SUITEMKT3K_BASENAME !== $plugin ) {
			return;
		}
		wp_cache_delete( 'active_plugins', 'options' );
		wp_cache_delete( 'alloptions', 'options' );
	},
	10,
	1
);

add_action(
	'plugins_loaded',
	static function () {
		if ( version_compare( PHP_VERSION, SUITEMKT3K_MIN_PHP, '<' ) ) {
			add_action(
				'admin_notices',
				static function () {
					printf(
						'<div class="notice notice-error"><p>%s</p></div>',
						esc_html(
							sprintf(
								/* translators: %1$s required PHP, %2$s current */
								__( 'SuiteMkt3k requires PHP %1$s or higher. You are running %2$s.', 'suitemkt3k' ),
								SUITEMKT3K_MIN_PHP,
								PHP_VERSION
							)
						)
					);
				}
			);
			return;
		}

		global $wp_version;
		if ( version_compare( $wp_version, SUITEMKT3K_MIN_WP, '<' ) ) {
			add_action(
				'admin_notices',
				static function () use ( $wp_version ) {
					printf(
						'<div class="notice notice-error"><p>%s</p></div>',
						esc_html(
							sprintf(
								/* translators: %1$s required WP, %2$s current */
								__( 'SuiteMkt3k requires WordPress %1$s or higher. You are running %2$s.', 'suitemkt3k' ),
								SUITEMKT3K_MIN_WP,
								$wp_version
							)
						)
					);
				}
			);
			return;
		}

		\SuiteMkt3k\Plugin::instance()->boot();
	},
	10
);
