Plugin Directory

Changeset 1490542


Ignore:
Timestamp:
09/05/2016 08:33:06 PM (9 years ago)
Author:
stuartobrien
Message:

fix folder structure

Location:
simply-show-hooks/trunk
Files:
2 added
7 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • simply-show-hooks/trunk/index.php

    r1161226 r1490542  
    1414defined( 'ABSPATH' ) or die( 'No Trespassing!' ); // Security
    1515
    16 if ( ! class_exists( 'Simply_Show_Hooks' ) ) :
    17 
    18 class Simply_Show_Hooks {
     16class CX_Simply_Show_Hooks {
    1917   
    2018    private $status;
     
    5452        // Use this to set any tags known to cause display problems.
    5553        // Will be display in sidebar.
    56         $this->ignore_hooks = apply_filters( 'ssh_ignore_hooks', array(
     54        $this->ignore_hooks = apply_filters( 'simply_show_hooks_ignore_hooks', array(
    5755            'attribute_escape',
    5856            'body_class',
     
    6563        add_action( 'plugins_loaded', array( $this, 'load_translation' ) );
    6664       
    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() {
    6979       
    7080        if ( ! isset( $this->status ) ) {
    7181           
    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'];
    8192            }
    8293            else{
     
    8495            }
    8596        }
     97    }
     98   
     99    /**
     100     * Helper function to attach the filter that render all the hook labels.
     101     */
     102    public function attach_hooks() {
    86103       
    87104        if ( $this->status == 'show-action-hooks' || $this->status == 'show-filter-hooks' ) {
     
    89106            add_filter( 'all', array( $this, 'hook_all_hooks' ), 100 );
    90107            add_action( 'shutdown', array( $this, 'notification_switch' ) );
    91            
    92108            add_action( 'shutdown', array( $this, 'filter_hooks_panel' ) );
    93109        }
    94110    }
     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   
    95122   
    96123    /*
     
    99126    function admin_bar_menu( $wp_admin_bar ) {
    100127       
     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       
    101134        if ( 'show-action-hooks' == $this->status ) {
    102135           
    103             $title  = __( 'Hide Action Hooks' , 'simply-show-hooks' );
    104             $href   = '?ssh-hooks=off';
    105             $css    = 'ssh-hooks-on ssh-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';
    106139        }
    107140        else {
    108141           
    109142            $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 );
    111144            $css    = '';
    112145        }
    113146       
    114         $wp_admin_bar->add_menu(array(
     147        $wp_admin_bar->add_menu( array(
    115148            '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',
    117150            'parent'    => false,
    118151            'href'      => $href,
    119         ));
    120        
    121         $wp_admin_bar->add_menu(array(
     152        ) );
     153       
     154        $wp_admin_bar->add_menu( array(
    122155            'title'     => $title,
    123             'id'        => 'ssh-simply-show-hooks',
    124             'parent'    => 'ssh-main-menu',
     156            'id'        => 'cxssh-simply-show-hooks',
     157            'parent'    => 'cxssh-main-menu',
    125158            'href'      => $href,
    126             'meta'      => array( 'class' => $css )
    127         ));
     159            'meta'      => array( 'class' => $css ),
     160        ) );
    128161       
    129162       
    130163        if ( $this->status=="show-filter-hooks" ) {
    131164           
    132             $title  = 'Hide Action & Filter Hooks';
    133             $href   = '?ssh-hooks=off';
    134             $css    = 'ssh-hooks-on ssh-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';
    135168        }
    136169        else {
    137170           
    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 );
    140173            $css    = '';
    141174        }
    142175       
    143         $wp_admin_bar->add_menu(array(
     176        $wp_admin_bar->add_menu( array(
    144177            'title'     => $title,
    145             'id'        => 'ssh-show-all-hooks',
    146             'parent'    => 'ssh-main-menu',
     178            'id'        => 'cxssh-show-all-hooks',
     179            'parent'    => 'cxssh-main-menu',
    147180            '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();
    150186    }
    151187   
     
    154190        ?>
    155191        <style>
    156         #wp-admin-bar-ssh-main-menu .ab-icon:before{
     192        #wp-admin-bar-cxssh-main-menu .ab-icon:before{
    157193            font-family: "dashicons" !important;
    158194            content: "\f323" !important;
     
    169205     */
    170206    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' );
    171213        ?>
    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' ); ?>
    175217        </a>
    176218        <?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        }
    183233       
    184234        // Enqueue Scripts/Styles - in head of admin
     
    208258   
    209259    public function enqueue_script() {
    210        
    211260        global $wp_scripts, $current_screen;
    212261       
    213262        // 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' );
    216265
    217266        // Main Scripts
    218267        /*
    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(
    222271            'home_url' => get_home_url(),
    223272            'admin_url' => admin_url(),
     
    269318   
    270319    public function hook_all_hooks( $hook ) {
    271        
    272320        global $wp_actions, $wp_filter;
    273321       
    274         if( !in_array( $hook, $this->recent_hooks ) ) {
     322        if ( ! in_array( $hook, $this->recent_hooks ) ) {
    275323           
    276324            if ( isset( $wp_actions[$hook] ) ) {
     
    294342        }
    295343       
    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 ) ) {
    298346        if ( isset( $wp_actions[$hook] ) && !in_array( $hook, $this->recent_hooks ) && !in_array( $hook, $this->ignore_hooks ) ) {
    299347           
     
    306354        }
    307355        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
    313361        // run recently then don't show it again.
    314362        // Better to use the once run or always run theory.
     
    318366        if ( count( $this->recent_hooks ) > 100 ) {
    319367            array_shift( $this->recent_hooks );
    320         }   
     368        }
    321369    }
    322370   
     
    326374     */
    327375    function render_action( $args = array() ) {
    328        
    329376        global $wp_filter;
    330377       
     
    340387        }
    341388        ?>
    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' : '' ; ?>" >
    343390           
    344391            <?php
    345392            if ( 'action' == $args['type'] ) {
    346393                ?>
    347                 <span class="ssh-hook-type ssh-hook-type">A</span>
     394                <span class="cxssh-hook-type cxssh-hook-type">A</span>
    348395                <?php
    349396            }
    350397            else if ( 'filter' == $args['type'] ) {
    351398                ?>
    352                 <span class="ssh-hook-type ssh-hook-type">F</span>
     399                <span class="cxssh-hook-type cxssh-hook-type">F</span>
    353400                <?php
    354401            }
     
    372419            if ( $nested_hooks_count ) {
    373420                ?>
    374                 <span class="ssh-hook-count">
     421                <span class="cxssh-hook-count">
    375422                    <?php echo $nested_hooks_count ?>
    376423                </span>
     
    385432                if ( $nested_hooks ):
    386433                    ?>
    387                     <ul class="ssh-hook-dropdown">
     434                    <ul class="cxssh-hook-dropdown">
    388435                       
    389                         <li class="ssh-hook-heading">
     436                        <li class="cxssh-hook-heading">
    390437                            <strong><?php echo $args['type'] ?>:</strong> <?php echo $args['ID']; ?>
    391438                        </li>
     
    396443                            // Show the priority number if the following hooked functions
    397444                            ?>
    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>
    400447                            </li>
    401448                            <?php
     
    411458                                        // Hooked function ( of type object->method() )
    412459                                        ?>
    413                                         <span class="ssh-function-string">
     460                                        <span class="cxssh-function-string">
    414461                                            <?php
    415462                                            $classname = false;
     
    418465                                               
    419466                                                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] );
    421468                                                }
    422469                                               
     
    436483                                        // Hooked function ( of type function() )
    437484                                        ?>
    438                                         <span class="ssh-function-string">
     485                                        <span class="cxssh-function-string">
    439486                                            <?php echo $nested_inner_key ?>
    440487                                        </span>
     
    465512     */
    466513    function filter_hooks_panel() {
    467        
    468514        global $wp_filter, $wp_actions;
    469        
    470515        ?>
    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' : '' ; ?> ">
    472517            <?php
    473518            foreach ( $this->all_hooks as $va_nested_value ) {
     
    478523                else{
    479524                    ?>
    480                     <div class="ssh-collection-divider">
     525                    <div class="cxssh-collection-divider">
    481526                        <?php echo $va_nested_value['ID'] ?>
    482527                    </div>
     
    496541        <?php
    497542    }
    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    }
    499570}
    500571
    501 Simply_Show_Hooks::get_instance();
    502 
    503 endif;
     572CX_Simply_Show_Hooks::get_instance();
  • simply-show-hooks/trunk/readme.txt

    r1161226 r1490542  
    5050= 1.1.1 =
    5151* 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.