Skip to content

Commit d08373f

Browse files
author
Ville Siltala
committed
The core returns also data for Debugger on DustPress.js ajax calls that render the response as HTML.
1 parent 573281b commit d08373f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

dustpress.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Author: Miika Arponen & Ville Siltala / Geniem Oy
77
Author URI: http://www.geniem.com
88
License: GPLv3
9-
Version: 1.2.2
9+
Version: 1.2.3
1010
*/
1111

1212
final class DustPress {
@@ -931,23 +931,35 @@ public function create_ajax_instance() {
931931

932932
// If we don't want to render, json-encode and return just the data
933933
if ( empty( $partial ) ) {
934-
die( json_encode( [ "success" => $instance->data ] ) );
934+
die( wp_json_encode( [ "success" => $instance->data ] ) );
935935
}
936936
else {
937937
$template_override = $instance->get_template();
938938

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

941-
if ( $tidy && is_array( $functions ) && count( $functions ) == 1 ) {
942-
die( json_encode( [ "success" => $this->render( [ "partial" => $partial, "data" => $instance->data->{$functions[0]}, "echo" => false ] ) ] ) );
941+
if ( $tidy && is_array( $functions ) && count( $functions ) === 1 ) {
942+
943+
$data = $instance->data->{$functions[0]};
944+
945+
$html = $this->render( [ "partial" => $partial, "data" => $data, "echo" => false ] );
943946
}
944947
else {
945-
die( json_encode( [ "success" => $this->render( [ "partial" => $partial, "data" => $instance->data, "echo" => false ] ) ] ) );
948+
$data = $instance->data;
949+
$html = $this->render( [ "partial" => $partial, "data" => $data, "echo" => false ] );
950+
}
951+
952+
$response = [ "success" => $html ];
953+
954+
if ( is_plugin_active( 'dustpress-debugger/plugin.php' ) ) {
955+
$response["debug"] = $data;
946956
}
957+
958+
die( wp_json_encode( $response ) );
947959
}
948960
}
949961
else {
950-
die( json_encode( [ "error" => "Model '". $model ."' does not exist." ] ) );
962+
die( wp_json_encode( [ "error" => "Model '". $model ."' does not exist." ] ) );
951963
}
952964
}
953965

0 commit comments

Comments
 (0)