enrich
3 weeks ago
event-definitions
4 months ago
events
1 week ago
formEvents
1 year ago
logger
4 months ago
views
1 week ago
class-consent.php
6 months ago
class-custom-event-factory.php
1 year ago
class-custom-event.php
3 weeks ago
class-event-definitions.php
4 months ago
class-event-id-generator.php
5 years ago
class-events-manager-ajax_hook.php
3 weeks ago
class-events-manager.php
3 weeks ago
class-fixed-notices.php
1 year ago
class-optin-notices.php
1 year ago
class-pixel.php
7 years ago
class-plugin-updater.php
9 months ago
class-plugin.php
7 years ago
class-pys.php
1 week ago
class-settings.php
4 months ago
functions-admin.php
3 weeks ago
functions-buttons.php
1 year ago
functions-common.php
3 weeks ago
functions-custom-event.php
1 week ago
functions-edd.php
2 years ago
functions-gdpr.php
11 months ago
functions-license.php
3 weeks ago
functions-migrate.php
9 months ago
functions-promo-notices.php
1 year ago
functions-system-report.php
7 years ago
functions-update-plugin.php
6 years ago
functions-woo.php
3 weeks ago
options_defaults.json
3 weeks ago
options_fields.json
3 weeks ago
functions-system-report.php
221 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PixelYourSite; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; // Exit if accessed directly. |
| 7 | } |
| 8 | |
| 9 | const HTML_WARNING = '<i class="fa fa-exclamation-triangle text-warning" aria-hidden="true" style="color: #fa0;"></i> '; |
| 10 | const HTML_CRITICAL = '<i class="fa fa-exclamation-circle" aria-hidden="true" style="color: #d64d4d;"></i> '; |
| 11 | const TEXT_WARNING = '[warning] '; |
| 12 | const TEXT_CRITICAL = '[critical] '; |
| 13 | |
| 14 | /** |
| 15 | * @return array |
| 16 | */ |
| 17 | function get_system_report_data( $for_download = false ) { |
| 18 | global $wpdb; |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * Wordpress |
| 23 | */ |
| 24 | |
| 25 | $wordpress = array( |
| 26 | 'Home URL' => get_option( 'home' ), |
| 27 | 'Site URL' => get_option( 'siteurl' ), |
| 28 | 'WP version' => get_bloginfo( 'version' ), |
| 29 | 'WP multisite' => is_multisite() ? 'Yes' : 'No', |
| 30 | 'Language' => get_locale(), |
| 31 | ); |
| 32 | |
| 33 | /** |
| 34 | * Server |
| 35 | */ |
| 36 | |
| 37 | // check php version |
| 38 | if ( version_compare( phpversion(), '5.3.0', '<' ) ) { |
| 39 | $version_check = $for_download ? TEXT_CRITICAL : HTML_CRITICAL; |
| 40 | $version_check .= 'Ask your hosting company to upgrade you to at least PHP 5.6.15 or newer. '; |
| 41 | } elseif ( version_compare( phpversion(), '5.6.14', '<' ) ) { |
| 42 | $version_check = $for_download ? TEXT_WARNING : HTML_WARNING; |
| 43 | $version_check .= 'Ask your hosting company to upgrade you to at least PHP 5.6.15 or newer. '; |
| 44 | } else { |
| 45 | $version_check = ''; |
| 46 | } |
| 47 | |
| 48 | // check mb_string extension presence |
| 49 | if ( extension_loaded( 'mbstring' ) ) { |
| 50 | $mb_string_check = 'Yes'; |
| 51 | } else { |
| 52 | $mb_string_check = $for_download ? TEXT_WARNING : HTML_WARNING; |
| 53 | $mb_string_check .= 'No. Ask your hosting company to upgrade to enable "mbstring" extension.'; |
| 54 | } |
| 55 | |
| 56 | $server = array( |
| 57 | 'Server info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown', |
| 58 | 'PHP version' => phpversion() . $version_check, |
| 59 | 'Multibyte string' => $mb_string_check, |
| 60 | 'MySQL version' => ( ! empty( $wpdb->is_mysql ) ? $wpdb->db_version() : 'Unknown' ), |
| 61 | ); |
| 62 | |
| 63 | /** |
| 64 | * Plugins |
| 65 | */ |
| 66 | |
| 67 | $plugins = array(); |
| 68 | |
| 69 | $conflict_plugins = array( |
| 70 | 'sumodiscounts/sumodiscounts.php' => array( |
| 71 | 'type' => 'warning', |
| 72 | ), |
| 73 | 'imagify/imagify.php' => array( |
| 74 | 'type' => 'warning', |
| 75 | ), |
| 76 | ); |
| 77 | |
| 78 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 79 | require_once( ABSPATH . 'wp-admin/includes/update.php' ); |
| 80 | |
| 81 | if ( function_exists( 'get_plugin_updates' ) ) { |
| 82 | |
| 83 | // Get both site plugins and network plugins |
| 84 | $active_plugins = (array) get_option( 'active_plugins', array() ); |
| 85 | if ( is_multisite() ) { |
| 86 | $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
| 87 | $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
| 88 | } |
| 89 | |
| 90 | $available_updates = get_plugin_updates(); |
| 91 | |
| 92 | foreach ( $active_plugins as $plugin ) { |
| 93 | |
| 94 | $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
| 95 | $name = $data['Name']; |
| 96 | $value = ''; |
| 97 | |
| 98 | // check for conflicts |
| 99 | if ( array_key_exists( $plugin, $conflict_plugins ) ) { |
| 100 | |
| 101 | $conflict_data = $conflict_plugins[ $plugin ]; |
| 102 | |
| 103 | if ( $for_download ) { |
| 104 | $value .= $conflict_data['type'] == 'warning' ? TEXT_WARNING : TEXT_CRITICAL; |
| 105 | } else { |
| 106 | $value .= $conflict_data['type'] == 'warning' ? HTML_WARNING : HTML_CRITICAL; |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | // add plugin author name and URL |
| 112 | if ( $for_download ) { |
| 113 | $value .= 'by ' . $data['AuthorName'] . ' [' . esc_url_raw( $data['PluginURI'] ) . ']'; |
| 114 | } else { |
| 115 | $value .= 'by <a href="' . esc_url_raw( $data['PluginURI'] ) . '" target="_blank">' . |
| 116 | $data['AuthorName'] . '</a> '; |
| 117 | } |
| 118 | |
| 119 | // plugin version |
| 120 | $value .= '[' . $data['Version'] . '] '; |
| 121 | |
| 122 | // available update version if any |
| 123 | if ( array_key_exists( $plugin, $available_updates ) ) { |
| 124 | $update = $available_updates[ $plugin ]; |
| 125 | $value .= '[Update available: ' . $update->update->new_version . '] '; |
| 126 | } |
| 127 | |
| 128 | // is network activated? |
| 129 | if ( $data['Network'] ) { |
| 130 | $value .= '[Network] '; |
| 131 | } |
| 132 | |
| 133 | $plugins[ $name ] = trim( $value ); |
| 134 | |
| 135 | } |
| 136 | |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Theme |
| 141 | */ |
| 142 | |
| 143 | $active_theme = wp_get_theme(); |
| 144 | |
| 145 | $theme = array( |
| 146 | 'Name' => $active_theme->Name, |
| 147 | 'Version' => $active_theme->Version, |
| 148 | 'Author URL' => esc_url_raw( $active_theme->{'Author URI'} ), |
| 149 | 'Child Theme' => is_child_theme() ? 'Yes' : 'No', |
| 150 | ); |
| 151 | |
| 152 | if ( is_child_theme() ) { |
| 153 | |
| 154 | $parent_theme = wp_get_theme( $active_theme->Template ); |
| 155 | |
| 156 | $theme['Parent Theme Name'] = $parent_theme->Name; |
| 157 | $theme['Parent Theme Version'] = $parent_theme->Version; |
| 158 | $theme['Parent Author URL'] = $parent_theme->{'Author URI'}; |
| 159 | |
| 160 | } |
| 161 | |
| 162 | $report = array( |
| 163 | 'WordPress Environment' => $wordpress, |
| 164 | 'Server Environment' => $server, |
| 165 | 'Active Plugins' => $plugins, |
| 166 | 'Theme' => $theme, |
| 167 | ); |
| 168 | |
| 169 | return apply_filters( 'pys_system_report', $report, $for_download ); |
| 170 | |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Process a system report download. |
| 175 | */ |
| 176 | function download_system_report() { |
| 177 | |
| 178 | if ( empty( $_POST['pys_action'] ) || 'download_system_report' !== $_POST['pys_action'] ) { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'pys_download_system_report_nonce' ) ) { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | if ( ! current_user_can( 'manage_options' ) ) { |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | // prepare human-readable system report |
| 191 | $output = ""; |
| 192 | $report_data = get_system_report_data( true ); |
| 193 | |
| 194 | foreach ( $report_data as $section_name => $section_report ) { |
| 195 | |
| 196 | $output .= "\r\n"; |
| 197 | $output .= "### {$section_name } ###"; |
| 198 | $output .= "\r\n"; |
| 199 | $output .= "\r\n"; |
| 200 | |
| 201 | foreach ( $section_report as $name => $value ) { |
| 202 | |
| 203 | $output .= "{$name}: $value"; |
| 204 | $output .= "\r\n"; |
| 205 | |
| 206 | } |
| 207 | |
| 208 | } |
| 209 | |
| 210 | // send report to client browser |
| 211 | ignore_user_abort( true ); |
| 212 | nocache_headers(); |
| 213 | header( 'Content-Type: text/plain; charset=utf-8' ); |
| 214 | header( 'Content-Disposition: attachment; filename=pys-system-report-' . date( 'm-d-Y' ) . '.txt' ); |
| 215 | header( "Expires: 0" ); |
| 216 | echo $output; |
| 217 | exit; |
| 218 | |
| 219 | } |
| 220 | |
| 221 | add_action( 'admin_init', 'PixelYourSite\download_system_report' ); |