PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.13.1
Translate and Go multilingual – Automatic AI translation – wpLingua v2.13.1
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.13.1, at inc/admin/option-page.php

648 lines 18.5 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 * Note: wpLingua does not officially support multisite installations and
456 * does not guarantee compatibility. Advanced users can bypass this
457 * incompatibility check by returning true from the
458 * `wplng_bypass_multisite_incompatibility` filter.
459 *
460 * @see apply_filters( 'wplng_bypass_multisite_incompatibility', false )
461 *
462 * @return void|string Outputs the admin notice if applicable, or returns void if no action is needed.
463 */
464 function wplng_admin_notice_incompatible_multisite() {
465
466 // Advanced users can bypass the multisite incompatibility notice by
467 // returning true to this filter. Note that bypassing does NOT make
468 // wpLingua officially compatible with multisite installations.
469 if ( ! is_multisite()
470 || apply_filters( 'wplng_bypass_multisite_incompatibility', false )
471 ) {
472 return;
473 }
474
475 $html = '<div ';
476 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
477 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
478 $html .= '<p style="font-weight: 600;">';
479 $html .= '<span class="dashicons dashicons-translation"></span> ';
480 $html .= esc_html__( 'wpLingua - Incompatible with multisite', 'wplingua' );
481 $html .= '</p>';
482 $html .= '<p>';
483 $html .= esc_html__( 'wpLingua is not compatible with multisite.', 'wplingua' );
484 $html .= '</p>';
485 $html .= '</div>'; // End .notice
486
487 echo $html;
488 }
489
490
491 /**
492 * Display a notice if the WordPress installed in a subfolder
493 *
494 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is needed.
495 */
496 function wplng_admin_notice_incompatible_sub_folder() {
497
498 if ( ! wplng_website_in_sub_folder() ) {
499 return;
500 }
501
502 $html = '<div ';
503 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
504 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
505 $html .= '<p style="font-weight: 600;">';
506 $html .= '<span class="dashicons dashicons-translation"></span> ';
507 $html .= esc_html__( 'wpLingua - Incompatible with WordPress installed in a subfolder', 'wplingua' );
508 $html .= '</p>';
509 $html .= '<p>';
510 $html .= esc_html__( 'wpLingua is not compatible with WordPress installed in a subfolder.', 'wplingua' );
511 $html .= '</p>';
512 $html .= '</div>'; // End .notice
513
514 echo $html;
515 }
516
517
518 /**
519 * Display a notice if the PHP version is incompatible
520 *
521 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required.
522 */
523 function wplng_admin_notice_incompatible_php_version() {
524
525 if ( version_compare( PHP_VERSION, WPLNG_PHP_MIN_VERSION ) >= 0 ) {
526 return;
527 }
528
529 $html = '<div ';
530 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
531 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
532 $html .= '<p style="font-weight: 600;">';
533 $html .= '<span class="dashicons dashicons-translation"></span> ';
534 $html .= esc_html__( 'wpLingua - Incompatible PHP version', 'wplingua' );
535 $html .= '</p>';
536 $html .= '<p>';
537 $html .= esc_html__( 'wpLingua is not compatible with your PHP version. wpLingua requires PHP 7.4 or higher.', 'wplingua' );
538 $html .= '</p>';
539 $html .= '</div>'; // End .notice
540
541 echo $html;
542 }
543
544
545 /**
546 * Check if the HTACCESS file contain code of another plugin who break translated pages
547 *
548 * @return bool HTACCESS file is valid for wpLingua
549 */
550 function wplng_htaccess_is_valid() {
551
552 $htaccess_path = ABSPATH . '.htaccess';
553
554 if ( ! file_exists( $htaccess_path ) ) {
555 return true;
556 }
557
558 $htaccess_content = file_get_contents( $htaccess_path );
559
560 return ! (
561 strpos( $htaccess_content, 'GTranslate' ) !== false
562 || strpos( $htaccess_content, 'LINGUISE' ) !== false
563 );
564 }
565
566
567 /**
568 * Display a notice if the HTACCESS file is incompatible
569 *
570 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required.
571 */
572 function wplng_admin_notice_incompatible_htaccess() {
573
574 $htaccess_path = ABSPATH . '.htaccess';
575
576 if ( ! file_exists( $htaccess_path ) ) {
577 return;
578 }
579
580 $htaccess_content = file_get_contents( $htaccess_path );
581 $message = '';
582
583 if ( strpos( $htaccess_content, 'GTranslate' ) !== false ) {
584 $message .= '### BEGIN GTranslate config ###' . PHP_EOL;
585 $message .= '...' . PHP_EOL;
586 $message .= '### END GTranslate config ###';
587 } elseif ( strpos( $htaccess_content, 'LINGUISE' ) !== false ) {
588 $message .= '#### LINGUISE DO NOT EDIT ####' . PHP_EOL;
589 $message .= '...' . PHP_EOL;
590 $message .= '#### LINGUISE DO NOT EDIT END ####';
591 }
592
593 if ( ! empty( $message ) ) {
594
595 $html = '<div ';
596 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
597 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
598 $html .= '<p style="font-weight: 600;">';
599 $html .= '<span class="dashicons dashicons-translation"></span> ';
600 $html .= esc_html__( 'wpLingua - Incompatible HTACCESS file', 'wplingua' );
601 $html .= '</p>';
602 $html .= '<p>';
603 $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' );
604 $html .= '<pre style="border: 1px solid #c3c4c7; padding: 8px; background-color: rgba(0,0,0,.05);">';
605 $html .= $message;
606 $html .= '</pre>';
607 $html .= '</p>';
608 $html .= '</div>'; // End .notice
609
610 echo $html;
611 }
612 }
613
614
615 /**
616 * Display a notice if the permalink structure is set to Plain
617 *
618 * @return void|string Outputs the admin notice if applicable, or returns void if no notice is required.
619 */
620 function wplng_admin_notice_incompatible_plain_permalink() {
621
622 if ( ! empty( get_option( 'permalink_structure' ) ) ) {
623 return;
624 }
625
626 $url_permalinks = get_admin_url() . 'options-permalink.php';
627
628 $html = '<div ';
629 $html .= 'class="wplng-notice notice notice-error is-dismissible" ';
630 $html .= 'style="background-color: rgba(255, 0, 0, .1);">';
631 $html .= '<p style="font-weight: 600;">';
632 $html .= '<span class="dashicons dashicons-translation"></span> ';
633 $html .= esc_html__( 'wpLingua - Incompatible permalink structure', 'wplingua' );
634 $html .= '</p>';
635 $html .= '<p>';
636 $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' );
637 $html .= '</p>';
638 $html .= '<a ';
639 $html .= 'href="' . esc_url( $url_permalinks ) . '" ';
640 $html .= 'class="button button-primary" ';
641 $html .= 'style="margin-bottom: 10px;">';
642 $html .= esc_html__( 'Manage permalink settings', 'wplingua' );
643 $html .= '</a>';
644 $html .= '</div>'; // End .notice
645
646 echo $html;
647 }
648