$plugin_data ) { if ( isset( $plugin_data['TextDomain'] ) && in_array( $plugin_data['TextDomain'], $text_domains, true ) ) { $candidates[] = (string) $basename; } } foreach ( array_unique( $candidates ) as $basename ) { $file = realpath( WP_PLUGIN_DIR . '/' . $basename ); if ( false !== $file && $file !== $own_file && is_file( $file ) ) { return true; } } return false; } } if ( ! function_exists( 'image_ai_seo_uninstall_site' ) ) { /** * Drop this plugin's two custom tables and delete its 11 site-scoped options * for whichever site is "current" at the time this runs (the main site on a * single-site install, or the currently-switched-to site inside the * multisite loop below). */ function image_ai_seo_uninstall_site() { global $wpdb; $history_table = $wpdb->prefix . 'image_ai_seo_history'; $redirect_table = $wpdb->prefix . 'image_ai_seo_redirects'; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- table names cannot be parameterized. $wpdb->query( "DROP TABLE IF EXISTS {$history_table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- table names cannot be parameterized. $wpdb->query( "DROP TABLE IF EXISTS {$redirect_table}" ); $site_options = array( 'image_ai_seo_api_key', 'image_ai_seo_remaining_credits', 'image_ai_seo_auto_optimize', 'image_ai_seo_language', 'image_ai_seo_main_keyword', 'image_ai_seo_additional_keywords', 'image_ai_seo_website_description', 'image_ai_seo_total_optimized', 'image_ai_seo_db_version', 'image_ai_seo_consent', 'image_ai_seo_site_profile_auto_run', ); foreach ( $site_options as $option_name ) { delete_option( $option_name ); } /* * Deliberate exception, not an oversight (DIST-04, Phase 9 Plan 05): the two * attachment postmeta keys this plugin writes, `_image_ai_seo_optimized` * (see Image_AI_SEO_Metadata_Handler::OPTIMIZATION_META_KEY) and * `_image_ai_seo_needs_attention` (see * Image_AI_SEO_Metadata_Handler::NEEDS_ATTENTION_META_KEY), are * intentionally NOT deleted here. They live on individual attachment * posts (user content), and WordPress.org's convention is that uninstall * removes the plugin's own settings/data stores, not metadata attached to * a site's existing content. Deleting them would also silently discard * the record of which images were already optimized if the plugin is * ever reinstalled. If a future requirement needs this metadata gone, * add an explicit, separately-reviewed cleanup step -- do not "fix" this * as a missing DELETE. See tests/integration/test-uninstall-multisite.php * for a test asserting this postmeta positively survives uninstall. */ } } // Another copy (an old Image AI SEO or Image AI SEO Pro, or a second Altimo) still uses every option, table and the API key: keep it all. if ( image_ai_seo_uninstall_other_variant_installed() ) { return; } if ( is_multisite() ) { $image_ai_seo_site_ids = get_sites( array( 'fields' => 'ids' ) ); foreach ( $image_ai_seo_site_ids as $image_ai_seo_site_id ) { switch_to_blog( $image_ai_seo_site_id ); image_ai_seo_uninstall_site(); restore_current_blog(); } // Network-scoped key (D-01/MULTI-02), cleaned up once, outside the loop. delete_site_option( 'image_ai_seo_network_api_key' ); } else { image_ai_seo_uninstall_site(); }