| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall Front End PM |
| 4 |
* |
| 5 |
* Deletes all the plugin data |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit; |
| 10 |
|
| 11 |
if( ! function_exists( 'fep_get_option' ) ){ |
| 12 |
include_once( 'functions.php' ); |
| 13 |
} |
| 14 |
|
| 15 |
global $wpdb; |
| 16 |
|
| 17 |
if( fep_get_option( 'delete_data_on_uninstall', false ) ) { |
| 18 |
|
| 19 |
/** Delete All the Custom Post Types of Front End PM */ |
| 20 |
$post_types = array( 'fep_message', 'fep_announcement' ); |
| 21 |
|
| 22 |
foreach ( $post_types as $post_type ) { |
| 23 |
|
| 24 |
$items = get_posts( array( 'post_type' => $post_type, 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids' ) ); |
| 25 |
|
| 26 |
if ( $items ) { |
| 27 |
foreach ( $items as $item ) { |
| 28 |
wp_delete_post( $item, true); |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
/** Delete all the Plugin Options */ |
| 34 |
delete_option( 'FEP_admin_options' ); |
| 35 |
delete_metadata( 'user', 0, $wpdb->get_blog_prefix() . 'FEP_user_options', '', true ); |
| 36 |
delete_metadata( 'user', 0, $wpdb->get_blog_prefix() . '_fep_user_message_count', '', true ); |
| 37 |
delete_metadata( 'user', 0, $wpdb->get_blog_prefix() . '_fep_user_announcement_count', '', true ); |
| 38 |
delete_metadata( 'user', 0, $wpdb->get_blog_prefix() . '_fep_notification_dismiss', '', true ); |
| 39 |
|
| 40 |
$roles = array( 'administrator', 'editor' ); |
| 41 |
$caps = fep_get_plugin_caps(); |
| 42 |
|
| 43 |
foreach( $roles as $role ) { |
| 44 |
$role_obj = get_role( $role ); |
| 45 |
if( !$role_obj ) |
| 46 |
continue; |
| 47 |
|
| 48 |
foreach( $caps as $cap ) { |
| 49 |
$role_obj->remove_cap( $cap ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
// Remove all database tables of Front End PM (if any) |
| 54 |
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "fep_messages" ); |
| 55 |
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "fep_meta" ); |
| 56 |
|
| 57 |
// Remove any transients we've left behind |
| 58 |
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_fep\_%'" ); |
| 59 |
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_timeout\_fep\_%'" ); |
| 60 |
} |
| 61 |
|