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

515 lines 18.4 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 <h1 class="wplng-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Register API key', 'wplingua' ); ?></h1>
115
116 <div class="wrap">
117 <hr class="wp-header-end">
118 <form method="post" action="options.php">
119 <?php
120 // Output settings fields and sections for the plugin
121 settings_fields( 'wplng_settings' );
122 do_settings_sections( 'wplng_settings' );
123 ?>
124 <table class="form-table wplng-form-table">
125
126 <?php if ( ! empty( $mail ) ) : ?>
127
128 <tr>
129 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'API key created', 'wplingua' ); ?></th>
130 <td id="wplng-register-success-message">
131
132 <p id="wplng-register-success-title">
133 <span class="dashicons dashicons-email-alt"></span> <?php esc_html_e( 'API key created and sent by email', 'wplingua' ); ?>
134 </p>
135
136 <p>
137 <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>
138 </p>
139
140 <hr>
141
142 <p>
143 <?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' ); ?>
144 </p>
145
146 <?php if ( ! wplng_str_ends_with( $mail, '@gmail.com' ) ) : ?>
147 <hr>
148 <p>
149 <strong><?php esc_html_e( 'Please note:', 'wplingua' ); ?></strong>
150 <?php
151 printf(
152 /* translators: %s: link to request a new API key */
153 wp_kses(
154 __( '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' ),
155 array(
156 'a' => array(
157 'href' => array(),
158 'style' => array(),
159 ),
160 )
161 ),
162 '<a href="' . esc_url( admin_url( 'admin.php?page=wplingua-settings' ) ) . '" style="text-decoration: underline;">' .
163 esc_html__( 'try requesting a new API key', 'wplingua' ) .
164 '</a>'
165 );
166 ?>
167 </p>
168 <?php endif; ?>
169
170 </td>
171 </tr>
172
173 <tr>
174 <th scope="row"><span class="dashicons dashicons-admin-network"></span> <?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th>
175 <td class="wplng-td-last">
176 <?php wplng_register_part_api_key( $api_key ); ?>
177 </td>
178 </tr>
179
180 <?php else : ?>
181
182 <!-- Display forms for getting or setting the API key -->
183 <tr id="wplng-get-api-key">
184 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'Get API key', 'wplingua' ); ?></th>
185 <td class="wplng-flex-container">
186 <?php wplng_register_part_free_api_key(); ?>
187 </td>
188 </tr>
189
190 <tr id="wplng-set-api-key">
191 <th scope="row"><span class="dashicons dashicons-admin-network"></span> <?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th>
192 <td>
193 <?php wplng_register_part_api_key( $api_key ); ?>
194 </td>
195 </tr>
196
197 <tr class="wplng-flex-container">
198 <th scope="row"><span class="dashicons dashicons-info"></span> <?php esc_html_e( 'Start with wpLingua', 'wplingua' ); ?></th>
199 <td>
200 <p>
201 <strong><?php esc_html_e( 'You are just a few clicks away from making your website multilingual!', 'wplingua' ); ?></strong>
202 </p>
203
204 <hr>
205
206 <p>
207 <?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' ); ?>
208 </p>
209
210 <br>
211 <hr>
212
213 <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>
214
215 <hr>
216
217 <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>
218
219 <hr>
220
221 <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>
222
223 <hr>
224
225 <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>
226
227 <hr>
228 <br>
229
230 <div class="wplng-flex-row">
231 <div class="wplng-flex-item">
232 <a href="#wplng-get-api-key" class="button button-primary"><?php esc_html_e( 'Get API key', 'wplingua' ); ?></a>
233 </div>
234
235 <div class="wplng-flex-item">
236 <a href="#wplng-set-api-key" class="button button-primary"><?php esc_html_e( 'Set API key', 'wplingua' ); ?></a>
237 </div>
238 </div>
239
240 </td>
241 </tr>
242
243 <tr>
244 <th scope="row"><span class="dashicons dashicons-admin-settings"></span> <?php esc_html_e( 'Advanced API features', 'wplingua' ); ?></th>
245 <td class="wplng-td-last">
246 <?php wplng_register_part_premium(); ?>
247 </td>
248 </tr>
249
250 <?php endif; ?>
251
252 </table>
253 </form>
254 </div>
255 <?php
256 }
257
258
259 /**
260 * Display a notice for websites incompatible with string translation
261 *
262 * @return void
263 */
264 function wplng_register_part_incompatible_db() {
265 ?>
266 <h1 class="wplng-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua', 'wplingua' ); ?></h1>
267
268 <div class="wrap">
269 <hr class="wp-header-end">
270 <table class="form-table wplng-form-table">
271
272 <tr>
273 <th scope="row"><span class="dashicons dashicons-warning"></span> <?php esc_html_e( 'Important Notice', 'wplingua' ); ?></th>
274 <td>
275 <p><strong><?php esc_html_e( 'Website incompatible with string translation', 'wplingua' ); ?></strong></p>
276
277 <hr>
278
279 <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>
280
281 <br>
282 <hr>
283
284 <p><strong><?php esc_html_e( 'Why the website is incompatible', 'wplingua' ); ?></strong></p>
285
286 <hr>
287
288 <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>
289
290 <br>
291 <hr>
292
293 <p><strong><?php esc_html_e( 'Recommended solution', 'wplingua' ); ?></strong></p>
294
295 <hr>
296
297 <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>
298 </td>
299 </tr>
300
301 </table>
302 </div>
303 <?php
304 }
305
306
307 /**
308 * Print HTML subsection of Option page : wpLingua Register - API Key
309 *
310 * @param string $api_key
311 * @return void
312 */
313 function wplng_register_part_api_key( $api_key ) {
314 ?>
315 <fieldset>
316 <p>
317 <label for="wplng_api_key"><strong><?php esc_html_e( 'Set the wpLingua API key: ', 'wplingua' ); ?></strong></label>
318 </p>
319
320 <hr>
321
322 <p>
323 <?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>.
324 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-api-key"></span>
325 </p>
326
327 <div class="wplng-help-box" id="wplng-hb-api-key">
328 <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>
329 </div>
330
331 <hr>
332
333 <input type="text" name="wplng_api_key" id="wplng_api_key" value="<?php echo esc_attr( $api_key ); ?>"></input>
334
335 <hr>
336 <br>
337
338 <?php
339 submit_button(
340 __( 'Set API key', 'wplingua' ),
341 'primary',
342 'submit',
343 false
344 );
345 ?>
346 </fieldset>
347 <?php
348 }
349
350
351 /**
352 * Print HTML subsection of Option page : wpLingua Register - Register free API Key
353 *
354 * @return void
355 */
356 function wplng_register_part_free_api_key() {
357
358 $locale = strtolower( substr( get_locale(), 0, 2 ) );
359 $url = get_home_url();
360 $email = sanitize_email( get_bloginfo( 'admin_email' ) );
361
362 $host = parse_url( $url, PHP_URL_HOST );
363
364 if ( wplng_str_contains( $email, '.local' )
365 || wplng_str_contains( $email, 'admin' )
366 || ( is_string( $host ) && wplng_str_contains( $email, $host ) )
367 ) {
368 $email = '';
369 }
370
371 if ( ! wplng_is_valid_language_id( $locale ) ) {
372 $locale = 'en';
373 }
374
375 ?>
376 <p for="wplng_api_key">
377 <strong><?php esc_html_e( 'Register wpLingua API key: ', 'wplingua' ); ?></strong>
378 </p>
379
380 <hr>
381
382 <p>
383 <?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' ); ?>
384 </p>
385
386 <br>
387 <hr>
388
389 <fieldset class="wplng-flex-row">
390 <div class="wplng-flex-item">
391 <label for="wplng-email">
392 <strong><?php esc_html_e( 'Email address: ', 'wplingua' ); ?> </strong>
393 </label>
394 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-email"></span>
395 </div>
396 <div class="wplng-flex-item">
397 <input type="email" name="wplng-email" id="wplng-email" class="wplng-width-full" value="<?php echo esc_attr( $email ); ?>">
398 </div>
399 </fieldset>
400
401 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-email">
402 <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>
403 <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>
404 </div>
405
406 <hr>
407
408 <fieldset class="wplng-flex-row">
409 <div class="wplng-flex-item">
410 <label for="wplng-website-url">
411 <strong><?php esc_html_e( 'Website URL: ', 'wplingua' ); ?> </strong>
412 </label>
413 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-url"></span>
414 </div>
415 <div class="wplng-flex-item">
416 <input type="url" name="wplng-website-url" id="wplng-website-url" class="wplng-width-full" value="<?php echo esc_url( $url ); ?>">
417 </div>
418 </fieldset>
419
420 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-url">
421 <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>
422 </div>
423
424 <hr>
425
426 <fieldset class="wplng-flex-row">
427 <div class="wplng-flex-item">
428 <label for="wplng-language-website">
429 <strong><?php esc_html_e( 'Website language: ', 'wplingua' ); ?> </strong>
430 </label>
431 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-language-website"></span>
432 </div>
433 <div class="wplng-flex-item">
434 <select name="wplng-language-website" id="wplng-language-website" class="wplng-width-full"></select>
435 </div>
436 </fieldset>
437
438 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-language-website">
439 <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>
440 </div>
441
442 <hr>
443
444 <fieldset class="wplng-flex-row">
445 <div class="wplng-flex-item">
446 <label for="wplng-language-target">
447 <strong><?php esc_html_e( 'Language to add: ', 'wplingua' ); ?> </strong>
448 </label>
449 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-register-language-target"></span>
450 </div>
451 <div class="wplng-flex-item">
452 <select name="wplng-language-target" id="wplng-language-target" class="wplng-width-full"></select>
453 </div>
454 </fieldset>
455
456 <div class="wplng-help-box wplng-spacing-top" id="wplng-hb-register-language-target">
457 <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>
458 </div>
459
460 <hr>
461
462 <p>
463 <fieldset>
464 <input type="checkbox" name="wplng-accept-eula" id="wplng-accept-eula">
465 <label for="wplng-accept-eula">
466 <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>
467 </label>
468 </fieldset>
469 </p>
470
471 <hr>
472
473 <fieldset style="display: none;">
474 <p><?php esc_html_e( 'Website Locale: ', 'wplingua' ); ?> <span id="wplng-website-locale"><?php echo esc_html( $locale ); ?></span></p>
475 <textarea name="wplng_request_free_key" id="wplng_request_free_key"></textarea>
476 </fieldset>
477
478 <br>
479
480 <button id="wplng-get-free-api-submit" class="button button-primary">
481 <?php esc_html_e( 'Get API key', 'wplingua' ); ?>
482 </button>
483 <?php
484 }
485
486
487 /**
488 * Print HTML subsection of Option page : wpLingua Register - Premium informations
489 *
490 * @return void
491 */
492 function wplng_register_part_premium() {
493 ?>
494 <p>
495 <strong><?php esc_html_e( 'Get more target languages and advanced features: ', 'wplingua' ); ?></strong>
496 </p>
497
498 <hr>
499
500 <p>
501 <?php esc_html_e( 'To translate your website into more languages and access advanced features, visit wpLingua website.', 'wplingua' ); ?>
502 </p>
503
504 <ul style="list-style: inside; padding: 0 0 0 15px;">
505 <li><?php esc_html_e( 'Use wpLingua on commercial website', 'wplingua' ); ?></li>
506 <li><?php esc_html_e( 'Allow search from all languages', 'wplingua' ); ?></li>
507 <li><?php esc_html_e( 'Get more target languages', 'wplingua' ); ?></li>
508 </ul>
509
510 <br>
511
512 <a class="button button-primary" href="https://wplingua.com/" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Visit wpLingua website', 'wplingua' ); ?></a>
513 <?php
514 }
515