| @@ -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.6 | |
| 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,9 +11,9 @@ | ||
| 11 | 11 | Text Domain: code-profiler |
| 12 | 12 | Domain Path: /languages |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -define('CODE_PROFILER_VERSION', '1.6.6'); | |
| 15 | +define('CODE_PROFILER_VERSION', '1.9.6'); | |
| 16 | 16 | /** |
| 17 | 17 | +=====================================================================+ |
| 18 | 18 | | ____ _ ____ __ _ _ | |
| 19 | 19 | | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ | |
| @@ -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') ) { |
| @@ -28,27 +28,29 @@ | ||
| 28 | 28 | if (! defined('ABSPATH') ) { |
| 29 | 29 | die('Forbidden'); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -// ===================================================================== 2023-08-20 | |
| 32 | +// ===================================================================== | |
| 33 | 33 | // Menu functions |
| 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.', '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 | 51 | if ( version_compare( $wp_version, '5.0', '<') ) { |
| 50 | - exit( sprintf( | |
| 52 | + wp_die( sprintf( | |
| 51 | 53 | esc_html__('Code Profiler requires WordPress %s or greater but your current version is %s.', |
| 52 | 54 | 'code-profiler'), |
| 53 | 55 | '5.0', |
| 54 | 56 | esc_html( $wp_version ) |
| @@ -55,9 +57,9 @@ | ||
| 55 | 57 | ) ); |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | if ( version_compare( PHP_VERSION, '7.1', '<') ) { |
| 59 | - exit( sprintf( | |
| 61 | + wp_die( sprintf( | |
| 60 | 62 | esc_html__('Code Profiler requires PHP 7.1 or greater but your current version is %s.', |
| 61 | 63 | 'code-profiler'), |
| 62 | 64 | esc_html( PHP_VERSION ) |
| 63 | 65 | ) ); |
| @@ -64,9 +66,9 @@ | ||
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | // If the pro version is active, we refuse to run and throw an error message |
| 67 | 69 | if ( is_plugin_active('code-profiler-pro/index.php') ) { |
| 68 | - exit( esc_html__('Code Profiler Pro is active on this site, please disable it first if you '. | |
| 70 | + wp_die( esc_html__('Code Profiler Pro is active on this site, please disable it first if you '. | |
| 69 | 71 | 'want to run the free version.', 'code-profiler') |
| 70 | 72 | ); |
| 71 | 73 | } |
| 72 | 74 | |
| @@ -77,19 +79,26 @@ | ||
| 77 | 79 | $cp_options = get_option('code-profiler'); |
| 78 | 80 | if ( $cp_options === false ) { |
| 79 | 81 | code_profiler_default_options(); |
| 80 | 82 | } |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Install scheduled tasks on the main site only. | |
| 86 | + */ | |
| 87 | + if ( is_main_site() ) { | |
| 88 | + CodeProfiler_WPCron::install(); | |
| 89 | + } | |
| 81 | 90 | } |
| 82 | 91 | |
| 83 | 92 | register_activation_hook( __FILE__, 'code_profiler_activate'); |
| 84 | 93 | |
| 85 | -// ===================================================================== 2023-06-17 | |
| 94 | +// ===================================================================== | |
| 86 | 95 | // Deactivation. |
| 87 | 96 | |
| 88 | 97 | function code_profiler_deactivate() { |
| 89 | 98 | |
| 90 | 99 | if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) { |
| 91 | - 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') ); | |
| 92 | 101 | } |
| 93 | 102 | |
| 94 | 103 | // Remove the MU plugin |
| 95 | 104 | if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) { |
| @@ -94,13 +103,18 @@ | ||
| 94 | 103 | // Remove the MU plugin |
| 95 | 104 | if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) { |
| 96 | 105 | unlink( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ); |
| 97 | 106 | } |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Uninstall scheduled tasks. | |
| 110 | + */ | |
| 111 | + CodeProfiler_WPCron::uninstall(); | |
| 98 | 112 | } |
| 99 | 113 | |
| 100 | 114 | register_deactivation_hook( __FILE__, 'code_profiler_deactivate'); |
| 101 | 115 | |
| 102 | -// ===================================================================== 2023-06-14 | |
| 116 | +// ===================================================================== | |
| 103 | 117 | // Create Profiler's menu. |
| 104 | 118 | |
| 105 | 119 | function code_profiler_admin_menu() { |
| 106 | 120 | |
| @@ -195,10 +209,14 @@ | ||
| 195 | 209 | 'code-profiler'), |
| 196 | 210 | 'missing_username' => |
| 197 | 211 | esc_attr__('Please enter the name of the user.', 'code-profiler'), |
| 198 | 212 | 'missing_ajax' => |
| 199 | - esc_attr__('Please enter a valid AJAX payload, or change the content-type option. '. | |
| 200 | - 'If you want to send an empty value, enter: {}', 'code-profiler'), | |
| 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'), | |
| 201 | 219 | 'missing_post' => |
| 202 | 220 | esc_attr__('Please select a page to profile.', 'code-profiler'), |
| 203 | 221 | 'unknown_error' => |
| 204 | 222 | esc_attr__('Unknown error returned by AJAX', 'code-profiler'), |
| @@ -207,18 +225,14 @@ | ||
| 207 | 225 | 'timeout_error' => |
| 208 | 226 | esc_attr__('You can try to select a lower Accuracy and Precision level in the Settings page', |
| 209 | 227 | 'code-profiler'), |
| 210 | 228 | 'notfound_error' => |
| 211 | - esc_attr__('The requested page does not seem to exist. Please check the syntax of the URL '. | |
| 212 | - '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', | |
| 213 | 230 | 'code-profiler'), |
| 214 | 231 | 'forbidden_error' => |
| 215 | - esc_attr__('The server rejected and blocked the requested page. Make sure you are allowed '. | |
| 216 | - 'to access that page or that there is no security plugin or application blocking it', | |
| 217 | - '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'), | |
| 218 | 233 | 'internal_error' => |
| 219 | - esc_attr__('This is an internal server error. Please check your server, PHP and Code '. | |
| 220 | - 'Profiler logs as they may contain more 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'), | |
| 221 | 235 | 'unknown_error' => |
| 222 | 236 | esc_attr__('An unknown error occurred:', 'code-profiler'), |
| 223 | 237 | 'preparing_report' => |
| 224 | 238 | esc_attr__('Preparing the report', 'code-profiler') .'...', |
| @@ -266,9 +280,9 @@ | ||
| 266 | 280 | function code_profiler_settings_link( $links ) { |
| 267 | 281 | |
| 268 | 282 | $links[] = '<a href="'. get_admin_url( null, 'admin.php?page=code-profiler') .'">'. |
| 269 | 283 | esc_html__('Start Profiling', 'code-profiler'). '</a>'; |
| 270 | - $links[] = '<a style="font-weight:700;color:#006393;" href="https://code-profiler.com/" '. | |
| 284 | + $links[] = '<a style="font-weight:700;color:#006393;" href="https://nintechnet.com/codeprofiler/" '. | |
| 271 | 285 | 'target="_blank" rel="noopener noreferrer">'. |
| 272 | 286 | esc_html__('Go Pro', 'code-profiler'). '</a>'; |
| 273 | 287 | return $links; |
| 274 | 288 | } |