Açıklama Yok

uninstall.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /**
  3. * Uninstall all WP Mail SMTP data.
  4. *
  5. * @since 1.3.0
  6. */
  7. // Exit if accessed directly.
  8. if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
  9. exit;
  10. }
  11. // Load plugin file.
  12. require_once 'wp_mail_smtp.php';
  13. require_once dirname( __FILE__ ) . '/vendor/woocommerce/action-scheduler/action-scheduler.php';
  14. global $wpdb;
  15. /*
  16. * Remove Legacy options.
  17. */
  18. $options = [
  19. '_amn_smtp_last_checked',
  20. 'pepipost_ssl',
  21. 'pepipost_port',
  22. 'pepipost_pass',
  23. 'pepipost_user',
  24. 'smtp_pass',
  25. 'smtp_user',
  26. 'smtp_auth',
  27. 'smtp_ssl',
  28. 'smtp_port',
  29. 'smtp_host',
  30. 'mail_set_return_path',
  31. 'mailer',
  32. 'mail_from_name',
  33. 'mail_from',
  34. ];
  35. /**
  36. * Remove AM announcement posts.
  37. */
  38. $am_announcement_params = [
  39. 'post_type' => [ 'amn_smtp' ],
  40. 'post_status' => 'any',
  41. 'numberposts' => - 1,
  42. 'fields' => 'ids',
  43. ];
  44. /**
  45. * Disable Action Schedule Queue Runner, to prevent a fatal error on the shutdown WP hook.
  46. */
  47. if ( class_exists( 'ActionScheduler_QueueRunner' ) ) {
  48. $as_queue_runner = \ActionScheduler_QueueRunner::instance();
  49. if ( method_exists( $as_queue_runner, 'unhook_dispatch_async_request' ) ) {
  50. $as_queue_runner->unhook_dispatch_async_request();
  51. }
  52. }
  53. // WP MS uninstall process.
  54. if ( is_multisite() ) {
  55. $main_site_settings = get_blog_option( get_main_site_id(), 'wp_mail_smtp', [] );
  56. $network_wide = ! empty( $main_site_settings['general']['network_wide'] );
  57. $network_uninstall = ! empty( $main_site_settings['general']['uninstall'] );
  58. $sites = get_sites();
  59. foreach ( $sites as $site ) {
  60. $settings = get_blog_option( $site->blog_id, 'wp_mail_smtp', [] );
  61. // Confirm network site admin has decided to remove all data, otherwise skip.
  62. if (
  63. ( $network_wide && ! $network_uninstall ) ||
  64. ( ! $network_wide && empty( $settings['general']['uninstall'] ) )
  65. ) {
  66. continue;
  67. }
  68. /*
  69. * Delete network site plugin options.
  70. */
  71. foreach ( $options as $option ) {
  72. delete_blog_option( $site->blog_id, $option );
  73. }
  74. // Switch to the current network site.
  75. switch_to_blog( $site->blog_id );
  76. // Delete plugin settings.
  77. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wp\_mail\_smtp%'" ); // phpcs:ignore WordPress.DB
  78. // Delete plugin user meta.
  79. $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  80. // Remove any transients we've left behind.
  81. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  82. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  83. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  84. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_timeout\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  85. // Delete debug events table.
  86. $debug_events_table = \WPMailSMTP\Admin\DebugEvents\DebugEvents::get_table_name();
  87. $wpdb->query( "DROP TABLE IF EXISTS $debug_events_table;" ); // phpcs:ignore WordPress.DB
  88. /*
  89. * Delete network site product announcements.
  90. */
  91. $announcements = get_posts( $am_announcement_params );
  92. if ( ! empty( $announcements ) ) {
  93. foreach ( $announcements as $announcement ) {
  94. wp_delete_post( $announcement, true );
  95. }
  96. }
  97. /*
  98. * Cleanup network site data for Pro plugin only.
  99. */
  100. if (
  101. function_exists( 'wp_mail_smtp' ) &&
  102. is_readable( wp_mail_smtp()->plugin_path . '/src/Pro/Pro.php' )
  103. ) {
  104. // Delete logs table.
  105. $table = \WPMailSMTP\Pro\Emails\Logs\Logs::get_table_name();
  106. $wpdb->query( "DROP TABLE IF EXISTS $table;" ); // phpcs:ignore WordPress.DB
  107. // Delete attachments tables.
  108. $attachment_files_table = \WPMailSMTP\Pro\Emails\Logs\Attachments\Attachments::get_attachment_files_table_name();
  109. $wpdb->query( "DROP TABLE IF EXISTS $attachment_files_table;" ); // phpcs:ignore WordPress.DB
  110. $email_attachments_table = \WPMailSMTP\Pro\Emails\Logs\Attachments\Attachments::get_email_attachments_table_name();
  111. $wpdb->query( "DROP TABLE IF EXISTS $email_attachments_table;" ); // phpcs:ignore WordPress.DB
  112. // Delete all attachments if any.
  113. ( new \WPMailSMTP\Pro\Emails\Logs\Attachments\Attachments() )->delete_all_attachments();
  114. // Delete tracking tables.
  115. $tracking_events_table = \WPMailSMTP\Pro\Emails\Logs\Tracking\Tracking::get_events_table_name();
  116. $wpdb->query( "DROP TABLE IF EXISTS $tracking_events_table;" ); // phpcs:ignore WordPress.DB
  117. $tracking_links_table = \WPMailSMTP\Pro\Emails\Logs\Tracking\Tracking::get_links_table_name();
  118. $wpdb->query( "DROP TABLE IF EXISTS $tracking_links_table;" ); // phpcs:ignore WordPress.DB
  119. }
  120. /*
  121. * Drop all Action Scheduler data and unschedule all plugin ActionScheduler actions.
  122. */
  123. ( new \WPMailSMTP\Tasks\Tasks() )->cancel_all();
  124. $meta_table = \WPMailSMTP\Tasks\Meta::get_table_name();
  125. $wpdb->query( "DROP TABLE IF EXISTS $meta_table;" ); // phpcs:ignore WordPress.DB
  126. // Restore the current network site back to the original one.
  127. restore_current_blog();
  128. }
  129. } else { // Non WP MS uninstall process (for normal WP installs).
  130. // Confirm user has decided to remove all data, otherwise stop.
  131. $settings = get_option( 'wp_mail_smtp', [] );
  132. if ( empty( $settings['general']['uninstall'] ) ) {
  133. return;
  134. }
  135. /*
  136. * Delete plugin options.
  137. */
  138. foreach ( $options as $option ) {
  139. delete_option( $option );
  140. }
  141. // Delete plugin settings.
  142. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wp\_mail\_smtp%'" ); // phpcs:ignore WordPress.DB
  143. // Delete plugin user meta.
  144. $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  145. // Remove any transients we've left behind.
  146. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  147. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  148. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  149. $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_site\_transient\_timeout\_wp\_mail\_smtp\_%'" ); // phpcs:ignore WordPress.DB
  150. // Delete debug events table.
  151. $debug_events_table = \WPMailSMTP\Admin\DebugEvents\DebugEvents::get_table_name();
  152. $wpdb->query( "DROP TABLE IF EXISTS $debug_events_table;" ); // phpcs:ignore WordPress.DB
  153. /*
  154. * Remove product announcements.
  155. */
  156. $announcements = get_posts( $am_announcement_params );
  157. if ( ! empty( $announcements ) ) {
  158. foreach ( $announcements as $announcement ) {
  159. wp_delete_post( $announcement, true );
  160. }
  161. }
  162. /*
  163. * Cleanup data for Pro plugin only.
  164. */
  165. if (
  166. function_exists( 'wp_mail_smtp' ) &&
  167. is_readable( wp_mail_smtp()->plugin_path . '/src/Pro/Pro.php' )
  168. ) {
  169. // Delete logs table.
  170. $table = \WPMailSMTP\Pro\Emails\Logs\Logs::get_table_name();
  171. $wpdb->query( "DROP TABLE IF EXISTS $table;" ); // phpcs:ignore WordPress.DB
  172. // Delete attachments tables.
  173. $attachment_files_table = \WPMailSMTP\Pro\Emails\Logs\Attachments\Attachments::get_attachment_files_table_name();
  174. $wpdb->query( "DROP TABLE IF EXISTS $attachment_files_table;" ); // phpcs:ignore WordPress.DB
  175. $email_attachments_table = \WPMailSMTP\Pro\Emails\Logs\Attachments\Attachments::get_email_attachments_table_name();
  176. $wpdb->query( "DROP TABLE IF EXISTS $email_attachments_table;" ); // phpcs:ignore WordPress.DB
  177. // Delete all attachments if any.
  178. ( new \WPMailSMTP\Pro\Emails\Logs\Attachments\Attachments() )->delete_all_attachments();
  179. // Delete tracking tables.
  180. $tracking_events_table = \WPMailSMTP\Pro\Emails\Logs\Tracking\Tracking::get_events_table_name();
  181. $wpdb->query( "DROP TABLE IF EXISTS $tracking_events_table;" ); // phpcs:ignore WordPress.DB
  182. $tracking_links_table = \WPMailSMTP\Pro\Emails\Logs\Tracking\Tracking::get_links_table_name();
  183. $wpdb->query( "DROP TABLE IF EXISTS $tracking_links_table;" ); // phpcs:ignore WordPress.DB
  184. }
  185. /*
  186. * Drop all Action Scheduler data and unschedule all plugin ActionScheduler actions.
  187. */
  188. ( new \WPMailSMTP\Tasks\Tasks() )->cancel_all();
  189. $meta_table = \WPMailSMTP\Tasks\Meta::get_table_name();
  190. $wpdb->query( "DROP TABLE IF EXISTS $meta_table;" ); // phpcs:ignore WordPress.DB
  191. }