<?php
/**
 * Plugin Name: UFPE Google OIDC Login
 * Description: Autenticacao institucional WordPress via Google OpenID Connect restrita ao dominio ufpe.br.
 * Version: 0.1.0
 * Author: UFPE
 * Requires PHP: 7.4
 * Requires at least: 6.0
 */

declare(strict_types=1);

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

define('UFPE_GOOGLE_OIDC_VERSION', '0.1.0');
define('UFPE_GOOGLE_OIDC_FILE', __FILE__);
define('UFPE_GOOGLE_OIDC_DIR', plugin_dir_path(__FILE__));

spl_autoload_register(static function (string $class): void {
    $prefix = 'UFPE\\GoogleOIDC\\';

    if (strpos($class, $prefix) !== 0) {
        return;
    }

    $relative = substr($class, strlen($prefix));
    $path = UFPE_GOOGLE_OIDC_DIR . 'src/' . str_replace('\\', '/', $relative) . '.php';

    if (is_readable($path)) {
        require_once $path;
    }
});

register_activation_hook(__FILE__, ['UFPE\\GoogleOIDC\\Plugin', 'activate']);
add_action('plugins_loaded', ['UFPE\\GoogleOIDC\\Plugin', 'boot']);
