Plugin Directory

Changeset 225203


Ignore:
Timestamp:
04/04/2010 01:00:48 PM (16 years ago)
Author:
nkuttler
Message:

performe options upgrade

Location:
custom-avatars-for-comments/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • custom-avatars-for-comments/trunk/comment_avatars.php

    r225201 r225203  
    7676     * @since 0.0.2
    7777     */
    78     function get_option ( $option ) {
     78    function get_option( $option ) {
    7979        if ( isset ( $this->options[$option] ) )
    8080            return $this->options[$option];
  • custom-avatars-for-comments/trunk/inc/admin.php

    r225202 r225203  
    99class CommentAvatarsAdmin extends CommentAvatars {
    1010
     11   
     12    /**
     13     * Version of the options format
     14     *
     15     * @since 0.2.0.0
     16     * @var string
     17     */
     18    var $version = '0.2.0.0';
     19
    1120    /**
    1221     * Path to the main plugin file
     
    3140     *
    3241     * @return none
    33      * @since 3.0.0.0
     42     * @since 0.0.2
    3443     */
    3544    function __construct () {
    3645        CommentAvatars::__construct ();
    3746
     47        $this->check_upgrade();
     48
    3849        // Full path to main file
    3950        $this->plugin_file = dirname ( dirname ( __FILE__ ) ) . '/comment_avatars.php';
     
    7081    function defaults () {
    7182        $defaults = array (
    72                 'version'           =>  '0.1.2',
     83                'version'           =>  '0.2.0.0',
    7384                'usedefaultpng'     =>  '0',
    7485                'hidedefaultpng'    =>  '0',
     
    92103     * @since 0.0.2
    93104     */
    94     function init () {
     105    function init() {
    95106        if ( ! get_option ( 'commentavatars' ) )
    96107            add_option ( 'commentavatars' , $this->defaults () );
    97     }
     108        else
     109            $this->check_upgrade();
     110    }
     111
     112    /**
     113     * Check if we need to perform an upgrade
     114     *
     115     * @return none
     116     * @since 0.2.0.0
     117     */
     118     function check_upgrade() {
     119        if ( version_compare ( $this->get_option( 'version' ), $this->version, '<' ) )
     120            $this->upgrade();
     121     }
     122
     123    /**
     124     * Perform an upgrade
     125     *
     126     * @return none
     127     * @since 0.2.0.0
     128     */
     129     function upgrade() {
     130        if ( version_compare( $this->get_option( 'version' ), '0.2.0.0' ) == -1 ) {
     131            // If the plugin was already in use we assume the user added the
     132            // select field by hand and hide it.
     133            $newopts = $this->defaults();
     134            $this->options = array_merge( $this->options , $newopts );
     135            $this->options['removeselect'] = '1';
     136            #var_dump( $this->options );
     137            update_option( 'commentavatars', $this->options );
     138        }
     139     }
    98140
    99141    /**
     
    103145     * @since 0.0.2
    104146     */
    105     function add_page () {
     147    function add_page() {
    106148        if ( current_user_can ( 'manage_options' ) && function_exists ( 'add_options_page' ) ) {
    107149            $options_page = add_options_page ( __( 'Comment Avatars' , 'custom-avatars-for-comments' ) , __( 'Comment Avatars' , 'custom-avatars-for-comments' ) , 'manage_options' , 'commentavatars' , array ( &$this , 'admin_page' ) );
     
    163205            <form method="post" action="options.php"> <?php
    164206                settings_fields( 'commentavatars_options' ); ?>
     207                <input type="hidden" name="commentavatars[version]" value="<?php echo $this->get_option( 'version' ) ?>" />
    165208                <table class="form-table form-table-clearnone" >
    166209
     
    262305                    </tr>
    263306
    264                 </table>
    265307                    <tr valign="top">
    266308                        <th scope="row"> <?php
Note: See TracChangeset for help on using the changeset viewer.