<?php
/**
 * Plugin Name:       SEOvault AI
 * Plugin URI:        https://seovaultai.com/
 * Description:       Lightweight WordPress SEO plugin built for AI-assisted content workflows. Owns SEO output, stores SEOvault-owned SEO fields, and connects cleanly to the SEOvault AI web app.
 * Version:           1.1.2
 * Requires at least: 5.9
 * Requires PHP:      7.4
 * Author:            SEOvault AI
 * Author URI:        https://seovaultai.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       seovault-ai
 * Domain Path:       /languages
 *
 * @package SEOvaultSEO
 */

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

// Plugin constants
define( 'SEOVAULT_SEO_VERSION', '1.1.2' );
// Extension API version is decoupled from plugin semver. Pro checks this contract.
define( 'SEOVAULT_SEO_EXTENSION_API_VERSION', '1.2' );
define( 'SEOVAULT_SEO_FILE', __FILE__ );
define( 'SEOVAULT_SEO_DIR', plugin_dir_path( __FILE__ ) );
define( 'SEOVAULT_SEO_URL', plugin_dir_url( __FILE__ ) );
define( 'SEOVAULT_SEO_BASENAME', plugin_basename( __FILE__ ) );

// Autoloader for SEOvaultSEO namespace
spl_autoload_register(
	function ( $class ) {
		// Project-specific namespace prefix
		$prefix = 'SEOvaultSEO\\';

		// Base directory for the namespace prefix
		$base_dir = SEOVAULT_SEO_DIR . 'includes/';

		// Does the class use the namespace prefix?
		$len = strlen( $prefix );
		if ( strncmp( $prefix, $class, $len ) !== 0 ) {
				return;
		}

		// Get the relative class name
		$relative_class = substr( $class, $len );

		// Replace namespace separators with directory separators
		$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';

		// If the file exists, require it
		if ( file_exists( $file ) ) {
			require $file;
		}
	}
);

// Activation hook
register_activation_hook( __FILE__, 'seovaultseo_activate' );

function seovaultseo_activate( $network_wide ) {
	SEOvaultSEO\Core\Activator::activate( $network_wide );
}

// Deactivation hook
register_deactivation_hook( __FILE__, 'seovaultseo_deactivate' );

function seovaultseo_deactivate() {
	SEOvaultSEO\Core\Activator::deactivate();
}

// Initialize the plugin
add_action( 'plugins_loaded', 'seovaultseo_init' );

function seovaultseo_init() {
	if ( ! class_exists( 'SEOvaultSEO\Core\Plugin' ) ) {
		return;
	}

	SEOvaultSEO\Core\Plugin::get_instance()->init();
}
