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