| 1 |
<?php |
| 2 |
/** |
| 3 |
* EverestForms Uninstall |
| 4 |
* |
| 5 |
* Uninstalls the plugin deletes user roles, tables, and options. |
| 6 |
* |
| 7 |
* @package EverestForms\Uninstaller |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
defined( 'WP_UNINSTALL_PLUGIN' ) || exit; |
| 12 |
|
| 13 |
global $wpdb; |
| 14 |
|
| 15 |
wp_clear_scheduled_hook( 'everest_forms_cleanup_sessions' ); |
| 16 |
|
| 17 |
/* |
| 18 |
* Only remove ALL data if EVF_REMOVE_ALL_DATA constant is set to true in user's |
| 19 |
* wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
| 20 |
* and to ensure only the site owner can perform this action. |
| 21 |
*/ |
| 22 |
if ( defined( 'EVF_REMOVE_ALL_DATA' ) && true === EVF_REMOVE_ALL_DATA ) { |
| 23 |
include_once( dirname( __FILE__ ) . '/includes/class-evf-install.php' ); |
| 24 |
|
| 25 |
// Roles + caps. |
| 26 |
EVF_Install::remove_roles(); |
| 27 |
|
| 28 |
// Tables. |
| 29 |
EVF_Install::drop_tables(); |
| 30 |
|
| 31 |
// Pages. |
| 32 |
wp_trash_post( get_option( 'evf_default_form_page_id' ) ); |
| 33 |
|
| 34 |
// Delete options. |
| 35 |
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'evf\_%';" ); |
| 36 |
|
| 37 |
// Delete usermeta. |
| 38 |
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'evf\_%';" ); |
| 39 |
|
| 40 |
// Delete posts + data. |
| 41 |
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'everest_form' );" ); |
| 42 |
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); |
| 43 |
|
| 44 |
// Clear any cached data that has been removed. |
| 45 |
wp_cache_flush(); |
| 46 |
} |
| 47 |
|