Guest User

Untitled

a guest
Jun 2nd, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. #################### update function ############################
  2. function sb_update_plugin(){ //runs when all plugins are loaded (needs to be deleted after register_update_hook is avaiable)
  3.     global $wpdb, $sb_ip_log;
  4.  
  5.     if(sb_get_plugin_version() != get_option('sb_plugin_version') OR get_option('sb_plugin_version') == FALSE){
  6.         add_action('admin_notices', 'sb_activation_notice'); //show activation message
  7.  
  8.         sb_create_db_table(); //update the plugin table to a desired structure
  9.  
  10.             #### now comes everything what must be changed in the new version
  11.  
  12.             if(get_option('sb_plugin_version') == '1.3'){ //upgrade to v1.4:               
  13.                 add_option('sb_automatic_ip_address_duplication', '0', '', 'yes');
  14.                 add_option('sb_automatic_ip_address_duplication_recurrence', 'twicedaily', '', 'yes');
  15.                 add_option('sb_spam_comment_automatic_elimination', '1', '', 'yes');
  16.                 add_option('sb_automatic_ip_address_duplication_last_cron_run_time', '', '', 'yes');
  17.  
  18.                 //renaming options and values -- v1.5 - zpetna kompatibilita
  19.                 add_option('sb_access_restrictions', '1', '', 'yes'); //adding new option
  20.                 delete_option('sb_detection_of_spammers_cookies');
  21.                 add_option('sb_detection_of_spammers_method', '1', '', 'yes');
  22.  
  23.                 delete_option('sb_detection_of_spammers_time');
  24.                 add_option('sb_detection_of_spammers_time', '2592000', '', 'yes');
  25.             }
  26.  
  27.             if(get_option('sb_plugin_version') == '1.4'){ //upgrade to v1.5
  28.                 add_option('sb_access_restrictions', '1', '', 'yes'); //adding new option
  29.  
  30.                 //renaming options and values
  31.                 delete_option('sb_detection_of_spammers_cookies');
  32.                 add_option('sb_detection_of_spammers_method', '1', '', 'yes');
  33.  
  34.                 delete_option('sb_detection_of_spammers_time');
  35.                 add_option('sb_detection_of_spammers_time', '2592000', '', 'yes');
  36.  
  37.                 //add new column hits to sb_ip_log table
  38.                 $wpdb->query("ALTER TABLE $sb_ip_log ADD hits INT;");
  39.                 //add 1 to all rows
  40.                 $wpdb->query("UPDATE $sb_ip_log SET hits = '1';");         
  41.             }
  42.  
  43.             #### -/changes
  44.  
  45.         update_option('sb_plugin_version', sb_get_plugin_version(), '', 'yes'); //update plugin version in DB
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment