| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* Register wpLingua assets for option page : Settings |
| 11 |
* |
| 12 |
* @param string $hook |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
function wplng_option_page_settings_assets( $hook ) { |
| 16 |
|
| 17 |
if ( ! is_admin() |
| 18 |
|| $hook !== 'toplevel_page_wplingua-settings' |
| 19 |
|| empty( wplng_get_api_key() ) |
| 20 |
) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Enqueue jQuery |
| 26 |
*/ |
| 27 |
|
| 28 |
wp_enqueue_script( 'jquery' ); |
| 29 |
|
| 30 |
/** |
| 31 |
* Enqueue wpLingua JS scripts |
| 32 |
*/ |
| 33 |
|
| 34 |
wp_enqueue_script( |
| 35 |
'wplingua-option-settings', |
| 36 |
plugins_url() . '/wplingua/assets/js/admin/option-page-settings.js', |
| 37 |
array( 'jquery' ), |
| 38 |
WPLNG_API_VERSION |
| 39 |
); |
| 40 |
|
| 41 |
/** |
| 42 |
* Enqueue wpLingua CSS styles |
| 43 |
*/ |
| 44 |
|
| 45 |
wp_enqueue_style( |
| 46 |
'wplingua-option-settings', |
| 47 |
plugins_url() . '/wplingua/assets/css/admin/option-page-settings.css', |
| 48 |
array(), |
| 49 |
WPLNG_API_VERSION |
| 50 |
); |
| 51 |
|
| 52 |
wp_enqueue_style( |
| 53 |
'wplingua-option-pages', |
| 54 |
plugins_url() . '/wplingua/assets/css/admin/option-page.css', |
| 55 |
array(), |
| 56 |
WPLNG_API_VERSION |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
/** |
| 62 |
* Register wpLingua assets for option page : Register |
| 63 |
* |
| 64 |
* @param string $hook |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
function wplng_option_page_register_assets( $hook ) { |
| 68 |
|
| 69 |
if ( ! is_admin() |
| 70 |
|| $hook !== 'toplevel_page_wplingua-settings' |
| 71 |
) { |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Enqueue jQuery |
| 77 |
*/ |
| 78 |
|
| 79 |
wp_enqueue_script( 'jquery' ); |
| 80 |
|
| 81 |
/** |
| 82 |
* Enqueue wpLingua JS scripts |
| 83 |
*/ |
| 84 |
|
| 85 |
wp_enqueue_script( |
| 86 |
'wplingua-option-register', |
| 87 |
plugins_url() . '/wplingua/assets/js/admin/option-page-register.js', |
| 88 |
array( 'jquery' ), |
| 89 |
WPLNG_API_VERSION |
| 90 |
); |
| 91 |
|
| 92 |
/** |
| 93 |
* Enqueue wpLingua CSS styles |
| 94 |
*/ |
| 95 |
|
| 96 |
wp_enqueue_style( |
| 97 |
'wplingua-option-register', |
| 98 |
plugins_url() . '/wplingua/assets/css/admin/option-page-register.css', |
| 99 |
array(), |
| 100 |
WPLNG_API_VERSION |
| 101 |
); |
| 102 |
|
| 103 |
wp_enqueue_style( |
| 104 |
'wplingua-option-pages', |
| 105 |
plugins_url() . '/wplingua/assets/css/admin/option-page.css', |
| 106 |
array(), |
| 107 |
WPLNG_API_VERSION |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
/** |
| 113 |
* Register wpLingua assets for option page : Switcher |
| 114 |
* |
| 115 |
* @param string $hook |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
function wplng_option_page_switcher_assets( $hook ) { |
| 119 |
|
| 120 |
if ( ! is_admin() |
| 121 |
|| $hook !== 'wplingua_page_wplingua-switcher' |
| 122 |
) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Enqueue jQuery |
| 128 |
*/ |
| 129 |
|
| 130 |
wp_enqueue_script( 'jquery' ); |
| 131 |
|
| 132 |
/** |
| 133 |
* Enqueue wpLingua JS scripts |
| 134 |
*/ |
| 135 |
|
| 136 |
wp_enqueue_script( |
| 137 |
'wplingua-option-switcher', |
| 138 |
plugins_url() . '/wplingua/assets/js/admin/option-page-switcher.js', |
| 139 |
array( 'jquery' ), |
| 140 |
WPLNG_API_VERSION |
| 141 |
); |
| 142 |
|
| 143 |
wp_enqueue_script( |
| 144 |
'wplingua-script', |
| 145 |
plugins_url() . '/wplingua/assets/js/script.js', |
| 146 |
array( 'jquery' ), |
| 147 |
WPLNG_API_VERSION |
| 148 |
); |
| 149 |
|
| 150 |
/** |
| 151 |
* Enqueue wpLingua CSS styles |
| 152 |
*/ |
| 153 |
|
| 154 |
wp_enqueue_style( |
| 155 |
'wplingua-option-switcher', |
| 156 |
plugins_url() . '/wplingua/assets/css/admin/option-page-switcher.css', |
| 157 |
array(), |
| 158 |
WPLNG_API_VERSION |
| 159 |
); |
| 160 |
|
| 161 |
wp_enqueue_style( |
| 162 |
'wplingua-option-pages', |
| 163 |
plugins_url() . '/wplingua/assets/css/admin/option-page.css', |
| 164 |
array(), |
| 165 |
WPLNG_API_VERSION |
| 166 |
); |
| 167 |
|
| 168 |
wp_enqueue_style( |
| 169 |
'wplingua', |
| 170 |
plugins_url() . '/wplingua/assets/css/front.css', |
| 171 |
array(), |
| 172 |
WPLNG_API_VERSION |
| 173 |
); |
| 174 |
|
| 175 |
/** |
| 176 |
* Enqueue CSS and JS for the code editor |
| 177 |
*/ |
| 178 |
|
| 179 |
if ( function_exists( 'wp_enqueue_code_editor' ) ) { |
| 180 |
$cm_settings = array(); |
| 181 |
$cm_settings['codeEditor'] = wp_enqueue_code_editor( |
| 182 |
array( 'type' => 'text/css' ) |
| 183 |
); |
| 184 |
|
| 185 |
wp_localize_script( 'jquery', 'cm_settings', $cm_settings ); |
| 186 |
wp_enqueue_script( 'wp-theme-plugin-editor' ); |
| 187 |
wp_enqueue_style( 'wp-codemirror' ); |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Add inline style for wpLingua custom CSS |
| 192 |
*/ |
| 193 |
|
| 194 |
$custom_css = get_option( 'wplng_custom_css' ); |
| 195 |
|
| 196 |
if ( ! empty( $custom_css ) |
| 197 |
&& is_string( $custom_css ) |
| 198 |
) { |
| 199 |
$custom_css = wp_strip_all_tags( $custom_css ); |
| 200 |
wp_add_inline_style( 'wplingua', $custom_css ); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
/** |
| 206 |
* Register wpLingua assets for option page : Exclusions |
| 207 |
* |
| 208 |
* @param string $hook |
| 209 |
* @return void |
| 210 |
*/ |
| 211 |
function wplng_option_page_exclusions_assets( $hook ) { |
| 212 |
|
| 213 |
if ( ! is_admin() |
| 214 |
|| $hook !== 'wplingua_page_wplingua-exclusions' |
| 215 |
) { |
| 216 |
return; |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Enqueue jQuery |
| 221 |
*/ |
| 222 |
|
| 223 |
wp_enqueue_script( 'jquery' ); |
| 224 |
|
| 225 |
/** |
| 226 |
* Enqueue wpLingua CSS styles |
| 227 |
*/ |
| 228 |
|
| 229 |
wp_enqueue_style( |
| 230 |
'wplingua-option-exclusions', |
| 231 |
plugins_url() . '/wplingua/assets/css/admin/option-page-exclusions.css', |
| 232 |
array(), |
| 233 |
WPLNG_API_VERSION |
| 234 |
); |
| 235 |
|
| 236 |
wp_enqueue_style( |
| 237 |
'wplingua-option-pages', |
| 238 |
plugins_url() . '/wplingua/assets/css/admin/option-page.css', |
| 239 |
array(), |
| 240 |
WPLNG_API_VERSION |
| 241 |
); |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
/** |
| 247 |
* Register wpLingua assets on translations edit pages |
| 248 |
* |
| 249 |
* @return void |
| 250 |
*/ |
| 251 |
function wplng_translation_assets() { |
| 252 |
|
| 253 |
global $post_type; |
| 254 |
|
| 255 |
if ( 'wplng_translation' === $post_type ) { |
| 256 |
|
| 257 |
/** |
| 258 |
* Enqueue jQuery |
| 259 |
*/ |
| 260 |
|
| 261 |
wp_enqueue_script( 'jquery' ); |
| 262 |
|
| 263 |
/** |
| 264 |
* Enqueue wpLingua JS scripts |
| 265 |
*/ |
| 266 |
|
| 267 |
wp_enqueue_script( |
| 268 |
'wplingua-translation', |
| 269 |
plugins_url() . '/wplingua/assets/js/admin/translation.js', |
| 270 |
array( 'jquery' ), |
| 271 |
WPLNG_API_VERSION |
| 272 |
); |
| 273 |
|
| 274 |
/** |
| 275 |
* Localize script for AJAX |
| 276 |
*/ |
| 277 |
|
| 278 |
wp_localize_script( |
| 279 |
'wplingua-translation', |
| 280 |
'adminAjax', |
| 281 |
array( |
| 282 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 283 |
) |
| 284 |
); |
| 285 |
|
| 286 |
/** |
| 287 |
* Enqueue wpLingua CSS styles |
| 288 |
*/ |
| 289 |
|
| 290 |
wp_enqueue_style( |
| 291 |
'wplingua-translation', |
| 292 |
plugins_url() . '/wplingua/assets/css/admin/translation.css', |
| 293 |
array(), |
| 294 |
WPLNG_API_VERSION |
| 295 |
); |
| 296 |
|
| 297 |
} |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
/** |
| 303 |
* Print wpLingua head script (JSON with all languages informations) |
| 304 |
* |
| 305 |
* @return void |
| 306 |
*/ |
| 307 |
function wplng_inline_script_languages() { |
| 308 |
|
| 309 |
$languages = array(); |
| 310 |
$languages_allow = wplng_get_languages_allow(); |
| 311 |
|
| 312 |
if ( ! empty( $languages_allow ) && is_array( $languages_allow ) ) { |
| 313 |
|
| 314 |
$language_website = wplng_get_language_website(); |
| 315 |
|
| 316 |
if ( ! in_array( $language_website, $languages_allow, true ) ) { |
| 317 |
$languages_allow[] = $language_website; |
| 318 |
} |
| 319 |
|
| 320 |
$languages = $languages_allow; |
| 321 |
|
| 322 |
} else { |
| 323 |
$languages = wplng_get_languages_all(); |
| 324 |
} |
| 325 |
|
| 326 |
?><script>var wplngAllLanguages = <?php echo wp_json_encode( $languages ); ?>;</script> |
| 327 |
<?php |
| 328 |
} |
| 329 |
|