Browse code

アップデート時にプラグインバージョン情報更新処理追加

nita authored on 2015/10/17 20:17:03
Showing 2 changed files
... ...
@@ -15,8 +15,10 @@ class Class_Rucy_Component {
15 15
     }
16 16
     public function get_support_post_type() {
17 17
         $res = get_option( RC_SETTING_OPTION_KEY );
18
-        if( !is_array( $res ) ) {
18
+        if( !$res ) {
19 19
             $res = array( 'post', 'page' );
20
+        } else if ( !is_array( $res ) ) {
21
+            $res = explode( ',' , $res );
20 22
         }
21 23
         return $res;
22 24
     }
... ...
@@ -16,6 +16,7 @@ define( 'RC_TXT_DOMAIN', 'rucy' );
16 16
 define( 'RC_CRON_HOOK', 'rucy_update_reserved_content' );
17 17
 define( 'RC_SETTING_UPDATE', 'rucy_setting_update' );
18 18
 define( 'RC_SETTING_ERROR', 'rucy_setting_error' );
19
+define( 'RC_VERSION', '0.4.0' );
19 20
 load_plugin_textdomain( RC_TXT_DOMAIN, false, 'rucy/lang' );
20 21
 
21 22
 require_once RC_PLUGIN_DIR . '/inc/class-rucy-component.php';
... ...
@@ -28,6 +29,7 @@ class Rucy_Class {
28 28
     
29 29
     public function __construct() {
30 30
         register_activation_hook( plugin_basename(__FILE__), array( $this, 'activate_plugin' ) );
31
+        add_action( 'admin_init', array( $this, 'rucy_upgrade' ) );
31 32
         add_action('admin_enqueue_scripts', array( $this, 'enqueue_style_script' ));
32 33
         add_action( 'admin_menu', array( $this, 'enqueue_pointer_menu' ) );
33 34
         add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_setting_link' ) );
... ...
@@ -114,6 +116,7 @@ class Rucy_Class {
114 114
     public function uninstall_rucy() {
115 115
         wp_clear_scheduled_hook( RC_CRON_HOOK );
116 116
         delete_option( RC_SETTING_OPTION_KEY );
117
+        delete_option( RC_VERSION );
117 118
         $all_posts = get_posts( 'numberposts=-1&post_status=' );
118 119
         $component = new Class_Rucy_Component();
119 120
         $post_meta_keys = $component->get_post_meta_keys();
... ...
@@ -123,5 +126,27 @@ class Rucy_Class {
123 123
             }
124 124
         }
125 125
     }
126
+    
127
+    public function rucy_upgrade() {
128
+        $rc_version = get_option( 'rucy_version' );
129
+        $rc_support_types = get_option( RC_SETTING_OPTION_KEY );
130
+        $is_old = false;
131
+        if ( $rc_version ) {
132
+            // compare
133
+            $new_version = RC_VERSION;
134
+            if ( $rc_version != $new_version ) {
135
+                $is_old = true;
136
+            }
137
+        } else {
138
+            // old version lessthan 0.3.0
139
+            $is_old = true;
140
+            if ( !is_array( $rc_support_types ) ) {
141
+                update_option( RC_SETTING_OPTION_KEY, explode( ',', $rc_support_types ) );
142
+            }
143
+        }
144
+        if ( $is_old ) {
145
+            update_option( 'rucy_version' , RC_VERSION );
146
+        }
147
+    }
126 148
 }
127 149
 new Rucy_Class();
128 150
\ No newline at end of file