コード例 #1
0
 public function install_or_update_plugin()
 {
     $installer = new WPBDP_Installer();
     $installer->install();
 }
コード例 #2
0
 public function uninstall_plugin()
 {
     global $wpdb;
     $nonce = isset($_POST['_wpnonce']) ? trim($_POST['_wpnonce']) : '';
     if ($nonce && wp_verify_nonce($nonce, 'uninstall bd')) {
         $installer = new WPBDP_Installer();
         // Delete listings.
         $post_ids = $wpdb->get_col($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_type = %s", WPBDP_POST_TYPE));
         foreach ($post_ids as $post_id) {
             wp_delete_post($post_id, true);
         }
         // Drop tables.
         $tables = array_keys($installer->get_database_schema());
         foreach ($tables as &$table) {
             $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}wpbdp_{$table}");
         }
         // Delete options.
         delete_option('wpbdp-db-version');
         delete_option('wpbusdirman_db_version');
         $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", 'wpbdp%'));
         // Clear scheduled hooks.
         wp_clear_scheduled_hook('wpbdp_listings_expiration_check');
         $tracking = new WPBDP_SiteTracking();
         $tracking->track_uninstall(isset($_POST['uninstall']) ? $_POST['uninstall'] : null);
         // Deactivate plugin.
         $real_path = WPBDP_PATH . 'business-directory-plugin.php';
         // if the plugin directory is a symlink, plugin_basename will return
         // the real path, which may not be the same path WP associated to
         // the plugin. Plugin paths must be of the form:
         // wp-content/plugins/plugin-directory/plugin-file.php
         $fixed_path = WP_CONTENT_DIR . '/plugins/' . basename(dirname($real_path)) . '/' . basename($real_path);
         deactivate_plugins($fixed_path, true);
         echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/uninstall-complete.tpl.php');
     } else {
         echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/uninstall-confirm.tpl.php');
     }
 }