wpml.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | |
| 5 | function kubio_wpml_is_active(): bool { |
| 6 | if(!kubio_is_pro()) { |
| 7 | return false; |
| 8 | } |
| 9 | static $is_active = null; |
| 10 | if ( $is_active === null ) { |
| 11 | $is_active = defined( 'ICL_SITEPRESS_VERSION' ); |
| 12 | } |
| 13 | |
| 14 | return $is_active && ! kubio_polylang_is_active(); |
| 15 | } |
| 16 | |
| 17 | |
| 18 | function kubio_wpml_get_translated_string( $string ) { |
| 19 | if ( ! kubio_wpml_is_active() || ! is_string( $string ) ) { |
| 20 | return $string; |
| 21 | } |
| 22 | return apply_filters( 'wpml_translate_single_string', $string, KUBIO_WPML_BLOCK_DEFAULTS_ID, $string ); |
| 23 | } |
| 24 | |
| 25 | function kubio_wpml_get_translated_media_id( $id ) { |
| 26 | if ( ! kubio_wpml_is_active() ) { |
| 27 | return $id; |
| 28 | |
| 29 | } |
| 30 | $current_language = apply_filters( 'wpml_current_language', null ); |
| 31 | |
| 32 | $translated_attachment_id = apply_filters( 'wpml_object_id', $id, 'attachment', true, $current_language ); |
| 33 | |
| 34 | return $translated_attachment_id; |
| 35 | |
| 36 | } |
| 37 | |
| 38 | function kubio_wpml_get_translated_media_url( $url ) { |
| 39 | if ( ! kubio_wpml_is_active() || empty( $url ) ) { |
| 40 | return $url; |
| 41 | } |
| 42 | $image_id = attachment_url_to_postid( $url ); |
| 43 | if ( ! $image_id ) { |
| 44 | return $url; |
| 45 | } |
| 46 | |
| 47 | $translated_image_id = \kubio_wpml_get_translated_media_id( $image_id ); |
| 48 | if ( ! $translated_image_id ) { |
| 49 | return $url; |
| 50 | } |
| 51 | $new_url = wp_get_attachment_url( $translated_image_id ); |
| 52 | if ( $new_url ) { |
| 53 | return $new_url; |
| 54 | } |
| 55 | return $url; |
| 56 | } |
| 57 | |
| 58 | function kubio_wpml_get_original_language_post_id($post_id, $post_type) { |
| 59 | if(!kubio_wpml_is_active()) { |
| 60 | return $post_id; |
| 61 | } |
| 62 | |
| 63 | $translated_id = apply_filters( 'wpml_object_id', $post_id , $post_type, true, wpml_get_default_language() ); |
| 64 | if(!empty($translated_id) && $translated_id !== 0 && $translated_id !== $post_id) { |
| 65 | $post_id = $translated_id; |
| 66 | } |
| 67 | |
| 68 | return $post_id; |
| 69 | } |
| 70 | |
| 71 |