Browse code

プラグイン停止、削除時処理

nita authored on 2015/10/14 02:02:51
Showing 1 changed files
... ...
@@ -46,6 +46,10 @@ class Rucy_Class {
46 46
             add_filter('manage_'.$p.'_columns', array( $this, 'manage_rucy_cols' ) );
47 47
             add_action('manage_'.$p.'_custom_column', array( $this, 'add_rucy_col' ), 10, 2); 
48 48
         }
49
+        // deactivation this plugin
50
+        register_deactivation_hook( __FILE__ , array( $this, 'uninstall_rucy' ) );
51
+        // uninstall this plugin
52
+        register_uninstall_hook( __FILE__, array( $this, 'uninstall_rucy' ) );
49 53
     }
50 54
     
51 55
     public function activate_plugin() {
... ...
@@ -102,5 +106,17 @@ class Rucy_Class {
102 102
             }
103 103
         }
104 104
     }
105
+    
106
+    public function uninstall_rucy() {
107
+        wp_clear_scheduled_hook( RC_CRON_HOOK );
108
+        delete_option( RC_SETTING_OPTION_KEY );
109
+        $all_posts = get_posts( 'numberposts=-1&post_status=' );
110
+        $meta_keys = array( 'accept', 'content', 'date', 'feature_img', 'accept_feature_img', 'accept_update' );
111
+        foreach ( $all_posts as $post_info ) {
112
+            foreach ( $meta_keys as $key ) {
113
+                delete_post_meta( $post_info->ID, $key );
114
+            }
115
+        }
116
+    }
105 117
 }
106 118
 new Rucy_Class();
107 119
\ No newline at end of file