I have a WordPress multisite, which is in both english and french. On the french site, localization is working great (using date_l18n() for dates, and __(), etc. for the rest).

When an AJAX call sends off to WP and returns data (the same rendering functions being called from initial page load and AJAX), however, they are returning English date values.

Example: Date archive says "septembre 2013". You click the Next Month button, which sends off to AJAX and returns the new month header, and article listing. It's returning "October 2013" rather than "octobre 2013".

Is this a known bug, or should I be submitting this to track?

function render_event_archive_month_header( $date = null, $echo = true ) {
    $date_str = strtotime( $date );

    if( ! $echo )
        ob_start();

    <?php echo date_i18n('F Y', $date_str ); ?>

    <?php
    if( ! $echo ) {
        $data = ob_get_contents();
        ob_end_clean();
        return $data;
    }
}

This is being passed a yyyy-mm-dd date value, like so

render_event_archive_month_header( '2013-10' );

from within my Ajax action callback.

  • 3
    Depends on the code creating the response. Please add it to your question. Do you use date_i18n()? – fuxia Sep 19 '13 at 19:48
  • 1
    What do you get when you let the AJAX function return $GLOBALS['wp_locale']? – fuxia Sep 19 '13 at 20:18
  • 1
    Hm, strange. Try 'en_US' === get_locale() or load_default_textdomain(); in your AJAX callback. If that doesn’t work, the language is not detected correctly. – fuxia Sep 19 '13 at 20:32
  • 1
    @toscho "It's returning the English values" tells me that the user didn't actually dump what you asked for, but described his problem again. – kaiser Sep 19 '13 at 20:47
  • 1
    @toscho Yeah, you know that I know that. :) But the comment from the OP tells me that he didn't dump it, but just repeated his question/problem. – kaiser Sep 19 '13 at 20:53

Thank you for all the help Toscho! The issue was actually quite obvious after a night of sleep. I am using WP Native Dashboard. In case you don't know what that is, it allows you to change the language of the Admin section of the site.

Considering WP Ajax is considered to be admin, it's changing the language like so. Once I logged out, or changed the back end language to FR, it's working as intended.

I'll report this to the plugin author as a bug.

  • 1
    This isn’t really a bug. There is no safe way to know in admin-ajax if a function was called from front end or back end. But it is good to see you figured it out. – fuxia Sep 20 '13 at 13:48
  • does admin-ajax receive a referrer or origin? If so, perhaps a simple URL check for wp-admin would do the trick for any of these plugins. :) – Eric Holmes Sep 20 '13 at 14:49
  • Plugins don’t have to send a referer value with their requests. – fuxia Sep 20 '13 at 14:51

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.