| Conditions | 58 |
| Paths | > 20000 |
| Total Lines | 270 |
| Code Lines | 163 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 72 | function give_tools_sysinfo_get() { |
||
| 73 | global $wpdb, $give_options; |
||
| 74 | |||
| 75 | if ( ! class_exists( 'Browser' ) ) { |
||
| 76 | require_once GIVE_PLUGIN_DIR . 'includes/libraries/browser.php'; |
||
| 77 | } |
||
| 78 | |||
| 79 | $browser = new Browser(); |
||
| 80 | |||
| 81 | // Get theme info |
||
| 82 | if ( get_bloginfo( 'version' ) < '3.4' ) { |
||
| 83 | $theme_data = wp_get_theme( get_stylesheet_directory() . '/style.css' ); |
||
| 84 | $theme = $theme_data['Name'] . ' ' . $theme_data['Version']; |
||
| 85 | } else { |
||
| 86 | $theme_data = wp_get_theme(); |
||
| 87 | $theme = $theme_data->Name . ' ' . $theme_data->Version; |
||
| 88 | } |
||
| 89 | |||
| 90 | // Try to identify the hosting provider |
||
| 91 | $host = give_get_host(); |
||
| 92 | |||
| 93 | $return = '### Begin System Info ###' . "\n\n"; |
||
| 94 | |||
| 95 | // Start with the basics... |
||
| 96 | $return .= '-- Site Info' . "\n\n"; |
||
| 97 | $return .= 'Site URL: ' . site_url() . "\n"; |
||
| 98 | $return .= 'Home URL: ' . home_url() . "\n"; |
||
| 99 | $return .= 'Multisite: ' . ( is_multisite() ? 'Yes' : 'No' ) . "\n"; |
||
| 100 | |||
| 101 | $return = apply_filters( 'give_sysinfo_after_site_info', $return ); |
||
| 102 | |||
| 103 | // Can we determine the site's host? |
||
| 104 | if ( $host ) { |
||
| 105 | $return .= "\n" . '-- Hosting Provider' . "\n\n"; |
||
| 106 | $return .= 'Host: ' . $host . "\n"; |
||
| 107 | |||
| 108 | $return = apply_filters( 'give_sysinfo_after_host_info', $return ); |
||
| 109 | } |
||
| 110 | |||
| 111 | // The local users' browser information, handled by the Browser class |
||
| 112 | $return .= "\n" . '-- User Browser' . "\n\n"; |
||
| 113 | $return .= $browser; |
||
| 114 | |||
| 115 | $return = apply_filters( 'give_sysinfo_after_user_browser', $return ); |
||
| 116 | |||
| 117 | // WordPress configuration |
||
| 118 | $return .= "\n" . '-- WordPress Configuration' . "\n\n"; |
||
| 119 | $return .= 'Version: ' . get_bloginfo( 'version' ) . "\n"; |
||
| 120 | $return .= 'Language: ' . ( defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US' ) . "\n"; |
||
| 121 | $return .= 'Permalink Structure: ' . ( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' ) . "\n"; |
||
| 122 | $return .= 'Active Theme: ' . $theme . "\n"; |
||
| 123 | $return .= 'Show On Front: ' . get_option( 'show_on_front' ) . "\n"; |
||
| 124 | |||
| 125 | // Only show page specs if frontpage is set to 'page' |
||
| 126 | if ( get_option( 'show_on_front' ) == 'page' ) { |
||
| 127 | $front_page_id = get_option( 'page_on_front' ); |
||
| 128 | $blog_page_id = get_option( 'page_for_posts' ); |
||
| 129 | |||
| 130 | $return .= 'Page On Front: ' . ( $front_page_id != 0 ? get_the_title( $front_page_id ) . ' (#' . $front_page_id . ')' : 'Unset' ) . "\n"; |
||
| 131 | $return .= 'Page For Posts: ' . ( $blog_page_id != 0 ? get_the_title( $blog_page_id ) . ' (#' . $blog_page_id . ')' : 'Unset' ) . "\n"; |
||
| 132 | } |
||
| 133 | |||
| 134 | // Make sure wp_remote_post() is working |
||
| 135 | $request['cmd'] = '_notify-validate'; |
||
| 136 | |||
| 137 | $params = array( |
||
| 138 | 'sslverify' => false, |
||
| 139 | 'timeout' => 60, |
||
| 140 | 'user-agent' => 'Give/' . GIVE_VERSION, |
||
| 141 | 'body' => $request |
||
| 142 | ); |
||
| 143 | |||
| 144 | $response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params ); |
||
| 145 | |||
| 146 | if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) { |
||
| 147 | $WP_REMOTE_POST = 'wp_remote_post() works'; |
||
| 148 | } else { |
||
| 149 | $WP_REMOTE_POST = 'wp_remote_post() does not work'; |
||
| 150 | } |
||
| 151 | |||
| 152 | $return .= 'Remote Post: ' . $WP_REMOTE_POST . "\n"; |
||
| 153 | $return .= 'Table Prefix: ' . 'Length: ' . strlen( $wpdb->prefix ) . ' Status: ' . ( strlen( $wpdb->prefix ) > 16 ? 'ERROR: Too long' : 'Acceptable' ) . "\n"; |
||
| 154 | $return .= 'Admin AJAX: ' . ( give_test_ajax_works() ? 'Accessible' : 'Inaccessible' ) . "\n"; |
||
| 155 | $return .= 'WP_DEBUG: ' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ) . "\n"; |
||
| 156 | $return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; |
||
| 157 | $return .= 'Registered Post Stati: ' . implode( ', ', get_post_stati() ) . "\n"; |
||
| 158 | |||
| 159 | $return = apply_filters( 'give_sysinfo_after_wordpress_config', $return ); |
||
| 160 | |||
| 161 | // GIVE configuration |
||
| 162 | $return .= "\n" . '-- Give Configuration' . "\n\n"; |
||
| 163 | $return .= 'Version: ' . GIVE_VERSION . "\n"; |
||
| 164 | $return .= 'Upgraded From: ' . get_option( 'give_version_upgraded_from', 'None' ) . "\n"; |
||
| 165 | $return .= 'Test Mode: ' . ( give_is_test_mode() ? "Enabled\n" : "Disabled\n" ); |
||
| 166 | $return .= 'Currency Code: ' . give_get_currency() . "\n"; |
||
| 167 | $return .= 'Currency Position: ' . give_get_option( 'currency_position', 'before' ) . "\n"; |
||
| 168 | $return .= 'Decimal Separator: ' . give_get_option( 'decimal_separator', '.' ) . "\n"; |
||
| 169 | $return .= 'Thousands Separator: ' . give_get_option( 'thousands_separator', ',' ) . "\n"; |
||
| 170 | |||
| 171 | $return = apply_filters( 'give_sysinfo_after_give_config', $return ); |
||
| 172 | |||
| 173 | // GIVE pages |
||
| 174 | $return .= "\n" . '-- Give Page Configuration' . "\n\n"; |
||
| 175 | $return .= 'Success Page: ' . ( ! empty( $give_options['success_page'] ) ? get_permalink( $give_options['success_page'] ) . "\n" : "Unset\n" ); |
||
| 176 | $return .= 'Failure Page: ' . ( ! empty( $give_options['failure_page'] ) ? get_permalink( $give_options['failure_page'] ) . "\n" : "Unset\n" ); |
||
| 177 | $return .= 'Give Forms Slug: ' . ( defined( 'GIVE_SLUG' ) ? '/' . GIVE_SLUG . "\n" : "/donations\n" ); |
||
| 178 | |||
| 179 | $return = apply_filters( 'give_sysinfo_after_give_pages', $return ); |
||
| 180 | |||
| 181 | // GIVE gateways |
||
| 182 | $return .= "\n" . '-- Give Gateway Configuration' . "\n\n"; |
||
| 183 | |||
| 184 | $active_gateways = give_get_enabled_payment_gateways(); |
||
| 185 | if ( $active_gateways ) { |
||
| 186 | $default_gateway_is_active = give_is_gateway_active( give_get_default_gateway( null ) ); |
||
| 187 | if ( $default_gateway_is_active ) { |
||
| 188 | $default_gateway = give_get_default_gateway( null ); |
||
| 189 | $default_gateway = $active_gateways[ $default_gateway ]['admin_label']; |
||
| 190 | } else { |
||
| 191 | $default_gateway = 'Test Payment'; |
||
| 192 | } |
||
| 193 | |||
| 194 | $gateways = array(); |
||
| 195 | foreach ( $active_gateways as $gateway ) { |
||
| 196 | $gateways[] = $gateway['admin_label']; |
||
| 197 | } |
||
| 198 | |||
| 199 | $return .= 'Enabled Gateways: ' . implode( ', ', $gateways ) . "\n"; |
||
| 200 | $return .= 'Default Gateway: ' . $default_gateway . "\n"; |
||
| 201 | } else { |
||
| 202 | $return .= 'Enabled Gateways: None' . "\n"; |
||
| 203 | } |
||
| 204 | |||
| 205 | $return = apply_filters( 'give_sysinfo_after_give_gateways', $return ); |
||
| 206 | |||
| 207 | // GIVE Templates |
||
| 208 | $dir = get_stylesheet_directory() . '/give_templates/*'; |
||
| 209 | if ( is_dir( $dir ) && ( count( glob( "$dir/*" ) ) !== 0 ) ) { |
||
| 210 | $return .= "\n" . '-- Give Template Overrides' . "\n\n"; |
||
| 211 | |||
| 212 | foreach ( glob( $dir ) as $file ) { |
||
| 213 | $return .= 'Filename: ' . basename( $file ) . "\n"; |
||
| 214 | } |
||
| 215 | |||
| 216 | $return = apply_filters( 'give_sysinfo_after_give_templates', $return ); |
||
| 217 | } |
||
| 218 | |||
| 219 | // Must-use plugins |
||
| 220 | $muplugins = get_mu_plugins(); |
||
| 221 | if ( count( $muplugins > 0 ) ) { |
||
| 222 | $return .= "\n" . '-- Must-Use Plugins' . "\n\n"; |
||
| 223 | |||
| 224 | foreach ( $muplugins as $plugin => $plugin_data ) { |
||
| 225 | $return .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "\n"; |
||
| 226 | } |
||
| 227 | |||
| 228 | $return = apply_filters( 'give_sysinfo_after_wordpress_mu_plugins', $return ); |
||
| 229 | } |
||
| 230 | |||
| 231 | // WordPress active plugins |
||
| 232 | $return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; |
||
| 233 | |||
| 234 | $plugins = get_plugins(); |
||
| 235 | $active_plugins = get_option( 'active_plugins', array() ); |
||
| 236 | |||
| 237 | foreach ( $plugins as $plugin_path => $plugin ) { |
||
| 238 | if ( ! in_array( $plugin_path, $active_plugins ) ) { |
||
| 239 | continue; |
||
| 240 | } |
||
| 241 | |||
| 242 | $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
||
| 243 | } |
||
| 244 | |||
| 245 | $return = apply_filters( 'give_sysinfo_after_wordpress_plugins', $return ); |
||
| 246 | |||
| 247 | // WordPress inactive plugins |
||
| 248 | $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; |
||
| 249 | |||
| 250 | foreach ( $plugins as $plugin_path => $plugin ) { |
||
| 251 | if ( in_array( $plugin_path, $active_plugins ) ) { |
||
| 252 | continue; |
||
| 253 | } |
||
| 254 | |||
| 255 | $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
||
| 256 | } |
||
| 257 | |||
| 258 | $return = apply_filters( 'give_sysinfo_after_wordpress_plugins_inactive', $return ); |
||
| 259 | |||
| 260 | if ( is_multisite() ) { |
||
| 261 | // WordPress Multisite active plugins |
||
| 262 | $return .= "\n" . '-- Network Active Plugins' . "\n\n"; |
||
| 263 | |||
| 264 | $plugins = wp_get_active_network_plugins(); |
||
| 265 | $active_plugins = get_site_option( 'active_sitewide_plugins', array() ); |
||
| 266 | |||
| 267 | foreach ( $plugins as $plugin_path ) { |
||
| 268 | $plugin_base = plugin_basename( $plugin_path ); |
||
| 269 | |||
| 270 | if ( ! array_key_exists( $plugin_base, $active_plugins ) ) { |
||
| 271 | continue; |
||
| 272 | } |
||
| 273 | |||
| 274 | $plugin = get_plugin_data( $plugin_path ); |
||
| 275 | $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
||
| 276 | } |
||
| 277 | |||
| 278 | $return = apply_filters( 'give_sysinfo_after_wordpress_ms_plugins', $return ); |
||
| 279 | } |
||
| 280 | |||
| 281 | // Server configuration (really just versioning) |
||
| 282 | $return .= "\n" . '-- Webserver Configuration' . "\n\n"; |
||
| 283 | $return .= 'PHP Version: ' . PHP_VERSION . "\n"; |
||
| 284 | $return .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; |
||
| 285 | $return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; |
||
| 286 | |||
| 287 | $return = apply_filters( 'give_sysinfo_after_webserver_config', $return ); |
||
| 288 | |||
| 289 | // PHP configs... now we're getting to the important stuff |
||
| 290 | $return .= "\n" . '-- PHP Configuration' . "\n\n"; |
||
| 291 | $return .= 'Safe Mode: ' . ( ini_get( 'safe_mode' ) ? 'Enabled' : 'Disabled' . "\n" ); |
||
| 292 | $return .= 'Memory Limit: ' . ini_get( 'memory_limit' ) . "\n"; |
||
| 293 | $return .= 'Upload Max Size: ' . ini_get( 'upload_max_filesize' ) . "\n"; |
||
| 294 | $return .= 'Post Max Size: ' . ini_get( 'post_max_size' ) . "\n"; |
||
| 295 | $return .= 'Upload Max Filesize: ' . ini_get( 'upload_max_filesize' ) . "\n"; |
||
| 296 | $return .= 'Time Limit: ' . ini_get( 'max_execution_time' ) . "\n"; |
||
| 297 | $return .= 'Max Input Vars: ' . ini_get( 'max_input_vars' ) . "\n"; |
||
| 298 | $return .= 'URL-aware fopen: ' . ( ini_get( 'allow_url_fopen' ) ? 'On (' . ini_get( 'allow_url_fopen' ) . ')' : 'N/A' ) . "\n"; |
||
| 299 | $return .= 'Display Errors: ' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ) . "\n"; |
||
| 300 | |||
| 301 | $return = apply_filters( 'give_sysinfo_after_php_config', $return ); |
||
| 302 | |||
| 303 | // PHP extensions and such |
||
| 304 | $return .= "\n" . '-- PHP Extensions' . "\n\n"; |
||
| 305 | $return .= 'cURL: ' . ( function_exists( 'curl_init' ) ? 'Supported' : 'Not Supported' ) . "\n"; |
||
| 306 | |||
| 307 | //cURL version |
||
| 308 | if ( function_exists( 'curl_init' ) && function_exists( 'curl_version' ) ) { |
||
| 309 | $curl_values = curl_version(); |
||
| 310 | $return .= 'cURL Version: ' . $curl_values["version"] . "\n"; |
||
| 311 | } |
||
| 312 | $return .= 'zlib: ' . ( function_exists( 'gzcompress' ) ? 'Supported' : 'Not Supported' ) . "\n"; |
||
| 313 | $return .= 'GD: ' . ( ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) ? 'Supported' : 'Not Supported' ) . "\n"; |
||
| 314 | $return .= 'fsockopen: ' . ( function_exists( 'fsockopen' ) ? 'Supported' : 'Not Supported' ) . "\n"; |
||
| 315 | $return .= 'SOAP Client: ' . ( class_exists( 'SoapClient' ) ? 'Installed' : 'Not Installed' ) . "\n"; |
||
| 316 | $return .= 'Suhosin: ' . ( extension_loaded( 'suhosin' ) ? 'Installed' : 'Not Installed' ) . "\n"; |
||
| 317 | $return .= 'DOM: ' . ( extension_loaded( 'dom' ) ? 'Installed' : 'Not Installed' ) . "\n"; |
||
| 318 | $return .= 'MBString: ' . ( extension_loaded( 'mbstring' ) ? 'Installed' : 'Not Installed' ) . "\n"; |
||
| 319 | |||
| 320 | $return = apply_filters( 'give_sysinfo_after_php_ext', $return ); |
||
| 321 | |||
| 322 | // Session stuff |
||
| 323 | $return .= "\n" . '-- Session Configuration' . "\n\n"; |
||
| 324 | $return .= 'Give Use Sessions: ' . ( defined( 'GIVE_USE_PHP_SESSIONS' ) && GIVE_USE_PHP_SESSIONS ? 'Enforced' : ( Give()->session->use_php_sessions() ? 'Enabled' : 'Disabled' ) ) . "\n"; |
||
| 325 | $return .= 'Session: ' . ( isset( $_SESSION ) ? 'Enabled' : 'Disabled' ) . "\n"; |
||
| 326 | |||
| 327 | // The rest of this is only relevant is session is enabled |
||
| 328 | if ( isset( $_SESSION ) ) { |
||
| 329 | $return .= 'Session Name: ' . esc_html( ini_get( 'session.name' ) ) . "\n"; |
||
| 330 | $return .= 'Cookie Path: ' . esc_html( ini_get( 'session.cookie_path' ) ) . "\n"; |
||
| 331 | $return .= 'Save Path: ' . esc_html( ini_get( 'session.save_path' ) ) . "\n"; |
||
| 332 | $return .= 'Use Cookies: ' . ( ini_get( 'session.use_cookies' ) ? 'On' : 'Off' ) . "\n"; |
||
| 333 | $return .= 'Use Only Cookies: ' . ( ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off' ) . "\n"; |
||
| 334 | } |
||
| 335 | |||
| 336 | $return = apply_filters( 'give_sysinfo_after_session_config', $return ); |
||
| 337 | |||
| 338 | $return .= "\n" . '### End System Info ###'; |
||
| 339 | |||
| 340 | return $return; |
||
| 341 | } |
||
| 342 | |||
| 365 | add_action( 'give_download_sysinfo', 'give_tools_sysinfo_download' ); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.