Skip navigation

Resolved

Reported for: WPML Multilingual CMS 3.3.5

Resolved in: 3.4

Overview of the issue

A 404 error:

«Failed to load resource: the server responded with a status of 404 (Not Found)»

when calling admin_url( ‘admin-ajax.php’ ).

The problem appears when you use the «A different domain per language» setting.

 

When you call admin_url( ‘admin-ajax.php’ ), you see something like this:

http://secondary-language-domain.com/secondary-lang-code/wp-admin/admin-ajax.php

instead of:

http://secondary-language-domain.com/wp-admin/admin-ajax.php.

 

This results in a 404 error:

«Failed to load resource: the server responded with a status of 404 (Not Found)».

 

It will be fixed in the next release.

Workaround

Log into your FTP and find the wpml-url-converter.class.php file located in wp-content/plugins/sitepress-multilingual-cms/inc/url-handling/wpml-url-converter.class.php.

Search for the admin_url_filter function (around line 39) and change the following code:

public function admin_url_filter( $url, $path ) {
    if ( 'admin-ajax.php' === $path ) {
        $url = $this->get_admin_ajax_url( $url );
    }
    return $url;
}

to:

public function admin_url_filter( $url, $path ) {
    if ( ( strpos( $url, 'http://' ) === 0 
      || strpos( $url, 'https://' ) === 0 ) 
      && 'admin-ajax.php' === $path 
      && $this->wpml_wp_api->is_front_end() ) {
        global $sitepress;
    
        $url = $this->convert_url( $url,
        $sitepress->get_current_language() );
    }

    return $url;
}

Always remember to make a backup first before you change anything in your files.