1 <?php
2
3 /**
4 * Vanilla WMPL related enhancements.
5 *
6 * @author Nevma, http://www.nevma.gr, info@nevma.gr
7 *
8 * @license http://www.gnu.org/licenses/gpl-3.0.en.html GPLv3
9 */
10
11
12
13 /**
14 * Define language settings for WPML.
15 */
16
17 global $LANG;
18
19 $LANG = defined( 'WPLANG' ) ? WPLANG : 'el';
20
21 if ( function_exists ( 'icl_object_id' ) ) {
22 $LANG = ICL_LANGUAGE_CODE;
23 }
24
25
26
27 /**
28 * Removes WMPL scripts and styles from theme.
29 *
30 * @return void
31 */
32
33 function vanilla_wpml_cleanup () {
34
35 if ( ! function_exists ( 'icl_object_id' ) ) {
36 return;
37 }
38
39 define( 'ICL_DONT_LOAD_LANGUAGES_JS', true );
40 define( 'ICL_DONT_LOAD_NAVIGATION_CSS', true );
41 define( 'ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true );
42
43 global $sitepress;
44
45 remove_action( 'wp_head', array( $sitepress, 'meta_generator_tag' ) );
46
47 }
48
49
50
51 /**
52 * Create an HTML unordered list of available languages for the current
53 * post. It works for any post type the current post belongs to.
54 *
55 * @param array $args An associative array with the 'id' and 'class' of the
56 * generated HTML list element and an associative array
57 * named 'languages' with associations of language codes
58 * with custom names for the respective language.
59 *
60 * @return string The HTML UL element string of the available languages.
61 */
62
63 function vanilla_wpml_language_switcher ( $args ) {
64
65 if ( ! function_exists( 'icl_get_languages' ) ) {
66 return '';
67 }
68
69 $args = array_merge( $args, array( 'id' => null, 'class' => null, 'languages' => array(), 'skip_missing' => 1 ) );
70
71 $output = '';
72
73 $languages = icl_get_languages( 'skip_missing=' . $args['skip_missing'] );
74
75 if ( $languages ) {
76
77 $output .=
78 '<ul'.
79 ( $args['id'] ? ' id = "' . $args['id'] . '" ' : ' ' ) .
80 'class = "vanilla-language-switcher' . ( $args['class'] ? ' ' . ' ' . $args['class'] : '' ) . '">';
81
82 foreach ( $languages as $language ) {
83
84 $language_string = ! empty( $args['languages'][$language['language_code']] ) ? $args['languages'][$language['language_code']] : $language['native_name'];
85
86 $output .=
87 '<li class = "vanilla-language vanilla-language-' . $language['language_code'] . '">' .
88 '<a href = "' . $language['url'] . '" title = "' . $language_string . '">' . $language_string . '</a>' .
89 '</li>';
90
91 }
92
93 $output .=
94 '</ul><!-- .vanilla-language-switcher -->';
95 }
96
97 return $output;
98
99 }
100
101
102
103 /**
104 * WPML helper function that gets the ID of an object's version in another
105 * language, if this object has been translated.
106 *
107 * @param int $object_id The ID of the object.
108 * @param string $object_type The type of the object. Defaults to the
109 * value 'post'.
110 * @param boolean $return_original Whether to return the orginal object if
111 * the translation is missing. Defaults to
112 * false.
113 * @param string $language_code The two letter code of the language in
114 * which the original object's version is
115 * being sought. Defaults to null.
116 *
117 * @return int The ID of the object that corresponds the original object's
118 * version in the requested language.
119 */
120
121 function vanilla_wpml_get_translation ( $object_id, $object_type='post', $return_original=false, $language_code=null ) {
122
123 if ( function_exists ( 'icl_object_id' ) ) {
124 return icl_object_id ( $object_id, $object_type, $return_original, $language_code );
125 } else {
126 return $object_id;
127 }
128
129 }
130
131 ?>