<?php
/*
Plugin Name: ZERTI
Plugin URI: https://wordpress.org/plugins/zerti/
Description: Unified WooCommerce admin panel with multilingual UI support.
Version: 2.0.9
Requires at least: 6.0
Requires PHP: 7.4
Author: ZERTI
Contributors: ZERTI
Author URI: https://zerti.shop
Author Email: admin@zerti.shop
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: zerti
Domain Path: /languages
Requires Plugins: woocommerce
*/

/*
Copyright (C) 2026 ZERTI

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/

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

if (version_compare(PHP_VERSION, '7.4', '<')) {
    add_action('admin_notices', static function (): void {
        echo '<div class="notice notice-error"><p>'
            . esc_html__('ZERTI requires PHP 7.4 or newer.', 'zerti')
            . '</p></div>';
    });

    return;
}

if (!function_exists('zerti_str_starts_with')) {
    /**
     * PHP 7.x polyfill (core plugin code must not assume PHP 8+).
     */
    function zerti_str_starts_with(string $haystack, string $needle): bool
    {
        if ($needle === '') {
            return true;
        }

        return strncmp($haystack, $needle, strlen($needle)) === 0;
    }
}

if (!function_exists('zerti_str_contains')) {
    /**
     * PHP 7.x polyfill (core plugin code must not assume PHP 8+).
     */
    function zerti_str_contains(string $haystack, string $needle): bool
    {
        if ($needle === '') {
            return true;
        }

        return strpos($haystack, $needle) !== false;
    }
}

define('ZERTI_VERSION', '2.0.9');
define('ZERTI_ADMIN_PAGE_SLUG', 'zerti-admin');
define('ZERTI_FONTAWESOME_VERSION', '6.5.1');
define('ZERTI_BOOTSTRAP_VERSION', '5.3.8');
define('ZERTI_THEME_STORAGE_KEY', 'zertiAdminColorTheme');

/** Absolute path to the main plugin file (used for paths/URLs from includes). */
define('ZERTI_PLUGIN_FILE', __FILE__);

add_filter(
    'wp_plugin_check_ignore_directories',
    static function (array $directories): array {
        foreach (['bin', 'tests', 'docs', 'tools'] as $directory) {
            if (!in_array($directory, $directories, true)) {
                $directories[] = $directory;
            }
        }

        return $directories;
    }
);

require_once plugin_dir_path(__FILE__) . 'includes/zerti-routes.php';
require_once plugin_dir_path(__FILE__) . 'includes/capabilities.php';
require_once plugin_dir_path(__FILE__) . 'includes/zerti-bootstrap.php';

register_activation_hook(__FILE__, 'zerti_plugin_activate');

/**
 * Plugin activation: assets + role capabilities.
 */
function zerti_plugin_activate(): void
{
    zerti_ensure_fontawesome_webfonts();
    zerti_ensure_role_capabilities();
}
