Browse: Home / Functions /

learndash_ajax_switch_to_site_locale

learndash_ajax_switch_to_site_locale()

Switches the current admin-ajax request’s locale to the site (front-end) locale.


Description #

AJAX handlers that render front-end content (course/profile/quiz blocks) hit admin-ajax.php where is_admin() is true, so determine_locale() returns get_user_locale() (the user’s profile/admin language) instead of the site locale. Content then comes back in a different language than what the visitor sees on the page. This forces the site locale so the AJAX response matches.

Only runs inside admin-ajax — callers outside that context would also need to pair this with restore_previous_locale() themselves, which is easy to miss.


Return #

(void)


Source #

File: includes/ld-misc-functions.php


Changelog #

Changelog
Version Description
5.1.4 Introduced.