PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.6.3
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.6.3
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 1.6.8 All 40 releases
code-profiler / index.php

index.php in Code Profiler – WordPress Performance Profiling and Debugging Made Easy 1.6.3, at index.php

299 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Code Profiler
4 Plugin URI: https://code-profiler.com/
5 Description: A profiler to measure the performance of your WordPress plugins and themes.
6 Author: Jerome Bruandet ~ NinTechNet Ltd.
7 Author URI: https://nintechnet.com/
8 Version: 1.6.3
9 Network: true
10 License: GPLv3 or later
11 Text Domain: code-profiler
12 Domain Path: /languages
13 */
14
15 define('CODE_PROFILER_VERSION', '1.6.3');
16 /*
17 +=====================================================================+
18 | ____ _ ____ __ _ _ |
19 | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ |
20 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
21 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
22 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
23 | |
24 | (c) Jerome Bruandet ~ https://code-profiler.com/ |
25 +=====================================================================+
26 */
27
28 if (! defined('ABSPATH') ) {
29 die('Forbidden');
30 }
31
32 // =====================================================================
33 // Menu functions
34 require __DIR__ .'/lib/menu.php';
35 // Helper (can be already loaded by the MU plugin)
36 require_once __DIR__ .'/lib/helper.php';
37 // AJAX calls
38 require __DIR__ .'/lib/ajax.php';
39 // ===================================================================== 2023-06-17
40 // Activation: make sure the blog meets the requirements.
41
42 function code_profiler_activate() {
43
44 if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) {
45 exit( esc_html__('Your are not allowed to activate plugins.',
46 'code-profiler')
47 );
48 }
49
50 global $wp_version;
51 if ( version_compare( $wp_version, '5.0', '<') ) {
52 exit( sprintf(
53 esc_html__('Code Profiler requires WordPress %s or greater but '.
54 'your current version is %s.', 'code-profiler'),
55 '5.0',
56 esc_html( $wp_version )
57 ) );
58 }
59
60 if ( version_compare( PHP_VERSION, '7.1', '<') ) {
61 exit( sprintf(
62 esc_html__('Code Profiler requires PHP 7.1 or greater but your '.
63 'current version is %s.',
64 'code-profiler'),
65 esc_html( PHP_VERSION )
66 ) );
67 }
68
69 // If the pro version is active, we refuse to run and throw an error message
70 if ( is_plugin_active('code-profiler-pro/index.php') ) {
71 exit( esc_html__('Code Profiler Pro is active on this site, '.
72 'please disable it first if you want to run the free version.',
73 'code-profiler')
74 );
75 }
76
77 // Verify/create our storage folder
78 code_profiler_check_uploadsdir();
79
80 // If we don't have any options yet, create them
81 $cp_options = get_option('code-profiler');
82 if ( $cp_options === false ) {
83 code_profiler_default_options();
84 }
85 }
86
87 register_activation_hook( __FILE__, 'code_profiler_activate');
88
89 // ===================================================================== 2023-06-17
90 // Deactivation.
91
92 function code_profiler_deactivate() {
93
94 if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) {
95 exit( esc_html__('Your are not allowed to deactivate plugins.',
96 'code-profiler')
97 );
98 }
99
100 // Remove the MU plugin
101 if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) {
102 unlink( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN );
103 }
104 }
105
106 register_deactivation_hook( __FILE__, 'code_profiler_deactivate');
107
108 // ===================================================================== 2023-06-14
109 // Create Profiler's menu.
110
111 function code_profiler_admin_menu() {
112
113 // In a MU environment, only the superadmin can run Code Profiler
114 if (! is_super_admin() ) {
115 return;
116 }
117
118 add_menu_page(
119 'Code Profiler',
120 'Code Profiler',
121 'manage_options',
122 'code-profiler',
123 'code_profiler_main_menu',
124 plugins_url('/static/dashicon-16x16.png', __FILE__ )
125 );
126 }
127
128 add_action('admin_menu', 'code_profiler_admin_menu');
129
130 // =====================================================================
131 // Register scripts and styles.
132
133 function code_profiler_enqueue( $hook ) {
134
135 if (! is_super_admin() ) {
136 return;
137 }
138
139 // Load files only if we're in Code Profiler's main page
140 if ( $hook != 'toplevel_page_code-profiler') {
141 return;
142 }
143
144 // We load Thickbox if we're viewing section 4 only
145 if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 4 ) {
146 $extra_js = ['jquery', 'thickbox'];
147 $extra_css = ['thickbox'];
148 } else {
149 $extra_js = ['jquery'];
150 $extra_css = null;
151 }
152
153 wp_enqueue_script(
154 'code_profiler_javascript',
155 plugin_dir_url( __FILE__ ) .'static/code-profiler.js',
156 $extra_js,
157 CODE_PROFILER_VERSION
158 );
159
160 wp_enqueue_script(
161 'code-profiler_tiptip',
162 plugin_dir_url( __FILE__ ) .'static/vendor/jquery.tipTip.js',
163 ['jquery'],
164 CODE_PROFILER_VERSION
165 );
166
167 wp_enqueue_style(
168 'code-profiler_style',
169 plugin_dir_url( __FILE__ ) .'static/code-profiler.css',
170 $extra_css,
171 CODE_PROFILER_VERSION
172 );
173
174 // Enqueue Chart.js if we're viewing a profile
175 if ( isset( $_REQUEST['action'] ) &&
176 $_REQUEST['action'] == 'view_profile') {
177
178 wp_enqueue_script(
179 'code_profiler_charts',
180 plugin_dir_url( __FILE__ ) .'static/vendor/chart.min.js',
181 ['jquery'],
182 CODE_PROFILER_VERSION,
183 // We load it in the footer, because some plugins loads it too
184 // on every pages and that could mess with our pages
185 true
186 );
187 }
188
189 // JS i18n
190 $code_profiler_i18n = [
191 'missing_nonce' =>
192 esc_attr__('Security nonce is missing, try to reload the page.',
193 'code-profiler'),
194 'missing_frontbackend' =>
195 esc_attr__('Please select either the fontend or backend option.',
196 'code-profiler'),
197 'missing_profileid' =>
198 esc_attr__('Missing profile identifier.', 'code-profiler'),
199 'missing_profilename' =>
200 esc_attr__('Please enter a name for this profile.',
201 'code-profiler'),
202 'missing_userauth' =>
203 esc_attr__('Please select whether the profiler should run as '.
204 'an authenticated user or not.', 'code-profiler'),
205 'missing_username' =>
206 esc_attr__('Please enter the name of the user.',
207 'code-profiler'),
208 'missing_post' =>
209 esc_attr__('Please select a page to profile.',
210 'code-profiler'),
211 'unknown_error' =>
212 esc_attr__('Unknown error returned by AJAX',
213 'code-profiler'),
214 'http_error' =>
215 esc_attr__('The HTTP server returned the following error:',
216 'code-profiler'),
217 'timeout_error' =>
218 esc_attr__('You can try to select a lower Accuracy and Precision'.
219 ' level in the Settings page', 'code-profiler'),
220 'notfound_error' =>
221 esc_attr__('The requested page does not seem to exist. Please '.
222 'check the syntax of the URL you want to profile',
223 'code-profiler'),
224 'forbidden_error' =>
225 esc_attr__('The server rejected and blocked the requested page. '.
226 'Make sure you are allowed to access that page or that there is '.
227 'no security plugin or application blocking it', 'code-profiler'),
228 'internal_error' =>
229 esc_attr__('This is an internal server error. Please check your '.
230 'server, PHP and Code Profiler logs as they may contain more '.
231 'details about the error', 'code-profiler'),
232 'unknown_error' =>
233 esc_attr__('An unknown error occurred:', 'code-profiler'),
234 'preparing_report' =>
235 esc_attr__('Preparing the report', 'code-profiler') .'...',
236 'empty_log' =>
237 esc_attr__('No records were found that match the specified '.
238 'search criteria.', 'code-profiler'),
239 'delete_log' =>
240 esc_attr__('Delete log?', 'code-profiler'),
241 'delete_profile' =>
242 esc_attr__('Delete this profile?', 'code-profiler'),
243 // Charts
244 'exec_sec_plugins' =>
245 esc_attr__('Execution time in seconds', 'code-profiler'),
246 'pc_plugins' =>
247 /* Translators: xx% of all plugins and the theme */
248 esc_attr__('% of all plugins and the theme', 'code-profiler'),
249 'exec_tot_plugins_1' =>
250 esc_attr__('Plugins and theme execution time, in seconds',
251 'code-profiler'),
252 'chart_total' =>
253 esc_attr__('total:', 'code-profiler'),
254 'iolist_total_calls' =>
255 esc_attr__('Total calls', 'code-profiler'),
256 'io_calls' =>
257 esc_attr__('File I/O operations', 'code-profiler'),
258 'disk_io_bytes' =>
259 esc_attr__('Total bytes', 'code-profiler'),
260 'disk_io_title' =>
261 esc_attr__('Total Disk I/O read and write, in bytes',
262 'code-profiler'),
263 'text_copied' =>
264 esc_attr__('The text was successfully copied to the clipboard.',
265 'code-profiler')
266
267 ];
268 wp_localize_script(
269 'code_profiler_javascript',
270 'cpi18n',
271 $code_profiler_i18n
272 );
273 }
274
275 add_action('admin_enqueue_scripts', 'code_profiler_enqueue');
276
277 // =====================================================================
278 // Display the settings link in the "Plugins" page.
279
280 function code_profiler_settings_link( $links ) {
281
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://code-profiler.com/" target="_blank" rel="noopener noreferrer">'.
285 esc_html__('Go Pro', 'code-profiler'). '</a>';
286 return $links;
287 }
288
289 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link');
290
291 // =====================================================================
292 // WP CLI commands.
293
294 if ( defined('WP_CLI') && WP_CLI ) {
295 require_once __DIR__ . '/lib/class-cli.php';
296 }
297 // =====================================================================
298 // EOF
299