Ajax.php
869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace WPML\Language\Detection;
use WPML\FP\Maybe;
use WPML\FP\Obj;
use WPML\FP\Lst;
use WPML\FP\Str;
use WPML\FP\Fns;
use \WPML_Request;
class Ajax extends WPML_Request {
public function get_requested_lang() {
return Maybe::of( $_REQUEST )
->map( Obj::prop( 'lang' ) )
->filter( Lst::includes( Fns::__, $this->active_languages ) )
->map( 'sanitize_text_field' )
->getOrElse(
function () {
return $this->get_cookie_lang();
}
);
}
protected function get_cookie_name() {
return $this->cookieLanguage->getAjaxCookieName( $this->is_admin_action_from_referer() );
}
/**
* @return bool
*/
private function is_admin_action_from_referer() {
return (bool) Maybe::of( $_SERVER )
->map( Obj::prop( 'HTTP_REFERER' ) )
->map( Str::pos( '/wp-admin/' ) )
->getOrElse( false );
}
}