This article documents the three maintenance subsystems the wpresidence-translate plugin exposes: translation cache purging, the data reset routine, and the batch delete-translations processor. Each is a small, self-contained module under includes/admin/. Pair this with the user-facing article and the multi-language real estate website overview.
Cache Purge
Two helpers live in includes/admin/cache-purge.php:
wpr_translate_purge_wpestate_cache()
Fires a signed wp_remote_post() to admin-post.php against the WPResidence action wpestate_purge_cache. The request forwards the current admin cookies so the target endpoint treats it as an authenticated purge:
$purge_url = admin_url( 'admin-post.php' );
$nonce = wp_create_nonce( 'wpestate_purge_cache' );
$response = wp_remote_post(
$purge_url,
array(
'timeout' => 30,
'redirection' => 5,
'cookies' => $cookies, // built from $_COOKIE
'body' => array(
'action' => 'wpestate_purge_cache',
'_wpnonce' => $nonce,
),
)
);
Return values: true on HTTP 2xx/3xx, a WP_Error with code wpr_translate_cache_purge_failed otherwise (the error message carries the HTTP status).
wpr_translate_ajax_purge_cache()
Registered on wp_ajax_wpr_translate_purge_cache. Used by the bulk auto-translate admin page after all posts have been processed. Verifies:
- The AJAX nonce action
wpr_translate_purge_cache(fieldnonce). - The
manage_optionscapability.
On success, responds with wp_send_json_success( [ 'message' => 'Cache purged successfully.' ] ).
Transient Cleanup Helper
includes/admin/theme-transients.php provides wpr_translate_admin_clear_theme_search_transients( $context ), invoked after theme admin-string updates. It clears these WPResidence transients (both the base key and one per active language slug):
wpestate_get_action_select_list
wpestate_get_category_select_list
wpestate_get_city_select_list
wpestate_get_area_select_list
wpestate_get_county_state_select_list
wpestate_get_status_select_list
wpestate_get_features_select_list
Language suffixes are collected from wpr_translate_get_active_languages() (via wpr_translate_get_language_slug()) plus the ICL_LANGUAGE_CODE constant when defined. The function only runs when $context matches the stored theme admin strings domain (falling back to wpresidence_admin if no domain is stored).
Reset Settings
includes/admin/reset-settings.php exposes two functions.
wpr_translate_admin_handle_reset_settings()
Hooked on admin_init (registered in menu.php). Its guard chain:
- Returns silently if
$_POST['wpr_translate_reset_settings']is empty. - Returns if the user lacks
manage_options. check_admin_referer( 'wpr_translate_reset_settings', 'wpr_translate_reset_settings_nonce' )— hard-fails on bad nonce.- Calls
wpr_translate_admin_reset_plugin_data(). - Pushes a settings error (success or failure) and
wp_safe_redirect()s back to the Settings page.
wpr_translate_admin_reset_plugin_data()
The actual mutator. It returns true on success or WP_Error on failure and performs:
TRUNCATE TABLEon the six plugin tables (each guarded bySHOW TABLES LIKE):{prefix}wpestate_translation_translations {prefix}wpestate_translation_strings {prefix}wpestate_translation_slugs {prefix}wpestate_translation_glossary {prefix}wpestate_translation_memory {prefix}wpestate_translation_languagesFailure of any
TRUNCATEshort-circuits with the error codewpr_translate_reset_table_failed.delete_option()across this list:wpr_translate_version wpr_translate_languages wpr_translate_language_catalog wpr_translate_settings wpr_translate_auto_translation wpr_translate_glossary wpr_translate_theme_admin_strings_domain wpr_translate_theme_admin_strings_hash wpr_translate_theme_widget_strings_domain wpr_translate_theme_widget_strings_hash wpr_translate_scan_state wpr_translate_custom_directory wpr_cf_rules_defaults wpr_cf_rule_overrides wpr_cf_file_state wpr_translate_language_switcher- Calls
wpr_translate_clear_custom_field_rules_cache()when available. - Invokes
wpr_translate_activate_plugin()to rebuild defaults in place (tables, default language, merged settings, rewrite flush).
The reset never touches posts or terms — translated content is preserved as plain WordPress objects. Re-linking requires a fresh import or manual re-link because the translations table has been truncated.
Delete Translations (Batch)
includes/admin/delete-translations.php implements two AJAX actions, both registered in menu.php:
add_action( 'wp_ajax_wpr_translate_count_translations', 'wpr_translate_admin_ajax_count_translations' );
add_action( 'wp_ajax_wpr_translate_delete_translations', 'wpr_translate_admin_ajax_delete_translations' );
Both share the nonce action string wpr_translate_delete_translations.
Shared Request Shape
| POST field | Meaning |
|---|---|
type |
posts or terms. |
element_types[] |
Post type slugs or taxonomy slugs. |
language |
Target language code (never the default). |
nonce |
Nonce for action wpr_translate_delete_translations. |
Guard Chain (applied to both handlers)
check_ajax_referer()on the shared action.current_user_can( 'manage_options' ).- Reject if
type,element_types, orlanguageis empty. - Compare
languageagainstwpr_translation_get_default_language_code( wpr_translation_get_active_languages() )— the default is always rejected with “Cannot delete content in the default language.”
Count Handler
wpr_translate_admin_ajax_count_translations() sums COUNT(*) queries against {prefix}wpestate_translation_translations for every requested element type, filtering on language_code = %s AND original = 0. It resolves each slug via wpr_translation_get_element_type() (for posts) or wpr_translation_get_taxonomy_element_type() (for terms). Responds with { count: int }.
Delete Handler
wpr_translate_admin_ajax_delete_translations() processes up to 20 items per call. The loop:
- Resolves every submitted slug to its
element_typestring. - For each element type,
SELECT element_id, trid FROM ... WHERE element_type = %s AND language_code = %s AND original = 0 LIMIT %dwhere the limit is the remaining batch slot count. - For each row, applies Layer-5 safety: post deletion requires both
wpr_translated_languageandwpr_translated_original_post_idpost meta; term deletion requireswpr_original_term_idterm meta. Rows missing markers are counted as skipped, not deleted. - Posts:
wp_delete_post( $id, true )plus a manual$wpdb->delete()on the translations table (posts have no auto-cleanup hook). - Terms:
wp_delete_term( $id, $taxonomy )(taxonomy is extracted by stripping thetax_prefix from the element type) plusdelete_term_meta( $original_id, 'wpr_translated_term_' . $language )on the original term. - After the batch, re-count remaining rows so the JavaScript progress bar can tick down.
Response shape: { deleted: int, skipped: int, remaining: int }. Clients loop until remaining === 0.
Function Map
| File | Function |
|---|---|
includes/admin/cache-purge.php |
wpr_translate_purge_wpestate_cache(), wpr_translate_ajax_purge_cache() |
includes/admin/theme-transients.php |
wpr_translate_admin_clear_theme_search_transients() |
includes/admin/reset-settings.php |
wpr_translate_admin_handle_reset_settings(), wpr_translate_admin_reset_plugin_data() |
includes/admin/delete-translations.php |
wpr_translate_admin_ajax_count_translations(), wpr_translate_admin_ajax_delete_translations() |
Extension Points
- To purge additional transients on string updates, extend
wpr_translate_admin_clear_theme_search_transients()or hook into the update path yourself — the helper only targets the known WPResidence select-list caches. - The delete-translations handler is intentionally conservative. If you have custom translation markers, either add the expected meta (
wpr_translated_language,wpr_translated_original_post_id, orwpr_original_term_id) or write your own cleanup routine. - Batch size of 20 is hard-coded. If you need bigger batches for a one-off migration, wrap your own WP-CLI command around the same SQL — do not raise the AJAX limit, because the frontend progress loop expects it.
Gotchas
TRUNCATE TABLEis used instead ofDELETE, so auto-increment counters reset to zero. Any code that persists translation IDs across a reset must account for this.- The reset re-runs the full activation — including
flush_rewrite_rules(). Any runtime-registered rewrite rules outside the plugin will also be refreshed. - The cache purge uses cookie-forwarded
wp_remote_post(). On hosts that block loopback requests this can fail silently; checkWP_Error->get_error_message()in the auto-translate finish step. - Delete-translations never touches the default language — enforced both in the UI (default excluded from the dropdown) and on the server. Do not rely on the UI exclusion alone.
Related Articles
- Installation, Activation & Uninstall (Developer) — what the activator (re-)runs at the end of a reset.
- Settings Page (Developer) — the form that surfaces these tools.
- Automatic Translation — the caller of
wpr_translate_ajax_purge_cache.
For the product-level framing around these maintenance controls, see the multi-language real estate website overview.