Plugin Directory

Changeset 1190755


Ignore:
Timestamp:
07/01/2015 12:04:18 PM (11 years ago)
Author:
krozero199
Message:

db update fix for v 1.1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-custom-widget-area/trunk/wp-custom-widget-area.php

    r1190664 r1190755  
    4242require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-custom-widget-area-deactivator.php';
    4343
     44
     45
    4446/** This action is documented in includes/class-wp-custom-widget-area-activator.php */
    4547register_activation_hook( __FILE__, array( 'Custom_Widget_Area_Activator', 'activate' ) );
     
    7375    echo "welcome to first metabox showcase";
    7476}
     77
     78
     79// db fix for new version
     80function db_update(){
     81    global $wpdb;
     82    $table_name = 'wp_cwa';
     83    if(!!! $session_id)
     84        session_start();
     85
     86    if(!isset($_SESSION['db_update'])){
     87        $row = $wpdb->get_results(  "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
     88        WHERE table_name = '$table_name' AND column_name = 'cwa_type'"  );
     89       
     90        if(empty($row)){
     91           $wpdb->query("ALTER TABLE $table_name ADD cwa_type varchar (10) ");
     92           $updaterow = $wpdb->get_results(  "SELECT id FROM $table_name");
     93           foreach ($updaterow as $data) {
     94            # code...
     95            $up = $wpdb->update($table_name, array('cwa_type'=> 'widget'), array('id'=>$data->id));
     96           }
     97        }
     98        $_SESSION['db_update'] = true;
     99    }
     100   
     101}
     102
     103db_update();
Note: See TracChangeset for help on using the changeset viewer.