prefix . 'affirm_signed_urls'; $charset = $wpdb->get_charset_collate(); $sql = "CREATE TABLE IF NOT EXISTS $table ( id bigint(20) NOT NULL AUTO_INCREMENT, image_id varchar(64) NOT NULL, signed_url text NOT NULL, expires_at bigint(20) NOT NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY image_id (image_id), KEY expires_at (expires_at) ) $charset;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); // Create scanned images table for image scanner $scan_table = $wpdb->prefix . 'affirm_scanned_images'; $sql2 = "CREATE TABLE IF NOT EXISTS $scan_table ( id bigint(20) NOT NULL AUTO_INCREMENT, post_id bigint(20) NOT NULL, image_src text NOT NULL, img_tag text NOT NULL, alt_text varchar(500) DEFAULT '', width int(11) DEFAULT 0, height int(11) DEFAULT 0, status varchar(20) DEFAULT 'pending', affirm_image_id varchar(64) DEFAULT NULL, error_message text DEFAULT NULL, scanned_at datetime DEFAULT CURRENT_TIMESTAMP, protected_at datetime DEFAULT NULL, PRIMARY KEY (id), KEY post_id (post_id), KEY status (status), KEY affirm_image_id (affirm_image_id) ) $charset;"; dbDelta($sql2); } // Deactivation Hook register_deactivation_hook(__FILE__, 'affirm_deactivate'); function affirm_deactivate() { wp_clear_scheduled_hook('affirm_bulk_process_batch'); } // Uninstall Hook register_uninstall_hook(__FILE__, 'affirm_uninstall'); function affirm_uninstall() { delete_option('affirm_api_key'); delete_option('affirm_frontend_url'); delete_option('affirm_backend_url'); delete_option('affirm_render_mode'); delete_option('affirm_signed_url_ttl'); global $wpdb; // Custom tables must be removed on uninstall; schema change is intentional and one-time. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}affirm_signed_urls"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}affirm_scanned_images"); delete_option('affirm_current_bulk_job'); // Clean up vault featured image meta from all posts delete_metadata('post', 0, 'affirm_featured_image_id', '', true); delete_metadata('post', 0, 'affirm_featured_thumbnail_url', '', true); delete_metadata('post', 0, 'affirm_featured_filename', '', true); }