PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.12.3
Translate and Go multilingual – Automatic AI translation – wpLingua v2.12.3
2.16.7 2.16.6 2.16.5 2.16.4 2.16.3 2.16.2 2.16.1 2.16.0 2.15.2 2.15.1 2.15.0 2.14.3 2.14.2 2.14.1 2.14.0 2.13.1 2.13.0 2.12.3 2.12.2 2.12.1 trunk 1.0.3 1.0.4 1.0.5 1.1.0 All 112 releases
wplingua / inc / admin / option-page.php

option-page.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.12.3, at inc/admin/option-page.php

636 lines 17.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8
9 /**
10 * Add wpLingua admin menu when API Key is not registered
11 *
12 * @return void
13 */
14 function wplng_create_menu_register() {
15
16 add_menu_page(
17 __( 'wpLingua: Register', 'wplingua' ),
18 __( 'wpLingua', 'wplingua' ),
19 'edit_posts',
20 'wplingua-settings',
21 'wplng_option_page_register',
22 'dashicons-translation',
23 31
24 );
25 }
26
27
28 /**
29 * Add wpLingua admin menu when key is registered
30 *
31 * @return void
32 */
33 function wplng_create_menu() {
34
35 add_menu_page(
36 __( 'wpLingua: Settings', 'wplingua' ),
37 __( 'wpLingua', 'wplingua' ),
38 'edit_posts',
39 'wplingua-settings',
40 '',
41 'dashicons-translation',
42 31
43 );
44
45 add_submenu_page(
46 'wplingua-settings',
47 __( 'wpLingua: Settings', 'wplingua' ),
48 __( 'General settings', 'wplingua' ),
49 'edit_posts',
50 'wplingua-settings',
51 'wplng_option_page_settings'
52 );
53
54 add_submenu_page(
55 'wplingua-settings',
56 __( 'wpLingua: Switcher', 'wplingua' ),
57 __( 'Switcher', 'wplingua' ),
58 'edit_posts',
59 'wplingua-switcher',
60 'wplng_option_page_switcher'
61 );
62
63 add_submenu_page(
64 'wplingua-settings',
65 __( 'wpLingua: Exclusion', 'wplingua' ),
66 __( 'Exclusion', 'wplingua' ),
67 'edit_posts',
68 'wplingua-exclusions',
69 'wplng_option_page_exclusions'
70 );
71
72 add_submenu_page(
73 'wplingua-settings',
74 __( 'wpLingua: Dictionary', 'wplingua' ),
75 __( 'Dictionary', 'wplingua' ),
76 'edit_posts',
77 'wplingua-dictionary',
78 'wplng_option_page_dictionary'
79 );
80
81 add_submenu_page(
82 'wplingua-settings',
83 __( 'wplingua: Links & Medias', 'wplingua' ),
84 __( 'Links & Medias', 'wplingua' ),
85 'edit_posts',
86 'wplingua-link-media',
87 'wplng_option_page_link_media'
88 );
89
90 add_submenu_page(
91 'wplingua-settings',
92 __( 'wpLingua: Website slugs', 'wplingua' ),
93 __( 'Website slugs', 'wplingua' ),
94 'edit_posts',
95 'edit.php?post_type=wplng_slug',
96 false
97 );
98
99 add_submenu_page(
100 'wplingua-settings',
101 __( 'wpLingua: Translations', 'wplingua' ),
102 __( 'All translations', 'wplingua' ),
103 'edit_posts',
104 'edit.php?post_type=wplng_translation',
105 false
106 );
107 }
108
109
110 /**
111 * Register wpLingua settings
112 *
113 * @return void
114 */
115 function wplng_register_settings() {
116
117 // Option page : Settings and register
118 register_setting( 'wplng_settings', 'wplng_website_language' );
119 register_setting( 'wplng_settings', 'wplng_website_flag' );
120 register_setting( 'wplng_settings', 'wplng_target_languages' );
121 register_setting( 'wplng_settings', 'wplng_translate_search' );
122 register_setting( 'wplng_settings', 'wplng_load_in_progress' );
123 register_setting( 'wplng_settings', 'wplng_sitemap_xml' );
124 register_setting( 'wplng_settings', 'wplng_sitemap_xsl_override' );
125 register_setting( 'wplng_settings', 'wplng_hreflang' );
126 register_setting( 'wplng_settings', 'wplng_browser_language_redirect' );
127 register_setting( 'wplng_settings', 'wplng_api_key' );
128 register_setting( 'wplng_settings', 'wplng_request_free_key' );
129
130 // Option page : Exclusions
131 register_setting( 'wplng_exclusions', 'wplng_excluded_selectors' );
132 register_setting( 'wplng_exclusions', 'wplng_excluded_url' );
133
134 // Option page : Switcher
135 register_setting( 'wplng_switcher', 'wplng_insert' );
136 register_setting( 'wplng_switcher', 'wplng_theme' );
137 register_setting( 'wplng_switcher', 'wplng_style' );
138 register_setting( 'wplng_switcher', 'wplng_name_format' );
139 register_setting( 'wplng_switcher', 'wplng_flags_style' );
140 register_setting( 'wplng_switcher', 'wplng_custom_css' );
141
142 // Option page : Dictionary
143 register_setting( 'wplng_dictionary', 'wplng_dictionary_entries' );
144
145 // Option page : Links & Medias
146 register_setting( 'wplng_link_media', 'wplng_link_media_entries' );
147 }
148
149
150 /**
151 * Return true if is a wpLingua Admin page
152 *
153 * @return bool Is a wpLingua Admin page
154 */
155 function wplng_is_wplingua_admin_page() {
156
157 global $pagenow;
158 global $post;
159
160 /**
161 * Check if is a wpLingua option page
162 */
163
164 if ( 'admin.php' === $pagenow
165 && isset( $_GET['page'] )
166 && (
167 $_GET['page'] === 'wplingua-settings'
168 || $_GET['page'] === 'wplingua-switcher'
169 || $_GET['page'] === 'wplingua-dictionary'
170 || $_GET['page'] === 'wplingua-exclusions'
171 || $_GET['page'] === 'wplingua-link-media'
172 )
173 ) {
174 return true;
175 }
176
177 /**
178 * Check if is a translations or slugs admin list
179 */
180
181 if (
182 'edit.php' === $pagenow
183 && isset( $_GET['post_type'] )
184 && (
185 $_GET['post_type'] === 'wplng_translation'
186 || $_GET['post_type'] === 'wplng_slug'
187 )
188 ) {
189 return true;
190 }
191
192 /**
193 * Check if is translations or slugs edition
194 */
195
196 if (
197 'post.php' === $pagenow
198 && isset( $post->post_type )
199 && (
200 $post->post_type === 'wplng_translation'
201 || $post->post_type === 'wplng_slug'
202 )
203 ) {
204 return true;
205 }
206
207 return false;
208 }
209
210
211 /**
212 * Customize the admin footer text displayed on wpLingua option pages.
213 *
214 * @param string $text The default footer text.
215 * @return string The customized footer text for wpLingua pages.
216 */
217 function wplng_admin_footer_text( $text ) {
218
219 if ( wplng_is_wplingua_admin_page() ) {
220
221 $text = '<span class="dashicons dashicons-heart"></span> ';
222
223 if ( empty( wplng_get_api_data() ) ) {
224 $text .= esc_html__( 'Thank you for choosing wpLingua!', 'wplingua' );
225 } else {
226 $text .= sprintf(
227 esc_html__( 'If you like wpLingua please leave us a %1$s rating. A huge thanks!', 'wplingua' ),
228 '<a href="https://wordpress.org/support/plugin/wplingua/reviews/?filter=5" target="_blank" class="wc-rating-link" aria-label="' . esc_attr__( 'five stars', 'wplingua' ) . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
229 );
230 }
231 }
232
233 return $text;
234 }
235
236
237 /**
238 * Set custom update_footer text on wpLingua options pages
239 *
240 * @param string $text The default footer text to be modified.
241 * @return string The customized footer text for wpLingua pages.
242 */
243 function wplng_update_footer( $text ) {
244
245 if ( wplng_is_wplingua_admin_page() ) {
246 $text = '<a href="https://wplingua.com/" target="_blank">';
247 $text .= 'wplingua.com';
248 $text .= '</a> | ';
249 $text .= '<a href="https://github.com/julien-jacob/wplingua" target="_blank">';
250 $text .= 'GitHub';
251 $text .= '</a> | ';
252 $text .= esc_html__( 'Version', 'wplingua' );
253 $text .= ' ' . esc_html( WPLNG_PLUGIN_VERSION );
254 }
255
256 return $text;
257 }
258
259
260 /**
261 * Add 'Settings' link on wpLingua in the plugin list
262 *
263 * @param array $settings
264 * @return array
265 */
266 function wplng_settings_link( $settings ) {
267
268 $url = add_query_arg(
269 'page',
270 'wplingua-settings',
271 get_admin_url() . 'admin.php'
272 );
273
274 $link = '<a href="' . esc_url( $url ) . '">';
275 $link .= esc_html__( 'Settings', 'wplingua' );
276 $link .= '</a>';
277
278 $settings[] = $link;
279
280 return $settings;
281 }
282
283
284 /**
285 * Redirect to the wpLingua settings page upon plugin activation.
286 *
287 * @param string $plugin The plugin file path that was activated.
288 * @return void
289 */
290 function wplng_plugin_activation_redirect( $plugin ) {
291
292 if ( ! wp_doing_ajax() && WPLNG_PLUGIN_FILE === $plugin ) {
293 wp_safe_redirect(
294 admin_url( 'admin.php?page=wplingua-settings' )
295 );
296 exit();
297 }
298 }
299
300
301 /**
302 * Display a notice if the plugin is activate but not configured
303 *
304 * @return void
305 */
306 function wplng_admin_notice_no_key_set() {
307
308 $url = add_query_arg(
309 'page',
310 'wplingua-settings',
311 get_admin_url() . 'admin.php'
312 );
313
314 $html = '<div class="notice notice-info is-dismissible">';
315 $html .= '<p style="font-weight: 600;">';
316 $html .= '<span class="dashicons dashicons-translation"></span> ';
317 $html .= esc_html__( 'wpLingua - Translation solution for multilingual website', 'wplingua' );
318 $html .= '</p>';
319 $html .= '<p>';
320 $html .= esc_html__( 'wpLingua is installed, but not yet configured. You are just a few clicks away from making your website multilingual!', 'wplingua' );
321 $html .= '<br> ';
322 $html .= '<a href="' . esc_url( $url ) . '">';
323 $html .= esc_html__( 'Go to the configuration page', 'wplingua' );
324 $html .= '</a>';
325 $html .= '</p>';
326 $html .= '</div>';
327
328 echo $html;
329 }
330
331
332 /**
333 * Get the list of activated incompatible plugins
334 *
335 * @return array [Plugin name => Plugin file]
336 */
337 function wplng_get_incompatible_plugins() {
338
339 if ( ! function_exists( 'is_plugin_active' ) ) {
340 require_once ABSPATH . '/wp-admin/includes/plugin.php';
341 }
342
343 /**
344 * Get incompatible plugins
345 */
346
347 $incompatible_list = array(
348 'Automatic Translator' => 'auto-translate/auto-translate.php',
349 'Autoglot' => 'autoglot/autoglot.php',
350 'clonable' => 'clonable/clonable-wp.php',
351 'ConveyThis Translate' => 'conveythis-translate/index.php',
352 'Falang' => 'falang/falang.php',
353 'Google Translator' => 'google-language-translator/google-language-translator.php',
354 'Google Website Translator' => 'google-website-translator/google-website-translator.php',
355 'Gtranslate' => 'gtranslate/gtranslate.php',
356 'linguise' => 'linguise/linguise.php',
357 'Lokalise' => 'lokalise/lokalise.php',
358 'localizejs' => 'localizejs/localizejs.php',
359 'Multilanguage' => 'multilanguage/multilanguage.php',
360 'Polylang' => 'polylang/polylang.php',
361 'TranslatePress' => 'translatepress-multilingual/index.php',
362 'WEGLOT' => 'weglot/weglot.php',
363 'WPML' => 'sitepress-multilingual-cms/sitepress.php',
364 'WP Multilang' => 'wp-multilang/wp-multilang.php',
365 );
366
367 $incompatible_detected = array();
368
369 foreach ( $incompatible_list as $name => $file ) {
370 if ( is_plugin_active( $file ) ) {
371 $incompatible_detected[ $name ] = $file;
372 }
373 }
374
375 return $incompatible_detected;
376 }
377
378
379 /**
380 * Display a notice if an incompatible plugin is detected.
381 *
382 * @return void|string Outputs the admin notice or returns nothing if no conflicts are found.
383 */
384 function wplng_admin_notice_incompatible_plugin() {
385
386 $incompatible_plugins = wplng_get_incompatible_plugins();
387
388 if ( empty( $incompatible_plugins ) ) {
389 return;
390 }
391
392 $html = '<div ';
393 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
394 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
395 $html .= '<p style="font-weight: 600;">';
396 $html .= '<span class="dashicons dashicons-translation"></span> ';
397 $html .= esc_html__( 'wpLingua - Incompatible plugin detected', 'wplingua' );
398 $html .= '</p>';
399 $html .= '<p>';
400 $html .= esc_html__( 'You have several translation plugins. This may result in unpredictable or incorrect behavior. For best results, use only one translation plugin at a time. These plugins can cause problems with wpLingua: ', 'wplingua' );
401
402 $html .= '<ul style="list-style: disc; margin-left: 15px;">';
403 foreach ( $incompatible_plugins as $name => $file ) {
404
405 $deactivate_url = wp_nonce_url(
406 add_query_arg(
407 array(
408 'action' => 'deactivate',
409 'plugin' => urlencode( $file ),
410 ),
411 get_admin_url() . 'plugins.php'
412 ),
413 'deactivate-plugin_' . $file
414 );
415
416 $deactivate_title = sprintf(
417 esc_html__( 'Deactivate plugin: %1$s', 'wplingua' ),
418 $name
419 );
420
421 $html .= '<li>';
422 $html .= '<strong>' . esc_html( $name ) . '</strong> | ';
423 $html .= '<a ';
424 $html .= 'href="' . esc_url( $deactivate_url ) . '" ';
425 $html .= 'title="' . esc_attr( $deactivate_title ) . '">';
426 $html .= esc_html__( 'Deactivate', 'wplingua' );
427 $html .= '</a>';
428 $html .= '</li>';
429 }
430 $html .= '</ul>';
431 $html .= '</p>';
432
433 $url_manage_plugins = add_query_arg(
434 'plugin_status',
435 'active',
436 get_admin_url() . 'plugins.php'
437 );
438
439 $html .= '<a ';
440 $html .= 'href="' . esc_url( $url_manage_plugins ) . '" ';
441 $html .= 'class="button button-primary" ';
442 $html .= 'style="margin-bottom: 10px;">';
443 $html .= esc_html__( 'Manage active plugins', 'wplingua' );
444 $html .= '</a>';
445
446 $html .= '</div>'; // End .notice
447
448 echo $html;
449 }
450
451
452 /**
453 * Display a notice if is a multisite
454 *
455 * @return void|string Outputs the admin notice if applicable, or returns void if no action is needed.
456 */
457 function wplng_admin_notice_incompatible_multisite() {
458
459 if ( ! is_multisite() ) {
460 return;
461 }
462
463 $html = '<div ';
464 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
465 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
466 $html .= '<p style="font-weight: 600;">';
467 $html .= '<span class="dashicons dashicons-translation"></span> ';
468 $html .= esc_html__( 'wpLingua - Incompatible with multisite', 'wplingua' );
469 $html .= '</p>';
470 $html .= '<p>';
471 $html .= esc_html__( 'wpLingua is not compatible with multisite.', 'wplingua' );
472 $html .= '</p>';
473 $html .= '</div>'; // End .notice
474
475 echo $html;
476 }
477
478
479 /**
480 * Display a notice if the WordPress installed in a subfolder
481 *
482 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is needed.
483 */
484 function wplng_admin_notice_incompatible_sub_folder() {
485
486 if ( ! wplng_website_in_sub_folder() ) {
487 return;
488 }
489
490 $html = '<div ';
491 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
492 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
493 $html .= '<p style="font-weight: 600;">';
494 $html .= '<span class="dashicons dashicons-translation"></span> ';
495 $html .= esc_html__( 'wpLingua - Incompatible with WordPress installed in a subfolder', 'wplingua' );
496 $html .= '</p>';
497 $html .= '<p>';
498 $html .= esc_html__( 'wpLingua is not compatible with WordPress installed in a subfolder.', 'wplingua' );
499 $html .= '</p>';
500 $html .= '</div>'; // End .notice
501
502 echo $html;
503 }
504
505
506 /**
507 * Display a notice if the PHP version is incompatible
508 *
509 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required.
510 */
511 function wplng_admin_notice_incompatible_php_version() {
512
513 if ( version_compare( PHP_VERSION, WPLNG_PHP_MIN_VERSION ) >= 0 ) {
514 return;
515 }
516
517 $html = '<div ';
518 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
519 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
520 $html .= '<p style="font-weight: 600;">';
521 $html .= '<span class="dashicons dashicons-translation"></span> ';
522 $html .= esc_html__( 'wpLingua - Incompatible PHP version', 'wplingua' );
523 $html .= '</p>';
524 $html .= '<p>';
525 $html .= esc_html__( 'wpLingua is not compatible with your PHP version. wpLingua requires PHP 7.4 or higher.', 'wplingua' );
526 $html .= '</p>';
527 $html .= '</div>'; // End .notice
528
529 echo $html;
530 }
531
532
533 /**
534 * Check if the HTACCESS file contain code of another plugin who break translated pages
535 *
536 * @return bool HTACCESS file is valid for wpLingua
537 */
538 function wplng_htaccess_is_valid() {
539
540 $htaccess_path = ABSPATH . '.htaccess';
541
542 if ( ! file_exists( $htaccess_path ) ) {
543 return true;
544 }
545
546 $htaccess_content = file_get_contents( $htaccess_path );
547
548 return ! (
549 strpos( $htaccess_content, 'GTranslate' ) !== false
550 || strpos( $htaccess_content, 'LINGUISE' ) !== false
551 );
552 }
553
554
555 /**
556 * Display a notice if the HTACCESS file is incompatible
557 *
558 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required.
559 */
560 function wplng_admin_notice_incompatible_htaccess() {
561
562 $htaccess_path = ABSPATH . '.htaccess';
563
564 if ( ! file_exists( $htaccess_path ) ) {
565 return;
566 }
567
568 $htaccess_content = file_get_contents( $htaccess_path );
569 $message = '';
570
571 if ( strpos( $htaccess_content, 'GTranslate' ) !== false ) {
572 $message .= '### BEGIN GTranslate config ###' . PHP_EOL;
573 $message .= '...' . PHP_EOL;
574 $message .= '### END GTranslate config ###';
575 } elseif ( strpos( $htaccess_content, 'LINGUISE' ) !== false ) {
576 $message .= '#### LINGUISE DO NOT EDIT ####' . PHP_EOL;
577 $message .= '...' . PHP_EOL;
578 $message .= '#### LINGUISE DO NOT EDIT END ####';
579 }
580
581 if ( ! empty( $message ) ) {
582
583 $html = '<div ';
584 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
585 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
586 $html .= '<p style="font-weight: 600;">';
587 $html .= '<span class="dashicons dashicons-translation"></span> ';
588 $html .= esc_html__( 'wpLingua - Incompatible HTACCESS file', 'wplingua' );
589 $html .= '</p>';
590 $html .= '<p>';
591 $html .= esc_html__( 'It seems that a plugin was incorrectly deactivated and corrupted the site\'s HTACCESS file, preventing the correct redirection of translated pages. Please edit the ".htaccess" file located at the root of the site and delete the lines between :', 'wplingua' );
592 $html .= '<pre style="border: 1px solid #c3c4c7; padding: 8px; background-color: rgba(0,0,0,.05);">';
593 $html .= $message;
594 $html .= '</pre>';
595 $html .= '</p>';
596 $html .= '</div>'; // End .notice
597
598 echo $html;
599 }
600 }
601
602
603 /**
604 * Display a notice if the permalink structure is set to Plain
605 *
606 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required.
607 */
608 function wplng_admin_notice_incompatible_plain_permalink() {
609
610 if ( ! empty( get_option( 'permalink_structure' ) ) ) {
611 return;
612 }
613
614 $url_permalinks = get_admin_url() . 'options-permalink.php';
615
616 $html = '<div ';
617 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
618 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
619 $html .= '<p style="font-weight: 600;">';
620 $html .= '<span class="dashicons dashicons-translation"></span> ';
621 $html .= esc_html__( 'wpLingua - Incompatible permalink structure', 'wplingua' );
622 $html .= '</p>';
623 $html .= '<p>';
624 $html .= esc_html__( 'wpLingua is not compatible with the "Plain" permalink structure. Please update your permalink settings to use "Post name" or "Custom Structure".', 'wplingua' );
625 $html .= '</p>';
626 $html .= '<a ';
627 $html .= 'href="' . esc_url( $url_permalinks ) . '" ';
628 $html .= 'class="button button-primary" ';
629 $html .= 'style="margin-bottom: 10px;">';
630 $html .= esc_html__( 'Manage permalink settings', 'wplingua' );
631 $html .= '</a>';
632 $html .= '</div>'; // End .notice
633
634 echo $html;
635 }
636