WordPress.org

Plugin Directory

Changeset 614739


Ignore:
Timestamp:
10/19/12 21:24:08 (18 months ago)
Author:
maor
Message:

Code optimization and documentation fixes

Location:
plugin-activation-date/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • plugin-activation-date/trunk/plugin-activation-date.php

    r596562 r614739  
    33 * Plugin Name: Plugin Activation Date 
    44 * Plugin URI: http://wordpress.org/extend/plugins/plugin-activation-date/ 
    5  * Description: Shows when each plugin was last activated. Useful in instances where many plugins are installed. 
    6  * Version: 1.0 
     5 * Description: Shows when each plugin's status was changed. Useful in instances where many plugins are installed. 
     6 * Version: 1.1 
    77 * Author: Maor Chasen 
    88 * Author URI: http://maorchasen.com 
     
    1313 
    1414/** 
    15  * Some optional features: 
     15 * Main plugin wrapper. 
     16 * 
     17 * @since  1.0 
    1618 * @todo make column sortable using WP_List_Table's built in sorting method 
    1719 * @todo support multisite 
     
    1921class Plugin_Activation_Date { 
    2022 
     23    /** 
     24     * Holds the de/activation date for all plugins. 
     25     * 
     26     * @since  1.0 
     27     * @access private 
     28     * @var array 
     29     */ 
    2130    private $options = array(); 
    2231 
     32    /** 
     33     * Constructor. 
     34     * Sets up activation hook, localization support and registers some essential hooks. 
     35     * 
     36     * @since  1.0 
     37     * @access public 
     38     * @return Plugin_Activation_Date 
     39     */ 
    2340    public function __construct() { 
    24         register_activation_hook( __FILE__, array( $this, 'activation' ) ); 
    25  
    26         // Load our text domain 
    27         load_plugin_textdomain( 'padate', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
    28  
    29         // Set up some hooks to power this plugin 
    30         add_filter( 'admin_init' , array( $this, 'register_settings_field' ) ); 
    31         add_filter( 'manage_plugins_columns', array( $this, 'plugins_columns' ) ); 
    32         add_action( 'activate_plugin', array( $this, 'pad_plugin_activated' ) ); 
    33         add_action( 'deactivate_plugin', array( $this, 'pad_plugin_deactivated' ) ); 
    34         add_action( 'admin_head-plugins.php', array( $this, 'column_css_styles' ) ); 
     41        // Register essential hooks. Pay special attention to {activate/deactivate}_plugin. 
     42        add_filter( 'admin_init' ,                  array( $this, 'register_settings_field' ) ); 
     43        add_filter( 'manage_plugins_columns',       array( $this, 'plugins_columns' ) ); 
     44        add_action( 'activate_plugin',              array( $this, 'pad_plugin_status_changed' ) ); 
     45        add_action( 'deactivate_plugin',            array( $this, 'pad_plugin_status_changed' ) ); 
     46        add_action( 'admin_head-plugins.php',       array( $this, 'column_css_styles' ) ); 
    3547        add_action( 'manage_plugins_custom_column', array( $this, 'activated_columns' ), 10, 3 ); 
    3648 
    3749        // Get them options, and keep around for later use 
    3850        $this->options = get_option( 'pad_activated_plugins', array() ); 
     51        // Load our text domain 
     52        load_plugin_textdomain( 'padate', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
     53        // Runs on activation only 
     54        register_activation_hook( __FILE__, array( $this, 'activation' ) ); 
    3955    } 
    4056 
    41     public function pad_plugin_activated( $plugin ) { 
     57    /** 
     58     * Runs when a plugin changes status, and adds the de/activation timestamp 
     59     * to $this->options, then stores it in the options table. 
     60     * 
     61     * @since  1.1 
     62     * @param string $plugin The path to the de/activated plugin 
     63     */ 
     64    public function pad_plugin_status_changed( $plugin ) { 
    4265        $this->options[ $plugin ] = array( 
    43             'status'    => 'activated', 
     66            'status'    => current_filter() == 'activate_plugin' ? 'activated' : 'deactivated', 
    4467            'timestamp' => current_time( 'timestamp' ) 
    4568        ); 
     
    4770    } 
    4871 
    49     public function pad_plugin_deactivated( $plugin ) { 
    50         $this->options[ $plugin ] = array( 
    51             'status'    => 'deactivated', 
    52             'timestamp' => current_time( 'timestamp' ) 
    53         ); 
    54         update_option( 'pad_activated_plugins', $this->options ); 
    55     } 
    56  
     72    /** 
     73     * Sets up the column headings. 
     74     *  
     75     * @since 1.0 
     76     * @uses   $status Indicates on which plugin screen we are currently 
     77     * @param  array $columns All of the columns for the plugins page 
     78     * @return array The same array with our new column 
     79     */ 
    5780    public function plugins_columns( $columns ) { 
    5881        global $status; 
    5982 
     83        // If we're either on the Must Use or Drop-ins tabs, there's no reason to show the column 
    6084        if ( ! in_array( $status, array( 'mustuse', 'dropins' ) ) ) 
    6185            if ( ! in_array( $status, array( 'recently_activated', 'inactive' ) ) ) 
     
    6892 
    6993    /** 
    70      * Output the date when this plugin was last activated. Repeats for all plugins. 
     94     * Outputs the date when this plugin was last activated. Repeats for all plugins. 
     95     * 
     96     * @since  1.0 
     97     * @param  string $column_name The column key 
     98     * @param  string $plugin_file The path to the current plugin in the loop 
     99     * @param  array $plugin_data Extra plugin data 
    71100     */ 
    72101    public function activated_columns( $column_name, $plugin_file, $plugin_data ) { 
     
    85114    } 
    86115 
     116    /** 
     117     * Register a settings field under Settings > General 
     118     * 
     119     * @since  1.0 
     120     * @uses register_setting Registers the setting option 
     121     * @uses add_settings_field Regisers the field 
     122     */ 
    87123    public function register_settings_field() { 
    88124        register_setting( 'general', 'pad_display_relative_date', 'esc_attr' ); 
     
    90126    } 
    91127 
     128    /** 
     129     * Prints the field's HTML 
     130     * 
     131     * @since  1.0 
     132     * @param  array $args Extra arguments passed by add_settings_field 
     133     */ 
    92134    public function fields_html( $args ) { 
    93135        $value = get_option( 'pad_display_relative_date', 0 ); 
     
    96138    } 
    97139 
     140    /** 
     141     * Displays the de/activation date for every plugin respectively. 
     142     * 
     143     * @since  1.0 
     144     * @uses apply_filters() Calls 'pad_date_time_format' for plugins to alter the output date format. 
     145     * @param  string $timestamp The timestamp for the current plugin in the loop 
     146     * @return string The formatted date 
     147     */ 
    98148    public function display_date( $timestamp ) { 
    99149        $is_relative = 'on' == get_option( 'pad_display_relative_date' ) ? true : false; 
     
    108158    /** 
    109159     * Set our column's width so it's more readable. 
    110      * We're rockin' HTML5 style, baby! 
     160     * 
     161     * @since  1.0 
    111162     */ 
    112163    public function column_css_styles() { 
     
    116167    } 
    117168 
     169    /** 
     170     * Runs on activation, registers a few options for this plugin to operate. 
     171     *  
     172     * @since 1.0 
     173     * @uses add_option() 
     174     */ 
    118175    public function activation() { 
    119176        add_option( 'pad_activated_plugins' ); 
     
    121178    } 
    122179} 
    123  
    124 new Plugin_Activation_Date; 
     180// Initiate the plugin. Access everywhere using $global plugin_activation_date 
     181$GLOBALS['plugin_activation_date'] = new Plugin_Activation_Date; 
  • plugin-activation-date/trunk/readme.txt

    r596560 r614739  
    44Requires at least: 3.0 
    55Tested up to: 3.4.2 
    6 Stable tag: 1.0 
     6Stable tag: 1.1 
    77License: GPLv2 or later 
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    3131== Changelog == 
    3232 
     33= 1.1 = 
     34* Code optimization and documentation fixes 
     35 
    3336= 1.0 = 
    3437* Initial release 
Note: See TracChangeset for help on using the changeset viewer.