| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | Plugin URI: https://code-profiler.com/ |
| 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.5 | |
| 8 | +Version: 1.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.5' ); | |
| 15 | +define('CODE_PROFILER_VERSION', '1.6'); | |
| 16 | 16 | /* |
| 17 | 17 | +=====================================================================+ |
| 18 | 18 | | ____ _ ____ __ _ _ | |
| 19 | 19 | | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ | |
| @@ -24,9 +24,11 @@ | ||
| 24 | 24 | | (c) Jerome Bruandet ~ https://code-profiler.com/ | |
| 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'; |
| @@ -39,13 +41,13 @@ | ||
| 39 | 41 | |
| 40 | 42 | function code_profiler_activate() { |
| 41 | 43 | |
| 42 | 44 | if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) { |
| 43 | - exit( esc_html__( 'Your are not allowed to activate plugins.', 'code-profiler' ) ); | |
| 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, '4.7.0', '<') ) { | |
| 48 | 50 | exit( sprintf( |
| 49 | 51 | esc_html__('Code Profiler requires WordPress %s or greater but your current version is %s.', 'code-profiler'), |
| 50 | 52 | '4.7.0', |
| 51 | 53 | esc_html( $wp_version ) |
| @@ -51,18 +53,18 @@ | ||
| 51 | 53 | esc_html( $wp_version ) |
| 52 | 54 | ) ); |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | - if ( version_compare( PHP_VERSION, '7.1', '<' ) ) { | |
| 57 | + if ( version_compare( PHP_VERSION, '7.1', '<') ) { | |
| 56 | 58 | exit( sprintf( |
| 57 | - esc_html__( 'Code Profiler requires PHP 7.1 or greater but your current version is %s.', | |
| 58 | - 'code-profiler' ), | |
| 59 | + esc_html__('Code Profiler requires PHP 7.1 or greater but your current version is %s.', | |
| 60 | + 'code-profiler'), | |
| 59 | 61 | esc_html( PHP_VERSION ) |
| 60 | 62 | ) ); |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | // 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' ) ) { | |
| 66 | + if ( is_plugin_active('code-profiler-pro/index.php') ) { | |
| 65 | 67 | 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') ); |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | 70 | // Verify/create our storage folder |
| @@ -68,15 +70,15 @@ | ||
| 68 | 70 | // Verify/create our storage folder |
| 69 | 71 | code_profiler_check_uploadsdir(); |
| 70 | 72 | |
| 71 | 73 | // If we don't have any options yet, create them |
| 72 | - $cp_options = get_option( 'code-profiler' ); | |
| 74 | + $cp_options = get_option('code-profiler'); | |
| 73 | 75 | if ( $cp_options === false ) { |
| 74 | 76 | code_profiler_default_options(); |
| 75 | 77 | } |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | -register_activation_hook( __FILE__, 'code_profiler_activate' ); | |
| 80 | +register_activation_hook( __FILE__, 'code_profiler_activate'); | |
| 79 | 81 | |
| 80 | 82 | // ===================================================================== |
| 81 | 83 | // Deactivation. |
| 82 | 84 | |
| @@ -82,9 +84,9 @@ | ||
| 82 | 84 | |
| 83 | 85 | function code_profiler_deactivate() { |
| 84 | 86 | |
| 85 | 87 | if (! defined('WP_CLI') && ! current_user_can('activate_plugins') ) { |
| 86 | - exit( esc_html__( 'Your are not allowed to deactivate plugins.', 'code-profiler' ) ); | |
| 88 | + exit( esc_html__('Your are not allowed to deactivate plugins.', 'code-profiler') ); | |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | 91 | // Remove the MU plugin |
| 90 | 92 | if ( file_exists( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ) ) { |
| @@ -91,9 +93,9 @@ | ||
| 91 | 93 | unlink( WPMU_PLUGIN_DIR .'/'. CODE_PROFILER_MUPLUGIN ); |
| 92 | 94 | } |
| 93 | 95 | } |
| 94 | 96 | |
| 95 | -register_deactivation_hook( __FILE__, 'code_profiler_deactivate' ); | |
| 97 | +register_deactivation_hook( __FILE__, 'code_profiler_deactivate'); | |
| 96 | 98 | |
| 97 | 99 | // ===================================================================== |
| 98 | 100 | // Create Profiler's menu. |
| 99 | 101 | |
| @@ -109,13 +111,13 @@ | ||
| 109 | 111 | 'Code Profiler', |
| 110 | 112 | 'manage_options', |
| 111 | 113 | 'code-profiler', |
| 112 | 114 | 'code_profiler_main_menu', |
| 113 | - plugins_url( '/static/dashicon-16x16.png', __FILE__ ) | |
| 115 | + plugins_url('/static/dashicon-16x16.png', __FILE__ ) | |
| 114 | 116 | ); |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | -add_action( 'admin_menu', 'code_profiler_admin_menu' ); | |
| 119 | +add_action('admin_menu', 'code_profiler_admin_menu'); | |
| 118 | 120 | |
| 119 | 121 | // ===================================================================== |
| 120 | 122 | // Register scripts and styles. |
| 121 | 123 | |
| @@ -120,23 +122,26 @@ | ||
| 120 | 122 | // Register scripts and styles. |
| 121 | 123 | |
| 122 | 124 | function code_profiler_enqueue( $hook ) { |
| 123 | 125 | |
| 124 | - if (! is_super_admin() ) { return; } | |
| 126 | + if (! is_super_admin() ) { | |
| 127 | + return; | |
| 128 | + } | |
| 125 | 129 | |
| 126 | 130 | // Load files only if we're in Code Profiler's main page |
| 127 | - if ( $hook != 'toplevel_page_code-profiler' ) { return; } | |
| 131 | + if ( $hook != 'toplevel_page_code-profiler') { | |
| 132 | + return; | |
| 133 | + } | |
| 128 | 134 | |
| 129 | 135 | // We load Thickbox if we're viewing section 4 only |
| 130 | 136 | if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == 4 ) { |
| 131 | - $extra_js = array( 'jquery', 'thickbox' ); | |
| 132 | - $extra_css = array( 'thickbox' ); | |
| 137 | + $extra_js = array('jquery', 'thickbox'); | |
| 138 | + $extra_css = array('thickbox'); | |
| 133 | 139 | } else { |
| 134 | - $extra_js = array( 'jquery' ); | |
| 140 | + $extra_js = array('jquery'); | |
| 135 | 141 | $extra_css = null; |
| 136 | 142 | } |
| 137 | 143 | |
| 138 | - | |
| 139 | 144 | wp_enqueue_script( |
| 140 | 145 | 'code_profiler_javascript', |
| 141 | 146 | plugin_dir_url( __FILE__ ) . 'static/code-profiler.js', |
| 142 | 147 | $extra_js, |
| @@ -145,9 +150,9 @@ | ||
| 145 | 150 | |
| 146 | 151 | wp_enqueue_script( |
| 147 | 152 | 'code-profiler_tiptip', |
| 148 | 153 | plugin_dir_url( __FILE__ ) .'static/vendor/jquery.tipTip.js', |
| 149 | - array( 'jquery' ), | |
| 154 | + array('jquery'), | |
| 150 | 155 | CODE_PROFILER_VERSION |
| 151 | 156 | ); |
| 152 | 157 | |
| 153 | 158 | wp_enqueue_style( |
| @@ -157,13 +162,13 @@ | ||
| 157 | 162 | CODE_PROFILER_VERSION |
| 158 | 163 | ); |
| 159 | 164 | |
| 160 | 165 | // Enqueue Chart.js if we're viewing a profile |
| 161 | - if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'view_profile' ) { | |
| 166 | + if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'view_profile') { | |
| 162 | 167 | wp_enqueue_script( |
| 163 | 168 | 'code_profiler_charts', |
| 164 | 169 | plugin_dir_url( __FILE__ ) . 'static/vendor/chart.min.js', |
| 165 | - array( 'jquery' ), | |
| 170 | + array('jquery'), | |
| 166 | 171 | CODE_PROFILER_VERSION, |
| 167 | 172 | // We load it in the footer, because some plugins loads it too |
| 168 | 173 | // on every pages and that could mess with our pages |
| 169 | 174 | true |
| @@ -172,21 +177,23 @@ | ||
| 172 | 177 | |
| 173 | 178 | // JS i18n |
| 174 | 179 | $code_profiler_i18n = array( |
| 175 | 180 | 'missing_nonce' => |
| 176 | - esc_attr__('Security nonce is missing, try to reload the page.', 'code-profiler' ), | |
| 181 | + esc_attr__('Security nonce is missing, try to reload the page.', 'code-profiler'), | |
| 177 | 182 | 'missing_frontbackend' => |
| 178 | - esc_attr__('Please select either the fontend or backend option.', 'code-profiler' ), | |
| 183 | + esc_attr__('Please select either the fontend or backend option.', 'code-profiler'), | |
| 184 | + 'missing_profileid' => | |
| 185 | + esc_attr__('Missing profile identifier.', 'code-profiler'), | |
| 179 | 186 | 'missing_profilename' => |
| 180 | - esc_attr__('Please enter a name for this profile.', 'code-profiler' ), | |
| 187 | + esc_attr__('Please enter a name for this profile.', 'code-profiler'), | |
| 181 | 188 | 'missing_userauth' => |
| 182 | - esc_attr__('Please select whether the profiler should run as an authenticated user or not.', 'code-profiler' ), | |
| 189 | + esc_attr__('Please select whether the profiler should run as an authenticated user or not.', 'code-profiler'), | |
| 183 | 190 | 'missing_username' => |
| 184 | - esc_attr__('Please enter the name of the user.', 'code-profiler' ), | |
| 191 | + esc_attr__('Please enter the name of the user.', 'code-profiler'), | |
| 185 | 192 | 'missing_post' => |
| 186 | - esc_attr__('Please select a page to profile.', 'code-profiler' ), | |
| 193 | + esc_attr__('Please select a page to profile.', 'code-profiler'), | |
| 187 | 194 | 'unknown_error' => |
| 188 | - esc_attr__('Unknown error returned by AJAX', 'code-profiler' ), | |
| 195 | + esc_attr__('Unknown error returned by AJAX', 'code-profiler'), | |
| 189 | 196 | 'http_error' => |
| 190 | 197 | esc_attr__('The HTTP server returned the following error:', 'code-profiler'), |
| 191 | 198 | 'timeout_error' => |
| 192 | 199 | esc_attr__('You can try to select a lower Accuracy and Precision level in the Settings page', 'code-profiler'), |
| @@ -198,9 +205,9 @@ | ||
| 198 | 205 | 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'), |
| 199 | 206 | 'unknown_error' => |
| 200 | 207 | esc_attr__('An unknown error occurred:', 'code-profiler'), |
| 201 | 208 | 'preparing_report' => |
| 202 | - esc_attr__('Preparing report', 'code-profiler') .'...', | |
| 209 | + esc_attr__('Preparing the report', 'code-profiler') .'...', | |
| 203 | 210 | 'empty_log' => |
| 204 | 211 | esc_attr__('No records were found that match the specified search criteria.', 'code-profiler'), |
| 205 | 212 | 'delete_log' => |
| 206 | 213 | esc_attr__('Delete log?', 'code-profiler'), |
| @@ -227,12 +234,12 @@ | ||
| 227 | 234 | 'text_copied' => |
| 228 | 235 | esc_attr__('The text was successfully copied to the clipboard.', 'code-profiler') |
| 229 | 236 | |
| 230 | 237 | ); |
| 231 | - wp_localize_script( 'code_profiler_javascript', 'cpi18n', $code_profiler_i18n ); | |
| 238 | + wp_localize_script('code_profiler_javascript', 'cpi18n', $code_profiler_i18n ); | |
| 232 | 239 | } |
| 233 | 240 | |
| 234 | -add_action( 'admin_enqueue_scripts', 'code_profiler_enqueue' ); | |
| 241 | +add_action('admin_enqueue_scripts', 'code_profiler_enqueue'); | |
| 235 | 242 | |
| 236 | 243 | // ===================================================================== |
| 237 | 244 | // Display the settings link in the "Plugins" page. |
| 238 | 245 | |
| @@ -244,14 +251,14 @@ | ||
| 244 | 251 | esc_html__('Go Pro', 'code-profiler'). '</a>'; |
| 245 | 252 | return $links; |
| 246 | 253 | } |
| 247 | 254 | |
| 248 | -add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link' ); | |
| 255 | +add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'code_profiler_settings_link'); | |
| 249 | 256 | |
| 250 | 257 | // ===================================================================== |
| 251 | 258 | // WP CLI commands. |
| 252 | 259 | |
| 253 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 260 | +if ( defined('WP_CLI') && WP_CLI ) { | |
| 254 | 261 | require_once __DIR__ . '/lib/class-cli.php'; |
| 255 | 262 | } |
| 256 | 263 | // ===================================================================== |
| 257 | 264 | // EOF |