Plugin Directory

Changeset 1526281


Ignore:
Timestamp:
11/01/2016 09:14:16 PM (9 years ago)
Author:
Dejan Batanjac
Message:

Maintenance release.

Location:
hooks/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • hooks/trunk/hooks.php

    r918589 r1526281  
    11<?php
    2 /*
    3 Plugin Name: hooks
    4 Plugin URI: http://programming-review.com/
    5 Description: Displays WordPress plugins hooks information
    6 Author: Dejan Batanjac
    7 Version: 1.0
    8 Author URI: http://programming-review.com/
    9 License: GPLv2 or later
    10  
     2/**
     3 * Plugin Name: hooks
     4 * Plugin URI: https://programming-review.com/
     5 * Description: Displays info about WordPress actions and filters inside plugins.
     6 * Author: Dejan Batanjac
     7 * Author URI: https://programming-review.com
     8 * Version: 1.1.0
     9 * Text Domain: hooks-domain
     10 * Domain Path: languages
     11 * License: GPLv2 or later
     12
     13* Plugin "hooks" is free software: you can redistribute it and/or modify
     14* it under the terms of the GNU General Public License as published by
     15* the Free Software Foundation, either version 2 of the License, or
     16* any later version.
     17*
     18* Plugin "hooks" plugin is distributed in the hope that it will be useful,
     19* but WITHOUT ANY WARRANTY; without even the implied warranty of
     20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     21* GNU General Public License for more details.
     22*
     23* You should have received a copy of the GNU General Public License
     24* along with plugin "hooks". If not, see <http://www.gnu.org/licenses/>.
     25*
     26* TODO: Improve internalization support.
     27* TODO: Transform echo into pritntf.
     28* TODO: Add the @doctype support.
    1129*/
    1230
    13 class hooks {
     31/**
     32 * WordPress version need to be at least 4.5.
     33 */
     34global $wp_version;
     35if ( version_compare( $wp_version, '4.5', '<' ) ) {
     36    if ( is_admin() ) {
     37    require_once ABSPATH . '/wp-admin/includes/plugin.php';
     38    deactivate_plugins( __FILE__ );
     39    wp_die( __( 'Hooks requires WordPress 4.5 or higher. The plugin has now disabled itself.' ) );
     40  }
     41}
    1442
    15     /*--------------------------------------------*
    16      * Constants
    17      *--------------------------------------------*/
    18     const name = 'hooks';
    19     const slug = 'hooks';
    20    
    21     /**
    22      * Constructor
    23      */
    24     function __construct() {
    25        
    26        
    27         ini_set('display_errors',1);
    28         ini_set('display_startup_errors',1);
    29         //error_reporting(-1); 
     43/**
     44* Make sure we don't have another class like this.
     45*/
     46if ( ! class_exists( 'DB_Plugin_Hooks' ) ) :
     47final class DB_Plugin_Hooks {
     48
     49  // Constant.
     50  const SLUG = 'hooks';
     51
     52  // Constructor.
     53  function __construct() {
     54
     55    // Register an activation hook for the plugin.
     56    register_activation_hook( __FILE__, array( &$this, 'install_hooks' ) );
     57
     58    // Hook up to the init action.
     59    add_action( 'init', array( &$this, 'init_hooks' ) );
     60    add_action( 'admin_menu', array( &$this, 'menu_item' ) );
     61  }
     62
     63  function menu_item() {
     64    add_submenu_page(
     65        'plugins.php', //tools.php
     66        'Hooks List',
     67        'Hooks List',
     68        'manage_options',
     69        'hooks',
     70        array( &$this, 'draw_' )
     71    );
     72  } // End function().
     73
     74  function draw_() {
     75    echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
     76    echo '<h2>List hooks from the plugins (actions & filters)</h2>';
     77    echo '<div>Plugins:</div>';
     78
     79    $path = realpath( WP_PLUGIN_DIR );
     80
     81    $plugins = array_filter( glob( WP_PLUGIN_DIR . '/*' ), 'is_dir' );
     82    $singlefileplugins = array_filter( glob( WP_PLUGIN_DIR . '/*.php' ) );
     83
     84    foreach ( $plugins as $pl ) {
     85
     86      $pls = str_replace( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR , '', $pl );
     87      echo '<a href="#' . $pls . '">';
     88      echo esc_html( $pls );
     89      echo '</a>';
     90      echo ', ';
     91    }
     92        // Add little distance.
     93    echo '<hr>';
     94    echo '<hr>';
     95
     96    $files = $this->return_files( $path );
     97    foreach ( $files as $f ) {
     98
     99      $id = str_replace( WP_PLUGIN_DIR, '', $f );
     100      $ids = explode( DIRECTORY_SEPARATOR, $id );
     101
     102      $f1 = str_replace( WP_PLUGIN_DIR, '', $f );
     103      echo '<a id="' . $ids[1] . '">' . $ids[1] . ':::' . $f1 . '</a>';
     104      $a = $this->get_actions( $f );
     105
     106      if ( ! empty( $a ) ) {
     107        echo '<br><strong>actions:</strong>';
     108        foreach ( $a as $k => $v ) {
     109          echo '<br>line:' . $k . ':' . $this->color_me( htmlspecialchars( $v ),'do_action' );
     110        }
     111      } // End if().
     112      else {
     113                echo '<br> (no actions)';
     114            }
     115
     116      $f = $this->get_filters( $f );
     117      if ( ! empty( $f ) ) {
     118
     119        echo '<br><strong>filters:</strong>';
     120        foreach ( $f as $k => $v ) {
     121          echo '<br>line:' . $k . ':' . $this->color_me( htmlspecialchars( $v ),'apply_filters' );
     122        }
     123        echo '<hr>';
     124      } // End if().
     125      else {
     126                echo '<br> (no filters)<hr>';
     127            }
     128      echo '</ hr>';
     129    }
     130    echo '</div>';
     131  } // End function().
     132
     133  function color_me( $text, $what_to_color ) {
     134    $r = str_replace( $what_to_color, '<span style="color:red">' . $what_to_color . '</span>', $text );
     135    return $r;
     136  }
     137
     138  function return_files( $path ) {
     139    $files = array();
     140
     141    $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::LEAVES_ONLY,
     142    RecursiveIteratorIterator::CATCH_GET_CHILD);
     143    foreach ( $objects as $name => $object ) {
     144      if ( 'php' == pathinfo( $name, PATHINFO_EXTENSION ) ) {
     145        $files[] = $name;
     146      }
     147    }
     148    return $files;
     149  }
     150
     151  function get_actions( $filename ) {
     152
     153      $lines = file( $filename );
     154      $lines = preg_grep( '/do_action/', $lines );
     155      return $lines;
     156
     157  }
    30158
    31159
    32         //register an activation hook for the plugin
    33         register_activation_hook( __FILE__, array( &$this, 'install_hooks' ) );
     160  function get_filters( $filename ) {
    34161
    35         //Hook up to the init action
    36         add_action( 'init', array( &$this, 'init_hooks' ) );
    37         add_action( 'admin_menu', array( &$this, 'menu_item' ) );
    38     }
    39    
    40     function menu_item(){
    41             add_submenu_page('plugins.php', //tools.php
    42                              'Hooks List',
    43                              'Hooks List',
    44                              'manage_options',         
    45                              'hooks',
    46                              array(&$this, 'draw_'));
    47                                    
    48     }
    49    
    50     function draw_(){
    51         echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
    52         echo '<h2>List hooks from the plugins (actions & filters)</h2>';
     162      $lines = file( $filename );
     163      $lines = preg_grep( '/apply_filters/', $lines );
     164      return $lines;
     165  }
    53166
    54         echo '<div>Plugins:</div>';
    55    
    56         $path = realpath(WP_PLUGIN_DIR);
    57        
    58         $plugins = array_filter(glob(WP_PLUGIN_DIR.'/*'), 'is_dir');
    59         $singlefileplugins = array_filter(glob(WP_PLUGIN_DIR.'/*.php'));
    60        
    61         foreach($plugins as $pl){
    62            
    63             $pls = str_replace(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR , '', $pl);
    64             echo '<a href="#'.$pls.'">';           
    65             echo $pls;
    66             echo '</a>';
    67             echo ', ';
    68         }
    69         echo '<hr>';
    70         echo '<hr>';
    71        
    72         $files = $this->return_files($path);
    73         foreach($files as $f){
    74            
    75             $id = str_replace(WP_PLUGIN_DIR, '', $f);
    76             $ids = explode(DIRECTORY_SEPARATOR, $id);
    77            
    78             $f1 = str_replace(WP_PLUGIN_DIR, '', $f);
    79             echo '<a id="'.$ids[1].'">' .$ids[1]. ':::' . $f1 . '</a>';
    80             $a= $this->get_actions($f);
    81             if(!empty ($a)) {
    82                 echo '<br><strong>actions:</strong>';
    83                 foreach($a as $k=>$v){
    84                     echo '<br>line:' . $k . ':' . $this->color_me(htmlspecialchars($v),'do_action');
    85                 }
    86             }
    87             else echo '<br> (no actions)';
    88            
    89             $f = $this->get_filters($f);
    90             if(!empty ($f)) {
    91                 echo '<br><strong>filters:</strong>';
    92                 foreach($f as $k=>$v){
    93                     echo '<br>line:' . $k . ':' . $this->color_me(htmlspecialchars($v),'apply_filters');
    94                 }
    95                 echo '<hr>';
    96             }
    97             else echo '<br> (no filters)<hr>';
    98             echo '</ hr>';
    99         }       
    100        
    101        
    102        
    103        
    104         echo '</div>';
    105    
    106     }
    107    
    108     function color_me($text, $what_to_color){
    109         $r = str_replace($what_to_color, '<span style="color:red">'.$what_to_color.'</span>', $text);
    110         return $r;     
    111     }
    112    
    113     function return_files($path){
    114         $files = array();
    115        
    116         $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY,
    117     RecursiveIteratorIterator::CATCH_GET_CHILD);
    118         foreach($objects as $name => $object){
    119             if("php" == pathinfo($name, PATHINFO_EXTENSION)){
    120                 $files[] = $name;               
    121             }           
    122         }
    123         return $files;
    124     }
    125    
    126     function get_actions($filename){
    127        
    128             $lines = file($filename);       
    129             $lines = preg_grep('/do_action/', $lines);
    130             return $lines;                     
    131            
    132     }
    133    
    134    
    135     function get_filters($filename){
    136        
    137             $lines = file($filename);           
    138             $lines = preg_grep('/apply_filters/', $lines);
    139             return $lines;                     
    140            
    141     }
    142    
    143  
    144     /**
    145      * Runs when the plugin is activated
    146      */ 
    147     function install_hooks() {
    148         // do not generate any output here
    149     }
    150  
    151     /**
    152      * Runs when the plugin is initialized
    153      */
    154     function init_hooks() {
    155         // TODO in future setup localization
    156         load_plugin_textdomain( self::slug, false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
    157         // Load JavaScript and stylesheets
    158         $this->register_scripts_and_styles();
    159167
    160    
    161         if ( is_admin() ) {
    162             //this will run when in the WordPress admin
    163         } else {
    164             //this will run when on the frontend
    165         }
    166        
    167         // http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
    168         add_action( 'your_action_here', array( &$this, 'action_callback_method_name' ) );
    169         add_filter( 'your_filter_here', array( &$this, 'filter_callback_method_name' ) );   
    170     }
     168  /**
     169   * Runs when the plugin is activated.
     170   */
     171  function install_hooks() {
     172    // Info that the plugin is activated.
     173        update_option( 'DB_Plugin_Hooks', true );
     174  }
    171175
    172     function action_callback_method_name() {
    173         // TODO define your action method here
    174     }
     176  /**
     177   * Runs when the plugin is initialized
     178   */
     179  function init_hooks() {
     180    // TODO in future setup localization.
     181    load_plugin_textdomain( self::SLUG, false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
     182  }
    175183
    176     function filter_callback_method_name() {
    177         // TODO define your filter method here
    178     }
    179  
    180     /**
    181      * TODO in future
    182      * Register and enqueues stylesheets for the administration panel and the
    183      * public facing site if needed.
    184      */
    185     private function register_scripts_and_styles() {
    186         if ( is_admin() ) {
    187184
    188         } else {
     185} // End class{}.
     186endif;
    189187
    190         } // end if/else
    191     } // end register_scripts_and_styles
    192    
    193     /**
    194      * Helper function for registering and enqueueing scripts and styles.
    195      *
    196      * @name    The     ID to register with WordPress
    197      * @file_path       The path to the actual file
    198      * @is_script       Optional argument for if the incoming file_path is a JavaScript source file.
    199      */
    200     private function load_file( $name, $file_path, $is_script = false ) {
    201 
    202         $url = plugins_url($file_path, __FILE__);
    203         $file = plugin_dir_path(__FILE__) . $file_path;
    204 
    205         if( file_exists( $file ) ) {
    206             if( $is_script ) {
    207                 wp_register_script( $name, $url, array('jquery') ); //depends on jquery
    208                 wp_enqueue_script( $name );
    209             } else {
    210                 wp_register_style( $name, $url );
    211                 wp_enqueue_style( $name );
    212             } // end if
    213         } // end if
    214 
    215     } // end load_file
    216  
    217 } // end class
    218 new hooks();
    219 
    220 ?>
     188new DB_Plugin_Hooks();
  • hooks/trunk/readme.txt

    r1372210 r1526281  
    22
    33Contributors: Dejan Batanjac
    4 Tags: hook, hooks, plugins, do_action, apply_filters, developers, actions, filters, analitics, wordpress analytics
     4Tags: hook, hooks, plugins, do_action, apply_filters, developers, actions, filters, analytics
    55Requires at least: 3.0
    66Tested up to: 4.2.2
    7 Stable tag: 1.0
     7Stable tag: 1.1.0
    88
    9 Displays WordPress plugins hooks information
     9Displays info about WordPress actions and filters inside plugins.
    1010
    1111== Description ==
     
    2525== Changelog ==
    2626
     27
     28= 1.1.0 =
     29Improved comments and style
     30
    2731= 1.0 =
    28 
    2932Initial version
Note: See TracChangeset for help on using the changeset viewer.