robotstxt-ai-translator/uninstall.php
2026-05-23 10:13:56 +00:00

50 lines
1.4 KiB
PHP

<?php
/**
* Uninstall handler for the AI Translator plugin.
*
* Plugin data is preserved by default. To delete every option and sitemeta entry,
* either set the constant AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL to true in wp-config.php,
* or define the site option 'ai_translator_delete_data_on_uninstall' as a truthy value.
*
* @package ROBOTSTXT\AI_Translator
* @since 1.0.0
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
$ai_translator_should_delete = false;
if ( defined( 'AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL' ) && AI_TRANSLATOR_DELETE_DATA_ON_UNINSTALL ) {
$ai_translator_should_delete = true;
}
if ( ! $ai_translator_should_delete && function_exists( 'get_site_option' ) ) {
$ai_translator_should_delete = (bool) get_site_option( 'ai_translator_delete_data_on_uninstall', false );
}
if ( ! $ai_translator_should_delete ) {
return;
}
if ( is_multisite() ) {
$ai_translator_sites = get_sites(
array(
'fields' => 'ids',
'number' => 0,
)
);
foreach ( $ai_translator_sites as $ai_translator_site_id ) {
switch_to_blog( (int) $ai_translator_site_id );
delete_option( 'ai_translator_settings' );
restore_current_blog();
}
delete_site_option( 'ai_translator_settings' );
delete_site_option( 'ai_translator_network_mode' );
delete_site_option( 'ai_translator_delete_data_on_uninstall' );
} else {
delete_option( 'ai_translator_settings' );
}