PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.4.1
Translate and Go multilingual – Automatic AI translation – wpLingua v2.4.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.4.1, at wplingua.php

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