Skip to content

Commit dc7c780

Browse files
author
Miika Arponen
committed
Uses core only via hooks now
1 parent bf61890 commit dc7c780

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

plugin.php

+42-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: DustPress Debugger
44
* Plugin URI: https://github.com/devgeniem/dustpress-debugger
55
* Description: Provides handy ajaxified debugger tool for DustPress based themes.
6-
* Version: 1.1.2
6+
* Version: 1.1.3
77
* Author: Geniem Oy / Miika Arponen & Ville Siltala
88
* Author URI: http://www.geniem.com
99
*/
@@ -27,6 +27,7 @@
2727
class Debugger {
2828

2929
private static $hash;
30+
private static $data = [];
3031

3132
/**
3233
* Add hooks if the user has correct capabilities.
@@ -46,7 +47,10 @@ public static function init() {
4647

4748
add_filter( "dustpress/data", array( __CLASS__, "set_hash" ) );
4849

49-
add_action( 'dustpress/data/after_render', array( __CLASS__, 'debugger' ), 1, 1 );
50+
add_action( 'dustpress/data/after_render', array( __CLASS__, 'debugger' ), 100, 1 );
51+
52+
// Register DustPress core helper hooks
53+
add_filter( 'dustpress/menu/data', array( __CLASS__, "gather_menu_helper_data") );
5054
}
5155
}
5256

@@ -77,14 +81,17 @@ public static function set_hash( $data ) {
7781
* @param string $hash The current data hash.
7882
*/
7983
public static function debugger( $data ) {
80-
$data = apply_filters( 'dustpress/debugger/data', $data );
84+
85+
$debugger_data = array_merge( $data, self::$data );
86+
87+
$debugger_data = apply_filters( 'dustpress/debugger/data', $debugger_data );
8188

8289
// start session for data storing
8390
if ( session_status() == PHP_SESSION_NONE ) {
8491
session_start();
8592
}
8693

87-
$_SESSION[ self::$hash ] = $data;
94+
$_SESSION[ self::$hash ] = $debugger_data;
8895

8996
session_write_close();
9097
}
@@ -117,6 +124,37 @@ public static function get_debugger_data() {
117124
wp_send_json( $output );
118125
}
119126
}
127+
128+
public static function gather_menu_helper_data( $data ) {
129+
self::set_debugger_data( 'Menu', $data );
130+
131+
return $data;
132+
}
133+
134+
/**
135+
* Gathers debug data from other sources than DustPress core.
136+
*/
137+
public static function set_debugger_data( $key, $data ) {
138+
if ( empty( $key ) ) {
139+
die( 'You did not set a key for your debugging data collection.' );
140+
} else {
141+
$debug_data_block_name = dustpress()->get_setting( "debug_data_block_name" );
142+
143+
$model_data = [];
144+
145+
if ( ! isset( $model_data[ $debug_data_block_name ] ) ) {
146+
$model_data[ $debug_data_block_name ] = [];
147+
}
148+
149+
if ( ! isset( $model_data[ $debug_data_block_name ][ $key ] ) ) {
150+
$model_data[ $debug_data_block_name ][ $key ] = [];
151+
}
152+
153+
$model_data[ $debug_data_block_name ][ $key ][] = $data;
154+
}
155+
156+
self::$data = array_merge( self::$data, $model_data );
157+
}
120158
}
121159

122160
add_action( 'init', __NAMESPACE__ . '\\Debugger::init' );

0 commit comments

Comments
 (0)