Advertisement
nshelper

Customize the default wp die page ( error 404 )

Feb 28th, 2025 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.68 KB | None | 0 0
  1. <?php
  2.  
  3.     add_filter('wp_die_handler', 'custom_wp_die_handler', 999, 3 );
  4.     function custom_wp_die_handler( $message, $title = '', $args = array() )
  5.         {
  6.             list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
  7.  
  8.             if ( is_string( $message ) ) {
  9.                 if ( ! empty( $parsed_args['additional_errors'] ) ) {
  10.                     $message = array_merge(
  11.                         array( $message ),
  12.                         wp_list_pluck( $parsed_args['additional_errors'], 'message' )
  13.                     );
  14.                     $message = "<ul>\n\t\t<li>" . implode( "</li>\n\t\t<li>", $message ) . "</li>\n\t</ul>";
  15.                 }
  16.  
  17.                 $message = sprintf(
  18.                     '<p>%s</p>',
  19.                     $message
  20.                 );
  21.             }
  22.  
  23.             $have_gettext = function_exists( '__' );
  24.  
  25.             if ( ! empty( $parsed_args['link_url'] ) && ! empty( $parsed_args['link_text'] ) ) {
  26.                 $link_url = $parsed_args['link_url'];
  27.                 if ( function_exists( 'esc_url' ) ) {
  28.                     $link_url = esc_url( $link_url );
  29.                 }
  30.                 $link_text = $parsed_args['link_text'];
  31.                 $message  .= "\n<p><a href='{$link_url}'>{$link_text}</a></p>";
  32.             }
  33.  
  34.             if ( isset( $parsed_args['back_link'] ) && $parsed_args['back_link'] ) {
  35.                 $back_text = $have_gettext ? __( '&laquo; Back' ) : '&laquo; Back';
  36.                 $message  .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
  37.             }
  38.  
  39.             if ( ! did_action( 'admin_head' ) ) :
  40.                 if ( ! headers_sent() ) {
  41.                     header( "Content-Type: text/html; charset={$parsed_args['charset']}" );
  42.                     status_header( $parsed_args['response'] );
  43.                     nocache_headers();
  44.                 }
  45.  
  46.                 $text_direction = $parsed_args['text_direction'];
  47.                 $dir_attr       = "dir='$text_direction'";
  48.  
  49.                 // If `text_direction` was not explicitly passed,
  50.                 // use get_language_attributes() if available.
  51.                 if ( empty( $args['text_direction'] )
  52.                     && function_exists( 'language_attributes' ) && function_exists( 'is_rtl' )
  53.                 ) {
  54.                     $dir_attr = get_language_attributes();
  55.                 }
  56.                 ?>
  57.             <!DOCTYPE html>
  58.             <html <?php echo $dir_attr; ?>>
  59.             <head>
  60.                 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $parsed_args['charset']; ?>" />
  61.                     <?php
  62.                     if ( function_exists( 'wp_robots' ) && function_exists( 'wp_robots_no_robots' ) && function_exists( 'add_filter' ) ) {
  63.                         add_filter( 'wp_robots', 'wp_robots_no_robots' );
  64.                         wp_robots();
  65.                     }
  66.                     ?>
  67.                 <title><?php echo $title; ?></title>
  68.  
  69.                 <meta http-equiv="X-UA-Compatible" content="IE=edge">
  70.                 <meta name="viewport" content="width=device-width, initial-scale=1">
  71.  
  72.                 <style media="all">
  73.                     @import url(https://fonts.googleapis.com/css?family=opensans:500);
  74.                     ._1,._404,.c{position:relative}body,hr{color:#fff}body,hr:after{background:#3c9}body{font-family:'Open Sans',sans-serif;max-height:700px;overflow:hidden}.c{text-align:center;display:block;width:80%;margin:100px auto}._404{font-size:220px;display:inline-block;z-index:2;height:250px;letter-spacing:15px}._1,hr:after{font-size:2em}._1,._2{display:block;text-align:center}._1{letter-spacing:12px;line-height:80%;padding:20px}._2{position:relative;font-size:20px}.btn,.text,hr:after{display:inline-block;position:relative}.text{font-size:70px;text-align:center;margin:19px 0 0;z-index:3;width:100%;line-height:1.2em}.btn{background-color:#fff;width:358px;padding:5px;z-index:5;font-size:25px;margin:0 10px 0 auto;color:#3c9;text-decoration:none}.cloud,.cloud:after,.cloud:before{position:absolute;background:#fff;z-index:-1}.right{float:right;width:60%}hr{padding:0;border:none;border-top:5px solid #fff;text-align:center;margin:0 auto;width:420px;height:10px;z-index:-10}hr:after{content:"\2022";top:-.75em;padding:0 .2em}.cloud{width:350px;height:120px;background:linear-gradient(top,#fff 100%);background:-webkit-linear-gradient(top,#fff 100%);background:-moz-linear-gradient(top,#fff 100%);background:-ms-linear-gradient(top,#fff 100%);background:-o-linear-gradient(top,#fff 100%);border-radius:100px;-webkit-border-radius:100px;-moz-border-radius:100px;margin:120px auto 20px;transition:1s}.cloud:after,.cloud:before{content:''}.cloud:after{width:100px;height:100px;top:-50px;left:50px;border-radius:100px;-webkit-border-radius:100px;-moz-border-radius:100px}.cloud:before{width:180px;height:180px;top:-90px;right:50px;border-radius:200px;-webkit-border-radius:200px;-moz-border-radius:200px}.x1{top:-50px;left:100px;-webkit-transform:scale(.3);-moz-transform:scale(.3);transform:scale(.3);opacity:.9;-webkit-animation:15s linear infinite moveclouds;-moz-animation:15s linear infinite moveclouds;-o-animation:15s linear infinite moveclouds}.x1_5{top:-80px;left:250px;-webkit-transform:scale(.3);-moz-transform:scale(.3);transform:scale(.3);-webkit-animation:17s linear infinite moveclouds;-moz-animation:17s linear infinite moveclouds;-o-animation:17s linear infinite moveclouds}.x2,.x3{left:250px;-webkit-animation:25s linear infinite moveclouds;-moz-animation:25s linear infinite moveclouds;-o-animation:25s linear infinite moveclouds}.x2{top:30px;-webkit-transform:scale(.6);-moz-transform:scale(.6);transform:scale(.6);opacity:.6}.x3{bottom:-70px;-webkit-transform:scale(.6);-moz-transform:scale(.6);transform:scale(.6);opacity:.8}.x4{left:470px;botttom:20px;-webkit-transform:scale(.75);-moz-transform:scale(.75);transform:scale(.75);opacity:.75;-webkit-animation:18s linear infinite moveclouds;-moz-animation:18s linear infinite moveclouds;-o-animation:18s linear infinite moveclouds}.x5{left:200px;top:300px;-webkit-transform:scale(.5);-moz-transform:scale(.5);transform:scale(.5);opacity:.8;-webkit-animation:20s linear infinite moveclouds;-moz-animation:20s linear infinite moveclouds;-o-animation:20s linear infinite moveclouds}@-webkit-keyframes moveclouds{0%{margin-left:1000px}100%{margin-left:-1000px}}@-moz-keyframes moveclouds{0%{margin-left:1000px}100%{margin-left:-1000px}}@-o-keyframes moveclouds{0%{margin-left:1000px}100%{margin-left:-1000px}}
  75.                 </style>
  76.  
  77.  
  78.                 </head>
  79.                 <body>
  80.                 <?php endif; // ! did_action( 'admin_head' ) ?>
  81.                
  82.                
  83.                  <div id="clouds">
  84.                     <div class="cloud x1"></div>
  85.                     <div class="cloud x1_5"></div>
  86.                     <div class="cloud x2"></div>
  87.                     <div class="cloud x3"></div>
  88.                     <div class="cloud x4"></div>
  89.                     <div class="cloud x5"></div>
  90.                 </div>
  91.                 <div class='c'>
  92.                     <div class='_404'><?php if ( isset ( $args['response'] ) ) { echo $args['response']; } else { echo '404'; } ?></div>
  93.                     <hr>
  94.                     <div class='_1'><?php echo $title ?></div>
  95.                     <div class='_2'>&nbsp;</div>
  96.                     <a class='btn' href='<?php echo get_site_url(); ?>'>BACK TO MARS</a>
  97.                 </div>
  98.                    
  99.  
  100.                 </body>
  101.                 </html>
  102.                 <?php
  103.                 if ( $parsed_args['exit'] ) {
  104.                     die();
  105.                 }                            
  106.            
  107.            
  108.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement