Skip to content

Commit 176533a

Browse files
author
Miika Arponen
committed
Added per profile option for the Debugger to show or not
1 parent 8111460 commit 176533a

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

plugin.php

+45-13
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.4
6+
* Version: 1.2.0
77
* Author: Geniem Oy / Miika Arponen & Ville Siltala
88
* Author URI: http://www.geniem.com
99
*/
@@ -34,23 +34,31 @@ class Debugger {
3434
*/
3535
public static function init() {
3636
if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
37-
// Register the debugger script
38-
wp_register_script( 'dustpress_debugger', plugin_dir_url( __FILE__ ) . 'js/dustpress-debugger-min.js', [ 'jquery' ], '0.0.2', true );
37+
// Register user option hooks
38+
add_action( 'show_user_profile', array( __CLASS__, "profile_option") );
39+
add_action( 'edit_user_profile', array( __CLASS__, "profile_option") );
40+
add_action( 'personal_options_update', array( __CLASS__, "save_profile_option") );
41+
add_action( 'edit_user_profile_update', array( __CLASS__, "save_profile_option") );
3942

40-
// JsonView jQuery plugin
41-
wp_enqueue_style( 'jquery.jsonview', plugin_dir_url( __FILE__ ) .'css/jquery.jsonview.css', null, null, null );
42-
wp_enqueue_script( 'jquery.jsonview', plugin_dir_url( __FILE__ ) .'js/jquery.jsonview.js', [ 'jquery' ], null, true );
43+
if ( get_the_author_meta( "dustpress_debugger", get_current_user_id() ) ) {
44+
// Register the debugger script
45+
wp_register_script( 'dustpress_debugger', plugin_dir_url( __FILE__ ) . 'js/dustpress-debugger-min.js', [ 'jquery' ], '0.0.2', true );
4346

44-
// Register debugger ajax hook
45-
add_action( 'wp_ajax_dustpress_debugger', array( __CLASS__, 'get_debugger_data' ) );
46-
add_action( 'wp_ajax_nopriv_dustpress_debugger', array( __CLASS__, 'get_debugger_data' ) );
47+
// JsonView jQuery plugin
48+
wp_enqueue_style( 'jquery.jsonview', plugin_dir_url( __FILE__ ) .'css/jquery.jsonview.css', null, null, null );
49+
wp_enqueue_script( 'jquery.jsonview', plugin_dir_url( __FILE__ ) .'js/jquery.jsonview.js', [ 'jquery' ], null, true );
4750

48-
add_filter( "dustpress/data", array( __CLASS__, "set_hash" ) );
51+
// Register debugger ajax hook
52+
add_action( 'wp_ajax_dustpress_debugger', array( __CLASS__, 'get_debugger_data' ) );
53+
add_action( 'wp_ajax_nopriv_dustpress_debugger', array( __CLASS__, 'get_debugger_data' ) );
4954

50-
add_action( 'dustpress/data/after_render', array( __CLASS__, 'debugger' ), 100, 1 );
55+
add_filter( "dustpress/data", array( __CLASS__, "set_hash" ) );
5156

52-
// Register DustPress core helper hooks
53-
add_filter( 'dustpress/menu/data', array( __CLASS__, "gather_menu_helper_data") );
57+
add_action( 'dustpress/data/after_render', array( __CLASS__, 'debugger' ), 100, 1 );
58+
59+
// Register DustPress core helper hooks
60+
add_filter( 'dustpress/menu/data', array( __CLASS__, "gather_menu_helper_data") );
61+
}
5462
}
5563
}
5664

@@ -151,6 +159,30 @@ public static function set_debugger_data( $key, $data ) {
151159
self::$data[ $debug_data_block_name ][ $key ][] = $data;
152160
}
153161
}
162+
163+
public static function profile_option( $user ) {
164+
$current_status = get_the_author_meta( "dustpress_debugger", $user->ID );
165+
166+
?>
167+
<h3>DustPress Debugger</h3>
168+
169+
<table class="form-table">
170+
<tr>
171+
<th><label for="dustpress_debugger">DustPress Debugger enabled</label></th>
172+
<td>
173+
<input type="checkbox" name="dustpress_debugger" id="dustpress_debugger"<?php if ( $current_status ): ?> checked="checked"<?php endif; ?>/>
174+
</td>
175+
</tr>
176+
</table>
177+
<?php }
178+
179+
public static function save_profile_option( $user_id ) {
180+
if ( ! current_user_can( "edit_user" ) ) {
181+
return false;
182+
}
183+
184+
update_usermeta( $user_id, "dustpress_debugger", $_POST["dustpress_debugger"] );
185+
}
154186
}
155187

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

0 commit comments

Comments
 (0)