PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.9.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.9.6
1.9.6 1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 All 41 releases
← All changes | index.php +72 -37 1.6.21.9.6 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 -/*
2 +/**
3 3 Plugin Name: Code Profiler
4 -Plugin URI: https://code-profiler.com/
4 +Plugin URI: https://nintechnet.com/codeprofiler/
5 5 Description: A profiler to measure the performance of your WordPress plugins and themes.
6 6 Author: Jerome Bruandet ~ NinTechNet Ltd.
7 7 Author URI: https://nintechnet.com/
8 -Version: 1.6.2
8 +Version: 1.9.6
9 9 Network: true
10 10 License: GPLv3 or later
11 11 Text Domain: code-profiler
12 12 Domain Path: /languages
@@ -11,10 +11,10 @@
11 11 Text Domain: code-profiler
12 12 Domain Path: /languages
13 13 */
14 14
15 -define('CODE_PROFILER_VERSION', '1.6.2');
16 -/*
15 +define('CODE_PROFILER_VERSION', '1.9.6');
16 +/**
17 17 +=====================================================================+
18 18 | ____ _ ____ __ _ _ |
19 19 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
20 20 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
@@ -20,9 +20,9 @@
20 20 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
21 21 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
22 22 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
23 23 | |
24 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
24 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
25 25 +=====================================================================+
26 26 */
27 27
28 28 if (! defined('ABSPATH') ) {
@@ -34,9 +34,11 @@
34 34 require __DIR__ .'/lib/menu.php';
35 35 // Helper (can be already loaded by the MU plugin)
36 36 require_once __DIR__ .'/lib/helper.php';
37 37 // AJAX calls
38 -require __DIR__ .'/lib/ajax.php';
38 +require __DIR__ .'/lib/class-ajax.php';
39 +// Scheduled tasks
40 +require_once __DIR__ .'/lib/class-wp-cron.php';
39 41 // =====================================================================
40 42 // Activation: make sure the blog meets the requirements.
41 43
42 44 function code_profiler_activate() {
@@ -41,22 +43,23 @@
41 43
42 44 function code_profiler_activate() {
43 45
44 46 if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) {
45 - exit( esc_html__('Your are not allowed to activate plugins.', 'code-profiler') );
47 + wp_die( esc_html__('Your are not allowed to activate plugins.', 'code-profiler') );
46 48 }
47 49
48 50 global $wp_version;
49 - if ( version_compare( $wp_version, '4.7.0', '<') ) {
50 - exit( sprintf(
51 - esc_html__('Code Profiler requires WordPress %s or greater but your current version is %s.', 'code-profiler'),
52 - '4.7.0',
51 + if ( version_compare( $wp_version, '5.0', '<') ) {
52 + wp_die( sprintf(
53 + esc_html__('Code Profiler requires WordPress %s or greater but your current version is %s.',
54 + 'code-profiler'),
55 + '5.0',
53 56 esc_html( $wp_version )
54 57 ) );
55 58 }
56 59
57 60 if ( version_compare( PHP_VERSION, '7.1', '<') ) {
58 - exit( sprintf(
61 + wp_die( sprintf(
59 62 esc_html__('Code Profiler requires PHP 7.1 or greater but your current version is %s.',
60 63 'code-profiler'),
61 64 esc_html( PHP_VERSION )
62 65 ) );
@@ -63,9 +66,11 @@
63 66 }
64 67
65 68 // If the pro version is active, we refuse to run and throw an error message
66 69 if ( is_plugin_active('code-profiler-pro/index.php') ) {
67 - exit( esc_html__('Code Profiler Pro is active on this site, please disable it first if you want to run the free version.', 'code-profiler') );
70 + wp_die( esc_html__('Code Profiler Pro is active on this site, please disable it first if you '.
71 + 'want to run the free version.', 'code-profiler')
72 + );
68 73 }
69 74
70 75 // Verify/create our storage folder
71 76 code_profiler_check_uploadsdir();
@@ -74,8 +79,15 @@
74 79 $cp_options = get_option('code-profiler');
75 80 if ( $cp_options === false ) {
76 81 code_profiler_default_options();
77 82 }
83 +
84 + /**
85 + * Install scheduled tasks on the main site only.
86 + */
87 + if ( is_main_site() ) {
88 + CodeProfiler_WPCron::install();
89 + }
78 90 }
79 91
80 92 register_activation_hook( __FILE__, 'code_profiler_activate');
81 93
@@ -84,9 +96,9 @@
84 96
85 97 function code_profiler_deactivate() {
86 98
87 99 if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) {
88 - exit( esc_html__('Your are not allowed to deactivate plugins.', 'code-profiler') );
100 + wp_die( esc_html__('Your are not allowed to deactivate plugins.', 'code-profiler') );
89 101 }
90 102
91 103 // Remove the MU plugin
92 104 if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) {
@@ -91,8 +103,13 @@
91 103 // Remove the MU plugin
92 104 if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) {
93 105 unlink( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN );
94 106 }
107 +
108 + /**
109 + * Uninstall scheduled tasks.
110 + */
111 + CodeProfiler_WPCron::uninstall();
95 112 }
96 113
97 114 register_deactivation_hook( __FILE__, 'code_profiler_deactivate');
98 115
@@ -117,9 +134,9 @@
117 134 }
118 135
119 136 add_action('admin_menu', 'code_profiler_admin_menu');
120 137
121 -// =====================================================================
138 +// ===================================================================== 2023-08-20
122 139 // Register scripts and styles.
123 140
124 141 function code_profiler_enqueue( $hook ) {
125 142
@@ -133,18 +150,18 @@
133 150 }
134 151
135 152 // We load Thickbox if we're viewing section 4 only
136 153 if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 4 ) {
137 - $extra_js = array('jquery', 'thickbox');
138 - $extra_css = array('thickbox');
154 + $extra_js = ['jquery', 'thickbox'];
155 + $extra_css = ['thickbox'];
139 156 } else {
140 - $extra_js = array('jquery');
141 - $extra_css = null;
157 + $extra_js = ['jquery'];
158 + $extra_css = null;
142 159 }
143 160
144 161 wp_enqueue_script(
145 162 'code_profiler_javascript',
146 - plugin_dir_url( __FILE__ ) . 'static/code-profiler.js',
163 + plugin_dir_url( __FILE__ ) .'static/code-profiler.js',
147 164 $extra_js,
148 165 CODE_PROFILER_VERSION
149 166 );
150 167
@@ -150,25 +167,27 @@
150 167
151 168 wp_enqueue_script(
152 169 'code-profiler_tiptip',
153 170 plugin_dir_url( __FILE__ ) .'static/vendor/jquery.tipTip.js',
154 - array('jquery'),
171 + ['jquery'],
155 172 CODE_PROFILER_VERSION
156 173 );
157 174
158 175 wp_enqueue_style(
159 176 'code-profiler_style',
160 - plugin_dir_url( __FILE__ ) . 'static/code-profiler.css',
177 + plugin_dir_url( __FILE__ ) .'static/code-profiler.css',
161 178 $extra_css,
162 179 CODE_PROFILER_VERSION
163 180 );
164 181
165 182 // Enqueue Chart.js if we're viewing a profile
166 - if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'view_profile') {
183 + if ( isset( $_REQUEST['action'] ) &&
184 + $_REQUEST['action'] == 'view_profile') {
185 +
167 186 wp_enqueue_script(
168 187 'code_profiler_charts',
169 - plugin_dir_url( __FILE__ ) . 'static/vendor/chart.min.js',
170 - array('jquery'),
188 + plugin_dir_url( __FILE__ ) .'static/vendor/chart.min.js',
189 + ['jquery'],
171 190 CODE_PROFILER_VERSION,
172 191 // We load it in the footer, because some plugins loads it too
173 192 // on every pages and that could mess with our pages
174 193 true
@@ -175,9 +194,9 @@
175 194 );
176 195 }
177 196
178 197 // JS i18n
179 - $code_profiler_i18n = array(
198 + $code_profiler_i18n = [
180 199 'missing_nonce' =>
181 200 esc_attr__('Security nonce is missing, try to reload the page.', 'code-profiler'),
182 201 'missing_frontbackend' =>
183 202 esc_attr__('Please select either the fontend or backend option.', 'code-profiler'),
@@ -185,11 +204,19 @@
185 204 esc_attr__('Missing profile identifier.', 'code-profiler'),
186 205 'missing_profilename' =>
187 206 esc_attr__('Please enter a name for this profile.', 'code-profiler'),
188 207 'missing_userauth' =>
189 - esc_attr__('Please select whether the profiler should run as an authenticated user or not.', 'code-profiler'),
208 + esc_attr__('Please select whether the profiler should run as an authenticated user or not.',
209 + 'code-profiler'),
190 210 'missing_username' =>
191 211 esc_attr__('Please enter the name of the user.', 'code-profiler'),
212 + 'missing_ajax' =>
213 + esc_attr__('Please enter a valid JSON-encoded payload, or change the content-type option. If you want to send an empty value, enter: {}', 'code-profiler'),
214 + 'missing_wpcron' =>
215 + esc_attr__('There are no cron events available, please select another page to profile.',
216 + 'code-profiler'),
217 + 'multiline_raw' =>
218 + esc_attr__('The raw POST payload should be on one single line only.', 'code-profiler'),
192 219 'missing_post' =>
193 220 esc_attr__('Please select a page to profile.', 'code-profiler'),
194 221 'unknown_error' =>
195 222 esc_attr__('Unknown error returned by AJAX', 'code-profiler'),
@@ -195,11 +222,13 @@
195 222 esc_attr__('Unknown error returned by AJAX', 'code-profiler'),
196 223 'http_error' =>
197 224 esc_attr__('The HTTP server returned the following error:', 'code-profiler'),
198 225 'timeout_error' =>
199 - esc_attr__('You can try to select a lower Accuracy and Precision level in the Settings page', 'code-profiler'),
226 + esc_attr__('You can try to select a lower Accuracy and Precision level in the Settings page',
227 + 'code-profiler'),
200 228 'notfound_error' =>
201 - esc_attr__('The requested page does not seem to exist. Please check the syntax of the URL you want to profile', 'code-profiler'),
229 + esc_attr__('The requested page does not seem to exist. Please check the syntax of the URL you want to profile',
230 + 'code-profiler'),
202 231 'forbidden_error' =>
203 232 esc_attr__('The server rejected and blocked the requested page. Make sure you are allowed to access that page or that there is no security plugin or application blocking it', 'code-profiler'),
204 233 'internal_error' =>
205 234 esc_attr__('This is an internal server error. Please check your server, PHP and Code Profiler logs as they may contain more details about the error', 'code-profiler'),
@@ -207,9 +236,10 @@
207 236 esc_attr__('An unknown error occurred:', 'code-profiler'),
208 237 'preparing_report' =>
209 238 esc_attr__('Preparing the report', 'code-profiler') .'...',
210 239 'empty_log' =>
211 - esc_attr__('No records were found that match the specified search criteria.', 'code-profiler'),
240 + esc_attr__('No records were found that match the specified search criteria.',
241 + 'code-profiler'),
212 242 'delete_log' =>
213 243 esc_attr__('Delete log?', 'code-profiler'),
214 244 'delete_profile' =>
215 245 esc_attr__('Delete this profile?', 'code-profiler'),
@@ -233,22 +263,27 @@
233 263 esc_attr__('Total Disk I/O read and write, in bytes', 'code-profiler'),
234 264 'text_copied' =>
235 265 esc_attr__('The text was successfully copied to the clipboard.', 'code-profiler')
236 266
267 + ];
268 + wp_localize_script(
269 + 'code_profiler_javascript',
270 + 'cpi18n',
271 + $code_profiler_i18n
237 272 );
238 - wp_localize_script('code_profiler_javascript', 'cpi18n', $code_profiler_i18n );
239 273 }
240 274
241 275 add_action('admin_enqueue_scripts', 'code_profiler_enqueue');
242 276
243 -// =====================================================================
277 +// ===================================================================== 2023-08-20
244 278 // Display the settings link in the "Plugins" page.
245 279
246 280 function code_profiler_settings_link( $links ) {
247 281
248 - $links[] = '<a href="'. get_admin_url( null, 'admin.php?page=code-profiler') .
249 - '">'. esc_html__('Start Profiling', 'code-profiler'). '</a>';
250 - $links[] = '<a style="font-weight:700;color:#006393;" href="https://code-profiler.com/" target="_blank" rel="noopener noreferrer">'.
282 + $links[] = '<a href="'. get_admin_url( null, 'admin.php?page=code-profiler') .'">'.
283 + esc_html__('Start Profiling', 'code-profiler'). '</a>';
284 + $links[] = '<a style="font-weight:700;color:#006393;" href="https://nintechnet.com/codeprofiler/" '.
285 + 'target="_blank" rel="noopener noreferrer">'.
251 286 esc_html__('Go Pro', 'code-profiler'). '</a>';
252 287 return $links;
253 288 }
254 289
@@ -253,9 +288,9 @@
253 288 }
254 289
255 290 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link');
256 291
257 -// =====================================================================
292 +// ===================================================================== 2023-08-20
258 293 // WP CLI commands.
259 294
260 295 if ( defined('WP_CLI') && WP_CLI ) {
261 296 require_once __DIR__ . '/lib/class-cli.php';