| 1 |
<?php |
| 2 |
|
| 3 |
namespace KaizenCoders\UpdateURLS; |
| 4 |
|
| 5 |
/** |
| 6 |
* Tracker |
| 7 |
* |
| 8 |
* @class Tracker |
| 9 |
* @since 1.2 |
| 10 |
* |
| 11 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 12 |
* @author KaizenCoders <hello@kaizencoders.com> |
| 13 |
*/ |
| 14 |
class Tracker { |
| 15 |
|
| 16 |
/** |
| 17 |
* Get Active, Inactive or all plugins info |
| 18 |
* |
| 19 |
* @since 1.2 |
| 20 |
* @return array |
| 21 |
* |
| 22 |
*/ |
| 23 |
public static function get_plugins( $status = 'all', $details = false ) { |
| 24 |
|
| 25 |
$plugins = [ |
| 26 |
'active_plugins' => [], |
| 27 |
'inactive_plugins' => [], |
| 28 |
]; |
| 29 |
|
| 30 |
// Check if get_plugins() function exists. This is required on the front end of the |
| 31 |
// site, since it is in a file that is normally only loaded in the admin. |
| 32 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 33 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 34 |
} |
| 35 |
|
| 36 |
$all_plugins = get_plugins(); |
| 37 |
$active_plugins = get_option( 'active_plugins', [] ); |
| 38 |
|
| 39 |
if ( is_multisite() ) { |
| 40 |
$sitewide_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', [] ) ); |
| 41 |
$active_plugins = ! empty( $active_plugins ) ? array_merge( $sitewide_activated_plugins, |
| 42 |
$active_plugins ) : $sitewide_activated_plugins; |
| 43 |
} |
| 44 |
|
| 45 |
foreach ( $all_plugins as $plugin_path => $plugin ) { |
| 46 |
// If the plugin isn't active, don't show it. |
| 47 |
if ( in_array( $plugin_path, $active_plugins ) ) { |
| 48 |
$slug = 'active_plugins'; |
| 49 |
$is_active = 1; |
| 50 |
} else { |
| 51 |
$slug = 'inactive_plugins'; |
| 52 |
$is_active = 0; |
| 53 |
} |
| 54 |
|
| 55 |
if ( $details ) { |
| 56 |
|
| 57 |
$plugin_data = [ |
| 58 |
'name' => $plugin['Name'], |
| 59 |
'version' => $plugin['Version'], |
| 60 |
'author' => $plugin['Author'], |
| 61 |
'author_uri' => $plugin['AuthorURI'], |
| 62 |
'plugin_uri' => $plugin['PluginURI'], |
| 63 |
'is_active' => $is_active, |
| 64 |
]; |
| 65 |
|
| 66 |
$plugins[ $slug ][ $plugin_path ] = $plugin_data; |
| 67 |
} else { |
| 68 |
$plugins[ $slug ][] = $plugin_path; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
if ( 'active' === $status ) { |
| 73 |
return $plugins['active_plugins']; |
| 74 |
} elseif ( 'inactive' === $status ) { |
| 75 |
return $plugins['inactive_plugins']; |
| 76 |
} else { |
| 77 |
return array_merge( $plugins['active_plugins'], $plugins['inactive_plugins'] ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Get Active Plugins |
| 83 |
* |
| 84 |
* @since 1.2 |
| 85 |
* |
| 86 |
* @param bool $details |
| 87 |
* |
| 88 |
* @return array |
| 89 |
* |
| 90 |
*/ |
| 91 |
public static function get_active_plugins( $details = false ) { |
| 92 |
return self::get_plugins( 'active', $details ); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Get Inactive plugins |
| 97 |
* |
| 98 |
* @since 1.2 |
| 99 |
* |
| 100 |
* @param bool $details |
| 101 |
* |
| 102 |
* @return array |
| 103 |
* |
| 104 |
*/ |
| 105 |
public static function get_inactive_plugins( $details = false ) { |
| 106 |
return self::get_plugins( 'inactive', $details ); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Check whether plugin is active or not. |
| 111 |
* |
| 112 |
* @since 1.2 |
| 113 |
* |
| 114 |
* @param string $plugin |
| 115 |
* |
| 116 |
* @return bool |
| 117 |
* |
| 118 |
*/ |
| 119 |
public static function is_plugin_activated( $plugin = '' ) { |
| 120 |
if ( empty( $plugin ) ) { |
| 121 |
return false; |
| 122 |
} |
| 123 |
|
| 124 |
$active_plugins = self::get_active_plugins(); |
| 125 |
|
| 126 |
if ( count( $active_plugins ) == 0 ) { |
| 127 |
return false; |
| 128 |
} |
| 129 |
|
| 130 |
if ( in_array( $plugin, $active_plugins ) ) { |
| 131 |
return true; |
| 132 |
} |
| 133 |
|
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Is plugin installed? |
| 139 |
* |
| 140 |
* @since 1.2 |
| 141 |
* |
| 142 |
* @param string $plugin |
| 143 |
* |
| 144 |
* @return bool |
| 145 |
* |
| 146 |
*/ |
| 147 |
public static function is_plugin_installed( $plugin = '' ) { |
| 148 |
if ( empty( $plugin ) ) { |
| 149 |
return false; |
| 150 |
} |
| 151 |
|
| 152 |
$all_plugins = self::get_plugins(); |
| 153 |
|
| 154 |
if ( count( $all_plugins ) == 0 ) { |
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
if ( in_array( $plugin, $all_plugins ) ) { |
| 159 |
return true; |
| 160 |
} |
| 161 |
|
| 162 |
return false; |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Get Current Theme Info |
| 167 |
* |
| 168 |
* @since 1.2 |
| 169 |
* @return array |
| 170 |
* |
| 171 |
*/ |
| 172 |
public static function get_current_theme_info() { |
| 173 |
$current_theme = []; |
| 174 |
if ( function_exists( 'wp_get_theme' ) ) { |
| 175 |
$theme_data = wp_get_theme(); |
| 176 |
$current_theme = [ |
| 177 |
'name' => $theme_data->get( 'Name' ), |
| 178 |
'version' => $theme_data->get( 'Version' ), |
| 179 |
'author' => $theme_data->get( 'Author' ), |
| 180 |
'author_uri' => $theme_data->get( 'AuthorURI' ), |
| 181 |
]; |
| 182 |
} elseif ( function_exists( 'get_theme_data' ) ) { |
| 183 |
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' ); |
| 184 |
$current_theme = [ |
| 185 |
'name' => $theme_data['Name'], |
| 186 |
'version' => $theme_data['Version'], |
| 187 |
'author' => $theme_data['Author'], |
| 188 |
'author_uri' => $theme_data['AuthorURI'], |
| 189 |
]; |
| 190 |
} |
| 191 |
|
| 192 |
return $current_theme; |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Get server info |
| 197 |
* |
| 198 |
* @since 1.2 |
| 199 |
* @return array |
| 200 |
* |
| 201 |
*/ |
| 202 |
public static function get_server_info() { |
| 203 |
global $wpdb; |
| 204 |
|
| 205 |
$server_info = [ |
| 206 |
'php_version' => PHP_VERSION, |
| 207 |
'mysql_version' => $wpdb->db_version(), |
| 208 |
'web_server_info' => $_SERVER['SERVER_SOFTWARE'], |
| 209 |
'user_agent' => $_SERVER['HTTP_USER_AGENT'], |
| 210 |
'php_memory_limit' => ini_get( 'memory_limit' ), |
| 211 |
'php_post_max_size' => ini_get( 'post_max_size' ), |
| 212 |
'php_upload_max_file_size' => ini_get( 'upload_max_filesize' ), |
| 213 |
'php_max_execution_time' => ini_get( 'max_execution_time' ), |
| 214 |
'session' => isset( $_SESSION ) ? 'enabled' : 'disabled', |
| 215 |
'session_name' => esc_html( ini_get( 'session.name' ) ), |
| 216 |
'cookie_path' => esc_html( ini_get( 'session.cookie_path' ) ), |
| 217 |
'session_save_path' => esc_html( ini_get( 'session.save_path' ) ), |
| 218 |
'use_cookies' => ini_get( 'session.use_cookies' ) ? 'on' : 'off', |
| 219 |
'use_only_cookies' => ini_get( 'session.use_only_cookies' ) ? 'on' : 'off', |
| 220 |
'ssl_support_extension_loaded' => extension_loaded( 'openssl' ) ? 'yes' : 'no', |
| 221 |
'mb_string_extension_loaded' => extension_loaded( 'mbstring' ) ? 'yes' : 'no', |
| 222 |
]; |
| 223 |
|
| 224 |
return $server_info; |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Get WordPress information |
| 229 |
* |
| 230 |
* @since 1.2 |
| 231 |
* @return array |
| 232 |
* |
| 233 |
*/ |
| 234 |
public static function get_wp_info() { |
| 235 |
global $wpdb; |
| 236 |
|
| 237 |
$wp_info = [ |
| 238 |
'site_url' => site_url(), |
| 239 |
'home_url' => home_url(), |
| 240 |
'wp_version' => get_bloginfo( 'version' ), |
| 241 |
'permalink_structure' => get_option( 'permalink_structure' ), |
| 242 |
'multisite' => is_multisite() ? 'yes' : 'no', |
| 243 |
'wp_debug' => defined( 'WP_DEBUG' ) ? ( WP_DEBUG ? 'enabled' : 'disabled' ) : '', |
| 244 |
'display_errors' => ( ini_get( 'display_errors' ) ) ? 'on' : 'off', |
| 245 |
'wp_table_prefix' => $wpdb->prefix, |
| 246 |
'wp_db_charset_Collate' => $wpdb->get_charset_collate(), |
| 247 |
'wp_memory_limit' => ( size_format( (int) WP_MEMORY_LIMIT * 1048576 ) ), |
| 248 |
'wp_upload_size' => ( size_format( wp_max_upload_size() ) ), |
| 249 |
'filesystem_method' => get_filesystem_method(), |
| 250 |
]; |
| 251 |
|
| 252 |
return $wp_info; |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Get the system info. |
| 257 |
* |
| 258 |
* @since 1.2.8 |
| 259 |
* @return string |
| 260 |
* |
| 261 |
*/ |
| 262 |
public static function get_system_info() { |
| 263 |
global $wpdb; |
| 264 |
|
| 265 |
$return = '### Begin System Info ###' . "\n\n"; |
| 266 |
|
| 267 |
// Basic site info |
| 268 |
$return .= '-- WordPress Configuration' . "\n\n"; |
| 269 |
$return .= 'Site URL: ' . site_url() . "\n"; |
| 270 |
$return .= 'Home URL: ' . home_url() . "\n"; |
| 271 |
$return .= 'Multisite: ' . ( is_multisite() ? 'Yes' : 'No' ) . "\n"; |
| 272 |
$return .= 'Version: ' . get_bloginfo( 'version' ) . "\n"; |
| 273 |
$return .= 'Language: ' . get_locale() . "\n"; |
| 274 |
$return .= 'Table Prefix: ' . 'Length: ' . strlen( $wpdb->prefix ) . "\n"; |
| 275 |
$return .= 'WP_DEBUG: ' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ) . "\n"; |
| 276 |
$return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; |
| 277 |
|
| 278 |
// Plugin Configuration |
| 279 |
$return .= "\n" . '-- Update URLS Configuration' . "\n\n"; |
| 280 |
$return .= 'Plugin Version: ' . KC_UU_PLUGIN_VERSION. "\n"; |
| 281 |
|
| 282 |
// Server Configuration |
| 283 |
$return .= "\n" . '-- Server Configuration' . "\n\n"; |
| 284 |
$os = self::get_os(); |
| 285 |
$return .= 'Operating System: ' . $os['name'] . "\n"; |
| 286 |
$return .= 'PHP Version: ' . PHP_VERSION . "\n"; |
| 287 |
$return .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; |
| 288 |
|
| 289 |
$return .= 'Server Software: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; |
| 290 |
|
| 291 |
// PHP configs... now we're getting to the important stuff |
| 292 |
$return .= "\n" . '-- PHP Configuration' . "\n\n"; |
| 293 |
$return .= 'Memory Limit: ' . ini_get( 'memory_limit' ) . "\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 .= 'Display Errors: ' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ) . "\n"; |
| 299 |
|
| 300 |
// WordPress active plugins |
| 301 |
$return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; |
| 302 |
$plugins = get_plugins(); |
| 303 |
$active_plugins = get_option( 'active_plugins', [] ); |
| 304 |
foreach ( $plugins as $plugin_path => $plugin ) { |
| 305 |
if ( ! in_array( $plugin_path, $active_plugins ) ) { |
| 306 |
continue; |
| 307 |
} |
| 308 |
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
| 309 |
} |
| 310 |
|
| 311 |
// WordPress inactive plugins |
| 312 |
$return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; |
| 313 |
foreach ( $plugins as $plugin_path => $plugin ) { |
| 314 |
if ( in_array( $plugin_path, $active_plugins ) ) { |
| 315 |
continue; |
| 316 |
} |
| 317 |
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
| 318 |
} |
| 319 |
|
| 320 |
if ( is_multisite() ) { |
| 321 |
// WordPress Multisite active plugins |
| 322 |
$return .= "\n" . '-- Network Active Plugins' . "\n\n"; |
| 323 |
$plugins = wp_get_active_network_plugins(); |
| 324 |
$active_plugins = get_site_option( 'active_sitewide_plugins', [] ); |
| 325 |
foreach ( $plugins as $plugin_path ) { |
| 326 |
$plugin_base = plugin_basename( $plugin_path ); |
| 327 |
if ( ! array_key_exists( $plugin_base, $active_plugins ) ) { |
| 328 |
continue; |
| 329 |
} |
| 330 |
$plugin = get_plugin_data( $plugin_path ); |
| 331 |
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
$return .= "\n" . '### End System Info ###'; |
| 336 |
|
| 337 |
return $return; |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* Determines the current operating system. |
| 342 |
* @access public |
| 343 |
* @since 1.2.8 |
| 344 |
* @return array |
| 345 |
*/ |
| 346 |
public static function get_os() { |
| 347 |
$os = []; |
| 348 |
$uname = php_uname( 's' ); |
| 349 |
$os['code'] = strtoupper( substr( $uname, 0, 3 ) ); |
| 350 |
$os['name'] = $uname; |
| 351 |
|
| 352 |
return $os; |
| 353 |
} |
| 354 |
|
| 355 |
} |