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

292 lines 9.7 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 * @return void
13 */
14 function wplng_option_page_register() {
15
16 if ( is_multisite() ) {
17 ?>
18 <div class="wplng-notice notice notice-info">
19 <p><?php esc_html_e( 'wpLingua is not compatible with Multisite.', 'wplingua' ); ?></p>
20 </div>
21 <?php
22 return;
23 }
24
25 $mail = '';
26 $api_key = wplng_get_api_key();
27 $json_request_key = get_option( 'wplng_request_free_key' );
28 $error_validation = get_transient( 'wplng_api_key_error' );
29 $error_validation = sanitize_text_field( $error_validation );
30
31 delete_transient( 'wplng_api_key_data' );
32
33 if ( ! empty( $error_validation )
34 && is_string( $error_validation )
35 ) :
36
37 delete_transient( 'wplng_api_key_error' );
38
39 $message = '';
40 $message .= __( 'Message: ', 'wplingua' );
41 $message .= $error_validation;
42
43 ?>
44 <div class="wplng-notice notice notice-error is-dismissible">
45 <p>
46 <strong><?php esc_html_e( 'An error occurred with API key.', 'wplingua' ); ?></strong>
47 <br>
48 <?php echo esc_html( $message ); ?>
49 </p>
50 </div>
51 <?php
52
53 elseif ( get_option( 'wplng_api_key' ) !== $api_key
54 && empty( wplng_get_api_data() )
55 ) :
56
57 update_option( 'wplng_api_key', '' );
58
59 if ( ! empty( get_option( 'wplng_api_key' ) ) ) :
60 ?>
61 <div class="wplng-notice notice notice-error is-dismissible">
62 <p><strong><?php esc_html_e( 'Invalid API key.', 'wplingua' ); ?></strong></p>
63 </div>
64 <?php
65 endif;
66
67 elseif ( ! empty( $json_request_key ) ) :
68
69 delete_option( 'wplng_request_free_key' );
70
71 $data_request_key = json_decode( $json_request_key, true );
72 $response = wplng_api_call_request_api_key( $data_request_key );
73
74 if ( ! empty( $response['error'] ) ) {
75
76 $message = '';
77
78 if ( ! empty( $response['message'] ) ) {
79 $message .= __( 'Message: ', 'wplingua' );
80 $message .= $response['message'];
81 }
82
83 ?>
84 <div class="wplng-notice notice notice-error is-dismissible">
85 <p>
86 <strong><?php esc_html_e( 'An error occurred while creating the API key.', 'wplingua' ); ?></strong>
87 <br>
88 <?php echo esc_html( $message ); ?>
89 </p>
90 </div>
91 <?php
92 } elseif ( ! empty( $response['register'] ) ) {
93 if ( ! empty( $data_request_key['mail_address'] )
94 && is_email( $data_request_key['mail_address'] )
95 ) {
96 $mail = sanitize_email( $data_request_key['mail_address'] );
97 }
98 }
99 endif;
100 ?>
101
102 <h1 class="wplin-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Register API key', 'wplingua' ); ?></h1>
103
104 <div class="wrap">
105 <hr class="wp-header-end">
106 <form method="post" action="options.php">
107 <?php
108 settings_fields( 'wplng_settings' );
109 do_settings_sections( 'wplng_settings' );
110 ?>
111 <table class="form-table wplng-form-table">
112
113 <?php
114 /**
115 * After register a new API key without error
116 */
117
118 if ( ! empty( $mail ) ) :
119 ?>
120
121 <tr>
122 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'API key created', 'wplingua' ); ?></th>
123 <td id="wplng-register-success-message">
124 <p id="wplng-register-success-title"><span class="dashicons dashicons-email-alt"></span> <?php esc_html_e( 'API key created and sent by email', 'wplingua' ); ?></p>
125
126 <p><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></p>
127
128 <hr>
129
130 <p><?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 site multilingual.', 'wplingua' ); ?></p>
131
132 </td>
133 </tr>
134
135 <tr>
136 <th scope="row"><span class="dashicons dashicons-admin-network"></span> <?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th>
137 <td>
138 <?php wplng_register_part_api_key( $api_key ); ?>
139 </td>
140 </tr>
141
142 <?php else : ?>
143
144 <tr>
145 <th scope="row"><span class="dashicons dashicons-info"></span> <?php esc_html_e( 'Start with wpLingua', 'wplingua' ); ?></th>
146 <td>
147 <p><strong><?php esc_html_e( 'You are just a few clicks away from making your site multilingual!', 'wplingua' ); ?></strong></p>
148
149 <p><?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' ); ?></p>
150 </td>
151 </tr>
152
153 <tr>
154 <th scope="row"><span class="dashicons dashicons-admin-network"></span> <?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th>
155 <td>
156 <?php wplng_register_part_api_key( $api_key ); ?>
157 </td>
158 </tr>
159
160 <tr>
161 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e( 'Get free API key', 'wplingua' ); ?></th>
162 <td>
163 <?php wplng_register_part_free_api_key(); ?>
164 </td>
165 </tr>
166
167 <tr>
168 <th scope="row"><span class="dashicons dashicons-admin-settings"></span> <?php esc_html_e( 'Advanced API features', 'wplingua' ); ?></th>
169 <td>
170 <?php wplng_register_part_premium(); ?>
171 </td>
172 </tr>
173
174 <?php endif; ?>
175
176 </table>
177 </form>
178 </div>
179 <?php
180 }
181
182
183 /**
184 * Print HTML subsection of Option page : wpLingua Register - API Key
185 *
186 * @param string $api_key
187 * @return void
188 */
189 function wplng_register_part_api_key( $api_key ) {
190 ?>
191 <fieldset>
192 <label for="wplng_api_key"><strong><?php esc_html_e( 'Set the wpLingua API key:', 'wplingua' ); ?></strong></label>
193 <p><?php esc_html_e( 'If you already have an API key, enter it below. If you\'ve forgotten your site\'s API key, visit', 'wplingua' ); ?> <a href="https://wplingua.com/recovery/" target="_blank"><?php esc_html_e( 'the API key retrieval page', 'wplingua' ); ?></a>.</p>
194 <br>
195 <input type="text" name="wplng_api_key" id="wplng_api_key" value="<?php echo esc_attr( $api_key ); ?>"></input>
196
197 <?php
198 submit_button(
199 __( 'Set API key', 'wplingua' ),
200 'primary',
201 'submit',
202 false
203 );
204 ?>
205 </fieldset>
206 <?php
207 }
208
209
210 /**
211 * Print HTML subsection of Option page : wpLingua Register - Register free API Key
212 *
213 * @return void
214 */
215 function wplng_register_part_free_api_key() {
216
217 $email = sanitize_email( get_bloginfo( 'admin_email' ) );
218 $locale = strtolower( substr( get_locale(), 0, 2 ) );
219
220 if ( ! wplng_is_valid_language_id( $locale ) ) {
221 $locale = 'en';
222 }
223
224 ?>
225 <p for="wplng_api_key"><strong><?php esc_html_e( 'Register free wpLingua API key:', 'wplingua' ); ?></strong></p>
226 <p><?php esc_html_e( 'Get a free wpLingua API key and make your website bilingual in a minute!', 'wplingua' ); ?></p>
227 <hr>
228 <br>
229 <fieldset>
230 <label for="wplng-website-url" class="wplng-fe-50">
231 <strong><?php esc_html_e( 'Website URL:', 'wplingua' ); ?> </strong>
232 </label>
233 <input type="url" name="wplng-website-url" id="wplng-website-url" class="wplng-fe-50" value="<?php echo esc_url( get_site_url() ); ?>">
234 </fieldset>
235 <br>
236 <fieldset>
237 <label for="wplng-email" class="wplng-fe-50">
238 <strong><?php esc_html_e( 'Mail address:', 'wplingua' ); ?> </strong>
239 </label>
240 <input type="email" name="wplng-email" id="wplng-email" class="wplng-fe-50" value="<?php echo esc_attr( $email ); ?>">
241 </fieldset>
242 <br>
243 <fieldset>
244 <label for="wplng-language-website" class="wplng-fe-50">
245 <strong><?php esc_html_e( 'Website language:', 'wplingua' ); ?> </strong>
246 </label>
247 <select name="wplng-language-website" id="wplng-language-website" class="wplng-fe-50"></select>
248 </fieldset>
249 <br>
250 <fieldset>
251 <label for="wplng-language-target" class="wplng-fe-50">
252 <strong><?php esc_html_e( 'Target language:', 'wplingua' ); ?> </strong>
253 </label>
254 <select name="wplng-language-target" id="wplng-language-target" class="wplng-fe-50"></select>
255 </fieldset>
256 <br>
257 <fieldset>
258 <input type="checkbox" name="wplng-accept-eula" id="wplng-accept-eula">
259 <label for="wplng-accept-eula">
260 <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>
261 </label>
262 </fieldset>
263 <fieldset style="display: none;">
264 <p><?php esc_html_e( 'Website Locale:', 'wplingua' ); ?> <span id="wplng-website-locale"><?php echo esc_html( $locale ); ?></span></p>
265 <textarea name="wplng_request_free_key" id="wplng_request_free_key"></textarea>
266 </fieldset>
267 <button id="wplng-get-free-api-submit" class="button button-primary">
268 <?php esc_html_e( 'Get a free API key', 'wplingua' ); ?>
269 </button>
270 <?php
271 }
272
273
274 /**
275 * Print HTML subsection of Option page : wpLingua Register - Premium informations
276 *
277 * @return void
278 */
279 function wplng_register_part_premium() {
280 ?>
281 <p><strong><?php esc_html_e( 'Get more target languages and advanced features:', 'wplingua' ); ?></strong></p>
282 <p><?php esc_html_e( 'To translate your site into more languages and access advanced features, visit wpLingua website.', 'wplingua' ); ?></p>
283 <ul style="list-style: inside; padding: 0 0 0 15px;">
284 <li><?php esc_html_e( 'Multilingual WooCommerce store', 'wplingua' ); ?></li>
285 <li><?php esc_html_e( 'Allow search from all languages', 'wplingua' ); ?></li>
286 <li><?php esc_html_e( 'Get more target languages', 'wplingua' ); ?></li>
287 </ul>
288 <br>
289 <a class="button button-primary" href="https://wplingua.com/" target="_blank"><?php esc_html_e( 'Visit wpLingua website', 'wplingua' ); ?></a>
290 <?php
291 }
292