PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / php / Utils / System_Info.php

System_Info.php in Code Snippets 4.0.0-beta.2, at php/Utils/System_Info.php

135 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Utils;
4
5 use const Code_Snippets\PLUGIN_VERSION;
6
7 /**
8 * Describes the site a feedback report came from.
9 *
10 * Everything here is collected on the server rather than in the browser, so a report carries
11 * the version numbers needed to reproduce a problem without the reporter having to look any
12 * of them up. The summary is the subset shown in the panel before the report is sent, so
13 * nothing leaves the site that the reporter has not been told about.
14 *
15 * @package Code_Snippets
16 */
17 class System_Info {
18
19 /**
20 * Collect the details describing this installation.
21 *
22 * @return array<string, mixed>
23 */
24 public static function get_system_info(): array {
25 global $wp_version, $wpdb;
26
27 $theme = wp_get_theme();
28 $plugins = self::get_active_plugins();
29
30 $info = [
31 'plugin_version' => PLUGIN_VERSION,
32 'edition' => self::get_edition(),
33 'wordpress_version' => $wp_version,
34 'php_version' => PHP_VERSION,
35 'database' => $wpdb->db_server_info(),
36 'active_theme' => trim( sprintf( '%s %s', $theme->get( 'Name' ), $theme->get( 'Version' ) ) ),
37 'active_plugins' => $plugins,
38 'plugin_count' => count( $plugins ),
39 'multisite' => is_multisite(),
40 'locale' => get_locale(),
41 'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
42 'wp_memory_limit' => defined( 'WP_MEMORY_LIMIT' ) ? WP_MEMORY_LIMIT : '',
43 'php_memory_limit' => ini_get( 'memory_limit' ),
44 'max_execution_time' => ini_get( 'max_execution_time' ),
45 'server_software' => isset( $_SERVER['SERVER_SOFTWARE'] )
46 ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) )
47 : '',
48 'site_url' => site_url(),
49 ];
50
51 return apply_filters( 'code_snippets_feedback_system_info', $info );
52 }
53
54 /**
55 * Describe the collected details in the form shown in the panel.
56 *
57 * Every value the report carries appears here. The panel is where the reporter is told
58 * what they are about to send, so anything left out would go without disclosure.
59 *
60 * @param array<string, mixed> $info Collected system information.
61 *
62 * @return array<string, string> Label and value pairs.
63 */
64 public static function get_summary( array $info ): array {
65 $version = sprintf(
66 '%s (%s)',
67 $info['plugin_version'],
68 'pro' === $info['edition']
69 ? __( 'Pro', 'code-snippets' )
70 : __( 'Free', 'code-snippets' )
71 );
72
73 $wordpress = $info['multisite']
74 ? sprintf( '%s (%s)', $info['wordpress_version'], __( 'multisite', 'code-snippets' ) )
75 : $info['wordpress_version'];
76
77 $limits = sprintf(
78 /* translators: 1: WordPress memory limit, 2: PHP memory limit, 3: maximum execution time, in seconds. */
79 __( 'WordPress %1$s, PHP %2$s, %3$ss execution', 'code-snippets' ),
80 $info['wp_memory_limit'],
81 $info['php_memory_limit'],
82 $info['max_execution_time']
83 );
84
85 return [
86 __( 'Code Snippets', 'code-snippets' ) => $version,
87 __( 'WordPress', 'code-snippets' ) => $wordpress,
88 __( 'PHP', 'code-snippets' ) => $info['php_version'],
89 __( 'Database', 'code-snippets' ) => $info['database'],
90 __( 'Theme', 'code-snippets' ) => $info['active_theme'],
91 __( 'Server', 'code-snippets' ) => $info['server_software'],
92 __( 'Language', 'code-snippets' ) => $info['locale'],
93 __( 'Debug mode', 'code-snippets' ) => $info['wp_debug'] ? __( 'on', 'code-snippets' ) : __( 'off', 'code-snippets' ),
94 __( 'Limits', 'code-snippets' ) => $limits,
95 __( 'Site address', 'code-snippets' ) => $info['site_url'],
96 __( 'Plugins', 'code-snippets' ) => $info['active_plugins']
97 ? implode( ', ', $info['active_plugins'] )
98 : __( 'none active', 'code-snippets' ),
99 ];
100 }
101
102 /**
103 * Which edition of the plugin is running.
104 *
105 * @return string Either 'free' or 'pro'.
106 */
107 public static function get_edition(): string {
108 return defined( 'CODE_SNIPPETS_PRO' ) && CODE_SNIPPETS_PRO ? 'pro' : 'free';
109 }
110
111 /**
112 * List the name and version of every active plugin, sorted for a stable comparison
113 * between one report and the next.
114 *
115 * @return string[]
116 */
117 private static function get_active_plugins(): array {
118 if ( ! function_exists( 'get_plugins' ) ) {
119 require_once ABSPATH . 'wp-admin/includes/plugin.php';
120 }
121
122 $plugins = [];
123
124 foreach ( get_plugins() as $file => $data ) {
125 if ( is_plugin_active( $file ) || is_plugin_active_for_network( $file ) ) {
126 $plugins[] = trim( sprintf( '%s %s', $data['Name'], $data['Version'] ) );
127 }
128 }
129
130 sort( $plugins );
131
132 return $plugins;
133 }
134 }
135