|
6 | 6 | Author: Miika Arponen & Ville Siltala / Geniem Oy
|
7 | 7 | Author URI: http://www.geniem.com
|
8 | 8 | License: GPLv3
|
9 |
| -Version: 1.2.2 |
| 9 | +Version: 1.2.3 |
10 | 10 | */
|
11 | 11 |
|
12 | 12 | final class DustPress {
|
@@ -931,23 +931,35 @@ public function create_ajax_instance() {
|
931 | 931 |
|
932 | 932 | // If we don't want to render, json-encode and return just the data
|
933 | 933 | if ( empty( $partial ) ) {
|
934 |
| - die( json_encode( [ "success" => $instance->data ] ) ); |
| 934 | + die( wp_json_encode( [ "success" => $instance->data ] ) ); |
935 | 935 | }
|
936 | 936 | else {
|
937 | 937 | $template_override = $instance->get_template();
|
938 | 938 |
|
939 | 939 | $partial = $template_override ? $template_override : strtolower( $this->camelcase_to_dashed( $partial ) );
|
940 | 940 |
|
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 ] ); |
943 | 946 | }
|
944 | 947 | 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; |
946 | 956 | }
|
| 957 | + |
| 958 | + die( wp_json_encode( $response ) ); |
947 | 959 | }
|
948 | 960 | }
|
949 | 961 | else {
|
950 |
| - die( json_encode( [ "error" => "Model '". $model ."' does not exist." ] ) ); |
| 962 | + die( wp_json_encode( [ "error" => "Model '". $model ."' does not exist." ] ) ); |
951 | 963 | }
|
952 | 964 | }
|
953 | 965 |
|
|
0 commit comments