# wplingua/1.0.4/inc/ob-callback/ajax.php

Translate and Go multilingual – Automatic AI translation – wpLingua, version 1.0.4. 59 lines.

- Page: https://pluginprobe.com/plugins/wplingua/1.0.4/code/inc/ob-callback/ajax.php
- Raw: https://pluginprobe.com/plugins/wplingua/1.0.4/raw/inc/ob-callback/ajax.php
- Modified: 2024-02-04T17:31:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wplingua/1.0.4/code/inc/ob-callback/ajax.php#L10-L20`.

```php
<?php

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}


/**
 * wpLingua OB Callback function : AJAX
 *
 * @param string $output
 * @return string
 */
function wplng_ob_callback_ajax( $output ) {

	if ( empty( $_SERVER['HTTP_REFERER'] ) ) {
		return $output;
	}

	$referer = sanitize_url( $_SERVER['HTTP_REFERER'] );

	// Check if the referer is clean
	if ( strtolower( esc_url_raw( $referer ) ) !== strtolower( $referer ) ) {
		return $output;
	}

	global $wplng_request_uri;
	$wplng_request_uri = wp_make_link_relative( $referer );

	if ( ! wplng_url_is_translatable( $wplng_request_uri )
		|| wplng_get_language_website_id() === wplng_get_language_current_id()
	) {
		return $output;
	}

	$output_translated = wplng_ob_callback_translate( $output );

	// Print debug data in debug.log file
	if ( true === WPLNG_LOG_AJAX_DEBUG ) {

		$debug = array(
			'title'       => 'wpLingua AJAX debug',
			'request_uri' => $wplng_request_uri,
			'value'       => $output,
			'translated'  => $output_translated,
		);

		error_log(
			var_export(
				$debug,
				true
			)
		);
	}

	return $output_translated;
}

```
