buffer['version'] = $this->version; $this->get_system_info('sysinfo'); $this->cp_info('code-profiler'); $this->function_exists('functions'); $this->check_wpdb('wpdb'); $this->get_all_plugins('plugins'); $this->get_theme('themes'); $export = json_encode( $this->buffer ); header('Content-Length: '. strlen( $export ) ); header('Content-Disposition: attachment; filename="support.txt"'); echo $export; } /** * Retrieve system info: * * PHP version * * PHP SAPI * * HTTP server * * Opcode cache * * PHP directives (time limit, memory available, temp dir etc) * * PHP last error */ private function get_system_info( $key ) { $this->buffer[ $key ]['OS'] = php_uname(); if (! empty( $_SERVER['SERVER_SOFTWARE'] ) ) { $this->buffer[ $key ]['HTTP server'] = $_SERVER['SERVER_SOFTWARE']; } else { $this->buffer[ $key ]['HTTP server'] = 'N/A'; } $this->buffer[ $key ]['PHP'] = strtoupper( PHP_SAPI ) .' '. PHP_VERSION; if ( extension_loaded('Zend OPcache') ) { $this->buffer[ $key ]['Opcode cache'] = sprintf( 'Zend OPcache (%s)', ini_get('opcache.enable') ? 'enabled':'disabled' ); } elseif ( extension_loaded('wincache') ) { $this->buffer[ $key ]['Opcode cache'] = sprintf( 'wincache (%s)', ini_get('wincache.fcenabled') ? 'enabled':'disabled' ); } $this->buffer[ $key ]['Memory limit'] = ini_get('memory_limit'); $this->buffer[ $key ]['Peak limit'] = number_format( memory_get_peak_usage() ); $this->buffer[ $key ]['Max execution time'] = ini_get('max_execution_time') .'s'; $this->buffer[ $key ]['Disabled functions'] = ini_get('disable_functions'); $this->buffer[ $key ]['Display errors'] = ini_get('display_errors'); $tmp = ini_get('sys_temp_dir'); if (! empty( $tmp ) ) { if ( is_writable( $tmp ) ) { $tmp .= ' (writable)'; } else { $tmp .= ' (not writable!)'; } } $tmp = $this->shorten_path( $tmp ); $this->buffer[ $key ]['Temp directory'] = $tmp; $this->buffer[ $key ]['Log errors'] = ini_get('log_errors'); $this->buffer[ $key ]['Error log'] = ini_get('error_log'); $this->buffer[ $key ]['Last error'] = error_get_last(); } /** * Verify if some important PHP functions are available. */ private function function_exists( $key ) { $required_functions = [ 'register_shutdown_function', 'register_tick_function', 'stream_wrapper_unregister', 'stream_wrapper_register', 'stream_wrapper_restore' ]; foreach ( $required_functions as $function ) { $this->buffer[ $key ][ $function ] = function_exists( $function ); } } /** * Return the version and type (free/pro) of Code Profiler. */ private function cp_info( $key ) { if ( defined('CODE_PROFILER_PRO_VERSION') ) { $this->buffer[ $key ]['slug'] = 'code-profiler-pro'; $this->buffer[ $key ]['version'] = CODE_PROFILER_PRO_VERSION; } elseif ( defined('CODE_PROFILER_VERSION') ) { $this->buffer[ $key ]['slug'] = 'code-profiler'; $this->buffer[ $key ]['version'] = CODE_PROFILER_VERSION; } else { exit('Error: Code Profiler is not active. Please activate it and run this script again.'); } // Data folder must be writable $upload_dir = wp_upload_dir(); $dir = $upload_dir['basedir'] .'/'. $this->buffer[ $key ]['slug']; $this->buffer[ $key ]['data_dir']['path'] = $this->shorten_path( $dir ); $this->buffer[ $key ]['data_dir']['exists'] = file_exists( $dir ); $this->buffer[ $key ]['data_dir']['writable'] = is_writable( $dir ); } /** * Check if there are subclasses of the wpdb class and * look for wp-content/db.php */ function check_wpdb( $key ) { foreach( get_declared_classes() as $class ) { $reflected = new ReflectionClass( $class ); if ( $reflected->isSubclassOf('wpdb') ) { $script = $reflected->getFileName(); $this->buffer[ $key ]['child'][$class] = $this->shorten_path( $script ); } } $this->buffer[ $key ]['db.php'] = file_exists( WP_CONTENT_DIR .'/db.php'); } /** * Check for advanced cache */ private function check_cache( $key ) { $this->buffer[ $key ]['cache'] = defined('WP_CACHE') && file_exists(WP_CONTENT_DIR . '/advanced-cache.php'); } /** * Retrieve the list of all plugins and sort them * (active or disabled). */ private function get_all_plugins( $key ) { if (! function_exists('get_plugins') ) { require_once ABSPATH .'wp-admin/includes/plugin.php'; } $plugins = get_plugins(); foreach( $plugins as $k => $v ) { if ( $slug = substr( $k, 0, strpos( $k, '/') ) ) { $this->buffer[ $key ][ $slug ] = $v['Version']; } } } /** * Retrieve the active theme. */ private function get_theme( $key ) { $themes = wp_get_themes(); $active = get_option('template'); foreach( $themes as $k => $v ) { $version = $v->Version; if ( $k == $active ) { $version .= ' (active)'; } $this->buffer[ $key ][ $k ] = $version; } } /** * Remove the ABSPATH from a path */ private function shorten_path( $path ) { return str_replace( ABSPATH, '', $path ); } } header('Content-Type: text/plain'); new CP_Troubleshooter();