Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1411841

    Hi,

    before I used ENFOLD’s custom 404 Error page, I added this code to ENFOLD’s 404.php which works fine and sent me alerts per email for 404 errors.
    But now I prefer to use my custom 404 Error page created with ALB.

    Where can I add now this code for “WordPress 404 email alerts” mentioned here:
    https://wp-mix.com/wordpress-404-email-alerts/

    Can I make a “snippet” for the CodeSnippets plugin out of it in some way (I’m not a coder), so that it works with ENFOLD’s custom 404 Error page, too please?

    Thank you.

    Here is the code from the link mentioned above:

    
    <?php // WP 404 ALERTS @ https://wp-mix.com/wordpress-404-email-alerts/
    
    // set status
    header("HTTP/1.1 404 Not Found");
    header("Status: 404 Not Found");
    
    // site info
    $blog  = get_bloginfo('name');
    $site  = get_bloginfo('url') . '/';
    $email = get_bloginfo('admin_email');
    
    // theme info
    if (!empty($_COOKIE["nkthemeswitch" . COOKIEHASH])) {
    	$theme = clean($_COOKIE["nkthemeswitch" . COOKIEHASH]);
    } else {
    	$theme_data = wp_get_theme();
    	$theme = clean($theme_data->Name);
    }
    
    // referrer
    if (isset($_SERVER['HTTP_REFERER'])) {
    	$referer = clean($_SERVER['HTTP_REFERER']);
    } else {
    	$referer = "undefined";
    }
    // request URI
    if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER["HTTP_HOST"])) {
    	$request = clean('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    } else {
    	$request = "undefined";
    }
    // query string
    if (isset($_SERVER['QUERY_STRING'])) {
    	$string = clean($_SERVER['QUERY_STRING']);
    } else {
    	$string = "undefined";
    }
    // IP address
    if (isset($_SERVER['REMOTE_ADDR'])) {
    	$address = clean($_SERVER['REMOTE_ADDR']);
    } else {
    	$address = "undefined";
    }
    // user agent
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
    	$agent = clean($_SERVER['HTTP_USER_AGENT']);
    } else {
    	$agent = "undefined";
    }
    // identity
    if (isset($_SERVER['REMOTE_IDENT'])) {
    	$remote = clean($_SERVER['REMOTE_IDENT']);
    } else {
    	$remote = "undefined";
    }
    // log time
    $time = clean(date("F jS Y, h:ia", time()));
    
    // sanitize
    function clean($string) {
    	$string = rtrim($string); 
    	$string = ltrim($string); 
    	$string = htmlentities($string, ENT_QUOTES); 
    	$string = str_replace("\n", "<br>", $string);
    
    	if (get_magic_quotes_gpc()) {
    		$string = stripslashes($string);
    	} 
    	return $string;
    }
    
    $message = 
    	"TIME: "            . $time    . "\n" . 
    	"*404: "            . $request . "\n" . 
    	"SITE: "            . $site    . "\n" . 
    	"THEME: "           . $theme   . "\n" . 
    	"REFERRER: "        . $referer . "\n" . 
    	"QUERY STRING: "    . $string  . "\n" . 
    	"REMOTE ADDRESS: "  . $address . "\n" . 
    	"REMOTE IDENTITY: " . $remote  . "\n" . 
    	"USER AGENT: "      . $agent   . "\n\n\n";
    
    mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email"); 
    
    ?>
    

    Thank you.

    #1411919

    Hey BeeCee,

    Thank you for the inquiry.

    You should be able to insert it using action hooks such as wp_head or init, then use a conditional function to only trigger the operation on 404 pages. Please check the documentations below for more info.

    // https://developer.wordpress.org/reference/hooks/wp_head/
    // https://developer.wordpress.org/reference/hooks/init/
    // https://developer.wordpress.org/reference/functions/is_404/

    Best regards,
    Ismael

    #1411959

    Thanks, but I am not a coder, so unfortunately your links doesn’t help me.

    #1412020

    Hi,

    Unfortunately, this type of modification exceeds the scope of our support. To further extend the functionality of the 404 option, you may consider hiring a freelance developer. Alternatively, you can contact our partner, Codeable, for additional customizations.

    You can reach out to them at: https://kriesi.at/contact/customization

    The developer should be able to utilize the hooks and functions we suggested earlier and incorporate them into your code.

    Best regards,
    Ismael

    #1412041

    I understand, thank you very much, you can close this ticket.

    Meanwhile I got an answer from the CodeSnippets Plugin authors themselves, this can be added in a code snippet of this plugin:

    https://codesnippets.cloud/snippet/zlobec/on-404

    add_action( 'template_redirect', function() {
    
        if (is_404()) {
    
            // site info
    
            $blog  = get_bloginfo('name');
    
            $site  = get_bloginfo('url') . '/';
    
            $email = get_bloginfo('admin_email');
    
     
    
            // theme info
    
            if (!empty($_COOKIE["nkthemeswitch" . COOKIEHASH])) {
    
                $theme = clean($_COOKIE["nkthemeswitch" . COOKIEHASH]);
    
            } else {
    
                $theme_data = wp_get_theme();
    
                $theme = clean($theme_data->Name);
    
            }
    
     
    
            // referrer
    
            if (isset($_SERVER['HTTP_REFERER'])) {
    
                $referer = clean($_SERVER['HTTP_REFERER']);
    
            } else {
    
                $referer = "undefined";
    
            }
    
            // request URI
    
            if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER["HTTP_HOST"])) {
    
                $request = clean('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    
            } else {
    
                $request = "undefined";
    
            }
    
            // query string
    
            if (isset($_SERVER['QUERY_STRING'])) {
    
                $string = clean($_SERVER['QUERY_STRING']);
    
            } else {
    
                $string = "undefined";
    
            }
    
            // IP address
    
            if (isset($_SERVER['REMOTE_ADDR'])) {
    
                $address = clean($_SERVER['REMOTE_ADDR']);
    
            } else {
    
                $address = "undefined";
    
            }
    
            // user agent
    
            if (isset($_SERVER['HTTP_USER_AGENT'])) {
    
                $agent = clean($_SERVER['HTTP_USER_AGENT']);
    
            } else {
    
                $agent = "undefined";
    
            }
    
            // identity
    
            if (isset($_SERVER['REMOTE_IDENT'])) {
    
                $remote = clean($_SERVER['REMOTE_IDENT']);
    
            } else {
    
                $remote = "undefined";
    
            }
    
            // log time
    
            $time = clean(date("F jS Y, h:ia", time()));
    
     
    
            $message =
    
                "TIME: "            . $time    . "\n" .
    
                "*404: "            . $request . "\n" .
    
                "SITE: "            . $site    . "\n" .
    
                "THEME: "           . $theme   . "\n" .
    
                "REFERRER: "        . $referer . "\n" .
    
                "QUERY STRING: "    . $string  . "\n" .
    
                "REMOTE ADDRESS: "  . $address . "\n" .
    
                "REMOTE IDENTITY: " . $remote  . "\n" .
    
                "USER AGENT: "      . $agent   . "\n\n\n";
    
     
    
            mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email");
    
        }
    
     
    
     
    
    });
    
     
    
    // sanitize
    
    function clean($string) {
    
        $string = rtrim($string);
    
        $string = ltrim($string);
    
        $string = htmlentities($string, ENT_QUOTES);
    
        $string = str_replace("\n", "<br>", $string);
    
     
    
        if (get_magic_quotes_gpc()) {
    
            $string = stripslashes($string);
    
        }
    
        return $string;
    
    }
    #1412088

    Hi,
    Glad to hear that you have this sorted out, and thank you for sharing your solution, perhaps this will help other users. We will close this thread as you asked, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘WordPress 404 email alerts with ENFOLD’s custom 404 error page’ is closed to new replies.