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

244 lines 8.5 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://github.com/julien-jacob/wplingua
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 Team
7 * Author URI: https://wplingua.com/
8 * Text Domain: wplingua
9 * Domain Path: /languages/
10 * Version: 1.4.5
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', '1.0' );
26 define( 'WPLNG_API_SSLVERIFY', true );
27 define( 'WPLNG_PLUGIN_VERSION', '1.4.5' );
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 plugin text domain
40 load_plugin_textdomain(
41 'wplingua',
42 false,
43 basename( dirname( __FILE__ ) ) . '/languages'
44 );
45
46
47 // Load all needed PHP files
48 require_once WPLNG_PLUGIN_PATH . '/loader.php';
49
50
51 /**
52 * Register all wpLingua Hook
53 *
54 * @return void
55 */
56 function wplng_start() {
57
58 // Clear cached variables
59 wp_cache_delete( 'wplng_get_language_website', 'wplingua' );
60 wp_cache_delete( 'wplng_get_languages_target_simplified', 'wplingua' );
61 wp_cache_delete( 'wplng_get_languages_target', 'wplingua' );
62 wp_cache_delete( 'wplng_get_language_current_id', 'wplingua' );
63 wp_cache_delete( 'wplng_get_languages_all', 'wplingua' );
64 wp_cache_delete( 'wplng_get_languages_allow', 'wplingua' );
65 wp_cache_delete( 'wplng_get_url_exclude_regex', 'wplingua' );
66
67 // The plugin version has changed
68 if ( get_option( 'wplng_version' ) !== WPLNG_PLUGIN_VERSION ) {
69 wplng_clear_translations_cache();
70 update_option( 'wplng_version', WPLNG_PLUGIN_VERSION, true );
71 }
72
73 // Define $wplng_request_uri
74 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
75
76 $request_uri = sanitize_url( $_SERVER['REQUEST_URI'] );
77
78 // Check if the referer is clean
79 if ( strtolower( esc_url_raw( $request_uri ) ) !== strtolower( $request_uri ) ) {
80 return;
81 }
82
83 global $wplng_request_uri;
84 $wplng_request_uri = $request_uri;
85
86 }
87
88 // Display a notice if an incompatible plugin is detected
89 add_action( 'admin_notices', 'wplng_admin_notice_incompatible_plugin', 1 );
90
91 // Register plugin settings
92 add_action( 'admin_init', 'wplng_register_settings' );
93
94 // Add settings link in plugin list
95 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wplng_settings_link' );
96
97 // Redirect to the settings page on plugin activation
98 add_action( 'activated_plugin', 'wplng_plugin_activation_redirect' );
99
100 // Set footer text for options pages
101 add_filter( 'admin_footer_text', 'wplng_admin_footer_text', 11 );
102 add_filter( 'update_footer', 'wplng_update_footer', 11 );
103
104 // Print head script (JSON with all languages informations)
105 add_action( 'toplevel_page_wplingua-settings', 'wplng_inline_script_languages' );
106
107 if ( empty( wplng_get_api_data() ) ) {
108
109 // Add Register option page in back office menu
110 add_action( 'admin_menu', 'wplng_create_menu_register' );
111
112 // Enqueue CSS and JS files for register option pages
113 add_action( 'admin_enqueue_scripts', 'wplng_option_page_register_assets' );
114
115 // Display a notice if the plugin is activate but not configured
116 add_action( 'admin_notices', 'wplng_admin_notice_no_key_set', 1 );
117
118 } else {
119
120 /**
121 * Back office
122 */
123
124 // Add menu in back office
125 add_action( 'admin_menu', 'wplng_create_menu' );
126
127 // Add admin Bar menu
128 add_action( 'admin_bar_menu', 'wplng_admin_bar_menu', 81 );
129
130 // Switcher in nav menu options
131 add_action( 'admin_enqueue_scripts', 'wplng_switcher_nav_menu_inline_scripts' );
132 add_action( 'admin_head-nav-menus.php', 'wp_nav_menu_switcher_box_add_register' );
133 add_action( 'wp_nav_menu_item_custom_fields', 'wp_nav_menu_switcher_box_edit', 10, 2 );
134
135 // Enqueue CSS and JS files for option pages
136 add_action( 'admin_enqueue_scripts', 'wplng_option_page_settings_assets' );
137 add_action( 'admin_enqueue_scripts', 'wplng_option_page_switcher_assets' );
138 add_action( 'admin_enqueue_scripts', 'wplng_option_page_exclusions_assets' );
139 add_action( 'admin_enqueue_scripts', 'wplng_option_page_dictionary_assets' );
140
141 // Update flags URL
142 add_action( 'update_option_wplng_flags_style', 'wplng_options_switcher_update_flags_style', 10, 2 );
143
144 // Reset API data on API key changing
145 add_action( 'update_option_wplng_api_key', 'wplng_on_update_option_wplng_api_key', 10, 2 );
146
147 /**
148 * wplng_translation : CPT, taxo, meta
149 */
150
151 // Register wplng_translation CPT
152 add_action( 'init', 'wplng_register_post_type_translation' );
153
154 // Add metabox for wplng_translation
155 add_action( 'add_meta_boxes_wplng_translation', 'wplng_translation_add_meta_box' );
156
157 // Save metabox on posts saving
158 add_action( 'save_post_wplng_translation', 'wplng_translation_save_meta_boxes_data', 10, 2 );
159
160 // Clear translation cache on trash / untrash
161 add_action( 'trashed_post', 'wplng_clear_translations_cache_trash_untrash' );
162 add_action( 'untrash_post', 'wplng_clear_translations_cache_trash_untrash' );
163 add_action( 'delete_post', 'wplng_clear_translations_cache_trash_untrash' );
164
165 // Enqueue Script for wplng_translation admin
166 add_action( 'admin_print_scripts-post-new.php', 'wplng_translation_assets' );
167 add_action( 'admin_print_scripts-post.php', 'wplng_translation_assets' );
168
169 // Remove Quick edit from translations list
170 add_filter( 'post_row_actions', 'wplng_translation_remove_quick_edit', 10, 2 );
171
172 // Ajax function for regenerate translation on edit page
173 add_action( 'wp_ajax_wplng_ajax_translation', 'wplng_ajax_generate_translation' );
174
175 // Ajax function for edit modal: Get HTML modal
176 add_action( 'wp_ajax_wplng_ajax_edit_modal', 'wplng_ajax_edit_modal' );
177
178 // Ajax function for edit modal: Save modal
179 add_action( 'wp_ajax_wplng_ajax_save_modal', 'wplng_ajax_save_modal' );
180
181 // Display 100 translation in admin area by default
182 add_filter( 'get_user_option_edit_wplng_translation_per_page', 'wplng_translation_per_page' );
183
184 // Filter translations by status
185 add_action( 'restrict_manage_posts', 'wplng_restrict_manage_posts_translation_status' );
186 add_filter( 'parse_query', 'wplng_posts_filter_translation_status' );
187
188 // Translation status on website translations list
189 add_filter( 'post_class', 'wplng_post_class_translation_status', 10, 3 );
190 add_filter( 'post_row_actions', 'wplng_post_row_actions_status', 10, 2 );
191 add_filter( 'manage_wplng_translation_posts_columns', 'wplng_translation_status_columns' );
192 add_action( 'manage_wplng_translation_posts_custom_column', 'wplng_translation_status_item', 10, 2 );
193 add_action( 'admin_head-edit.php', 'wplng_translation_status_style', 10, 2 );
194
195 /**
196 * Front
197 */
198
199 // Enqueue CSS and JS files
200 add_action( 'wp_enqueue_scripts', 'wplng_register_assets' );
201
202 // Add languages switcher before </body>
203 add_action( 'wp_footer', 'wplng_switcher_wp_footer' );
204
205 // Add languages switcher in nav menu
206 add_filter( 'wp_nav_menu_objects', 'wplng_switcher_nav_menu_replace_items' );
207 add_filter( 'nav_menu_link_attributes', 'wplng_add_nav_menu_link_attributes_atts', 10, 2 );
208
209 // Set alternate links with hreflang parametters
210 add_action( 'wp_head', 'wplng_link_alternate_hreflang' );
211
212 /**
213 * OB and REQUEST_URI
214 */
215
216 // Manage URL with REQUEST_URI and start OB
217 add_action( 'init', 'wplng_ob_start', 1 );
218
219 /**
220 * Features
221 */
222
223 // Search from translated languages
224 if ( ! empty( get_option( 'wplng_translate_search' ) )
225 && wplng_api_feature_is_allow( 'search' )
226 ) {
227 add_action( 'parse_query', 'wplng_translate_search_query' );
228 } else {
229 add_filter( 'wplng_url_is_translatable', 'wplng_exclude_search', 20 );
230 }
231
232 /**
233 * Shortcode
234 */
235
236 add_shortcode( 'wplng_switcher', 'wplng_shortcode_switcher' );
237 add_shortcode( 'wplng_notranslate', 'wplng_shortcode_notranslate' );
238 add_shortcode( 'wplng_only', 'wplng_shortcode_only' );
239
240 }
241
242 }
243 wplng_start();
244