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