<?php
/**
 * Plugin Name: Anar Premium Login Final
 * Description: نسخه نهایی و تضمینی برای رفع خطای Fatal Error.
 * Version: 8.0.0
 * Author: Anar Pardazesh
 */

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

// استفاده از نام کلاس کاملاً جدید برای دور زدن کش سرور
class Anar_New_Rescue_System {

    public static function start() {
        $self = new self();
        add_action( 'init', array( $self, 'handle_routing' ), 1 );
        add_action( 'login_enqueue_scripts', array( $self, 'assets' ) );
        add_action( 'login_footer', array( $self, 'ui_fix' ) );
        
        // اصلاح لوگو بدون استفاده از هیچ تابعی (مستقیم)
        add_filter( 'login_headerurl', function() { return home_url(); } );
        add_filter( 'login_headertext', function() { return get_bloginfo('name'); } );
    }

    public function handle_routing() {
        if ( is_user_logged_in() || defined('DOING_AJAX') ) return;

        // فقط یک آدرس ورود برای همه (ساده و بدون باگ)
        $login_slug = 'entry'; 
        $current_url = trim( $_SERVER['REQUEST_URI'], '/' );

        if ( $current_url === $login_slug ) {
            require_once ABSPATH . 'wp-login.php';
            exit;
        }

        if ( strpos($_SERVER['SCRIPT_NAME'], 'wp-login.php') !== false && !isset($_GET['action']) ) {
            wp_redirect( home_url( $login_slug ) );
            exit;
        }
    }

    public function assets() {
        echo '<style>
            body.login { background: #f4f7f9; display: flex; align-items: center; justify-content: center; height: 100vh; font-family: tahoma; }
            #login { background: #fff; padding: 25px; border-radius: 12px; box-shadow: 0 5px 25px rgba(0,0,0,0.05); width: 320px; }
            .pass-group { position: relative; }
            .eye-btn { position: absolute; left: 10px; top: 10px; border: none; background: none; cursor: pointer; font-size: 16px; color: #999; }
            #user_pass { padding-left: 35px !important; }
            .custom-footer { display: flex; justify-content: space-between; margin-top: 20px; font-size: 11px; }
        </style>';
    }

    public function ui_fix() {
        ?>
        <script>
        document.addEventListener('DOMContentLoaded', function() {
            var p = document.getElementById('user_pass');
            if(p) {
                var g = document.createElement('div'); g.className = 'pass-group';
                p.after(g); g.appendChild(p);
                var b = document.createElement('button'); b.type='button'; b.className='eye-btn'; b.innerHTML='👁️';
                g.appendChild(b); b.onclick = function() { p.type = (p.type === 'password' ? 'text' : 'password'); };
            }
            var f = document.getElementById('loginform'), n = document.getElementById('nav'), l = document.querySelector('.language-switcher');
            if(f) {
                var d = document.createElement('div'); d.className = 'custom-footer';
                var left = document.createElement('div'); if(l) left.appendChild(l);
                var right = document.createElement('div'); if(n) right.appendChild(n);
                d.append(left, right); f.after(d);
            }
        });
        </script>
        <?php
    }
}

Anar_New_Rescue_System::start();