Changeset 1490542
- Timestamp:
- 09/05/2016 08:33:06 PM (9 years ago)
- Location:
- simply-show-hooks/trunk
- Files:
-
- 2 added
- 7 deleted
- 2 edited
-
assets/css/cxssh-main.css (added)
-
assets/css/ssh-main.css (deleted)
-
assets/js/cxssh-main.js (added)
-
assets/js/ssh-main.js (deleted)
-
index.php (modified) (24 diffs)
-
localization/assets (deleted)
-
localization/index.php (deleted)
-
localization/readme.txt (deleted)
-
localization/screenshot-1.png (deleted)
-
localization/screenshot-2.png (deleted)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
simply-show-hooks/trunk/index.php
r1161226 r1490542 14 14 defined( 'ABSPATH' ) or die( 'No Trespassing!' ); // Security 15 15 16 if ( ! class_exists( 'Simply_Show_Hooks' ) ) : 17 18 class Simply_Show_Hooks { 16 class CX_Simply_Show_Hooks { 19 17 20 18 private $status; … … 54 52 // Use this to set any tags known to cause display problems. 55 53 // Will be display in sidebar. 56 $this->ignore_hooks = apply_filters( 's sh_ignore_hooks', array(54 $this->ignore_hooks = apply_filters( 'simply_show_hooks_ignore_hooks', array( 57 55 'attribute_escape', 58 56 'body_class', … … 65 63 add_action( 'plugins_loaded', array( $this, 'load_translation' ) ); 66 64 67 // Init 68 add_action( 'init', array( $this, 'wp_init' ) ); 65 // Set autive status property. 66 $this->set_active_status(); 67 68 // Attach the hooks as on plugin init. 69 $this->attach_hooks(); 70 71 // Init the plugin. 72 add_action( 'init', array( $this, 'plugin_init' ) ); 73 } 74 75 /** 76 * Helper function that sets the active status of the hooks displaying. 77 */ 78 public function set_active_status() { 69 79 70 80 if ( ! isset( $this->status ) ) { 71 81 72 if ( !isset( $_COOKIE['ssh_status']) ) 73 setcookie('ssh_status', 'off', time()+3600*24*100, '/'); 74 75 if ( isset( $_REQUEST['ssh-hooks']) ) { 76 setcookie('ssh_status', $_REQUEST['ssh-hooks'], time()+3600*24*100, '/'); 77 $this->status = $_REQUEST['ssh-hooks']; 78 } 79 elseif ( isset( $_COOKIE['ssh_status']) ) { 80 $this->status = $_COOKIE['ssh_status']; 82 if ( ! isset( $_COOKIE['cxssh_status'] ) ) { 83 setcookie( 'cxssh_status', 'off', time()+3600*24*100, '/' ); 84 } 85 86 if ( isset( $_REQUEST['cxssh-hooks'] ) ) { 87 setcookie( 'cxssh_status', $_REQUEST['cxssh-hooks'], time()+3600*24*100, '/' ); 88 $this->status = $_REQUEST['cxssh-hooks']; 89 } 90 elseif ( isset( $_COOKIE['cxssh_status'] ) ) { 91 $this->status = $_COOKIE['cxssh_status']; 81 92 } 82 93 else{ … … 84 95 } 85 96 } 97 } 98 99 /** 100 * Helper function to attach the filter that render all the hook labels. 101 */ 102 public function attach_hooks() { 86 103 87 104 if ( $this->status == 'show-action-hooks' || $this->status == 'show-filter-hooks' ) { … … 89 106 add_filter( 'all', array( $this, 'hook_all_hooks' ), 100 ); 90 107 add_action( 'shutdown', array( $this, 'notification_switch' ) ); 91 92 108 add_action( 'shutdown', array( $this, 'filter_hooks_panel' ) ); 93 109 } 94 110 } 111 112 /** 113 * Helper function to detach the filter that render all the hook labels. 114 */ 115 public function detach_hooks() { 116 117 remove_filter( 'all', array( $this, 'hook_all_hooks' ), 100 ); 118 remove_action( 'shutdown', array( $this, 'notification_switch' ) ); 119 remove_action( 'shutdown', array( $this, 'filter_hooks_panel' ) ); 120 } 121 95 122 96 123 /* … … 99 126 function admin_bar_menu( $wp_admin_bar ) { 100 127 128 // Suspend the hooks rendering. 129 $this->detach_hooks(); 130 131 // Setup a base URL and clear it of the intial `cxssh-hooks` arg. 132 $url = remove_query_arg( 'cxssh-hooks' ); 133 101 134 if ( 'show-action-hooks' == $this->status ) { 102 135 103 $title = __( ' HideAction Hooks' , 'simply-show-hooks' );104 $href = '?ssh-hooks=off';105 $css = ' ssh-hooks-onssh-hooks-normal';136 $title = __( 'Stop Showing Action Hooks' , 'simply-show-hooks' ); 137 $href = add_query_arg( 'cxssh-hooks', 'off', $url ); 138 $css = 'cxssh-hooks-on cxssh-hooks-normal'; 106 139 } 107 140 else { 108 141 109 142 $title = __( 'Show Action Hooks' , 'simply-show-hooks' ); 110 $href = '?ssh-hooks=show-action-hooks';143 $href = add_query_arg( 'cxssh-hooks', 'show-action-hooks', $url ); 111 144 $css = ''; 112 145 } 113 146 114 $wp_admin_bar->add_menu( array(147 $wp_admin_bar->add_menu( array( 115 148 'title' => '<span class="ab-icon"></span><span class="ab-label">' . __( 'Simply Show Hooks' , 'simply-show-hooks' ) . '</span>', 116 'id' => ' ssh-main-menu',149 'id' => 'cxssh-main-menu', 117 150 'parent' => false, 118 151 'href' => $href, 119 ) );120 121 $wp_admin_bar->add_menu( array(152 ) ); 153 154 $wp_admin_bar->add_menu( array( 122 155 'title' => $title, 123 'id' => ' ssh-simply-show-hooks',124 'parent' => ' ssh-main-menu',156 'id' => 'cxssh-simply-show-hooks', 157 'parent' => 'cxssh-main-menu', 125 158 'href' => $href, 126 'meta' => array( 'class' => $css ) 127 ) );159 'meta' => array( 'class' => $css ), 160 ) ); 128 161 129 162 130 163 if ( $this->status=="show-filter-hooks" ) { 131 164 132 $title = 'Hide Action & Filter Hooks';133 $href = '?ssh-hooks=off';134 $css = ' ssh-hooks-onssh-hooks-sidebar';165 $title = __( 'Stop Showing Action & Filter Hooks' , 'simply-show-hooks' ); 166 $href = add_query_arg( 'cxssh-hooks', 'off', $url ); 167 $css = 'cxssh-hooks-on cxssh-hooks-sidebar'; 135 168 } 136 169 else { 137 170 138 $title = 'Show Action & Filter Hooks';139 $href = '?ssh-hooks=show-filter-hooks';171 $title = __( 'Show Action & Filter Hooks' , 'simply-show-hooks' ); 172 $href = add_query_arg( 'cxssh-hooks', 'show-filter-hooks', $url ); 140 173 $css = ''; 141 174 } 142 175 143 $wp_admin_bar->add_menu( array(176 $wp_admin_bar->add_menu( array( 144 177 'title' => $title, 145 'id' => ' ssh-show-all-hooks',146 'parent' => ' ssh-main-menu',178 'id' => 'cxssh-show-all-hooks', 179 'parent' => 'cxssh-main-menu', 147 180 'href' => $href, 148 'meta' => array( 'class' => $css ) 149 )); 181 'meta' => array( 'class' => $css ), 182 ) ); 183 184 // De-suspend the hooks rendering. 185 $this->attach_hooks(); 150 186 } 151 187 … … 154 190 ?> 155 191 <style> 156 #wp-admin-bar- ssh-main-menu .ab-icon:before{192 #wp-admin-bar-cxssh-main-menu .ab-icon:before{ 157 193 font-family: "dashicons" !important; 158 194 content: "\f323" !important; … … 169 205 */ 170 206 function notification_switch() { 207 208 // Suspend the hooks rendering. 209 $this->detach_hooks(); 210 211 // Setup a base URL and clear it of the intial `cxssh-hooks` arg. 212 $url = add_query_arg( 'cxssh-hooks', 'off' ); 171 213 ?> 172 <a class=" ssh-notification-switch" href="?ssh-hooks=off">173 <span class=" ssh-notification-indicator"></span>174 <?php echo 'Hide Hooks' ; // _e( 'Hide Hooks' , 'simply-show-hooks' )?>214 <a class="cxssh-notification-switch" href="<?php echo esc_url( $url ); ?>"> 215 <span class="cxssh-notification-indicator"></span> 216 <?php echo _e( 'Stop Showing Hooks' , 'simply-show-hooks' ); ?> 175 217 </a> 176 218 <?php 177 } 178 179 function wp_init() { 180 181 // Restrict use to Admins only 182 if ( !current_user_can('manage_options') ) { return false; } 219 220 // De-suspend the hooks rendering. 221 $this->attach_hooks(); 222 } 223 224 function plugin_init() { 225 226 if ( 227 ! current_user_can( 'manage_options' ) || // Restrict use to Admins only 228 ! $this->plugin_active() // Allow filters to deactivate. 229 ) { 230 $this->status = 'off'; 231 return; 232 } 183 233 184 234 // Enqueue Scripts/Styles - in head of admin … … 208 258 209 259 public function enqueue_script() { 210 211 260 global $wp_scripts, $current_screen; 212 261 213 262 // Main Styles 214 wp_register_style( ' ssh-main-css', plugins_url( basename( plugin_dir_path( __FILE__ ) ) . '/assets/css/ssh-main.css', basename( __FILE__ ) ), '', '1.1.0', 'screen' );215 wp_enqueue_style( ' ssh-main-css' );263 wp_register_style( 'cxssh-main-css', plugins_url( basename( plugin_dir_path( __FILE__ ) ) . '/assets/css/cxssh-main.css', basename( __FILE__ ) ), '', '1.1.0', 'screen' ); 264 wp_enqueue_style( 'cxssh-main-css' ); 216 265 217 266 // Main Scripts 218 267 /* 219 wp_register_script( ' ssh-main-js', plugins_url( basename( plugin_dir_path( __FILE__ ) ) . '/assets/js/ssh-main.js', basename( __FILE__ ) ), array('jquery'), '1.1.0' );220 wp_enqueue_script( ' ssh-main-js' );221 wp_localize_script(' ssh-main-js', 'ssh-main-js', array(268 wp_register_script( 'cxssh-main-js', plugins_url( basename( plugin_dir_path( __FILE__ ) ) . '/assets/js/cxssh-main.js', basename( __FILE__ ) ), array('jquery'), '1.1.0' ); 269 wp_enqueue_script( 'cxssh-main-js' ); 270 wp_localize_script('cxssh-main-js', 'cxssh-main-js', array( 222 271 'home_url' => get_home_url(), 223 272 'admin_url' => admin_url(), … … 269 318 270 319 public function hook_all_hooks( $hook ) { 271 272 320 global $wp_actions, $wp_filter; 273 321 274 if ( !in_array( $hook, $this->recent_hooks ) ) {322 if ( ! in_array( $hook, $this->recent_hooks ) ) { 275 323 276 324 if ( isset( $wp_actions[$hook] ) ) { … … 294 342 } 295 343 296 // if ( isset( $wp_actions[$hook] ) && $wp_actions[$hook] == 1 && !in_array( $hook, $this->ignore_hooks ) ) {297 // if ( ( isset( $wp_actions[$hook] ) || isset( $wp_filter[$hook] ) ) && !in_array( $hook, $this->ignore_hooks ) ) {344 // if ( isset( $wp_actions[$hook] ) && $wp_actions[$hook] == 1 && !in_array( $hook, $this->ignore_hooks ) ) { 345 // if ( ( isset( $wp_actions[$hook] ) || isset( $wp_filter[$hook] ) ) && !in_array( $hook, $this->ignore_hooks ) ) { 298 346 if ( isset( $wp_actions[$hook] ) && !in_array( $hook, $this->recent_hooks ) && !in_array( $hook, $this->ignore_hooks ) ) { 299 347 … … 306 354 } 307 355 else{ 308 // s('(skiped-hook!)');309 // $this->render_action( $hook );310 } 311 312 // Discarded functionality: if the hook was 356 // s('(skiped-hook!)'); 357 // $this->render_action( $hook ); 358 } 359 360 // Discarded functionality: if the hook was 313 361 // run recently then don't show it again. 314 362 // Better to use the once run or always run theory. … … 318 366 if ( count( $this->recent_hooks ) > 100 ) { 319 367 array_shift( $this->recent_hooks ); 320 } 368 } 321 369 } 322 370 … … 326 374 */ 327 375 function render_action( $args = array() ) { 328 329 376 global $wp_filter; 330 377 … … 340 387 } 341 388 ?> 342 <span style="display:none;" class=" ssh-hook ssh-hook-<?php echo $args['type'] ?> <?php echo ( $nested_hooks ) ? 'ssh-hook-has-hooks' : '' ; ?>" >389 <span style="display:none;" class="cxssh-hook cxssh-hook-<?php echo $args['type'] ?> <?php echo ( $nested_hooks ) ? 'cxssh-hook-has-hooks' : '' ; ?>" > 343 390 344 391 <?php 345 392 if ( 'action' == $args['type'] ) { 346 393 ?> 347 <span class=" ssh-hook-typessh-hook-type">A</span>394 <span class="cxssh-hook-type cxssh-hook-type">A</span> 348 395 <?php 349 396 } 350 397 else if ( 'filter' == $args['type'] ) { 351 398 ?> 352 <span class=" ssh-hook-typessh-hook-type">F</span>399 <span class="cxssh-hook-type cxssh-hook-type">F</span> 353 400 <?php 354 401 } … … 372 419 if ( $nested_hooks_count ) { 373 420 ?> 374 <span class=" ssh-hook-count">421 <span class="cxssh-hook-count"> 375 422 <?php echo $nested_hooks_count ?> 376 423 </span> … … 385 432 if ( $nested_hooks ): 386 433 ?> 387 <ul class=" ssh-hook-dropdown">434 <ul class="cxssh-hook-dropdown"> 388 435 389 <li class=" ssh-hook-heading">436 <li class="cxssh-hook-heading"> 390 437 <strong><?php echo $args['type'] ?>:</strong> <?php echo $args['ID']; ?> 391 438 </li> … … 396 443 // Show the priority number if the following hooked functions 397 444 ?> 398 <li class=" ssh-priority">399 <span class=" ssh-priority-label"><strong><?php echo 'Priority:'; /* _e('Priority', 'simply-show-hooks') */ ?></strong> <?php echo $nested_key ?></span>445 <li class="cxssh-priority"> 446 <span class="cxssh-priority-label"><strong><?php echo 'Priority:'; /* _e('Priority', 'simply-show-hooks') */ ?></strong> <?php echo $nested_key ?></span> 400 447 </li> 401 448 <?php … … 411 458 // Hooked function ( of type object->method() ) 412 459 ?> 413 <span class=" ssh-function-string">460 <span class="cxssh-function-string"> 414 461 <?php 415 462 $classname = false; … … 418 465 419 466 if ( is_object( $nested_inner_value['function'][0] ) ) { 420 $classname = get_class($nested_inner_value['function'][0] );467 $classname = get_class($nested_inner_value['function'][0] ); 421 468 } 422 469 … … 436 483 // Hooked function ( of type function() ) 437 484 ?> 438 <span class=" ssh-function-string">485 <span class="cxssh-function-string"> 439 486 <?php echo $nested_inner_key ?> 440 487 </span> … … 465 512 */ 466 513 function filter_hooks_panel() { 467 468 514 global $wp_filter, $wp_actions; 469 470 515 ?> 471 <div class=" ssh-nested-hooks-block <?php echo ( 'show-filter-hooks' == $this->status ) ? 'ssh-active' : '' ; ?> ">516 <div class="cxssh-nested-hooks-block <?php echo ( 'show-filter-hooks' == $this->status ) ? 'cxssh-active' : '' ; ?> "> 472 517 <?php 473 518 foreach ( $this->all_hooks as $va_nested_value ) { … … 478 523 else{ 479 524 ?> 480 <div class=" ssh-collection-divider">525 <div class="cxssh-collection-divider"> 481 526 <?php echo $va_nested_value['ID'] ?> 482 527 </div> … … 496 541 <?php 497 542 } 498 543 544 function plugin_active() { 545 546 // Filters to deactivate our plugin - backend, frontend or sitewide. 547 // add_filter( 'simply_show_hooks_active', '__return_false' ); 548 // add_filter( 'simply_show_hooks_backend_active', '__return_false' ); 549 // add_filter( 'simply_show_hooks_frontend_active', '__return_false' ); 550 551 if ( ! apply_filters( 'simply_show_hooks_active', TRUE ) ) { 552 553 // Sitewide. 554 return FALSE; 555 } 556 557 if ( is_admin() ) { 558 559 // Backend. 560 if ( ! apply_filters( 'simply_show_hooks_backend_active', TRUE ) ) return FALSE; 561 } 562 else { 563 564 // Frontend. 565 if ( ! apply_filters( 'simply_show_hooks_frontend_active', TRUE ) ) return FALSE; 566 } 567 568 return TRUE; 569 } 499 570 } 500 571 501 Simply_Show_Hooks::get_instance(); 502 503 endif; 572 CX_Simply_Show_Hooks::get_instance(); -
simply-show-hooks/trunk/readme.txt
r1161226 r1490542 50 50 = 1.1.1 = 51 51 * Fixed small typo showing Filter as Action in heading. 52 53 = 1.2.1 = 54 * Respect existing query strings when switching the Show Hooks on and off. 55 * Changed the prefix slug `ssh` to a more unique `cxssh`. 56 * Use mono-space font to display hooks. 57 * Added filters to allow you to deactivate our plugin on the frontend, backend or sitewide - `simply_show_hooks_active, simply_show_hooks_backend_active, simply_show_hooks_frontend_active`.
Note: See TracChangeset
for help on using the changeset viewer.