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 / wplingua.php

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

193 lines 6.0 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.1.0
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.1.0' );
28 define( 'WPLNG_PLUGIN_PATH', dirname( __FILE__ ) );
29 define( 'WPLNG_MAX_TRANSLATIONS', 256 );
30 define( 'WPLNG_MAX_FILE_SIZE', 1000000 );
31 define( 'WPLNG_LOG_JSON_DEBUG', false );
32 define( 'WPLNG_LOG_AJAX_DEBUG', false );
33
34
35 // Load plugin text domain
36 load_plugin_textdomain(
37 'wplingua',
38 false,
39 basename( dirname( __FILE__ ) ) . '/languages'
40 );
41
42
43 // Load all needed PHP files
44 require_once WPLNG_PLUGIN_PATH . '/loader.php';
45
46
47 /**
48 * Register all wpLingua Hook
49 *
50 * @return void
51 */
52 function wplng_start() {
53
54 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
55
56 $request_uri = sanitize_url( $_SERVER['REQUEST_URI'] );
57
58 // Check if the referer is clean
59 if ( strtolower( esc_url_raw( $request_uri ) ) !== strtolower( $request_uri ) ) {
60 return;
61 }
62
63 global $wplng_request_uri;
64 $wplng_request_uri = $request_uri;
65
66 }
67
68 // Register plugin settings
69 add_action( 'admin_init', 'wplng_register_settings' );
70
71 // Add settings link in plugin list
72 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wplng_settings_link' );
73
74 // Print head script (JSON with all languages informations)
75 add_action( 'toplevel_page_wplingua-settings', 'wplng_inline_script_languages' );
76
77 if ( empty( wplng_get_api_data() ) ) {
78
79 // Add Register option page in back office menu
80 add_action( 'admin_menu', 'wplng_create_menu_register' );
81
82 // Enqueue CSS and JS files for register option pages
83 add_action( 'admin_enqueue_scripts', 'wplng_option_page_register_assets' );
84
85 // Display a notice if the plugin is activate but not configured
86 add_action( 'admin_notices', 'wplng_admin_notice_no_key_set' );
87
88 } else {
89
90 /**
91 * Back office
92 */
93
94 // Add menu in back office
95 add_action( 'admin_menu', 'wplng_create_menu' );
96
97 // Add admin Bar menu
98 add_action( 'admin_bar_menu', 'wplng_admin_bar_menu', 81 );
99
100 // Enqueue CSS and JS files for option pages
101 add_action( 'admin_enqueue_scripts', 'wplng_option_page_settings_assets' );
102 add_action( 'admin_enqueue_scripts', 'wplng_option_page_switcher_assets' );
103 add_action( 'admin_enqueue_scripts', 'wplng_option_page_exclusions_assets' );
104 add_action( 'admin_enqueue_scripts', 'wplng_option_page_dictionary_assets' );
105
106 // Update flags URL
107 add_action( 'update_option_wplng_flags_style', 'wplng_options_switcher_update_flags_style', 10, 2 );
108
109 // Reset API data on API key changing
110 add_action( 'update_option_wplng_api_key', 'wplng_on_update_option_wplng_api_key', 10, 2 );
111
112 /**
113 * wplng_translation : CPT, taxo, meta
114 */
115
116 // Register wplng_translation CPT
117 add_action( 'init', 'wplng_register_post_type_translation' );
118
119 // Add metabox for wplng_translation
120 add_action( 'add_meta_boxes_wplng_translation', 'wplng_translation_add_meta_box' );
121
122 // Save metabox on posts saving
123 add_action( 'save_post_wplng_translation', 'wplng_translation_save_meta_boxes_data', 10, 2 );
124
125 // Clear translation cache on trash / untrash
126 add_action( 'trashed_post', 'wplng_clear_translations_cache_trash_untrash' );
127 add_action( 'untrash_post', 'wplng_clear_translations_cache_trash_untrash' );
128 add_action( 'delete_post', 'wplng_clear_translations_cache_trash_untrash' );
129
130 // Enqueue Script for wplng_translation admin
131 add_action( 'admin_print_scripts-post-new.php', 'wplng_translation_assets' );
132 add_action( 'admin_print_scripts-post.php', 'wplng_translation_assets' );
133
134 // Remove Quick edit from translations list
135 add_filter( 'post_row_actions', 'wplng_translation_remove_quick_edit', 10, 2 );
136
137 // Ajax function for regenerate translation on edit page
138 add_action( 'wp_ajax_wplng_ajax_translation', 'wplng_ajax_generate_translation' );
139
140 // Display 100 translation in admin area by default
141 add_filter( 'get_user_option_edit_wplng_translation_per_page', 'wplng_translation_per_page' );
142
143 /**
144 * Front
145 */
146
147 // Enqueue CSS and JS files
148 add_action( 'wp_enqueue_scripts', 'wplng_register_assets' );
149
150 // Add languages switcher before </body>
151 add_action( 'wp_footer', 'wplng_switcher_wp_footer' );
152
153 // Set alternate links with hreflang parametters
154 add_action( 'wp_head', 'wplng_link_alternate_hreflang' );
155
156 /**
157 * OB and REQUEST_URI
158 */
159
160 // Manage URL with REQUEST_URI and start OB
161 add_action( 'init', 'wplng_ob_start', 1 );
162
163 /**
164 * Features
165 */
166
167 // Search from translated languages
168 if ( ! empty( get_option( 'wplng_translate_search' ) )
169 && wplng_api_feature_is_allow( 'search' )
170 ) {
171 add_action( 'parse_query', 'wplng_translate_search_query' );
172 } else {
173 add_filter( 'wplng_url_is_translatable', 'wplng_exclude_search', 20 );
174 }
175
176 // Woocommerce
177 if ( empty( get_option( 'wplng_translate_woocommerce' ) ) ) {
178 add_filter( 'wplng_url_exclude_regex', 'wplng_exclude_woocommerce_url', 20 );
179 }
180
181 /**
182 * Shortcode
183 */
184
185 add_shortcode( 'wplng_switcher', 'wplng_shortcode_switcher' );
186 add_shortcode( 'wplng_notranslate', 'wplng_shortcode_notranslate' );
187 add_shortcode( 'wplng_only', 'wplng_shortcode_only' );
188
189 }
190
191 }
192 wplng_start();
193