'string', 'sanitize_callback' => 'sanitize_title', 'default' => 'secure-login', ] ); register_setting( 'adlhpti_settings_group', 'adlhpti_enabled', [ 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => false, ] ); } public function adlhpti_render_settings_page() { $slug = get_option('adlhpti_custom_login_slug', 'secure-login'); $custom_login_url = site_url($slug); // No nonce for public URL $template = plugin_dir_path(__FILE__) . '../templates/admin-template.php'; if (file_exists($template)) { include $template; } else { echo '
' . esc_html__('Settings page template not found.', 'admin-login-hide-pti') . '
'; } } public function adlhpti_admin_enqueue_assets($hook) { if ($hook !== 'settings_page_adlhpti-settings') { return; } $base_url = plugin_dir_url(__FILE__) . '../assets/'; $base_path = plugin_dir_path(__FILE__) . '../assets/'; $css_path = $base_path . 'css/admin.css'; if (file_exists($css_path)) { wp_enqueue_style( 'adlhpti-admin-css', $base_url . 'css/admin.css', [], filemtime($css_path) ); } $js_path = $base_path . 'js/admin.js'; if (file_exists($js_path)) { wp_enqueue_script( 'adlhpti-admin-js', $base_url . 'js/admin.js', ['jquery'], filemtime($js_path), true ); } } public function adlhpti_custom_login_redirect() { $is_enabled = get_option('adlhpti_enabled', false); if (!$is_enabled) { return; } $custom_slug = trim(get_option('adlhpti_custom_login_slug', 'secure-login'), '/'); $request_uri_raw = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : ''; $parsed_request_uri = wp_parse_url($request_uri_raw); $request_path = isset($parsed_request_uri['path']) ? trim($parsed_request_uri['path'], '/') : ''; $parsed_site_url = wp_parse_url(site_url()); $site_path = isset($parsed_site_url['path']) ? trim($parsed_site_url['path'], '/') : ''; if (!empty($site_path) && strpos($request_path, $site_path) === 0) { $request_path = trim(substr($request_path, strlen($site_path)), '/'); } // Prevent direct wp-login.php unless POST or valid action if (strpos($request_path, 'wp-login.php') === 0) { $allowed_actions = ['logout', 'lostpassword', 'rp', 'resetpass', 'register']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only use of $_GET for display logic, not modifying data $action = isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only use of $_GET for display logic $logged_out = isset($_GET['loggedout']) ? sanitize_text_field(wp_unslash($_GET['loggedout'])) : ''; $method = strtoupper(sanitize_text_field(wp_unslash($_SERVER['REQUEST_METHOD'] ?? ''))); if ($method !== 'POST' && !in_array($action, $allowed_actions, true) && !$logged_out) { wp_die( esc_html__('Access denied. Please use the custom login URL.', 'admin-login-hide-pti'), '', ['response' => 403] ); } } if ( $request_path === $custom_slug ) { if ( is_user_logged_in() ) { wp_safe_redirect( admin_url() ); exit; } get_header(); echo '' . esc_html__( 'Login failed. Please try again.', 'admin-login-hide-pti' ) . '
'; } } wp_login_form( [ 'redirect' => admin_url(), ] ); echo '