|
3 | 3 | * Plugin Name: DustPress Debugger
|
4 | 4 | * Plugin URI: https://github.com/devgeniem/dustpress-debugger
|
5 | 5 | * Description: Provides handy ajaxified debugger tool for DustPress based themes.
|
6 |
| - * Version: 1.1.4 |
| 6 | + * Version: 1.2.0 |
7 | 7 | * Author: Geniem Oy / Miika Arponen & Ville Siltala
|
8 | 8 | * Author URI: http://www.geniem.com
|
9 | 9 | */
|
@@ -34,23 +34,31 @@ class Debugger {
|
34 | 34 | */
|
35 | 35 | public static function init() {
|
36 | 36 | 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") ); |
39 | 42 |
|
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 ); |
43 | 46 |
|
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 ); |
47 | 50 |
|
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' ) ); |
49 | 54 |
|
50 |
| - add_action( 'dustpress/data/after_render', array( __CLASS__, 'debugger' ), 100, 1 ); |
| 55 | + add_filter( "dustpress/data", array( __CLASS__, "set_hash" ) ); |
51 | 56 |
|
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 | + } |
54 | 62 | }
|
55 | 63 | }
|
56 | 64 |
|
@@ -151,6 +159,30 @@ public static function set_debugger_data( $key, $data ) {
|
151 | 159 | self::$data[ $debug_data_block_name ][ $key ][] = $data;
|
152 | 160 | }
|
153 | 161 | }
|
| 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 | + } |
154 | 186 | }
|
155 | 187 |
|
156 | 188 | add_action( 'init', __NAMESPACE__ . '\\Debugger::init' );
|
0 commit comments