Plugin Directory

Changeset 336399


Ignore:
Timestamp:
01/24/2011 05:23:12 AM (15 years ago)
Author:
mgolawala
Message:

Add Check for compatible PHP Version before initializing. Also add deactivation hook, that will clean up the option entry for the plugin

Location:
wp-category-manager/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-category-manager/trunk/readme.txt

    r293641 r336399  
    3939== Changelog ==
    4040
     41= 2.0.0.2 =
     42* Checks for compatible version of PHP before allowing plugin to be activated.
     43* Better cleanup on plugin deactivation. (Also means loss of settings on deactivation)
     44
    4145= 2.0.0.1 =
    4246* Minor Patch to stop loading of JS & CSS files outside the Admin section
  • wp-category-manager/trunk/wp-category-manager.php

    r293641 r336399  
    3535{
    3636    var $plugin_url;
    37    
     37
    3838    function CategoryManager()
    3939    {
     
    5050        }
    5151    }
    52    
    53     function add_dashboard_widgets() 
     52
     53    function add_dashboard_widgets()
    5454    {
    5555        if(wpcm_options::get_option('OnDashboard') == 'on' && (function_exists('current_user_can') ?  current_user_can('edit_posts') : true) )
     
    5959                , array(&$this, 'dashboard_widget_render_function'));
    6060        }
    61     } 
    62    
    63     function dashboard_widget_render_function() 
     61    }
     62
     63    function dashboard_widget_render_function()
    6464    {
    6565        $term = wpcm_options::get_option('defaultTerm');
    6666        $postlist = wpcm_functions::get_posts($term, 0);
    67        
     67
    6868
    6969        if(wpcm_options::get_option('enableDropdown') == 'on')
     
    7575            echo '<div class="catmanheader" style="display:none;">';
    7676        }
    77        
     77
    7878        echo '<span class="catmanpostcount"></span>';
    7979        echo '<span class="catmanselection">';
     
    8181        echo '</span>';
    8282        echo '</div>';
    83        
     83
    8484
    8585        echo '<div id="catmanpostlist" class="list:catmanpost" >';
     
    100100        echo '<span class="catmannextPage"><a href="javascript:void(0);">[Next]</a></span>';
    101101        echo '</div>';
    102     } 
    103    
     102    }
     103
    104104    // Set up default values
    105     function install()
    106     {
    107         wpcm_options::get_options();
     105    function install()
     106    {
     107        if (version_compare(PHP_VERSION, '5.0.0', '<') )
     108        {
     109            exit("Sorry, this version of WP-Category-Manager will only run on PHP version 5 or greater!\n");
     110        }
     111        wpcm_options::set_options();
     112    }
     113
     114    // Uninstall the options set for this plugin
     115    function uninstall()
     116    {
     117        wpcm_options::delete_options();
    108118    }
    109119
     
    207217        echo '</div>';
    208218    }
    209    
     219
    210220    function admin_menu()
    211221    {
    212222        add_options_page('Category Manager Options', 'Category Manager', 8, basename(__FILE__), array('wpcm_options', 'render_option_settings'));
    213223    }
    214    
     224
    215225    function print_scripts()
    216226    {
    217227        $nonce = wp_create_nonce("wp-category-manager");
    218                        
     228
    219229        wp_enqueue_script('jquery');
    220230        wp_enqueue_script('categoryManager_script', $this->plugin_url . 'wp-category-manager.js', array('jquery'));
     
    227237                , 'showConfirm' => wpcm_options::get_option('showConfirm')
    228238                ,'nonce' => $nonce));
    229                
    230     }
    231    
     239
     240    }
     241
    232242    function print_styles()
    233243    {
     
    237247}
    238248
    239 endif; 
     249endif;
    240250
    241251if ( class_exists('CategoryManager') ) :
    242    
     252
    243253    $categoryManager = new CategoryManager();
    244254    if (isset($categoryManager)) {
    245255        register_activation_hook( __FILE__, array(&$categoryManager, 'install') );
    246     }
    247    
     256        register_deactivation_hook(__FILE__, array(&$categoryManager, 'uninstall') );
     257    }
     258
    248259endif;
    249260
  • wp-category-manager/trunk/wpcm-options.php

    r293639 r336399  
    11<?php
    2 /* 
     2/*
    33 * This class acts as the interface to the wordpress options table and is used to get and set the option values
     4 * for the current plugin.
     5 * It is a simple wrapper around the WordPress Options API such that it abstracts out the maintenance
     6 * of a single options array for a given plugin.
     7 * ToDo : refactor the class such as the options array maintained by this class is defined by the
     8 *          plugin using this class. Right now it is hardcoded to maintain the specific options array
     9 *          associated with the category manager.
    410 */
    511if ( !class_exists('wpcm_options') ) :
     
    814{
    915    private static $db_option = 'CategoryManager_options';
    10    
     16
    1117    // handle the settings/options page
    1218    public static function render_option_settings()
    1319    {
    14         $options = self::get_options();
     20        $options = self::set_options();
    1521
    1622        if( isset($_POST['submitted']))
     
    4955
    5056    // Save/Update the options from the DB
    51     public static function get_options()
     57    public static function set_options()
    5258    {
    5359        $options = array
     
    7985    }
    8086
     87    // Retrieve the value of a specific option from the plugin's option set
    8188    public static function get_option($optionName)
    8289    {
    83         $options = self::get_options();
     90        $options = self::set_options();
    8491
    8592        return $options[$optionName];
    8693    }
    87    
     94
     95    // removes any option entries associated with the plugin from the options table
     96    public static function delete_options()
     97    {
     98        delete_option(self::$db_option);
     99    }
    88100}
    89101endif;
Note: See TracChangeset for help on using the changeset viewer.