Plugin Directory

Changeset 3476554


Ignore:
Timestamp:
03/06/2026 04:11:44 PM (4 weeks ago)
Author:
pipdig
Message:

refactor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 404-to-homepage/trunk/404-to-homepage.php

    r3466005 r3476554  
    1212add_action('template_redirect', function() {
    1313
    14     if (
    15         wp_doing_ajax() ||
    16         wp_doing_cron() ||
    17         is_admin() ||
    18         (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ||
    19         (defined('REST_REQUEST') && REST_REQUEST)
    20     ) return;
     14    if (wp_doing_ajax() || wp_doing_cron() || is_admin() || (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) || (defined('REST_REQUEST') && REST_REQUEST)) return;
    2115
    2216    if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') return;
     
    2620    $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    2721
    28     // Skip direct PHP file access
    2922    if (substr($path, -4) === '.php') return;
     23   
     24    if (substr($path, -4) === '.txt') return;
    3025
    31     // Skip sitemap
    3226    if (strpos($path, 'sitemap.xml') !== false) return;
    3327
     
    4337    global $wp_query;
    4438
    45     // Reliable low-level 404 check
    4639    if (empty($wp_query) || empty($wp_query->is_404)) return;
    4740
     
    5447
    5548}, PHP_INT_MAX);
    56 
    57 /*
    58 add_action('template_redirect', function() {
    59    
    60     if (wp_doing_ajax() || wp_doing_cron() || is_admin() || (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)) return;
    61    
    62     if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], 'sitemap.xml') !== false) return;
    63    
    64     global $wp_query;
    65     if ($wp_query->is_404 === false) return;
    66    
    67     if (wp_safe_redirect(home_url('/'), 301)) die;
    68    
    69 }, PHP_INT_MAX);
    70 */
Note: See TracChangeset for help on using the changeset viewer.