← Back
Editing: functions.php
<?php /** * Theme functions and definitions * * @package HelloElementorChild */ /** * Load child theme css and optional scripts * * @return void */ function hello_elementor_child_enqueue_scripts() { wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', [ 'hello-elementor-theme-style', ], '1.0.0' ); } add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts', 20 ); /** * Cambiar la URL de acceso de wp-login.php * Acceso amigable: /wp → redirige a wp-login.php?marypaz-key=1 */ define('CUSTOM_LOGIN_SLUG', 'wp'); define('CUSTOM_LOGIN_KEY', 'marypaz-key'); // 1. Redirigir /wp → wp-login.php con la clave secreta add_action('init', function () { $request = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); if ($request === CUSTOM_LOGIN_SLUG) { wp_safe_redirect(site_url('/wp-login.php?' . CUSTOM_LOGIN_KEY . '=1')); exit; } }); // 2. Bloquear wp-login.php si no llega con la clave secreta add_action('login_init', function () { // Permitir siempre logout y recuperación de contraseña $action = $_REQUEST['action'] ?? ''; if (in_array($action, ['logout', 'postpass', 'rp', 'resetpass', 'lostpassword', 'confirm_admin_email'], true)) { return; } // Permitir POST del formulario (submit del login) if ($_SERVER['REQUEST_METHOD'] === 'POST') { return; } // Permitir si llega la clave secreta if (isset($_GET[CUSTOM_LOGIN_KEY])) { return; } // Bloquear el resto status_header(404); nocache_headers(); wp_safe_redirect(home_url('/' . CUSTOM_LOGIN_SLUG)); exit; }, 1); // 3. Proteger /wp-admin/ — si no estás logueado, devolver al home en vez de a wp-login add_action('admin_init', function () { if (!is_user_logged_in() && !wp_doing_ajax()) { status_header(404); nocache_headers(); wp_safe_redirect(home_url('/' . CUSTOM_LOGIN_SLUG)); exit; } }); /** * Desactivar XML-RPC completamente */ // 1. Desactivar la API XML-RPC add_filter('xmlrpc_enabled', '__return_false'); // 2. Eliminar cabeceras que anuncian XML-RPC add_filter('wp_headers', function ($headers) { unset($headers['X-Pingback']); return $headers; }); // 3. Quitar el enlace pingback del <head> remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); // 4. Bloquear métodos pingback add_filter('xmlrpc_methods', function ($methods) { unset($methods['pingback.ping']); unset($methods['pingback.extensions.getPingbacks']); return $methods; });
Save File
Cancel