PluginProbe
DesignSetGo / trunk
DesignSetGo vtrunk
2.7.3 2.7.1 2.7.2 2.7.0 2.6.3 2.6.2 2.6.1 2.6.0 2.5.1 2.4.1-test 2.5.0 2.4.0 2.3.0 2.2.0 2.1.2 2.1.1 2.1.0 trunk 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 All 67 releases
designsetgo / uninstall.php

uninstall.php in DesignSetGo trunk, at uninstall.php

141 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall DesignSetGo Plugin
4 *
5 * Fired when plugin is deleted (not deactivated).
6 * Removes all plugin data from database.
7 *
8 * @package DesignSetGo
9 * @since 1.0.0
10 */
11
12 // Exit if not called by WordPress uninstaller.
13 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
14 exit;
15 }
16
17 global $wpdb;
18
19 /**
20 * Run a cleanup step, logging any failure without halting subsequent steps.
21 *
22 * @param string $label Human-readable step description for debug logs.
23 * @param callable $callback The cleanup operation to execute.
24 */
25 function designsetgo_uninstall_step( $label, $callback ) {
26 try {
27 $callback();
28 } catch ( \Throwable $e ) {
29 wp_trigger_error( __FUNCTION__, 'DesignSetGo uninstall (' . $label . '): ' . $e->getMessage(), E_USER_NOTICE );
30 }
31 }
32
33 // 1. Delete all form submissions (custom post type).
34 designsetgo_uninstall_step(
35 'form submissions',
36 function () use ( $wpdb ) {
37 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall bulk cleanup; no WP API for mass post deletion by type without loading each post.
38 $wpdb->query(
39 $wpdb->prepare(
40 "DELETE FROM {$wpdb->posts} WHERE post_type = %s",
41 'dsgo_form_submission'
42 )
43 );
44 }
45 );
46
47 // 2. Delete orphaned post meta (form submission metadata).
48 // Note: Meta keys use _dsg_ prefix (not _dsgo_) - verified in class-form-handler.php:442-447
49 designsetgo_uninstall_step(
50 'post meta',
51 function () use ( $wpdb ) {
52 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall bulk cleanup; no WP API for mass meta deletion by key pattern.
53 $wpdb->query(
54 $wpdb->prepare(
55 "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s",
56 $wpdb->esc_like( '_dsg_' ) . '%'
57 )
58 );
59 }
60 );
61
62 // 3. Remove physical llms.txt / llms-full.txt if we own them, then delete plugin options.
63 designsetgo_uninstall_step(
64 'options and llms.txt',
65 function () {
66 // wp_delete_file() uses @unlink() internally, safe to call without existence checks.
67 if ( get_option( 'designsetgo_llms_txt_physical' ) ) {
68 wp_delete_file( ABSPATH . 'llms.txt' );
69 }
70
71 if ( get_option( 'designsetgo_llms_full_txt_physical' ) ) {
72 wp_delete_file( ABSPATH . 'llms-full.txt' );
73 }
74
75 delete_option( 'designsetgo_global_styles' );
76 delete_option( 'designsetgo_settings' );
77 delete_option( 'designsetgo_llms_txt_physical' );
78 delete_option( 'designsetgo_llms_full_txt_physical' );
79 delete_option( 'designsetgo_llms_htaccess_backfilled' );
80 }
81 );
82
83 // 4. Delete all plugin transients (rate limiting, block detection, form counts).
84 designsetgo_uninstall_step(
85 'transients',
86 function () use ( $wpdb ) {
87 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall bulk cleanup; no WP API for mass transient deletion by pattern.
88 $wpdb->query(
89 $wpdb->prepare(
90 "DELETE FROM {$wpdb->options}
91 WHERE option_name LIKE %s
92 OR option_name LIKE %s
93 OR option_name LIKE %s",
94 $wpdb->esc_like( '_transient_dsgo_form_submit_' ) . '%',
95 $wpdb->esc_like( '_transient_dsgo_has_blocks_' ) . '%',
96 $wpdb->esc_like( '_transient_dsgo_form_submissions_count' ) . '%'
97 )
98 );
99
100 // Delete transient timeout entries.
101 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall bulk cleanup; no WP API for mass transient deletion by pattern.
102 $wpdb->query(
103 $wpdb->prepare(
104 "DELETE FROM {$wpdb->options}
105 WHERE option_name LIKE %s
106 OR option_name LIKE %s
107 OR option_name LIKE %s",
108 $wpdb->esc_like( '_transient_timeout_dsgo_form_submit_' ) . '%',
109 $wpdb->esc_like( '_transient_timeout_dsgo_has_blocks_' ) . '%',
110 $wpdb->esc_like( '_transient_timeout_dsgo_form_submissions_count' ) . '%'
111 )
112 );
113 }
114 );
115
116 // 5. Clear object cache (guard against missing or incompatible implementations).
117 designsetgo_uninstall_step(
118 'object cache',
119 function () {
120 if ( function_exists( 'wp_cache_delete_group' ) ) {
121 wp_cache_delete_group( 'designsetgo' );
122 } elseif ( function_exists( 'wp_cache_flush_group' ) ) {
123 wp_cache_flush_group( 'designsetgo' );
124 }
125 }
126 );
127
128 // 6. Clear scheduled cron jobs.
129 designsetgo_uninstall_step(
130 'cron jobs',
131 function () {
132 $timestamp = wp_next_scheduled( 'designsetgo_cleanup_old_submissions' );
133 if ( $timestamp ) {
134 wp_unschedule_event( $timestamp, 'designsetgo_cleanup_old_submissions' );
135 }
136 }
137 );
138
139 // Signal successful completion for debugging/testing hooks.
140 do_action( 'designsetgo_uninstalled' );
141