forked from Shelob9/translate-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweglot.php
More file actions
197 lines (165 loc) · 5.5 KB
/
weglot.php
File metadata and controls
197 lines (165 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
Plugin Name: Weglot Translate
Plugin URI: http://wordpress.org/plugins/weglot/
Description: Translate your website into multiple languages in minutes without doing any coding. Fully SEO compatible.
Author: Weglot Translate team
Author URI: https://weglot.com/
Text Domain: weglot
Domain Path: /languages/
Version: 3.0.6
*/
/**
* This file need to be compatible with PHP 5.3
* Example : Don't use short syntax for array()
*/
if ( ! defined('ABSPATH')) {
exit;
}
define('WEGLOT_NAME', 'Weglot');
define('WEGLOT_SLUG', 'weglot-translate');
define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
define('WEGLOT_VERSION', '3.0.6');
define('WEGLOT_PHP_MIN', '5.4');
define('WEGLOT_BNAME', plugin_basename(__FILE__));
define('WEGLOT_DIR', __DIR__ );
define('WEGLOT_DIR_LANGUAGES', WEGLOT_DIR . '/languages');
define('WEGLOT_DIR_DIST', WEGLOT_DIR . '/dist');
define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
define('WEGLOT_URL_DIST', WEGLOT_DIRURL . 'dist');
define('WEGLOT_LATEST_VERSION', '2.7.0');
define('WEGLOT_LIB_PARSER', '1');
define('WEGLOT_DEBUG', false);
define('WEGLOT_DEV', false);
define('WEGLOT_TEMPLATES', WEGLOT_DIR . '/templates');
define('WEGLOT_TEMPLATES_ADMIN', WEGLOT_TEMPLATES . '/admin');
define('WEGLOT_TEMPLATES_ADMIN_METABOXES', WEGLOT_TEMPLATES_ADMIN . '/metaboxes');
define('WEGLOT_TEMPLATES_ADMIN_NOTICES', WEGLOT_TEMPLATES_ADMIN . '/notices');
define('WEGLOT_TEMPLATES_ADMIN_PAGES', WEGLOT_TEMPLATES_ADMIN . '/pages');
// Compatibility Yoast premium Redirection
$dir_yoast_premium = plugin_dir_path(__DIR__) . 'wordpress-seo-premium';
if ( file_exists( $dir_yoast_premium . '/wp-seo-premium.php' ) ) {
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
if ( ! weglot_is_compatible() ) {
return;
}
$yoast_plugin_data = get_plugin_data( $dir_yoast_premium . '/wp-seo-premium.php' );
$dir_yoast_premium_inside = $dir_yoast_premium . '/premium/';
// Override yoast redirect
if (
! is_admin() &&
version_compare( $yoast_plugin_data['Version'], '7.1.0', '>=' ) &&
is_plugin_active( 'wordpress-seo-premium/wp-seo-premium.php' ) &&
file_exists( $dir_yoast_premium_inside ) &&
file_exists( $dir_yoast_premium_inside . 'classes/redirect/redirect-handler.php' ) &&
file_exists( $dir_yoast_premium_inside . 'classes/redirect/redirect-util.php' )
) {
require_once __DIR__ . '/weglot-autoload.php';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/bootstrap.php';
require_once __DIR__ . '/weglot-functions.php';
include_once __DIR__ . '/src/third/yoast/redirect-premium.php';
}
}
/**
* Check compatibility this Weglot with WordPress config.
*/
function weglot_is_compatible() {
// Check php version.
if (version_compare(PHP_VERSION, WEGLOT_PHP_MIN) < 0) {
add_action('admin_notices', 'weglot_php_min_compatibility' );
return false;
}
return true;
}
/**
* Admin notices if weglot not compatible
*
* @return void
*/
function weglot_php_min_compatibility() {
if ( ! file_exists( WEGLOT_TEMPLATES_ADMIN_NOTICES . '/php-min.php' ) ) {
return;
}
include_once WEGLOT_TEMPLATES_ADMIN_NOTICES . '/php-min.php';
}
/**
* Activate Weglot.
*
* @since 2.0
*/
function weglot_plugin_activate() {
if ( ! weglot_is_compatible() ) {
return;
}
require_once __DIR__ . '/weglot-autoload.php';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/weglot-compatibility.php';
require_once __DIR__ . '/weglot-functions.php';
require_once __DIR__ . '/bootstrap.php';
Context_Weglot::weglot_get_context()->activate_plugin();
}
/**
* Deactivate Weglot.
*
* @since 2.0
*/
function weglot_plugin_deactivate() {
flush_rewrite_rules();
require_once __DIR__ . '/weglot-autoload.php';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/weglot-compatibility.php';
require_once __DIR__ . '/weglot-functions.php';
require_once __DIR__ . '/bootstrap.php';
Context_Weglot::weglot_get_context()->deactivate_plugin();
}
/**
* Uninstall Weglot.
*
* @since 2.0
*/
function weglot_plugin_uninstall() {
flush_rewrite_rules();
delete_option(WEGLOT_SLUG);
}
/**
* Rollback v2 => v1
*
* @return void
*/
function weglot_rollback( ) {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'weglot_rollback' ) ) {
wp_nonce_ays( '' );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$plugin = 'weglot';
$title = sprintf( __( '%s Update Rollback', 'weglot' ), WEGLOT_NAME );
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $plugin );
$version = WEGLOT_LATEST_VERSION;
$upgrader_skin = new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin', 'version' ) );
$rollback = new \WeglotWP\Helpers\Helper_Rollback_Weglot( $upgrader_skin );
$rollback->rollback($version);
}
/**
* Load Weglot.
*
* @since 2.0
*/
function weglot_plugin_loaded() {
require_once __DIR__ . '/weglot-autoload.php';
require_once __DIR__ . '/weglot-compatibility.php';
add_action( 'admin_post_weglot_rollback', 'weglot_rollback' );
if ( weglot_is_compatible() ) {
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/bootstrap.php';
require_once __DIR__ . '/weglot-functions.php';
weglot_init();
}
}
register_activation_hook(__FILE__, 'weglot_plugin_activate');
register_deactivation_hook(__FILE__, 'weglot_plugin_deactivate');
register_uninstall_hook(__FILE__, 'weglot_plugin_uninstall');
add_action('plugins_loaded', 'weglot_plugin_loaded');