/** * Bloqueo completo de wp-comments-post.php y comentarios públicos en WordPress. * * REUTILIZABLE EN CUALQUIER TEMA O CHILD THEME: * Para usar este código en otra instalación de WordPress, copia desde * "if (!function_exists('gr2_bloquear_wp_comments_post'))" hasta el final del archivo * y pégalo al final del archivo functions.php de tu child theme. */ if (!defined('ABSPATH')) { exit; } if (!function_exists('gr2_bloquear_wp_comments_post')) { /** * Bloquea cualquier petición directa a wp-comments-post.php con HTTP 403. * Se ejecuta en 'init' antes de que WordPress procese o guarde el comentario. */ function gr2_bloquear_wp_comments_post() { $script_name = isset($_SERVER['SCRIPT_NAME']) ? basename(wp_unslash($_SERVER['SCRIPT_NAME'])) : ''; $request_uri = isset($_SERVER['REQUEST_URI']) ? wp_unslash($_SERVER['REQUEST_URI']) : ''; if ($script_name === 'wp-comments-post.php' || strpos($request_uri, 'wp-comments-post.php') !== false) { wp_die( esc_html__('Los comentarios están deshabilitados en este sitio.', 'scout-sanbenito'), esc_html__('Acceso denegado', 'scout-sanbenito'), array('response' => 403) ); } } add_action('init', 'gr2_bloquear_wp_comments_post', 1); /** * Cierra comentarios y pingbacks/trackbacks en todo el frontend. */ add_filter('comments_open', '__return_false', 20, 2); add_filter('pings_open', '__return_false', 20, 2); /** * Elimina los endpoints públicos de comentarios en la API REST (/wp-json/wp/v2/comments) * para evitar spam automatizado por esa vía sin afectar a notas internas de WooCommerce. * * @param array $endpoints * @return array */ function gr2_deshabilitar_rest_comentarios($endpoints) { unset($endpoints['/wp/v2/comments']); unset($endpoints['/wp/v2/comments/(?P[\d]+)']); return $endpoints; } add_filter('rest_endpoints', 'gr2_deshabilitar_rest_comentarios'); } https://scoutsanbenito.es/wp-sitemap-posts-page-1.xmlhttps://scoutsanbenito.es/wp-sitemap-posts-product-1.xmlhttps://scoutsanbenito.es/wp-sitemap-taxonomies-product_cat-1.xml