add_filter( 'wpml_cross_domain_language_data', callable $function_to_add);
- Loại
- filter
- Danh mục
- Khác
- Phiên bản WPML
- 3.2.7
Miêu tả
- Truyền các thông tin cần thiết giữa các tên miền ngôn ngữ. Bạn có thể tìm hiểu thêm chi tiết trong tài liệu Truyền dữ liệu phiên giữa các ngôn ngữ trong các tên miền của chúng tôi.
- Điều này dành riêng cho việc hiển thị định dạng URL ngôn ngữ dưới dạng Một tên miền khác nhau cho mỗi ngôn ngữ.
- Để lấy lại dữ liệu, hãy sử dụng bộ lọc wpml_get_cross_domain_language_data.
Đối số
- $function_to_add
- (callable) (Bắt buộc) Hàm gọi lại của bạn sẽ được chạy khi bộ lọc được áp dụng.
Ví dụ sử dụng
Chúng ta sử dụng wpml_cross_domain_language_data để truyền dữ liệu cookie. Trong các miền khác, chúng ta sử dụng wpml_get_cross_domain_language_data để xử lý dữ liệu và lưu cookie.
Ví dụ
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 );
}
}
Các hook liên quan
icl_ls_languages, wpml_sync_custom_field_copied_value, wpml_ls_enable_ajax_navigation, wpml_element_type, wpml_setting, wpml_sub_setting, wpml_exclude_post_from_auto_translate, wpml_forms_config_ninja-forms, wpml_forms_config_wpforms, wpml_tf_feedback_open_link