-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtranslation-stats.php
193 lines (153 loc) · 6.49 KB
/
translation-stats.php
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
<?php
/**
* Translation Stats
*
* @package Translation Stats
* @link https://github.com/pedro-mendonca/Translation-Stats
* @author Pedro Mendonça
* @copyright 2018 Pedro Mendonça
* @license GPL2
*
* @wordpress-plugin
* Plugin Name: Translation Stats
* Plugin URI: https://translationstats.com
* GitHub Plugin URI: https://github.com/pedro-mendonca/Translation-Stats
* Description: Show plugins translation stats on your WordPress install.
* Version: 0.9.5.4
* Author: Pedro Mendonça
* Author URI: https://translationstats.com
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: translation-stats
* Domain Path: /languages
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Set Translation Stats plugin version.
define( 'TSTATS_VERSION', '0.9.5.4' );
// Set Translation Stats required PHP version. Needed for PHP compatibility check for WordPress < 5.1.
define( 'TSTATS_REQUIRED_PHP', '5.6' );
// Set the WordPress option to store Translation Stats settings.
define( 'TSTATS_WP_OPTION', 'tstats_settings' );
// Set Translation Stats settings page slug.
define( 'TSTATS_SETTINGS_PAGE', 'translation-stats' );
// Set Translation Stats transients prefix.
define( 'TSTATS_TRANSIENTS_PREFIX', 'translation_stats_plugin_' );
// Set Translation Stats transients default 24h expiration for Translations data.
define( 'TSTATS_TRANSIENTS_TRANSLATIONS_EXPIRATION', DAY_IN_SECONDS );
// Set Translation Stats transients 1 week expiration for Locales data.
define( 'TSTATS_TRANSIENTS_LOCALES_EXPIRATION', WEEK_IN_SECONDS );
// Set Translation Stats plugin URL.
define( 'TSTATS_DIR_URL', plugin_dir_url( __FILE__ ) );
// Set Translation Stats plugin filesystem path.
define( 'TSTATS_DIR_PATH', plugin_dir_path( __FILE__ ) );
// Set Translation Stats file path.
define( 'TSTATS_FILE', plugin_basename( __FILE__ ) );
// Set Translation Stats Debug ( true / false ).
// Use 'tstats_enable_debug' to enable debug ( e.g. add_filter( 'tstats_enable_debug', '__return_true' ) ).
define( 'TSTATS_DEBUG', apply_filters( 'tstats_enable_debug', false ) );
// Check for PHP compatibility.
// Adapted from https://pento.net/2014/02/18/dont-let-your-plugin-be-activated-on-incompatible-sites/.
add_action( 'admin_init', 'tstats_check_version' );
// Stop running the plugin if on an incompatible PHP version.
if ( ! tstats_compatible_version() ) {
return;
}
/**
* Backup sanity check, in case the plugin is activated, or the versions change after activation.
* WordPress 5.1 news: https://wordpress.org/news/2019/04/minimum-php-version-update/.
*
* If incompatible, deactivate the plugin and add an admin notice.
*
* @since 0.9.4.3
*/
function tstats_check_version() {
if ( ! tstats_compatible_version() ) {
if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
// Deactivate the plugin.
deactivate_plugins( plugin_basename( __FILE__ ) );
// Show disabled admin notice.
add_action( 'admin_notices', 'tstats_disabled_notice' );
}
}
}
/**
* Show disabled notice with the minimum required PHP version.
* Adapted from https://pento.net/2014/02/18/dont-let-your-plugin-be-activated-on-incompatible-sites/.
*
* @since 0.9.4.3
*/
function tstats_disabled_notice() {
// Get plugin data.
$plugin_data = get_plugin_data( __FILE__ );
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
printf(
/* translators: 1: Plugin file, 2: Error message. */
wp_kses_post( 'The plugin %1$s has been deactivated due to an error: %2$s', 'translation-stats' ),
'<strong>' . esc_html( $plugin_data['Name'] ) . '</strong>',
esc_html__( 'This plugin doesn’t work with your version of PHP.', 'translation-stats' )
);
?>
</p>
<p>
<?php
printf(
/* translators: %s Minimum PHP version required. */
esc_html__( 'Requires PHP version %s or higher.', 'translation-stats' ),
esc_html( TSTATS_REQUIRED_PHP )
);
// Show aditional update link if on WP version 5.1 or higher.
// Capability added in WP 5.1: https://core.trac.wordpress.org/ticket/44457.
// Introduced in WP 5.1: https://developer.wordpress.org/reference/functions/wp_get_update_php_url/.
if ( current_user_can( 'update_php' ) && version_compare( $GLOBALS['wp_version'], '5.1', '>=' ) ) {
printf(
/* translators: %s: URL to Update PHP page. */
' ' . wp_kses_post( '<a href="%s">Learn more about updating PHP</a>.', 'translation-stats' ),
esc_url( wp_get_update_php_url() )
);
}
?>
</p>
</div>
<?php
}
/**
* Check Translation Stats minimum requirements.
* Adapted from https://pento.net/2014/02/18/dont-let-your-plugin-be-activated-on-incompatible-sites/.
*
* @since 0.9.4.3
*
* @return bool
*/
function tstats_compatible_version() {
// Check minimum required PHP version.
if ( version_compare( PHP_VERSION, TSTATS_REQUIRED_PHP, '<=' ) ) {
return false;
}
return true;
}
// Include Composer autoload.
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
// Include class files used by the plugin.
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-main.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-globals.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-notices.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-transients.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-translations-api.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-settings-sidebar.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-settings-widgets.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-settings-footer.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-settings-api.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-settings-plugins.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-settings.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-gettext-jedgenerator.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-gettext.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-update-translations.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-update-core.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-plugins.php';
require_once dirname( __FILE__ ) . '/includes/classes/class-tstats-debug.php';