Skip Navigation
availability:

WPML Version: 3.2.7

description:
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
add_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 );
    }
}