PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.3.1
Translate and Go multilingual – Automatic AI translation – wpLingua v2.3.1
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 1.1.1 1.2.0 1.2.1 All 109 releases
wplingua / wplingua.php

wplingua.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.3.1, at wplingua.php

298 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: wpLingua
4 * Plugin URI: https://wplingua.com/
5 * Description: An all-in-one solution that makes your websites multilingual and translates them automatically, without word or page limits. The highlights: a free first language, an on-page visual editor for editing translations, a customizable language switcher, search engine optimization (SEO), self-hosted data and more!
6 * Author: wpLingua Translation Service
7 * Author URI: https://wplingua.com/
8 * Text Domain: wplingua
9 * Domain Path: /languages/
10 * Version: 2.3.1
11 * Requires PHP: 7.4
12 * License: GPL v2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 */
15
16
17 // If this file is called directly, abort.
18 if ( ! defined( 'WPINC' ) ) {
19 die;
20 }
21
22
23 // Define wpLingua constants
24 define( 'WPLNG_API_URL', 'https://api.wplingua.com' );
25 define( 'WPLNG_API_VERSION', '2.0' );
26 define( 'WPLNG_API_SSLVERIFY', true );
27 define( 'WPLNG_PLUGIN_VERSION', '2.3.1' );
28 define( 'WPLNG_PLUGIN_FILE', plugin_basename( __FILE__ ) );
29 define( 'WPLNG_PLUGIN_PATH', dirname( __FILE__ ) );
30 define( 'WPLNG_MAX_TRANSLATIONS', 256 );
31 define( 'WPLNG_MAX_FILE_SIZE', 5000000 );
32
33
34 // Define debug constants
35 defined( 'WPLNG_LOG_JSON_DEBUG' ) || define( 'WPLNG_LOG_JSON_DEBUG', false );
36 defined( 'WPLNG_LOG_AJAX_DEBUG' ) || define( 'WPLNG_LOG_AJAX_DEBUG', false );
37
38
39 // Load all needed PHP files
40 require_once WPLNG_PLUGIN_PATH . '/loader.php';
41
42
43 /**
44 * Loads wpLingua plugin's translated strings.
45 *
46 * @return void
47 */
48 function wplng_load_plugin_textdomain() {
49 load_plugin_textdomain(
50 'wplingua',
51 false,
52 'wplingua/languages'
53 );
54 }
55
56
57 /**
58 * Register all wpLingua Hook
59 *
60 * @return void
61 */
62 function wplng_start() {
63
64 // Define $wplng_request_uri
65 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
66
67 $request_uri = sanitize_url( $_SERVER['REQUEST_URI'] );
68
69 // Check if the referer is clean
70 if ( strtolower( esc_url_raw( $request_uri ) ) !== strtolower( $request_uri ) ) {
71 return;
72 }
73
74 global $wplng_request_uri;
75 $wplng_request_uri = $request_uri;
76
77 }
78
79 // The plugin version has changed
80 if ( get_option( 'wplng_version' ) !== WPLNG_PLUGIN_VERSION ) {
81 wplng_clear_translations_cache();
82 wplng_clear_slugs_cache();
83 update_option( 'wplng_version', WPLNG_PLUGIN_VERSION, true );
84 }
85
86 // Load plugin text domain /languages/
87 add_action( 'init', 'wplng_load_plugin_textdomain' );
88
89 // Display a notice if an incompatible plugin is detected
90 add_action( 'admin_notices', 'wplng_admin_notice_incompatible_plugin', 1 );
91
92 // Register plugin settings
93 add_action( 'admin_init', 'wplng_register_settings' );
94
95 // Add settings link in plugin list
96 add_filter( 'plugin_action_links_' . WPLNG_PLUGIN_FILE, 'wplng_settings_link' );
97
98 // Redirect to the settings page on plugin activation
99 add_action( 'activated_plugin', 'wplng_plugin_activation_redirect' );
100
101 // Set footer text for options pages
102 add_filter( 'admin_footer_text', 'wplng_admin_footer_text', 11 );
103 add_filter( 'update_footer', 'wplng_update_footer', 11 );
104
105 // Print head script (JSON with all languages informations)
106 add_action( 'toplevel_page_wplingua-settings', 'wplng_inline_script_languages' );
107
108 if ( empty( wplng_get_api_data() ) ) {
109
110 // Add Register option page in back office menu
111 add_action( 'admin_menu', 'wplng_create_menu_register' );
112
113 // Enqueue CSS and JS files for register option pages
114 add_action( 'admin_enqueue_scripts', 'wplng_option_page_register_assets' );
115
116 // Display a notice if the plugin is activate but not configured
117 add_action( 'admin_notices', 'wplng_admin_notice_no_key_set', 1 );
118
119 } else {
120
121 /**
122 * Back office
123 */
124
125 // Add menu in back office
126 add_action( 'admin_menu', 'wplng_create_menu' );
127
128 // Add admin Bar menu
129 add_action( 'admin_bar_menu', 'wplng_admin_bar_menu', 81 );
130
131 // Switcher in nav menu options
132 add_action( 'admin_enqueue_scripts', 'wplng_switcher_nav_menu_inline_scripts' );
133 add_action( 'admin_head-nav-menus.php', 'wp_nav_menu_switcher_box_add_register' );
134 add_action( 'wp_nav_menu_item_custom_fields', 'wp_nav_menu_switcher_box_edit', 10, 2 );
135
136 // Enqueue CSS and JS files for option pages
137 add_action( 'admin_enqueue_scripts', 'wplng_option_page_settings_assets' );
138 add_action( 'admin_enqueue_scripts', 'wplng_option_page_switcher_assets' );
139 add_action( 'admin_enqueue_scripts', 'wplng_option_page_exclusions_assets' );
140 add_action( 'admin_enqueue_scripts', 'wplng_option_page_dictionary_assets' );
141
142 // Update flags URL
143 add_action( 'update_option_wplng_flags_style', 'wplng_options_switcher_update_flags_style', 10, 2 );
144
145 // Reset API data on API key changing
146 add_action( 'update_option_wplng_api_key', 'wplng_on_update_option_wplng_api_key', 10, 2 );
147
148 /**
149 * wplng_translation : CPT, taxo, meta
150 */
151
152 // Register wplng_translation CPT
153 add_action( 'init', 'wplng_register_post_type_translation' );
154
155 // Add metabox for wplng_translation
156 add_action( 'add_meta_boxes_wplng_translation', 'wplng_translation_add_meta_box' );
157
158 // Save metabox on posts saving
159 add_action( 'save_post_wplng_translation', 'wplng_translation_save_meta_boxes_data', 10, 2 );
160
161 // Clear translation cache on trash / untrash
162 add_action( 'trashed_post', 'wplng_clear_translations_cache_trash_untrash' );
163 add_action( 'untrash_post', 'wplng_clear_translations_cache_trash_untrash' );
164 add_action( 'delete_post', 'wplng_clear_translations_cache_trash_untrash' );
165
166 // Enqueue Script for wplng_translation admin
167 add_action( 'admin_print_scripts-post-new.php', 'wplng_translation_assets' );
168 add_action( 'admin_print_scripts-post.php', 'wplng_translation_assets' );
169
170 // Remove Quick edit from translations list
171 add_filter( 'post_row_actions', 'wplng_translation_remove_quick_edit', 10, 2 );
172
173 // Ajax function for regenerate translation on edit page
174 add_action( 'wp_ajax_wplng_ajax_translation', 'wplng_ajax_generate_translation' );
175
176 // Ajax function for edit modal: Get HTML modal
177 add_action( 'wp_ajax_wplng_ajax_edit_modal', 'wplng_ajax_edit_modal' );
178
179 // Ajax function for edit modal: Save modal
180 add_action( 'wp_ajax_wplng_ajax_save_modal', 'wplng_ajax_save_modal' );
181
182 // Display 100 translation in admin area by default
183 add_filter( 'get_user_option_edit_wplng_translation_per_page', 'wplng_translation_per_page' );
184
185 // Filter translations by status
186 add_action( 'restrict_manage_posts', 'wplng_restrict_manage_posts_translation_status' );
187 add_filter( 'parse_query', 'wplng_posts_filter_translation_status' );
188
189 // Translation status on website translations list
190 add_filter( 'post_class', 'wplng_post_class_translation_status', 10, 3 );
191 add_filter( 'post_row_actions', 'wplng_post_row_actions_translation_status', 10, 2 );
192 add_filter( 'manage_wplng_translation_posts_columns', 'wplng_translation_status_columns' );
193 add_action( 'manage_wplng_translation_posts_custom_column', 'wplng_translation_status_item', 10, 2 );
194 add_action( 'admin_head-edit.php', 'wplng_translation_status_style', 10, 2 );
195
196 /**
197 * wplng_translation : CPT, taxo, meta
198 */
199
200 // Register wplng_translation CPT
201 add_action( 'init', 'wplng_register_post_type_slug' );
202
203 // Add metabox for wplng_slug
204 add_action( 'add_meta_boxes_wplng_slug', 'wplng_slug_add_meta_box' );
205
206 // Save metabox on posts saving
207 add_action( 'save_post_wplng_slug', 'wplng_slug_save_meta_boxes_data', 10, 2 );
208
209 // Clear slugs cache on trash / untrash
210 add_action( 'trashed_post', 'wplng_clear_slugs_cache_trash_untrash' );
211 add_action( 'untrash_post', 'wplng_clear_slugs_cache_trash_untrash' );
212 add_action( 'delete_post', 'wplng_clear_slugs_cache_trash_untrash' );
213
214 // Enqueue Script for wplng_translation admin
215 add_action( 'admin_print_scripts-post-new.php', 'wplng_slug_assets' );
216 add_action( 'admin_print_scripts-post.php', 'wplng_slug_assets' );
217
218 // Remove Quick edit from slugs list
219 add_filter( 'post_row_actions', 'wplng_slug_remove_quick_edit', 10, 2 );
220
221 // Ajax function for regenerate slug on edit page
222 add_action( 'wp_ajax_wplng_ajax_slug', 'wplng_ajax_generate_slug' );
223
224 // Display 100 translation in admin area by default
225 add_filter( 'get_user_option_edit_wplng_slug_per_page', 'wplng_slug_per_page' );
226
227 // Filter slugs by status
228 add_action( 'restrict_manage_posts', 'wplng_restrict_manage_posts_slug_status' );
229 add_filter( 'parse_query', 'wplng_posts_filter_slug_status' );
230
231 // Translation status on website slugs list
232 add_filter( 'post_class', 'wplng_post_class_slug_status', 10, 3 );
233 add_filter( 'post_row_actions', 'wplng_post_row_actions_slug_status', 10, 2 );
234 add_filter( 'manage_wplng_slug_posts_columns', 'wplng_slug_status_columns' );
235 add_action( 'manage_wplng_slug_posts_custom_column', 'wplng_slug_status_item', 10, 2 );
236 add_action( 'admin_head-edit.php', 'wplng_slug_status_style', 10, 2 );
237
238 /**
239 * Front
240 */
241
242 // Enqueue CSS and JS files
243 add_action( 'wp_enqueue_scripts', 'wplng_register_assets' );
244
245 // Add languages switcher before </body>
246 add_action( 'wp_footer', 'wplng_switcher_wp_footer' );
247
248 // Add languages switcher in nav menu
249 add_filter( 'wp_nav_menu_objects', 'wplng_switcher_nav_menu_replace_items' );
250 add_filter( 'nav_menu_link_attributes', 'wplng_add_nav_menu_link_attributes_atts', 10, 2 );
251
252 // Set alternate links with hreflang parametters
253 add_action( 'wp_head', 'wplng_link_alternate_hreflang', 2 );
254
255 /**
256 * OB and REQUEST_URI
257 */
258
259 // Manage URL with REQUEST_URI and start OB
260 add_action( 'init', 'wplng_ob_start', 1 );
261
262 // Redirect page if is called wiht an untranslate slug
263 add_action( 'template_redirect', 'wplng_redirect_translated_slug' );
264
265 /**
266 * Features
267 */
268
269 // Search from translated languages
270 if ( ! empty( get_option( 'wplng_translate_search' ) )
271 && wplng_api_feature_is_allow( 'search' )
272 ) {
273 add_action( 'parse_query', 'wplng_translate_search_query' );
274 } else {
275 add_filter( 'wplng_url_is_translatable', 'wplng_exclude_search', 20 );
276 }
277
278 /**
279 * Shortcode
280 */
281
282 add_shortcode( 'wplng_switcher', 'wplng_shortcode_switcher' );
283 add_shortcode( 'wplng_notranslate', 'wplng_shortcode_notranslate' );
284 add_shortcode( 'wplng_only', 'wplng_shortcode_only' );
285
286 /**
287 * Gutenberg
288 */
289
290 add_filter( 'block_categories_all', 'wplng_block_category' );
291 add_action( 'init', 'wplng_register_block' );
292 add_action( 'enqueue_block_editor_assets', 'wplng_register_block_assets' );
293
294 }
295
296 }
297 wplng_start();
298