| @@ -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.4.3 | |
| 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.4.3' ); | |
| 16 | -/* | |
| 15 | +define('CODE_PROFILER_VERSION', '1.9.6'); | |
| 16 | +/** | |
| 17 | 17 | +=====================================================================+ |
| 18 | 18 | | ____ _ ____ __ _ _ | |
| 19 | 19 | | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ | |
| 20 | 20 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| @@ -20,13 +20,15 @@ | ||
| 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 | -if (! defined( 'ABSPATH' ) ) { die( 'Forbidden' ); } | |
| 28 | +if (! defined('ABSPATH') ) { | |
| 29 | + die('Forbidden'); | |
| 30 | +} | |
| 29 | 31 | |
| 30 | 32 | // ===================================================================== |
| 31 | 33 | // Menu functions |
| 32 | 34 | require __DIR__ .'/lib/menu.php'; |
| @@ -32,9 +34,11 @@ | ||
| 32 | 34 | require __DIR__ .'/lib/menu.php'; |
| 33 | 35 | // Helper (can be already loaded by the MU plugin) |
| 34 | 36 | require_once __DIR__ .'/lib/helper.php'; |
| 35 | 37 | // AJAX calls |
| 36 | -require __DIR__ .'/lib/ajax.php'; | |
| 38 | +require __DIR__ .'/lib/class-ajax.php'; | |
| 39 | +// Scheduled tasks | |
| 40 | +require_once __DIR__ .'/lib/class-wp-cron.php'; | |
| 37 | 41 | // ===================================================================== |
| 38 | 42 | // Activation: make sure the blog meets the requirements. |
| 39 | 43 | |
| 40 | 44 | function code_profiler_activate() { |
| @@ -39,31 +43,34 @@ | ||
| 39 | 43 | |
| 40 | 44 | function code_profiler_activate() { |
| 41 | 45 | |
| 42 | 46 | if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) { |
| 43 | - 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') ); | |
| 44 | 48 | } |
| 45 | 49 | |
| 46 | 50 | global $wp_version; |
| 47 | - if ( version_compare( $wp_version, '4.7.0', '<' ) ) { | |
| 48 | - exit( sprintf( | |
| 49 | - esc_html__('Code Profiler requires WordPress %s or greater but your current version is %s.', 'code-profiler'), | |
| 50 | - '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', | |
| 51 | 56 | esc_html( $wp_version ) |
| 52 | 57 | ) ); |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - if ( version_compare( PHP_VERSION, '7.1', '<' ) ) { | |
| 56 | - exit( sprintf( | |
| 57 | - esc_html__( 'Code Profiler requires PHP 7.1 or greater but your current version is %s.', | |
| 58 | - 'code-profiler' ), | |
| 60 | + if ( version_compare( PHP_VERSION, '7.1', '<') ) { | |
| 61 | + wp_die( sprintf( | |
| 62 | + esc_html__('Code Profiler requires PHP 7.1 or greater but your current version is %s.', | |
| 63 | + 'code-profiler'), | |
| 59 | 64 | esc_html( PHP_VERSION ) |
| 60 | 65 | ) ); |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | 68 | // If the pro version is active, we refuse to run and throw an error message |
| 64 | - if ( is_plugin_active( 'code-profiler-pro/index.php' ) ) { | |
| 65 | - 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') ); | |
| 69 | + if ( is_plugin_active('code-profiler-pro/index.php') ) { | |
| 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 | + ); | |
| 66 | 73 | } |
| 67 | 74 | |
| 68 | 75 | // Verify/create our storage folder |
| 69 | 76 | code_profiler_check_uploadsdir(); |
| @@ -68,15 +75,22 @@ | ||
| 68 | 75 | // Verify/create our storage folder |
| 69 | 76 | code_profiler_check_uploadsdir(); |
| 70 | 77 | |
| 71 | 78 | // If we don't have any options yet, create them |
| 72 | - $cp_options = get_option( 'code-profiler' ); | |
| 79 | + $cp_options = get_option('code-profiler'); | |
| 73 | 80 | if ( $cp_options === false ) { |
| 74 | 81 | code_profiler_default_options(); |
| 75 | 82 | } |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Install scheduled tasks on the main site only. | |
| 86 | + */ | |
| 87 | + if ( is_main_site() ) { | |
| 88 | + CodeProfiler_WPCron::install(); | |
| 89 | + } | |
| 76 | 90 | } |
| 77 | 91 | |
| 78 | -register_activation_hook( __FILE__, 'code_profiler_activate' ); | |
| 92 | +register_activation_hook( __FILE__, 'code_profiler_activate'); | |
| 79 | 93 | |
| 80 | 94 | // ===================================================================== |
| 81 | 95 | // Deactivation. |
| 82 | 96 | |
| @@ -82,18 +96,23 @@ | ||
| 82 | 96 | |
| 83 | 97 | function code_profiler_deactivate() { |
| 84 | 98 | |
| 85 | 99 | if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) { |
| 86 | - 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') ); | |
| 87 | 101 | } |
| 88 | 102 | |
| 89 | 103 | // Remove the MU plugin |
| 90 | - if ( file_exists( WPMU_PLUGIN_DIR .'/0----code-profiler.php' ) ) { | |
| 91 | - unlink( WPMU_PLUGIN_DIR .'/0----code-profiler.php' ); | |
| 104 | + if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) { | |
| 105 | + unlink( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ); | |
| 92 | 106 | } |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Uninstall scheduled tasks. | |
| 110 | + */ | |
| 111 | + CodeProfiler_WPCron::uninstall(); | |
| 93 | 112 | } |
| 94 | 113 | |
| 95 | -register_deactivation_hook( __FILE__, 'code_profiler_deactivate' ); | |
| 114 | +register_deactivation_hook( __FILE__, 'code_profiler_deactivate'); | |
| 96 | 115 | |
| 97 | 116 | // ===================================================================== |
| 98 | 117 | // Create Profiler's menu. |
| 99 | 118 | |
| @@ -109,37 +128,40 @@ | ||
| 109 | 128 | 'Code Profiler', |
| 110 | 129 | 'manage_options', |
| 111 | 130 | 'code-profiler', |
| 112 | 131 | 'code_profiler_main_menu', |
| 113 | - plugins_url( '/static/dashicon-16x16.png', __FILE__ ) | |
| 132 | + plugins_url('/static/dashicon-16x16.png', __FILE__ ) | |
| 114 | 133 | ); |
| 115 | 134 | } |
| 116 | 135 | |
| 117 | -add_action( 'admin_menu', 'code_profiler_admin_menu' ); | |
| 136 | +add_action('admin_menu', 'code_profiler_admin_menu'); | |
| 118 | 137 | |
| 119 | -// ===================================================================== | |
| 138 | +// ===================================================================== 2023-08-20 | |
| 120 | 139 | // Register scripts and styles. |
| 121 | 140 | |
| 122 | 141 | function code_profiler_enqueue( $hook ) { |
| 123 | 142 | |
| 124 | - if (! is_super_admin() ) { return; } | |
| 143 | + if (! is_super_admin() ) { | |
| 144 | + return; | |
| 145 | + } | |
| 125 | 146 | |
| 126 | 147 | // Load files only if we're in Code Profiler's main page |
| 127 | - if ( $hook != 'toplevel_page_code-profiler' ) { return; } | |
| 148 | + if ( $hook != 'toplevel_page_code-profiler') { | |
| 149 | + return; | |
| 150 | + } | |
| 128 | 151 | |
| 129 | 152 | // We load Thickbox if we're viewing section 4 only |
| 130 | 153 | if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 4 ) { |
| 131 | - $extra_js = array( 'jquery', 'thickbox' ); | |
| 132 | - $extra_css = array( 'thickbox' ); | |
| 154 | + $extra_js = ['jquery', 'thickbox']; | |
| 155 | + $extra_css = ['thickbox']; | |
| 133 | 156 | } else { |
| 134 | - $extra_js = array( 'jquery' ); | |
| 135 | - $extra_css = null; | |
| 157 | + $extra_js = ['jquery']; | |
| 158 | + $extra_css = null; | |
| 136 | 159 | } |
| 137 | 160 | |
| 138 | - | |
| 139 | 161 | wp_enqueue_script( |
| 140 | 162 | 'code_profiler_javascript', |
| 141 | - plugin_dir_url( __FILE__ ) . 'static/code-profiler.js', | |
| 163 | + plugin_dir_url( __FILE__ ) .'static/code-profiler.js', | |
| 142 | 164 | $extra_js, |
| 143 | 165 | CODE_PROFILER_VERSION |
| 144 | 166 | ); |
| 145 | 167 | |
| @@ -145,25 +167,27 @@ | ||
| 145 | 167 | |
| 146 | 168 | wp_enqueue_script( |
| 147 | 169 | 'code-profiler_tiptip', |
| 148 | 170 | plugin_dir_url( __FILE__ ) .'static/vendor/jquery.tipTip.js', |
| 149 | - array( 'jquery' ), | |
| 171 | + ['jquery'], | |
| 150 | 172 | CODE_PROFILER_VERSION |
| 151 | 173 | ); |
| 152 | 174 | |
| 153 | 175 | wp_enqueue_style( |
| 154 | 176 | 'code-profiler_style', |
| 155 | - plugin_dir_url( __FILE__ ) . 'static/code-profiler.css', | |
| 177 | + plugin_dir_url( __FILE__ ) .'static/code-profiler.css', | |
| 156 | 178 | $extra_css, |
| 157 | 179 | CODE_PROFILER_VERSION |
| 158 | 180 | ); |
| 159 | 181 | |
| 160 | 182 | // Enqueue Chart.js if we're viewing a profile |
| 161 | - if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'view_profile' ) { | |
| 183 | + if ( isset( $_REQUEST['action'] ) && | |
| 184 | + $_REQUEST['action'] == 'view_profile') { | |
| 185 | + | |
| 162 | 186 | wp_enqueue_script( |
| 163 | 187 | 'code_profiler_charts', |
| 164 | - plugin_dir_url( __FILE__ ) . 'static/vendor/chart.min.js', | |
| 165 | - array( 'jquery' ), | |
| 188 | + plugin_dir_url( __FILE__ ) .'static/vendor/chart.min.js', | |
| 189 | + ['jquery'], | |
| 166 | 190 | CODE_PROFILER_VERSION, |
| 167 | 191 | // We load it in the footer, because some plugins loads it too |
| 168 | 192 | // on every pages and that could mess with our pages |
| 169 | 193 | true |
| @@ -170,31 +194,52 @@ | ||
| 170 | 194 | ); |
| 171 | 195 | } |
| 172 | 196 | |
| 173 | 197 | // JS i18n |
| 174 | - $code_profiler_i18n = array( | |
| 198 | + $code_profiler_i18n = [ | |
| 175 | 199 | 'missing_nonce' => |
| 176 | - esc_attr__('Security nonce is missing, try to reload the page.', 'code-profiler' ), | |
| 200 | + esc_attr__('Security nonce is missing, try to reload the page.', 'code-profiler'), | |
| 177 | 201 | 'missing_frontbackend' => |
| 178 | - esc_attr__('Please select either the fontend or backend option.', 'code-profiler' ), | |
| 202 | + esc_attr__('Please select either the fontend or backend option.', 'code-profiler'), | |
| 203 | + 'missing_profileid' => | |
| 204 | + esc_attr__('Missing profile identifier.', 'code-profiler'), | |
| 179 | 205 | 'missing_profilename' => |
| 180 | - esc_attr__('Please enter a name for this profile.', 'code-profiler' ), | |
| 206 | + esc_attr__('Please enter a name for this profile.', 'code-profiler'), | |
| 181 | 207 | 'missing_userauth' => |
| 182 | - 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'), | |
| 183 | 210 | 'missing_username' => |
| 184 | - esc_attr__('Please enter the name of the user.', 'code-profiler' ), | |
| 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'), | |
| 185 | 219 | 'missing_post' => |
| 186 | - esc_attr__('Please select a page to profile.', 'code-profiler' ), | |
| 220 | + esc_attr__('Please select a page to profile.', 'code-profiler'), | |
| 187 | 221 | 'unknown_error' => |
| 188 | - esc_attr__('Unknown error returned by AJAX', 'code-profiler' ), | |
| 222 | + esc_attr__('Unknown error returned by AJAX', 'code-profiler'), | |
| 189 | 223 | 'http_error' => |
| 190 | 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', | |
| 227 | + 'code-profiler'), | |
| 228 | + 'notfound_error' => | |
| 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'), | |
| 231 | + 'forbidden_error' => | |
| 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'), | |
| 233 | + 'internal_error' => | |
| 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'), | |
| 191 | 235 | 'unknown_error' => |
| 192 | 236 | esc_attr__('An unknown error occurred:', 'code-profiler'), |
| 193 | 237 | 'preparing_report' => |
| 194 | - esc_attr__('Preparing report', 'code-profiler') .'...', | |
| 238 | + esc_attr__('Preparing the report', 'code-profiler') .'...', | |
| 195 | 239 | 'empty_log' => |
| 196 | - 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'), | |
| 197 | 242 | 'delete_log' => |
| 198 | 243 | esc_attr__('Delete log?', 'code-profiler'), |
| 199 | 244 | 'delete_profile' => |
| 200 | 245 | esc_attr__('Delete this profile?', 'code-profiler'), |
| @@ -214,34 +259,41 @@ | ||
| 214 | 259 | esc_attr__('File I/O operations', 'code-profiler'), |
| 215 | 260 | 'disk_io_bytes' => |
| 216 | 261 | esc_attr__('Total bytes', 'code-profiler'), |
| 217 | 262 | 'disk_io_title' => |
| 218 | - esc_attr__('Total Disk I/O read and write, in bytes', 'code-profiler') | |
| 263 | + esc_attr__('Total Disk I/O read and write, in bytes', 'code-profiler'), | |
| 264 | + 'text_copied' => | |
| 265 | + esc_attr__('The text was successfully copied to the clipboard.', 'code-profiler') | |
| 219 | 266 | |
| 267 | + ]; | |
| 268 | + wp_localize_script( | |
| 269 | + 'code_profiler_javascript', | |
| 270 | + 'cpi18n', | |
| 271 | + $code_profiler_i18n | |
| 220 | 272 | ); |
| 221 | - wp_localize_script( 'code_profiler_javascript', 'cpi18n', $code_profiler_i18n ); | |
| 222 | 273 | } |
| 223 | 274 | |
| 224 | -add_action( 'admin_enqueue_scripts', 'code_profiler_enqueue' ); | |
| 275 | +add_action('admin_enqueue_scripts', 'code_profiler_enqueue'); | |
| 225 | 276 | |
| 226 | -// ===================================================================== | |
| 277 | +// ===================================================================== 2023-08-20 | |
| 227 | 278 | // Display the settings link in the "Plugins" page. |
| 228 | 279 | |
| 229 | 280 | function code_profiler_settings_link( $links ) { |
| 230 | 281 | |
| 231 | - $links[] = '<a href="'. get_admin_url( null, 'admin.php?page=code-profiler') . | |
| 232 | - '">'. esc_html__('Start Profiling', 'code-profiler'). '</a>'; | |
| 233 | - $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">'. | |
| 234 | 286 | esc_html__('Go Pro', 'code-profiler'). '</a>'; |
| 235 | 287 | return $links; |
| 236 | 288 | } |
| 237 | 289 | |
| 238 | -add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link' ); | |
| 290 | +add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link'); | |
| 239 | 291 | |
| 240 | -// ===================================================================== | |
| 292 | +// ===================================================================== 2023-08-20 | |
| 241 | 293 | // WP CLI commands. |
| 242 | 294 | |
| 243 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 295 | +if ( defined('WP_CLI') && WP_CLI ) { | |
| 244 | 296 | require_once __DIR__ . '/lib/class-cli.php'; |
| 245 | 297 | } |
| 246 | 298 | // ===================================================================== |
| 247 | 299 | // EOF |