PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.16.7
Translate and Go multilingual – Automatic AI translation – wpLingua v2.16.7
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-register.php

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

520 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 * Print HTML Option page : wpLingua Register
11 *
12 * This function generates the HTML for the wpLingua option page where users can register
13 * or set their API key. It handles various scenarios such as displaying error messages,
14 * validating API keys, and providing forms for API key registration and input.
15 *
16 * @return void
17 */
18 function wplng_option_page_register() {
19
20 // Check if DB size is compatible with wpLingua
21 if ( wplng_count_public_content() > 2500
22 && ! empty( wplng_get_translation_count() )
23 && ! empty( wplng_get_slug_count() )
24 ) {
25 wplng_register_part_incompatible_db();
26 return;
27 }
28
29 // Initialize variables
30 $mail = '';
31 $api_key = wplng_get_api_key();
32 $json_request_key = get_option( 'wplng_request_free_key' );
33 $error_validation = get_transient( 'wplng_api_key_error' );
34 $error_validation = sanitize_text_field( $error_validation );
35
36 // Clear any existing API key data
37 delete_option( 'wplng_api_key_data' );
38
39 // Handle API key error validation
40 if ( ! empty( $error_validation ) && is_string( $error_validation ) ) :
41
42 // Clear the transient storing the error message
43 delete_transient( 'wplng_api_key_error' );
44
45 // Display the error message
46 $message = '';
47 $message .= __( 'Message: ', 'wplingua' );
48 $message .= $error_validation;
49
50 ?>
51 <div class="wplng-notice notice notice-error is-dismissible">
52 <p>
53 <strong><?php esc_html_e( 'An error occurred with API key.', 'wplingua' ); ?></strong>
54 <br>
55 <?php echo esc_html( $message ); ?>
56 </p>
57 </div>
58 <?php
59
60 // Handle invalid API key scenario
61 elseif ( get_option( 'wplng_api_key' ) !== $api_key && empty( wplng_get_api_data() ) ) :
62
63 // Reset the API key option
64 update_option( 'wplng_api_key', '' );
65
66 // Display an error message if the API key is invalid
67 if ( ! empty( get_option( 'wplng_api_key' ) ) ) :
68 ?>
69 <div class="wplng-notice notice notice-error is-dismissible">
70 <p><strong><?php esc_html_e( 'Invalid API key.', 'wplingua' ); ?></strong></p>
71 </div>
72 <?php
73 endif;
74
75 // Handle free API key request
76 elseif ( ! empty( $json_request_key ) ) :
77
78 // Clear the free key request option
79 delete_option( 'wplng_request_free_key' );
80
81 // Decode the JSON request data
82 $data_request_key = json_decode( $json_request_key, true );
83 $response = wplng_api_call_request_api_key( $data_request_key ); // Make API call
84
85 // Handle errors in the API response
86 if ( ! empty( $response['error'] ) ) {
87
88 $message = '';
89
90 if ( ! empty( $response['message'] ) ) {
91 $message .= __( 'Message: ', 'wplingua' );
92 $message .= $response['message'];
93 }
94
95 ?>
96 <div class="wplng-notice notice notice-error is-dismissible">
97 <p>
98 <strong><?php esc_html_e( 'An error occurred while creating the API key.', 'wplingua' ); ?></strong>
99 <br>
100 <?php echo esc_html( $message ); ?>
101 </p>
102 </div>
103 <?php
104 } elseif ( ! empty( $response['register'] ) ) {
105 // If registration is successful, sanitize and store the email address
106 if ( ! empty( $data_request_key['mail_address'] ) && is_email( $data_request_key['mail_address'] ) ) {
107 $mail = sanitize_email( $data_request_key['mail_address'] );
108 }
109 }
110 endif;
111
112 // Display the main option page content
113 ?>
114
115 <div class="wrap">
116
117 <header id="wplng-option-page-header">
118 <h1 class="wplng-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Register API key', 'wplingua' ); ?></h1>
119 </header>
120
121 <hr class="wp-header-end">
122
123 <form method="post" action="options.php">
124 <?php
125 // Output settings fields and sections for the plugin
126 settings_fields( 'wplng_settings' );
127 do_settings_sections( 'wplng_settings' );
128 ?>
129 <table class="form-table wplng-form-table">
130
131 <?php if ( ! empty( $mail ) ) : ?>
132
133 <tr>
134 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'API key created', 'wplingua' ); ?></th>
135 <td id="wplng-register-success-message">
136
137 <p id="wplng-register-success-title">
138 <span class="dashicons dashicons-email-alt"></span> <?php esc_html_e( 'API key created and sent by email', 'wplingua' ); ?>
139 </p>
140
141 <p>
142 <strong><?php esc_html_e( 'The API key has been correctly created and sent to the following e-mail address: ', 'wplingua' ); ?><span id="wplng-register-success-mail"><?php echo esc_html( $mail ); ?><span></strong>
143 </p>
144
145 <hr>
146
147 <p>
148 <?php esc_html_e( 'Go to your mailbox and copy the API key sent to you (don\'t forget to check the spam section of your mailbox). Then paste it in the section below, and click "Set API key" to make your website multilingual.', 'wplingua' ); ?>
149 </p>
150
151 <?php if ( ! wplng_str_ends_with( $mail, '@gmail.com' ) ) : ?>
152 <hr>
153 <p>
154 <strong><?php esc_html_e( 'Please note:', 'wplingua' ); ?></strong>
155 <?php
156 printf(
157 /* translators: %s: link to request a new API key */
158 wp_kses(
159 __( 'Some web hosting providers may block or prevent emails from reaching your mailbox. If you don\'t receive the email, please %s using a different email address, such as a Gmail address.', 'wplingua' ),
160 array(
161 'a' => array(
162 'href' => array(),
163 'style' => array(),
164 ),
165 )
166 ),
167 '<a href="' . esc_url( admin_url( 'admin.php?page=wplingua-settings' ) ) . '" style="text-decoration: underline;">' .
168 esc_html__( 'try requesting a new API key', 'wplingua' ) .
169 '</a>'
170 );
171 ?>
172 </p>
173 <?php endif; ?>
174
175 </td>
176 </tr>
177
178 <tr>
179 <th scope="row"><span class="dashicons dashicons-admin-network"></span> <?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th>
180 <td class="wplng-td-last">
181 <?php wplng_register_part_api_key( $api_key ); ?>
182 </td>
183 </tr>
184
185 <?php else : ?>
186
187 <!-- Display forms for getting or setting the API key -->
188 <tr id="wplng-get-api-key">
189 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'Get API key', 'wplingua' ); ?></th>
190 <td class="wplng-flex-container">
191 <?php wplng_register_part_free_api_key(); ?>
192 </td>
193 </tr>
194
195 <tr id="wplng-set-api-key">
196 <th scope="row"><span class="dashicons dashicons-admin-network"></span> <?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th>
197 <td>
198 <?php wplng_register_part_api_key( $api_key ); ?>
199 </td>
200 </tr>
201
202 <tr class="wplng-flex-container">
203 <th scope="row"><span class="dashicons dashicons-info"></span> <?php esc_html_e( 'Start with wpLingua', 'wplingua' ); ?></th>
204 <td>
205 <p>
206 <strong><?php esc_html_e( 'You are just a few clicks away from making your website multilingual!', 'wplingua' ); ?></strong>
207 </p>
208
209 <hr>
210
211 <p>
212 <?php esc_html_e( 'For wpLingua to work, an API key is required so that your website has access to the automatic translation service. On this page you can enter your API key if you already have one, or create one for free.', 'wplingua' ); ?>
213 </p>
214
215 <br>
216 <hr>
217
218 <p><span class="dashicons dashicons-star-filled"></span> <?php echo wp_kses( __( 'An <strong>instantly multilingual website</strong> thanks to automatic text detection and translation. Easy to use, no knowledge required.', 'wplingua' ), array( 'strong' => array() ) ); ?></p>
219
220 <hr>
221
222 <p><span class="dashicons dashicons-admin-site"></span> <?php echo wp_kses( __( '<strong>SEO friendly</strong> to allow search engines to index translated pages. Open up your website and your business to the whole world.', 'wplingua' ), array( 'strong' => array() ) ); ?></p>
223
224 <hr>
225
226 <p><span class="dashicons dashicons-edit"></span> <?php echo wp_kses( __( 'All <strong>translations are editable</strong>. Discover the visual editor and edit translations simply by clicking on them. With a fully customizable language switcher.', 'wplingua' ), array( 'strong' => array() ) ); ?></p>
227
228 <hr>
229
230 <p><span class="dashicons dashicons-heart"></span> <?php echo wp_kses( __( 'One <strong>free and unlimited</strong> language for personal blogs and non-commercial websites. And many more features!', 'wplingua' ), array( 'strong' => array() ) ); ?></p>
231
232 <hr>
233 <br>
234
235 <div class="wplng-flex-row">
236 <div class="wplng-flex-item">
237 <a href="#wplng-get-api-key" class="button button-primary"><?php esc_html_e( 'Get API key', 'wplingua' ); ?></a>
238 </div>
239
240 <div class="wplng-flex-item">
241 <a href="#wplng-set-api-key" class="button button-primary"><?php esc_html_e( 'Set API key', 'wplingua' ); ?></a>
242 </div>
243 </div>
244
245 </td>
246 </tr>
247
248 <tr>
249 <th scope="row"><span class="dashicons dashicons-admin-settings"></span> <?php esc_html_e( 'Advanced API features', 'wplingua' ); ?></th>
250 <td class="wplng-td-last">
251 <?php wplng_register_part_premium(); ?>
252 </td>
253 </tr>
254
255 <?php endif; ?>
256
257 </table>
258 </form>
259 </div>
260 <?php
261 }
262
263
264 /**
265 * Display a notice for websites incompatible with string translation
266 *
267 * @return void
268 */
269 function wplng_register_part_incompatible_db() {
270 ?>
271 <h1 class="wplng-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua', 'wplingua' ); ?></h1>
272
273 <div class="wrap">
274 <hr class="wp-header-end">
275 <table class="form-table wplng-form-table">
276
277 <tr>
278 <th scope="row"><span class="dashicons dashicons-warning"></span> <?php esc_html_e( 'Important Notice', 'wplingua' ); ?></th>
279 <td>
280 <p><strong><?php esc_html_e( 'Website incompatible with string translation', 'wplingua' ); ?></strong></p>
281
282 <hr>
283
284 <p><?php esc_html_e( 'Your website contains a large amount of content, which exceeds the limits of the string translation method used by wpLingua.', 'wplingua' ); ?></p>
285
286 <br>
287 <hr>
288
289 <p><strong><?php esc_html_e( 'Why the website is incompatible', 'wplingua' ); ?></strong></p>
290
291 <hr>
292
293 <p><?php esc_html_e( 'wpLingua works by identifying and translating each string of characters individually. On a large website, this method generates a very large number of database entries, causing overload and slowdowns.' ); ?></p>
294
295 <br>
296 <hr>
297
298 <p><strong><?php esc_html_e( 'Recommended solution', 'wplingua' ); ?></strong></p>
299
300 <hr>
301
302 <p><?php esc_html_e( 'To make large websites multilingual, we recommend using a translation plugin based on content duplication, such as Polylang or WPML. These solutions are specifically designed to efficiently manage large websites.' ); ?></p>
303 </td>
304 </tr>
305
306 </table>
307 </div>
308 <?php
309 }
310
311
312 /**
313 * Print HTML subsection of Option page : wpLingua Register - API Key
314 *
315 * @param string $api_key
316 * @return void
317 */
318 function wplng_register_part_api_key( $api_key ) {
319 ?>
320 <fieldset>
321 <p>
322 <label for="wplng_api_key"><strong><?php esc_html_e( 'Set the wpLingua API key: ', 'wplingua' ); ?></strong></label>
323 </p>
324
325 <hr>
326
327 <p>
328 <?php esc_html_e( 'If you already have an API key, enter it below. If you\'ve forgotten your website\'s API key, visit', 'wplingua' ); ?> <a href="https://wplingua.com/recovery/" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'the API key retrieval page', 'wplingua' ); ?></a>.
329 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-api-key"></span>
330 </p>
331
332 <div class="wplng-help-box" id="wplng-hb-api-key">
333 <p><?php esc_html_e( 'A wpLingua API key consists of 42 characters (uppercase, lowercase and numbers). It is emailed to you when you request it using the form provided when you install the plugin. You must keep this key secret and only communicate it to wplingua.com services.', 'wplingua' ); ?></p>
334 </div>
335
336 <hr>
337
338 <input type="text" name="wplng_api_key" id="wplng_api_key" value="<?php echo esc_attr( $api_key ); ?>"></input>
339
340 <hr>
341 <br>
342
343 <?php
344 submit_button(
345 __( 'Set API key', 'wplingua' ),
346 'primary',
347 'submit',
348 false
349 );
350 ?>
351 </fieldset>
352 <?php
353 }
354
355
356 /**
357 * Print HTML subsection of Option page : wpLingua Register - Register free API Key
358 *
359 * @return void
360 */
361 function wplng_register_part_free_api_key() {
362
363 $locale = strtolower( substr( get_locale(), 0, 2 ) );
364 $url = get_home_url();
365 $email = sanitize_email( get_bloginfo( 'admin_email' ) );
366
367 $host = parse_url( $url, PHP_URL_HOST );
368
369 if ( wplng_str_contains( $email, '.local' )
370 || wplng_str_contains( $email, 'admin' )
371 || ( is_string( $host ) && wplng_str_contains( $email, $host ) )
372 ) {
373 $email = '';
374 }
375
376 if ( ! wplng_is_valid_language_id( $locale ) ) {
377 $locale = 'en';
378 }
379
380 ?>
381 <p for="wplng_api_key">
382 <strong><?php esc_html_e( 'Register wpLingua API key: ', 'wplingua' ); ?></strong>
383 </p>
384
385 <hr>
386
387 <p>
388 <?php esc_html_e( 'Claim a wpLingua API key and make your website multilingual in a minute! For a personal blog or a non-commercial website, get one unlimited free language.', 'wplingua' ); ?>
389 </p>
390
391 <br>
392 <hr>
393
394 <fieldset class="wplng-flex-row">
395 <div class="wplng-flex-item">
396 <label for="wplng-email">
397 <strong><?php esc_html_e( 'Email address: ', 'wplingua' ); ?> </strong>
398 </label>
399 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-email"></span>
400 </div>
401 <div class="wplng-flex-item">
402 <input type="email" name="wplng-email" id="wplng-email" class="wplng-width-full" value="<?php echo esc_attr( $email ); ?>">
403 </div>
404 </fieldset>
405
406 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-email">
407 <p><?php esc_html_e( 'For better reliability, we recommend using a personal email address such as Gmail, as some hosting providers may filter or block emails sent by external services.', 'wplingua' ); ?></p>
408 <p><?php esc_html_e( 'The email address is detected and pre-filled. This is the administrative email address entered in the Settings ➔ General tab. You can use another email address used to receive your API key.', 'wplingua' ); ?></p>
409 </div>
410
411 <hr>
412
413 <fieldset class="wplng-flex-row">
414 <div class="wplng-flex-item">
415 <label for="wplng-website-url">
416 <strong><?php esc_html_e( 'Website URL: ', 'wplingua' ); ?> </strong>
417 </label>
418 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-url"></span>
419 </div>
420 <div class="wplng-flex-item">
421 <input type="url" name="wplng-website-url" id="wplng-website-url" class="wplng-width-full" value="<?php echo esc_url( $url ); ?>">
422 </div>
423 </fieldset>
424
425 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-url">
426 <p><?php esc_html_e( 'This is the URL of your website, it is detected and pre-filled automatically. Please check it and only enter the address of your production website (no test website or development environment).', 'wplingua' ); ?></p>
427 </div>
428
429 <hr>
430
431 <fieldset class="wplng-flex-row">
432 <div class="wplng-flex-item">
433 <label for="wplng-language-website">
434 <strong><?php esc_html_e( 'Website language: ', 'wplingua' ); ?> </strong>
435 </label>
436 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-language-website"></span>
437 </div>
438 <div class="wplng-flex-item">
439 <select name="wplng-language-website" id="wplng-language-website" class="wplng-width-full"></select>
440 </div>
441 </fieldset>
442
443 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-language-website">
444 <p><?php esc_html_e( 'This is the language of your website, defined by the associated API key. Make sure your website language is also correctly set in WordPress options (Settings ➔ General ➔ Website Language).', 'wplingua' ); ?></p>
445 </div>
446
447 <hr>
448
449 <fieldset class="wplng-flex-row">
450 <div class="wplng-flex-item">
451 <label for="wplng-language-target">
452 <strong><?php esc_html_e( 'Language to add: ', 'wplingua' ); ?> </strong>
453 </label>
454 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-language-target"></span>
455 </div>
456 <div class="wplng-flex-item">
457 <select name="wplng-language-target" id="wplng-language-target" class="wplng-width-full"></select>
458 </div>
459 </fieldset>
460
461 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-language-target">
462 <p><?php esc_html_e( 'This is the language you want to translate your website into. Be careful not to make a mistake because you will not be able to change the language afterwards.', 'wplingua' ); ?></p>
463 </div>
464
465 <hr>
466
467 <p>
468 <fieldset>
469 <input type="checkbox" name="wplng-accept-eula" id="wplng-accept-eula">
470 <label for="wplng-accept-eula">
471 <strong><?php esc_html_e( 'I have read and accept the', 'wplingua' ); ?> <a href="https://wplingua.com/terms/" target="_blank" rel="noopener noreferrer" style="text-decoration: underline;"><?php esc_html_e( 'API terms of use', 'wplingua' ); ?></a> </strong>
472 </label>
473 </fieldset>
474 </p>
475
476 <hr>
477
478 <fieldset style="display: none;">
479 <p><?php esc_html_e( 'Website Locale: ', 'wplingua' ); ?> <span id="wplng-website-locale"><?php echo esc_html( $locale ); ?></span></p>
480 <textarea name="wplng_request_free_key" id="wplng_request_free_key"></textarea>
481 </fieldset>
482
483 <br>
484
485 <button id="wplng-get-free-api-submit" class="button button-primary">
486 <?php esc_html_e( 'Get API key', 'wplingua' ); ?>
487 </button>
488 <?php
489 }
490
491
492 /**
493 * Print HTML subsection of Option page : wpLingua Register - Premium informations
494 *
495 * @return void
496 */
497 function wplng_register_part_premium() {
498 ?>
499 <p>
500 <strong><?php esc_html_e( 'Get more target languages and advanced features: ', 'wplingua' ); ?></strong>
501 </p>
502
503 <hr>
504
505 <p>
506 <?php esc_html_e( 'To translate your website into more languages and access advanced features, visit wpLingua website.', 'wplingua' ); ?>
507 </p>
508
509 <ul style="list-style: inside; padding: 0 0 0 15px;">
510 <li><?php esc_html_e( 'Use wpLingua on commercial website', 'wplingua' ); ?></li>
511 <li><?php esc_html_e( 'Allow search from all languages', 'wplingua' ); ?></li>
512 <li><?php esc_html_e( 'Get more target languages', 'wplingua' ); ?></li>
513 </ul>
514
515 <br>
516
517 <a class="button button-primary" href="https://wplingua.com/" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Visit wpLingua website', 'wplingua' ); ?></a>
518 <?php
519 }
520