Skip to content
Permalink
Browse files

Merge pull request #120 from devgeniem/error404

Error404
  • Loading branch information
Nomafin committed Sep 20, 2019
2 parents 4e7fc1b + 0f7898a commit a4f2e8107336874fea12680b4793e5337d708fd2
Showing with 54 additions and 2 deletions.
  1. +5 −1 classes/model.php
  2. +49 −1 dustpress.php
@@ -850,7 +850,11 @@ protected function in_array_r($needle, $haystack, $strict = true) {
return false;
}

protected function terminate() {
public function terminate() {
$this->terminated = true;
}

public function get_terminated() {
return $this->terminated;
}
}
@@ -152,7 +152,7 @@ protected function __construct() {
add_action( 'init', [ $this, 'init_settings' ] );

// Register custom route rewrite tag
add_action( 'init', [ $this, 'rewrite_tags' ], 20 );
add_action( 'after_setup_theme', [ $this, 'rewrite_tags' ], 20 );

return;
}
@@ -244,6 +244,10 @@ public function create_instance() {

$this->model->fetch_data();

if ( $this->model->get_terminated() ) {
return;
}

do_action( 'dustpress/model_list', array_keys( (array) $this->model->get_submodels() ) );

$template_override = $this->model->get_template();
@@ -1686,6 +1690,50 @@ private function parse_request_data() {
die( json_encode( [ 'error' => 'Something went wrong. There was no dustpress_data present at the request.' ] ) );
}
}

/**
* Force 404 page and status from anywhere
*
* @type function
* @date 03/04/2019
* @since 1.23.0
*
* @return void
*/
public function error404( \DustPress\Model $model ) {
global $wp_query;

$model->terminate();

\status_header( 404 );

$template = 'Error404';

if ( class_exists ( $template ) ) {
$this->model = new $template();

$this->model->fetch_data();

$this->model->terminate();

do_action( 'dustpress/model_list', array_keys( (array) $this->model->get_submodels() ) );

$template_override = $this->model->get_template();

$partial = $template_override ? $template_override : strtolower( $this->camelcase_to_dashed( $template ) );

$this->render([
'partial' => $partial,
'main' => true,
'type' => 'default'
]);

$this->disable();
}
else {
die( 'DustPress error: No suitable model found. One of these is required: '. implode( ', ', $debugs ) );
}
}
}

// Global function that returns the DustPress singleton

0 comments on commit a4f2e81

Please sign in to comment.
You can’t perform that action at this time.