"Remove all forms // and submissions when the plugin is deleted"). Otherwise leave everything in place for a reinstall. if ( ! get_option( 'pubforms_delete_on_uninstall', false ) ) { return; } // Submissions stored in their own table. $pubforms_table = $wpdb->prefix . 'pubforms_entries'; $wpdb->query( "DROP TABLE IF EXISTS `{$pubforms_table}`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- uninstall only; the table name comes from $wpdb->prefix. // Forms are a private post type; delete their posts (before_delete_post already removed their entries). $pubforms_form_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", 'pubforms_form' ) ); foreach ( $pubforms_form_ids as $pubforms_form_id ) { wp_delete_post( (int) $pubforms_form_id, true ); } // Uploaded files and signatures (private folder under uploads), including the guard files. $pubforms_uploads = wp_upload_dir(); $pubforms_remove = function ( $path ) use ( &$pubforms_remove ) { if ( ! is_dir( $path ) ) { return; } foreach ( (array) scandir( $path ) as $name ) { if ( '.' === $name || '..' === $name ) { continue; } $child = $path . '/' . $name; if ( is_dir( $child ) && ! is_link( $child ) ) { $pubforms_remove( $child ); } else { wp_delete_file( $child ); } } rmdir( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- removing PubForms' own upload folder. }; $pubforms_remove( trailingslashit( $pubforms_uploads['basedir'] ) . 'pubforms' ); // Plugin options. $pubforms_options = array( 'pubforms_db_version', 'pubforms_default_notify_email', 'pubforms_sender_name', 'pubforms_sender_email', 'pubforms_submissions_per_hour', 'pubforms_auto_delete_days', 'pubforms_delete_on_uninstall', 'pubforms_uploads_guarded', 'pubforms_turnstile_site_key', 'pubforms_turnstile_secret_key', 'pubforms_hcaptcha_site_key', 'pubforms_hcaptcha_secret_key', 'pubforms_spam_method', 'pubforms_spam_questions', 'pubforms_spam_blocklist', 'pubforms_spam_max_links', 'pubforms_spam_min_seconds' ); foreach ( $pubforms_options as $pubforms_option ) { delete_option( $pubforms_option ); }