PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / trunk
Easy Invoice – Invoice Generator, PDF Quotes & Payments vtrunk
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / uninstall.php

uninstall.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments trunk, at uninstall.php

63 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Runs when the plugin is deleted from the Plugins screen.
4 *
5 * Invoices are tax records, so nothing is removed unless the site owner
6 * turned on Settings → Advanced → "Remove all data when the plugin is
7 * deleted". With it off, deleting and reinstalling the plugin picks up
8 * exactly where it left off.
9 *
10 * @package EasyInvoice
11 */
12
13 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
14 exit;
15 }
16
17 // Scheduled work stops either way — the code that would run it is gone.
18 foreach ( [ 'easy_invoice_payment_reminder', 'easy_invoice_quote_expiration_check', 'easy_invoice_send_payment_reminders' ] as $hook ) {
19 wp_clear_scheduled_hook( $hook );
20 }
21
22 if ( 'yes' !== get_option( 'easy_invoice_remove_data_on_uninstall', 'no' ) ) {
23 return;
24 }
25
26 global $wpdb;
27
28 // Documents and their meta: every post type the plugin and its addons
29 // register starts with easy_invoice (invoices, quotes, payments, credit
30 // notes, payment links…). Straight SQL, because the plugin is not loaded
31 // during uninstall and its own guard against deleting issued invoices
32 // must not apply to a deliberate wipe.
33 $ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type LIKE 'easy\_invoice%'" );
34 if ( ! empty( $ids ) ) {
35 $id_list = implode( ',', array_map( 'intval', $ids ) );
36 $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ({$id_list})" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- integers.
37 $wpdb->query( "DELETE FROM {$wpdb->term_relationships} WHERE object_id IN ({$id_list})" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- integers.
38 $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE ID IN ({$id_list})" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- integers.
39 }
40 // Meta the plugin attaches to other posts (WooCommerce orders, pages).
41 $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '\_easy\_invoice\_%' OR meta_key LIKE 'easy\_invoice\_%'" );
42
43 // Client records live on users as meta; the users themselves stay.
44 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '\\_easy\\_invoice\\_%' OR meta_key LIKE 'easy\\_invoice\\_%'" );
45
46 // Options and transients, ours and the addons'.
47 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'easy\\_invoice\\_%' OR option_name LIKE '\\_transient\\_easy\\_invoice\\_%' OR option_name LIKE '\\_transient\\_timeout\\_easy\\_invoice\\_%' OR option_name LIKE '\\_site\\_transient\\_easy\\_invoice\\_%'" );
48
49 // Tables the addons created.
50 $tables = $wpdb->get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->prefix . 'easy_invoice_' ) . '%' ) );
51 foreach ( $tables as $table ) {
52 $wpdb->query( "DROP TABLE IF EXISTS `{$table}`" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from SHOW TABLES.
53 }
54
55 // Roles the plugin added.
56 foreach ( [ 'ei_manager', 'ei_accountant', 'ei_sales', 'ei_viewer', 'easy_invoice_client' ] as $role ) {
57 if ( get_role( $role ) ) {
58 remove_role( $role );
59 }
60 }
61
62 wp_cache_flush();
63