add uninstall

This commit is contained in:
hanyixuanten
2026-07-26 11:22:27 +08:00
parent cb7cff4495
commit 24e7f81aa9
4 changed files with 54 additions and 0 deletions
+6
View File
@@ -6,5 +6,11 @@
/dist/
/phpunit.xml
/.intelephense/
.env
.env.*
!/env.example
/wp-config.php
/wordpress/
/wp-content/
.DS_Store
*.zip
+4
View File
@@ -57,6 +57,10 @@ Credentials are stored in the WordPress `wpt_settings` option and are not render
Use HTTPS and restrict database access appropriately because WordPress options are database-backed. Production sites should configure a real cron runner for reliable translation processing.
## Uninstalling
Uninstalling Btranslate permanently deletes its settings and credentials, retranslation batch state, all pending Btranslate cron events, and every site's `{$wpdb->prefix}wpt_translations` table. This removes all persisted translations. Deactivating the plugin does not delete these records.
## Development
Install development dependencies with `composer install`. The project includes WordPress API stubs for Intelephense and PHPUnit tests that use fake providers and storage, so they do not need WordPress, a database, credentials, or network access.
+4
View File
@@ -56,6 +56,10 @@ Btranslate 是一个 WordPress 插件骨架,使用百度翻译 API 持久化
由于 WordPress 选项由数据库保存,请使用 HTTPS 并适当限制数据库访问权限。生产站点应配置真实的 Cron 执行器,确保翻译任务可靠运行。
## 卸载
卸载 Btranslate 会永久删除其设置和凭据、重新翻译批处理状态、所有待执行的 Btranslate Cron 事件,以及每个站点的 `{$wpdb->prefix}wpt_translations` 表。这会删除所有已持久化的翻译。停用插件不会删除这些记录。
## 开发
使用 `composer install` 安装开发依赖。项目包含用于 Intelephense 的 WordPress API 存根,以及使用伪造提供程序和存储的 PHPUnit 测试;因此测试不需要 WordPress、数据库、凭据或网络访问。
+40
View File
@@ -0,0 +1,40 @@
<?php
/**
* Removes all data created by Btranslate.
*
* @package WPT
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
function wpt_uninstall_site_data() {
global $wpdb;
wp_clear_scheduled_hook( 'wpt_process_translation' );
wp_clear_scheduled_hook( 'wpt_process_term_translation' );
wp_clear_scheduled_hook( 'wpt_process_seo_output_translation' );
delete_option( 'wpt_settings' );
delete_option( 'wpt_retranslation_batch' );
$table_name = $wpdb->prefix . 'wpt_translations';
$wpdb->query( "DROP TABLE IF EXISTS {$table_name}" );
}
if ( is_multisite() ) {
$site_ids = get_sites(
array(
'fields' => 'ids',
'number' => 0,
)
);
foreach ( $site_ids as $site_id ) {
switch_to_blog( $site_id );
wpt_uninstall_site_data();
restore_current_blog();
}
} else {
wpt_uninstall_site_data();
}