This article documents the three maintenance subsystems of WPEstate Translate 1.0.9: the WPResidence cache-purge bridge, the data reset routine, and the batch delete-translations processor. Each is a small 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()
Calls the theme’s own purge routine in the same request, with no loopback:
function wpr_translate_purge_wpestate_cache() {
if ( ! function_exists( 'wpestate_delete_cache' ) ) {
return new WP_Error( 'wpr_translate_cache_purge_unavailable', ... );
}
wpestate_delete_cache();
return true;
}
wpestate_delete_cache() deletes every _transient_wpestate* option and flushes the object cache when one is in use. WPResidence Core defines it in api/cache/cache_reset.php; on WPRentals the theme defines it. The helper returns true after the purge, or a WP_Error with code wpr_translate_cache_purge_unavailable when neither is loaded.
Callers: wpr_translate_ajax_purge_cache() below, the Automatic Translate strings handler after its last batch (includes/admin/menu.php), and the Auto translate publish handler after the translation is published (includes/admin/post-editor.php). The Clear WpResidence Cache admin-bar link runs the same wpestate_delete_cache().
wpr_translate_ajax_purge_cache()
Registered on wp_ajax_wpr_translate_purge_cache. The bulk auto-translate screen calls it from finishProcessing() in assets/js/admin.js when a run ends; the nonce is localized as purgeNonce in includes/plugin-bootstrap.php. It verifies:
- The AJAX nonce action wpr_translate_purge_cache (field nonce).
- The manage_options capability.
On success it responds with wp_send_json_success( [ ‘message’ => ‘Cache purged successfully.’ ] ).
Transient Cleanup Helper
includes/admin/theme-transients.php defines wpr_translate_admin_clear_theme_search_transients( $context ). In 1.0.9 nothing in the plugin calls it. When you call it, it clears these WPResidence transients (the base key and one per active language slug and code):
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 come from wpr_translate_get_active_languages() (via wpr_translate_get_language_slug()) plus ICL_LANGUAGE_CODE when defined. It only runs when $context matches the stored theme admin strings domain (wpr_translate_theme_admin_strings_domain, falling back to wpresidence_admin).
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 a bad nonce.
- Calls wpr_translate_admin_reset_plugin_data().
- Stores the settings error (success or failure) in the settings_errors transient and wp_safe_redirect()s to admin.php?page=wpr-translate-settings&settings-updated=true.
wpr_translate_admin_reset_plugin_data()
Returns true on success or WP_Error on failure and performs:
- TRUNCATE TABLE on the two plugin tables (each guarded by SHOW TABLES LIKE):
{prefix}wpestate_translation_translations {prefix}wpestate_translation_stringsA failed TRUNCATE short-circuits with the error code wpr_translate_reset_table_failed.
- wpr_translate_runtime_strings_changed() – bumps the last_changed key of the wpr_translate_runtime_strings object-cache group so cached string maps are dropped.
- 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 widget_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, settings, custom-field rules from the theme JSON, _wpr_language stamping, rewrite flush).
The reset never touches posts, terms or their meta. Because 1.0.9 stores translation relationships in post meta (_wpr_language, _wpr_translations, wpr_translated_original_post_id) and term meta (wpr_term_language, wpr_original_term_id, wpr_translated_term_{code}), families created by 1.0.9 stay linked. Only families that exist solely in the legacy translations table lose their link.
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, or language is empty.
- Compare language against wpr_translation_get_default_language_code( wpr_translation_get_active_languages() ) – the default is always rejected with “Cannot delete content in the default language.”
Member Finder
Both handlers use wpr_translate_admin_find_translation_member_ids( $type, $scope, $language, $limit ):
- Posts: get_posts() on _wpr_language = $language across every registered post status (so trashed and auto-draft members are included), suppress_filters => true. Terms: term IDs whose wpr_term_language meta equals $language in that taxonomy.
- Adds legacy-only members: element_id rows from wpestate_translation_translations with the same element_type and language_code and original = 0.
- Validates each candidate through wpr_translate_relationship_get_post_family() / wpr_translate_relationship_get_term_family(). A candidate is kept only when it is not the family’s canonical (source) ID and it is the family’s member for $language.
Count Handler
wpr_translate_admin_ajax_count_translations() sums count( member IDs ) for every requested slug and responds with { count: int }. The JavaScript shows this count in a confirm() dialog before deleting.
Delete Handler
wpr_translate_admin_ajax_delete_translations() processes up to 20 items per call:
- For each slug, fetch member IDs with the remaining batch slots as the limit.
- Posts: wpr_translation_delete_cloned_attachments( $id ), then wp_delete_post( $id, true ). Shared files stay on disk while another attachment row still references them.
- Terms: wp_delete_term( $id, $taxonomy ). The relationship lifecycle hooks (pre_delete_term / delete_term in includes/translation-relationships-lifecycle.php) clean the source term’s map.
- After the batch, re-count remaining members so the progress loop can tick down.
Response shape: { deleted: int, skipped: int, remaining: int } (skipped is always 0 in 1.0.9). 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() (no callers) |
| 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_find_translation_member_ids(), wpr_translate_admin_ajax_count_translations(), wpr_translate_admin_ajax_delete_translations(), wpr_translation_delete_cloned_attachments() |
Extension Points
- To clear the WPResidence select-list transients after your own bulk string update, call wpr_translate_admin_clear_theme_search_transients( ‘wpresidence_admin’ ) yourself; the plugin does not call it.
- The delete handler only removes validated family members. Custom content becomes deletable once it is linked through the relationship meta above.
- The post types offered in the Delete card are show_ui post types minus wpr_translate_get_auto_translation_excluded_post_types() (filterable with wpr_translate_auto_translation_excluded_post_types).
- The batch size of 20 is hard-coded. For a one-off migration, write your own WP-CLI command around wpr_translate_admin_find_translation_member_ids().
Gotchas
- TRUNCATE TABLE is used instead of DELETE, so auto-increment counters reset.
- The reset re-runs the full activation, including flush_rewrite_rules() and the _wpr_language stamping query.
- The cache purge runs in the same PHP request as the caller. It sends no HTTP request, so hosts that block loopback requests do not affect it.
- Delete-translations never touches the default language – enforced in the UI 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.