0 ? (int) $translated : $id; } /** * Match template rules against the original content, not its translation. * * @param int $post_id Queried post id. * @return int */ function aumframe_wpml_like_template_post_id( $post_id ) { $post_id = (int) $post_id; if ( $post_id <= 0 || ! aumframe_wpml_like_active() ) { return $post_id; } $default = apply_filters( 'wpml_default_language', null ); if ( ! is_string( $default ) || '' === $default ) { return $post_id; } /* * The kit's rules were written against the default language's ids, so that is the language to * resolve back to — the mirror of what the AumLang bridge does with `get_source_id()`. */ return aumframe_wpml_like_object_id( $post_id, (string) get_post_type( $post_id ), $default ); } add_filter( 'aumframe/template_post_id', 'aumframe_wpml_like_template_post_id', 20 ); /** * Point a link binding at the current language's version. * * @param int $post_id Post named by the binding. * @return int */ function aumframe_wpml_like_link_post_id( $post_id ) { $lang = aumframe_wpml_like_current_code(); if ( '' === $lang ) { return $post_id; } return aumframe_wpml_like_object_id( $post_id, (string) get_post_type( (int) $post_id ), $lang ); } add_filter( 'aumframe/link_post_id', 'aumframe_wpml_like_link_post_id', 20 ); /** * Same for a term archive link. * * @param int $term_id Term named by the binding. * @return int */ function aumframe_wpml_like_link_term_id( $term_id ) { $lang = aumframe_wpml_like_current_code(); $term = $lang ? get_term( (int) $term_id ) : null; if ( '' === $lang || ! $term instanceof \WP_Term ) { return $term_id; } return aumframe_wpml_like_object_id( $term_id, $term->taxonomy, $lang ); } add_filter( 'aumframe/link_term_id', 'aumframe_wpml_like_link_term_id', 20 ); /** * Put the language into an address that has no object to swap — a content type archive. * * @param string $url Resolved address. * @param string $expr Binding expression. * @return string */ function aumframe_wpml_like_link_url( $url, $expr ) { $lang = aumframe_wpml_like_current_code(); if ( '' === $lang || 0 !== strpos( (string) $expr, 'link.archive.' ) ) { return $url; } $converted = apply_filters( 'wpml_permalink', (string) $url, $lang ); return is_string( $converted ) && '' !== $converted ? $converted : $url; } add_filter( 'aumframe/link_url', 'aumframe_wpml_like_link_url', 20, 2 ); /** * Same for WPML / Polylang. * * @param string $lang Current value. * @return string */ function aumframe_wpml_like_layout_language( $lang ) { $code = aumframe_wpml_like_current_code(); return '' !== $code ? $code : $lang; } add_filter( 'aumframe/current_language', 'aumframe_wpml_like_layout_language', 20 ); /** * Same for WPML / Polylang. * * `wpml_active_languages` is the shared shape here — WPML defines it and Polylang implements it. * * @param array $languages code => label. * @return array */ function aumframe_wpml_like_translatable_languages( $languages ) { if ( ! aumframe_wpml_like_active() ) { return $languages; } $active = apply_filters( 'wpml_active_languages', null, array( 'skip_missing' => 0 ) ); $default = apply_filters( 'wpml_default_language', null ); if ( ! is_array( $active ) ) { return $languages; } foreach ( $active as $code => $info ) { if ( $code === $default ) { continue; } $label = ''; if ( is_array( $info ) ) { foreach ( array( 'translated_name', 'native_name' ) as $key ) { if ( ! empty( $info[ $key ] ) && is_string( $info[ $key ] ) ) { $label = $info[ $key ]; break; } } } $languages[ $code ] = '' !== $label ? $label : $code; } return $languages; } add_filter( 'aumframe/translatable_languages', 'aumframe_wpml_like_translatable_languages', 20 );