WP Residence Help WP Residence Help

  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / 30. WPResidence Translate Plugin / Cache Purge & Reset Tools — Developer Reference

Cache Purge & Reset Tools — Developer Reference

1 view 0

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:

  1. The AJAX nonce action wpr_translate_purge_cache (field nonce).
  2. The manage_options capability.

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).

Screenshot: VS Code showing cache-purge.php and theme-transients.php side by side

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:

  1. Returns silently if $_POST['wpr_translate_reset_settings'] is empty.
  2. Returns if the user lacks manage_options.
  3. check_admin_referer( 'wpr_translate_reset_settings', 'wpr_translate_reset_settings_nonce' ) — hard-fails on bad nonce.
  4. Calls wpr_translate_admin_reset_plugin_data().
  5. 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:

  1. TRUNCATE TABLE on the six plugin tables (each guarded by SHOW 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_languages
    

    Failure of any TRUNCATE short-circuits with the error code wpr_translate_reset_table_failed.

  2. 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
    
  3. Calls wpr_translate_clear_custom_field_rules_cache() when available.
  4. 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)

  1. check_ajax_referer() on the shared action.
  2. current_user_can( 'manage_options' ).
  3. Reject if type, element_types, or language is empty.
  4. 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.”

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:

  1. Resolves every submitted slug to its element_type string.
  2. For each element type, SELECT element_id, trid FROM ... WHERE element_type = %s AND language_code = %s AND original = 0 LIMIT %d where the limit is the remaining batch slot count.
  3. For each row, applies Layer-5 safety: post deletion requires both wpr_translated_language and wpr_translated_original_post_id post meta; term deletion requires wpr_original_term_id term meta. Rows missing markers are counted as skipped, not deleted.
  4. Posts: wp_delete_post( $id, true ) plus a manual $wpdb->delete() on the translations table (posts have no auto-cleanup hook).
  5. Terms: wp_delete_term( $id, $taxonomy ) (taxonomy is extracted by stripping the tax_ prefix from the element type) plus delete_term_meta( $original_id, 'wpr_translated_term_' . $language ) on the original term.
  6. 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.

Screenshot: Browser devtools showing repeated wpr_translate_delete_translations AJAX calls with decrementing remaining counts

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, or wpr_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 TABLE is used instead of DELETE, 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; check WP_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.

30. WPResidence Translate Plugin

Related Articles

  • String Scanner — Developer Guide
  • The String Scanner
  • Gettext Pipeline & MO Files — Developer Guide
  • Gettext & MO Files — Making Translations Appear on the Front End

WP Residence Documentation

  • 01. Getting Started
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 02. Installation & Setup
  • 03. Installation FAQ
  • 06. Search & Filtering
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 09. Agent, Agency & Developers
  • 08. Property Pages & Layouts
  • 07. Property Lists, Categories & Archive
  • 13. WPResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • 04. Theme Options & Global Settings
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • 20. Translations & Languages
  • 26. FAQ
  • 10. Pages
  • 11. Header
  • 12. Footer
  • 05. Maps & Location Settings
  • 18. Payments & Monetization
  • Plugins
    • 19. Included Plugins
    • 22. Third Party Plugins – IDX Compatibility
    • 21. Third-Party Plugins – Multi-Language
    • 23. Third party Plugins – Other
  • Technical
    • 24. Technical how to | Custom Code Required
    • 25. Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API