| @@ -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.4 | |
| 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.4'); | |
| 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,25 +34,25 @@ | ||
| 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'; | |
| 39 | -// ===================================================================== 2023-06-17 | |
| 38 | +require __DIR__ .'/lib/class-ajax.php'; | |
| 39 | +// Scheduled tasks | |
| 40 | +require_once __DIR__ .'/lib/class-wp-cron.php'; | |
| 41 | +// ===================================================================== | |
| 40 | 42 | // Activation: make sure the blog meets the requirements. |
| 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.', | |
| 46 | - 'code-profiler') | |
| 47 | - ); | |
| 47 | + wp_die( esc_html__('Your are not allowed to activate plugins.', 'code-profiler') ); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | global $wp_version; |
| 51 | 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'), | |
| 52 | + wp_die( sprintf( | |
| 53 | + esc_html__('Code Profiler requires WordPress %s or greater but your current version is %s.', | |
| 54 | + 'code-profiler'), | |
| 55 | 55 | '5.0', |
| 56 | 56 | esc_html( $wp_version ) |
| 57 | 57 | ) ); |
| 58 | 58 | } |
| @@ -57,11 +57,10 @@ | ||
| 57 | 57 | ) ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 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.', | |
| 61 | + wp_die( sprintf( | |
| 62 | + esc_html__('Code Profiler requires PHP 7.1 or greater but your current version is %s.', | |
| 64 | 63 | 'code-profiler'), |
| 65 | 64 | esc_html( PHP_VERSION ) |
| 66 | 65 | ) ); |
| 67 | 66 | } |
| @@ -67,11 +66,10 @@ | ||
| 67 | 66 | } |
| 68 | 67 | |
| 69 | 68 | // If the pro version is active, we refuse to run and throw an error message |
| 70 | 69 | 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') | |
| 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') | |
| 74 | 72 | ); |
| 75 | 73 | } |
| 76 | 74 | |
| 77 | 75 | // Verify/create our storage folder |
| @@ -81,21 +79,26 @@ | ||
| 81 | 79 | $cp_options = get_option('code-profiler'); |
| 82 | 80 | if ( $cp_options === false ) { |
| 83 | 81 | code_profiler_default_options(); |
| 84 | 82 | } |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Install scheduled tasks on the main site only. | |
| 86 | + */ | |
| 87 | + if ( is_main_site() ) { | |
| 88 | + CodeProfiler_WPCron::install(); | |
| 89 | + } | |
| 85 | 90 | } |
| 86 | 91 | |
| 87 | 92 | register_activation_hook( __FILE__, 'code_profiler_activate'); |
| 88 | 93 | |
| 89 | -// ===================================================================== 2023-06-17 | |
| 94 | +// ===================================================================== | |
| 90 | 95 | // Deactivation. |
| 91 | 96 | |
| 92 | 97 | function code_profiler_deactivate() { |
| 93 | 98 | |
| 94 | 99 | if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) { |
| 95 | - exit( esc_html__('Your are not allowed to deactivate plugins.', | |
| 96 | - 'code-profiler') | |
| 97 | - ); | |
| 100 | + wp_die( esc_html__('Your are not allowed to deactivate plugins.', 'code-profiler') ); | |
| 98 | 101 | } |
| 99 | 102 | |
| 100 | 103 | // Remove the MU plugin |
| 101 | 104 | if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) { |
| @@ -100,13 +103,18 @@ | ||
| 100 | 103 | // Remove the MU plugin |
| 101 | 104 | if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) { |
| 102 | 105 | unlink( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ); |
| 103 | 106 | } |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Uninstall scheduled tasks. | |
| 110 | + */ | |
| 111 | + CodeProfiler_WPCron::uninstall(); | |
| 104 | 112 | } |
| 105 | 113 | |
| 106 | 114 | register_deactivation_hook( __FILE__, 'code_profiler_deactivate'); |
| 107 | 115 | |
| 108 | -// ===================================================================== 2023-06-14 | |
| 116 | +// ===================================================================== | |
| 109 | 117 | // Create Profiler's menu. |
| 110 | 118 | |
| 111 | 119 | function code_profiler_admin_menu() { |
| 112 | 120 | |
| @@ -126,9 +134,9 @@ | ||
| 126 | 134 | } |
| 127 | 135 | |
| 128 | 136 | add_action('admin_menu', 'code_profiler_admin_menu'); |
| 129 | 137 | |
| 130 | -// ===================================================================== | |
| 138 | +// ===================================================================== 2023-08-20 | |
| 131 | 139 | // Register scripts and styles. |
| 132 | 140 | |
| 133 | 141 | function code_profiler_enqueue( $hook ) { |
| 134 | 142 | |
| @@ -188,55 +196,50 @@ | ||
| 188 | 196 | |
| 189 | 197 | // JS i18n |
| 190 | 198 | $code_profiler_i18n = [ |
| 191 | 199 | 'missing_nonce' => |
| 192 | - esc_attr__('Security nonce is missing, try to reload the page.', | |
| 193 | - 'code-profiler'), | |
| 200 | + esc_attr__('Security nonce is missing, try to reload the page.', 'code-profiler'), | |
| 194 | 201 | 'missing_frontbackend' => |
| 195 | - esc_attr__('Please select either the fontend or backend option.', | |
| 196 | - 'code-profiler'), | |
| 202 | + esc_attr__('Please select either the fontend or backend option.', 'code-profiler'), | |
| 197 | 203 | 'missing_profileid' => |
| 198 | 204 | esc_attr__('Missing profile identifier.', 'code-profiler'), |
| 199 | 205 | 'missing_profilename' => |
| 200 | - esc_attr__('Please enter a name for this profile.', | |
| 206 | + esc_attr__('Please enter a name for this profile.', 'code-profiler'), | |
| 207 | + 'missing_userauth' => | |
| 208 | + esc_attr__('Please select whether the profiler should run as an authenticated user or not.', | |
| 201 | 209 | '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 | 210 | 'missing_username' => |
| 206 | - esc_attr__('Please enter the name of the user.', | |
| 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.', | |
| 207 | 216 | 'code-profiler'), |
| 217 | + 'multiline_raw' => | |
| 218 | + esc_attr__('The raw POST payload should be on one single line only.', 'code-profiler'), | |
| 208 | 219 | 'missing_post' => |
| 209 | - esc_attr__('Please select a page to profile.', | |
| 210 | - 'code-profiler'), | |
| 220 | + esc_attr__('Please select a page to profile.', 'code-profiler'), | |
| 211 | 221 | 'unknown_error' => |
| 212 | - esc_attr__('Unknown error returned by AJAX', | |
| 213 | - 'code-profiler'), | |
| 222 | + esc_attr__('Unknown error returned by AJAX', 'code-profiler'), | |
| 214 | 223 | 'http_error' => |
| 215 | - esc_attr__('The HTTP server returned the following error:', | |
| 224 | + esc_attr__('The HTTP server returned the following error:', 'code-profiler'), | |
| 225 | + 'timeout_error' => | |
| 226 | + esc_attr__('You can try to select a lower Accuracy and Precision level in the Settings page', | |
| 216 | 227 | '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 | 228 | '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', | |
| 229 | + esc_attr__('The requested page does not seem to exist. Please check the syntax of the URL you want to profile', | |
| 223 | 230 | 'code-profiler'), |
| 224 | 231 | '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'), | |
| 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'), | |
| 228 | 233 | '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'), | |
| 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'), | |
| 232 | 235 | 'unknown_error' => |
| 233 | 236 | esc_attr__('An unknown error occurred:', 'code-profiler'), |
| 234 | 237 | 'preparing_report' => |
| 235 | 238 | esc_attr__('Preparing the report', 'code-profiler') .'...', |
| 236 | 239 | 'empty_log' => |
| 237 | - esc_attr__('No records were found that match the specified '. | |
| 238 | - 'search criteria.', 'code-profiler'), | |
| 240 | + esc_attr__('No records were found that match the specified search criteria.', | |
| 241 | + 'code-profiler'), | |
| 239 | 242 | 'delete_log' => |
| 240 | 243 | esc_attr__('Delete log?', 'code-profiler'), |
| 241 | 244 | 'delete_profile' => |
| 242 | 245 | esc_attr__('Delete this profile?', 'code-profiler'), |
| @@ -246,10 +249,9 @@ | ||
| 246 | 249 | 'pc_plugins' => |
| 247 | 250 | /* Translators: xx% of all plugins and the theme */ |
| 248 | 251 | esc_attr__('% of all plugins and the theme', 'code-profiler'), |
| 249 | 252 | 'exec_tot_plugins_1' => |
| 250 | - esc_attr__('Plugins and theme execution time, in seconds', | |
| 251 | - 'code-profiler'), | |
| 253 | + esc_attr__('Plugins and theme execution time, in seconds', 'code-profiler'), | |
| 252 | 254 | 'chart_total' => |
| 253 | 255 | esc_attr__('total:', 'code-profiler'), |
| 254 | 256 | 'iolist_total_calls' => |
| 255 | 257 | esc_attr__('Total calls', 'code-profiler'), |
| @@ -257,13 +259,11 @@ | ||
| 257 | 259 | esc_attr__('File I/O operations', 'code-profiler'), |
| 258 | 260 | 'disk_io_bytes' => |
| 259 | 261 | esc_attr__('Total bytes', 'code-profiler'), |
| 260 | 262 | 'disk_io_title' => |
| 261 | - esc_attr__('Total Disk I/O read and write, in bytes', | |
| 262 | - 'code-profiler'), | |
| 263 | + esc_attr__('Total Disk I/O read and write, in bytes', 'code-profiler'), | |
| 263 | 264 | 'text_copied' => |
| 264 | - esc_attr__('The text was successfully copied to the clipboard.', | |
| 265 | - 'code-profiler') | |
| 265 | + esc_attr__('The text was successfully copied to the clipboard.', 'code-profiler') | |
| 266 | 266 | |
| 267 | 267 | ]; |
| 268 | 268 | wp_localize_script( |
| 269 | 269 | 'code_profiler_javascript', |
| @@ -273,16 +273,17 @@ | ||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | add_action('admin_enqueue_scripts', 'code_profiler_enqueue'); |
| 276 | 276 | |
| 277 | -// ===================================================================== | |
| 277 | +// ===================================================================== 2023-08-20 | |
| 278 | 278 | // Display the settings link in the "Plugins" page. |
| 279 | 279 | |
| 280 | 280 | function code_profiler_settings_link( $links ) { |
| 281 | 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">'. | |
| 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">'. | |
| 285 | 286 | esc_html__('Go Pro', 'code-profiler'). '</a>'; |
| 286 | 287 | return $links; |
| 287 | 288 | } |
| 288 | 289 | |
| @@ -287,9 +288,9 @@ | ||
| 287 | 288 | } |
| 288 | 289 | |
| 289 | 290 | add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link'); |
| 290 | 291 | |
| 291 | -// ===================================================================== | |
| 292 | +// ===================================================================== 2023-08-20 | |
| 292 | 293 | // WP CLI commands. |
| 293 | 294 | |
| 294 | 295 | if ( defined('WP_CLI') && WP_CLI ) { |
| 295 | 296 | require_once __DIR__ . '/lib/class-cli.php'; |