• Resolved tobaco

    (@tobaco)


    Hi,

    we’ve build a multilanguage site and the tracking doesn’t work for all languages except the main language (german). The plugin tries to call the rest url with the language appended, which returns the 404 page.

    Here’s the url for one of the languages:
    https://mydomain.dev/en/wp-json/burst/v1/track/?token=dmiketo&_locale=user

    How can we avoid this?

    Thanks and kind regards!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    The language plugin probably inserts the language in the rest_api url. What plugin are you using?

    The default configuration is tracking with an endpoint instead of the rest api. The endpoint is located in wp-content/plugins/burst-statistics/endpoint.php

    If the rest api is used, this means the endpoint is probably blocked by either a security plugin or your hosting provider.

    If this block can be removed, the site can use the endpoint again, which could be a work around for the language insertion in the URL.

    Thread Starter tobaco

    (@tobaco)

    Hi and thanks for your response!

    We are using WPML for the languages. How does the plugin decide between endpoint and api? We don’t have any security plugins enabled right now. I also changed the access rights for the endpoint.php to 664. But it still uses the api for tracking. This also applies to the backend display of the stats. This also only works in the main language, not in the other ones. Here it’s the same problem with the appended lang slug for the api call.

    Thanks for your help!

    Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    Can you try to add the following snippet to your site as an mu-plugin?

    It will strip the language from the Burst rest api.

    /**
     * Fix for WPML issue where WPML breaks the rest api by adding a language locale in the url
     *
     * @param $url
     * @param $path
     * @param $blog_id
     * @param $scheme
     *
     * @return string
     */
    function burst_my_fix_rest_url_for_wpml($url, $path, $blog_id, $scheme)
    {
    	if (strpos($url, 'burst/v') === false) {
    		return $url;
    	}
    
    	$current_language = false;
    	if (function_exists('icl_register_string')) {
    		$current_language = apply_filters('wpml_current_language', null);
    	}
    
    	if ($current_language) {
    		if (strpos($url, '/'.$current_language.'/wp-json/')) {
    			$url = str_replace('/'.$current_language.'/wp-json/', '/wp-json/', $url);
    		}
    	}
    
    	return $url;
    }
    
    add_filter('rest_url', 'burst_my_fix_rest_url_for_wpml', 10, 4);
    Thread Starter tobaco

    (@tobaco)

    Thanks for the function, but this doesn’t seem to work. I logged the urls, which run trough this filter, but there are none with “burst” in it.

    The api calls seem to use the url, which is defined in the html:

    wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "https://mydomain.dev/en/wp-json/" ) );

    Api calls from other plugins use this rootUrl (with language) without problems (returns json and not a 404), so I can’t modify every rest url. :-/

    Plugin Author Rogier Lankhorst

    (@rogierlankhorst)

    @tobaco this is the filter for all REST url’s, so Burst should pass through it as well. Could this be caused by caching?

    Not sure why other plugins don’t have this issue, but it could be they already have a fix in place, or they don’t use the wp.apiFetch method? The REST route is declared with standard WordPress code.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.