Nessuna descrizione

uninstall.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * Uninstall UM
  4. *
  5. */
  6. // Exit if accessed directly.
  7. if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit;
  8. if ( ! defined( 'um_path' ) )
  9. define( 'um_path', plugin_dir_path( __FILE__ ) );
  10. if ( ! defined( 'um_url' ) )
  11. define( 'um_url', plugin_dir_url( __FILE__ ) );
  12. if ( ! defined( 'um_plugin' ) )
  13. define( 'um_plugin', plugin_basename( __FILE__ ) );
  14. //for delete Email options only for Core email notifications
  15. remove_all_filters( 'um_email_notifications' );
  16. //for delete only Core Theme Link pages
  17. remove_all_filters( 'um_core_pages' );
  18. require_once plugin_dir_path( __FILE__ ) . 'includes/class-functions.php';
  19. require_once plugin_dir_path( __FILE__ ) . 'includes/class-init.php';
  20. $delete_options = UM()->options()->get( 'uninstall_on_delete' );
  21. if ( ! empty( $delete_options ) ) {
  22. //remove uploads
  23. $upl_folder = UM()->files()->upload_basedir;
  24. UM()->files()->remove_dir( $upl_folder );
  25. //remove core pages
  26. foreach ( UM()->config()->core_pages as $page_key => $page_value ) {
  27. $page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) );
  28. if ( ! empty( $page_id ) )
  29. wp_delete_post( $page_id, true );
  30. }
  31. //remove core settings
  32. $settings_defaults = UM()->config()->settings_defaults;
  33. foreach ( $settings_defaults as $k => $v ) {
  34. UM()->options()->remove( $k );
  35. }
  36. //delete UM Custom Post Types posts
  37. $um_posts = get_posts( array(
  38. 'post_type' => array(
  39. 'um_form',
  40. 'um_directory',
  41. 'um_role',
  42. 'um_private_content',
  43. 'um_mailchimp',
  44. 'um_profile_tabs',
  45. 'um_social_login',
  46. 'um_review',
  47. 'um_frontend_posting',
  48. 'um_notice'
  49. ),
  50. 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
  51. 'numberposts' => -1
  52. ) );
  53. foreach ( $um_posts as $um_post ){
  54. delete_option( 'um_existing_rows_' . $um_post->ID );
  55. delete_option( 'um_form_rowdata_' . $um_post->ID );
  56. wp_delete_post( $um_post->ID, 1 );
  57. }
  58. //remove user role meta
  59. $role_keys = get_option( 'um_roles', array() );
  60. if ( $role_keys ) {
  61. foreach ( $role_keys as $role_key ) {
  62. delete_option( 'um_role_' . $role_key . '_meta' );
  63. }
  64. }
  65. delete_option( '__ultimatemember_sitekey' );
  66. delete_option( 'um_flush_rewrite_rules' );
  67. //remove all users cache
  68. UM()->user()->remove_cache_all_users();
  69. global $wpdb;
  70. //remove extensions core pages
  71. $ext_pages = $wpdb->get_results( "
  72. SELECT post_id
  73. FROM {$wpdb->postmeta}
  74. WHERE meta_key = '_um_core'
  75. ", ARRAY_A );
  76. foreach ( $ext_pages as $page_id ) {
  77. wp_delete_post( $page_id['post_id'], 1 );
  78. }
  79. $wpdb->query(
  80. "DELETE
  81. FROM {$wpdb->usermeta}
  82. WHERE meta_key LIKE '_um%' OR
  83. meta_key LIKE 'um%' OR
  84. meta_key LIKE 'reviews%' OR
  85. meta_key = 'submitted' OR
  86. meta_key = 'account_status' OR
  87. meta_key = 'password_rst_attempts' OR
  88. meta_key = 'profile_photo' OR
  89. meta_key = '_enable_new_follow' OR
  90. meta_key = '_enable_new_friend' OR
  91. meta_key = '_mylists' OR
  92. meta_key = '_enable_new_pm' OR
  93. meta_key = '_hidden_conversations' OR
  94. meta_key = '_pm_blocked' OR
  95. meta_key = '_notifications_prefs' OR
  96. meta_key = '_profile_progress' OR
  97. meta_key = '_completed' OR
  98. meta_key = '_cannot_add_review' OR
  99. meta_key = 'synced_profile_photo' OR
  100. meta_key = 'full_name' OR
  101. meta_key = '_reviews' OR
  102. meta_key = '_reviews_compound' OR
  103. meta_key = '_reviews_total' OR
  104. meta_key = '_reviews_avg'"
  105. );
  106. $wpdb->query(
  107. "DELETE
  108. FROM {$wpdb->postmeta}
  109. WHERE meta_key LIKE '_um%' OR
  110. meta_key LIKE 'um%'"
  111. );
  112. //remove all tables from extensions
  113. $all_tables = "SHOW TABLES LIKE '{$wpdb->prefix}um\_%'";
  114. $results = $wpdb->get_results( $all_tables );
  115. if( $results ){
  116. foreach( $results as $index => $value ) {
  117. foreach( $value as $table_name ) {
  118. $um_groups_members = $wpdb->prefix.'um_groups_members';
  119. if( $table_name == $um_groups_members ){
  120. $wpdb->query( "
  121. DELETE posts, term_rel, pmeta, terms, tax, commetns
  122. FROM {$wpdb->posts} posts
  123. LEFT JOIN {$wpdb->term_relationships} term_rel
  124. ON (posts.ID = term_rel.object_id)
  125. LEFT JOIN {$wpdb->postmeta} pmeta
  126. ON (posts.ID = pmeta.post_id)
  127. LEFT JOIN {$wpdb->terms} terms
  128. ON (term_rel.term_taxonomy_id = terms.term_id)
  129. LEFT JOIN {$wpdb->term_taxonomy} tax
  130. ON (term_rel.term_taxonomy_id = tax.term_taxonomy_id)
  131. LEFT JOIN {$wpdb->comments} commetns
  132. ON (commetns.comment_post_ID = posts.ID)
  133. WHERE posts.post_type = 'um_groups' OR posts.post_type = 'um_groups_discussion'"
  134. );
  135. }
  136. $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
  137. }
  138. }
  139. }
  140. //remove options from extensions
  141. //user photos
  142. $um_user_photos = get_posts( array(
  143. 'post_type' => array(
  144. 'um_user_photos'
  145. ),
  146. 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
  147. 'numberposts' => -1
  148. ) );
  149. if( $um_user_photos ) {
  150. foreach ( $um_user_photos as $um_user_photo ) {
  151. $attachments = get_attached_media( 'image', $um_user_photo->ID );
  152. foreach ( $attachments as $attachment ) {
  153. wp_delete_attachment( $attachment->ID, 1 );
  154. }
  155. wp_delete_post( $um_user_photo->ID, 1 );
  156. }
  157. }
  158. //user notes
  159. $um_notes = get_posts( array(
  160. 'post_type' => array(
  161. 'um_notes'
  162. ),
  163. 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
  164. 'numberposts' => -1
  165. ) );
  166. if( $um_notes ){
  167. foreach ( $um_notes as $um_note ){
  168. $attachments = get_attached_media( 'image', $um_note->ID );
  169. foreach ( $attachments as $attachment ){
  170. wp_delete_attachment( $attachment->ID, 1 );
  171. }
  172. wp_delete_post( $um_note->ID, 1 );
  173. }
  174. }
  175. //user tags
  176. $wpdb->query( "
  177. DELETE tax, terms
  178. FROM {$wpdb->term_taxonomy} tax
  179. LEFT JOIN {$wpdb->terms} terms
  180. ON (tax.term_taxonomy_id = terms.term_id)
  181. WHERE tax.taxonomy = 'um_user_tag'"
  182. );
  183. //mailchimp
  184. $mailchimp_log = UM()->files()->upload_basedir . 'mailchimp.log';
  185. if ( file_exists( $mailchimp_log ) ) {
  186. unlink( $mailchimp_log );
  187. }
  188. $um_options = $wpdb->get_results(
  189. "SELECT option_name
  190. FROM {$wpdb->options}
  191. WHERE option_name LIKE '_um%' OR
  192. option_name LIKE 'um_%' OR
  193. option_name LIKE 'widget_um%' OR
  194. option_name LIKE 'ultimatemember_%'" );
  195. foreach( $um_options as $um_option ) {
  196. delete_option( $um_option->option_name );
  197. }
  198. //social activity
  199. $um_activities = get_posts( array(
  200. 'post_type' => array(
  201. 'um_activity'
  202. ),
  203. 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
  204. 'numberposts' => -1
  205. ) );
  206. foreach ( $um_activities as $um_activity ) {
  207. $image = get_post_meta( $um_activity->ID, '_photo', true );
  208. if( $image ){
  209. $user_id = get_post_meta( $um_activity->ID, '_user_id', true );
  210. $upload_dir = wp_upload_dir();
  211. $image_path = $upload_dir['basedir'] . '/ultimatemember/' . $user_id . '/' . $image;
  212. if ( file_exists( $image_path ) ) {
  213. unlink( $image_path );
  214. }
  215. }
  216. wp_delete_post( $um_activity->ID, 1 );
  217. }
  218. }