<?php

declare(strict_types=1);

namespace SiteFort\Includes;

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

/**
 * Request-context checks used to keep management-only work off the front end.
 */
final class RequestContext {

    public static function is_login_request(): bool {
        return isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'];
    }

    /**
     * Whether the request is a privileged context that runs the plugin's
     * management work: admin (including admin-ajax), WP-Cron, or WP-CLI.
     * Anonymous front-end page views are not, so one-time setup, migrations,
     * and credential-dependent work can be skipped for them.
     */
    public static function is_privileged(): bool {
        return ( defined( 'WP_CLI' ) && WP_CLI )
            || ( function_exists( 'wp_doing_cron' ) && wp_doing_cron() )
            || is_admin();
    }

    public static function allows_inline_migrations(): bool {
        return self::is_privileged() || self::is_login_request();
    }
}
