@@ -87,6 +87,9 @@ private function __construct() {
8787 add_action ( 'admin_bar_menu ' , array ( $ this , 'register_menu ' ), 99 );
8888 add_action ( 'all ' , array ( $ this , 'parent_hook ' ) );
8989 add_action ( 'shutdown ' , array ( $ this , 'print_hookr_flowchart ' ), 9999 );
90+ add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'enqueue_stuff ' ) );
91+ add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_stuff ' ) );
92+ add_action ( 'init ' , array ( $ this , 'show_flowchart ' ), 9999 );
9093 }
9194
9295 /**
@@ -181,12 +184,9 @@ public static function activate( $network_wide ) {
181184
182185 restore_current_blog ();
183186 }
184- } else {
185- self ::single_activate ();
186187 }
187- } else {
188- self ::single_activate ();
189188 }
189+ self ::single_activate ();
190190 }
191191
192192 /**
@@ -197,9 +197,9 @@ public static function activate( $network_wide ) {
197197 */
198198 function register_menu ( $ wp_admin_bar ) {
199199 $ wp_admin_bar ->add_node ( array (
200- 'id ' => 'hook-flowchart ' ,
201- 'title ' => 'Hook FlowChart ' ,
202- 'href ' => '# '
200+ 'id ' => 'hook-flowchart ' ,
201+ 'title ' => 'Hook FlowChart ' ,
202+ 'href ' => '# '
203203 ) );
204204 }
205205
@@ -225,7 +225,7 @@ private static function single_activate() {
225225 *
226226 * @since 1.0.0
227227 */
228- function parent_hook () {
228+ public function parent_hook () {
229229 global $ wp_current_filter ;
230230 foreach ( $ wp_current_filter as $ child => $ hook_name ) {
231231 if ( $ child === 0 && !isset ( $ this ->hooks [ $ hook_name ] ) ) {
@@ -240,22 +240,58 @@ function parent_hook() {
240240 }
241241 }
242242
243+ public function enqueue_stuff () {
244+ if ( is_user_logged_in () ) {
245+ wp_enqueue_style ( HF_TEXTDOMAIN . '-plugin-styles ' , plugins_url ( 'public/assets/css/mermaid.css ' , HF_PLUGIN_ABSOLUTE ), array (), HF_VERSION );
246+ wp_enqueue_script ( HF_TEXTDOMAIN . '-mermaid ' , plugins_url ( 'public/assets/js/mermaid.js ' , HF_PLUGIN_ABSOLUTE ), array ( 'jquery ' ), HF_VERSION );
247+ wp_enqueue_script ( HF_TEXTDOMAIN . '-plugin-script ' , plugins_url ( 'public/assets/js/popupcode.js ' , HF_PLUGIN_ABSOLUTE ), array ( 'jquery ' ), HF_VERSION );
248+ }
249+ }
250+
243251 /**
244252 * Generate the window
245253 *
246254 * @since 1.0.0
247255 */
248256 function print_hookr_flowchart () {
249- $ html = '' ;
250- ksort ( $ this ->hooks );
251- $ exclude = get_option ( $ this ->get_plugin_slug () );
252- $ exclude = explode ( ', ' , $ exclude [ 'excluded ' ] );
253- foreach ( $ exclude as $ key => $ value ) {
254- if ( isset ( $ this ->hooks [ $ value ] ) ) {
255- unset( $ this ->hooks [ $ value ] );
257+ if ( !isset ( $ _GET [ 'hookr-flowchart ' ] ) ) {
258+ ksort ( $ this ->hooks );
259+ $ exclude = get_option ( $ this ->get_plugin_slug () );
260+ $ exclude = explode ( ', ' , $ exclude [ 'excluded ' ] );
261+ foreach ( $ exclude as $ key => $ value ) {
262+ if ( isset ( $ this ->hooks [ $ value ] ) ) {
263+ unset( $ this ->hooks [ $ value ] );
264+ }
256265 }
266+
267+ echo '<div class="hookr-flowchart" style="display:none;z-index:9999;"> '
268+ . '<div class="body" style="padding-left:20px"><h1>Hook Flowchart</h1><h3> ' . "\n"
269+ . __ ( 'Use ctrl + f to use your browser search function or click on that buttons to jump to the parent hook, check the hook to hide ' , $ this ->get_plugin_slug () ) . '</h3><span class="buttons"></span> ' . "\n"
270+ . $ this ->array_to_mermaid ( $ this ->hooks ) . "\n"
271+ . '<button class="button button-primary gotop" style="float:right;position:fixed;bottom:10px;right:10px;"> ' . __ ( 'Go Top ' , $ this ->get_plugin_slug () ) . '</button></div> '
272+ . '</div><style>.hookr-flowchart {z-index: 9999;position: absolute;}.wp-admin .hookr-flowchart{margin-left: 160px;}</style><script> '
273+ . 'jQuery(document).ready(function() { '
274+ . 'jQuery( "#wp-admin-bar-hook-flowchart a" ).click(function() {
275+ jQuery(".hookr-flowchart").show();
276+ }); '
277+ . '}); '
278+ . '</script> ' ;
257279 }
258- foreach ( $ this ->hooks as $ hook_father => $ hook_son ) {
280+ }
281+
282+ public function show_flowchart () {
283+ if ( is_user_logged_in () ) {
284+ if ( isset ( $ _GET [ 'hookr-flowchart ' ] ) ) {
285+ $ hooks = str_replace ( '\" ' , '" ' , $ _GET [ 'hookr-flowchart ' ] );
286+ ;
287+ die ();
288+ }
289+ }
290+ }
291+
292+ public function array_to_mermaid ( $ hooks ) {
293+ $ html = '' ;
294+ foreach ( $ hooks as $ hook_father => $ hook_son ) {
259295 if ( is_array ( $ hook_son ) && count ( $ hook_son ) > 1 ) {
260296 $ html .= '<div class="mermaid-noise" style="display:none"> ' ;
261297 $ html .= '[n]graph LR ' . "[n] " ;
@@ -284,22 +320,7 @@ function print_hookr_flowchart() {
284320 $ html .= '</div> ' ;
285321 }
286322 }
287- $ html = '<html><head><title>Hook Flowchart - ' . $ _SERVER [ 'REQUEST_URI ' ] . '</title> '
288- . '<link rel="stylesheet" type="text/css" href=" ' . get_site_url () . '/wp-admin/load-styles.php?c=1&dir=ltr&load=wp-admin,buttons" /> '
289- . '<link rel="stylesheet" type="text/css" href=" ' . plugins_url ( 'assets/css/mermaid.css ' , __FILE__ ) . '" /> '
290- . '<script type="text/javascript" src=" ' . plugins_url ( 'assets/js/mermaid.js ' , __FILE__ ) . '"></script> '
291- . '<script type="text/javascript" src=" ' . plugins_url ( 'assets/js/popupcode.js ' , __FILE__ ) . '"></script> '
292- . '</head><body class="wp-core-ui"><div class="body" style="padding-left:20px"><h1>Hook Flowchart - ' . get_site_url () . $ _SERVER [ 'REQUEST_URI ' ] . '</h1><h3> ' . __ ( 'Use ctrl + f to use your browser search function or click on that buttons to jump to the parent hook, check the hook to hide ' , $ this ->get_plugin_slug () ) . '</h3><span class="buttons"></span> ' . $ html . '<button class="button button-primary gotop" style="float:right;position:fixed;bottom:10px;right:10px;"> ' . __ ( 'Go Top ' , $ this ->get_plugin_slug () ) . '</button></div></body></html> ' ;
293- echo '<script> '
294- . 'jQuery(document).ready(function() { '
295- . 'jQuery( "#wp-admin-bar-hook-flowchart a" ).click(function() {
296- html = jQuery("<div/>").html(" ' . htmlentities ( $ html ) . '").text();
297- url = \'data:text/html, \' + html;
298- var win = window.open(url, "_blank");
299- win.focus();
300- }); '
301- . '}); '
302- . '</script> ' ;
323+ return $ html ;
303324 }
304325
305326}
0 commit comments