Skip to content

Commit

Permalink
Merge pull request #10 from level-level/fix/crash_deleted_404_page
Browse files Browse the repository at this point in the history
Fix crash if 404 page has been deleted
  • Loading branch information
menno-ll authored Sep 30, 2024
2 parents 2ac350c + 3142eb2 commit c9157b0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions clarkson-404.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Plugin Name: Custom 404 page
* Version: 1.0.2
* Version: 1.0.3
* Description: A plugin to set a custom page as 404 for Clarkson
* Author: Level Level
* Author URI: http://www.level-level.com
Expand Down Expand Up @@ -55,19 +55,22 @@ public function add_404_object( $objects ) {
}

$id = get_option( 'clarkson-page-for-404', false );

if ( ! $id ) {
return $objects;
}

$id = get_post( $id );
$page_not_found_post = get_post( $id );
if ( ! $page_not_found_post instanceof WP_Post ) {
return $objects;
}

global $post;
$post = $id;
$post = $page_not_found_post;

$object_loader = Objects::get_instance();

try {
$page = $object_loader->get_object( $id );
$page = $object_loader->get_object( $page_not_found_post );
} catch ( \Exception $e ) {
return $objects;
}
Expand Down

0 comments on commit c9157b0

Please sign in to comment.