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-register.php

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

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