- availability:
-
WPML Version: 3.2.7
- description:
-
- Pass the necessary information among language domains. You can find more details in our document Passing session data between languages in domains.
- This is specific for displaying the language URL format as A different domain per language.
- To get back the data, use the filter wpml_get_cross_domain_language_data.
- type:
- filter
- category:
- Miscellaneous
- parameters:
-
add_filter( 'wpml_cross_domain_language_data', callable $function_to_add);
- $function_to_add
- (callable) (Required) Your callback to be run when the filter is applied.
- hook example usage:
-
We use wpml_cross_domain_language_data to pass the cookie data. In other domains, we use wpml_get_cross_domain_language_data to handle the data and save the cookie.
Example
12345678910111213141516171819add_filter(
'wpml_cross_domain_language_data'
,
'pass_data_to_domain'
);
// after plugins loaded
// this will be executed on the original domain where we have access to the cookie
function
pass_data_to_domain(
$xdomain_data
) {
if
( isset (
$_COOKIE
[
'cookie_name'
] ) ) {
$xdomain_data
[
'cookie_name'
] =
$_COOKIE
[
'cookie_name'
];
}
return
$xdomain_data
;
}
add_action(
'init'
,
'set_xdomain_data_cookie'
);
// this handle the xdomain_data and set the cookie
function
set_xdomain_data_cookie() {
$xdomain_data
= apply_filters(
'wpml_get_cross_domain_language_data'
,
array
() );
if
( isset (
$xdomain_data
[
'cookie_name'
] ) ) {
setcookie(
'cookie_name'
,
$xdomain_data
[
'cookie_name'
], time() + 30 * DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
}
}