Completed
Push — 137-feature/construct-post-mod... ( 2fadb4...c92423 )
by Maria Daniel Deepak
03:42
created

BD_System_Info_page::render_body()   D

Complexity

Conditions 27
Paths 20

Size

Total Lines 112
Code Lines 96

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 756

Importance

Changes 0
Metric Value
cc 27
eloc 96
nc 20
nop 0
dl 0
loc 112
ccs 0
cts 17
cp 0
crap 756
rs 4.509
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * Display System Info.
4
 *
5
 * Also provide an option to download system info for using in support requests.
6
 *
7
 * @since       5.5.4
8
 * @note        Based on the code from Easy Digital Downloads plugin
9
 *
10
 * @author		Sudar
11
 *
12
 * @package     BulkDelete\Admin
13
 */
14
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
15
16
/**
17
 * Encapsulates System info.
18
 *
19
 * @since 5.5.4
20
 */
21
class BD_System_Info_page extends BD_Base_Page {
22
	/**
23
	 * Make this class a "hybrid Singleton".
24
	 *
25
	 * @static
26
	 *
27
	 * @since 5.5.4
28
	 */
29 1
	public static function factory() {
30 1
		static $instance = false;
31
32 1
		if ( ! $instance ) {
33 1
			$instance = new self;
34
		}
35
36 1
		return $instance;
37
	}
38
39
	/**
40
	 * Initialize and setup variables.
41
	 *
42
	 * @since 5.5.4
43
	 */
44 1
	protected function initialize() {
45 1
		$this->page_slug   = 'bulk-delete-info';
46 1
		$this->menu_action = 'bd_after_all_menus';
47 1
		$this->actions     = array( 'download_sysinfo' );
48
49 1
		$this->label = array(
50 1
			'page_title' => __( 'Bulk Delete - System Info', 'bulk-delete' ),
51 1
			'menu_title' => __( 'System Info', 'bulk-delete' ),
52
		);
53
54 1
		$this->messages = array(
55 1
			'info_message' => __( 'Please include this information when posting support requests.', 'bulk-delete' ),
56
		);
57
58 1
		add_action( 'bd_download_sysinfo', array( $this, 'generate_sysinfo_download' ) );
59 1
	}
60
61
	/**
62
	 * Render header.
63
	 *
64
	 * @since 5.5.4
65
	 */
66
	protected function render_header() {
67
?>
68
		<div class="updated">
69
			<p><strong><?php echo $this->messages['info_message']; ?></strong></p>
70
		</div>
71
72
		<?php if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { ?>
73
			<div class="notice notice-warning">
74
				<p><strong>
75
					<?php printf( __( 'SAVEQUERIES is <a href="%s" target="_blank">enabled</a>. This puts additional load on the memory and will restrict the number of items that can be deleted.', 'bulk-delete' ), 'https://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis' ); ?>
76
				</strong></p>
77
			</div>
78
		<?php } ?>
79
80
		<?php if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { ?>
81
			<div class="notice notice-warning">
82
				<p><strong>
83
					<?php printf( __( 'DISABLE_WP_CRON is <a href="%s" target="_blank">enabled</a>. This prevents scheduler from running.', 'bulk-delete' ), 'https://codex.wordpress.org/Editing_wp-config.php#Disable_Cron_and_Cron_Timeout' ); ?>
84
				</strong></p>
85
			</div>
86
		<?php } ?>
87
88
<?php
89
	}
90
91
	/**
92
	 * Shows the system info panel which contains version data and debug info.
93
	 *
94
	 * @since 5.5.4
95
	 *
96
	 * @global $wpdb Global object $wpdb Used to query the database using the WordPress Database API
97
	 */
98
	protected function render_body() {
99
		global $wpdb;
100
?>
101
		<textarea wrap="off" style="width:100%;height:500px;font-family:Menlo,Monaco,monospace;white-space:pre;" readonly="readonly" onclick="this.focus();this.select()" id="system-info-textarea" name="bulk-delete-sysinfo" title="<?php _e( 'To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'bulk-delete' ); ?>">
102
### Begin System Info ###
103
<?php
104
		/**
105
		 * Runs before displaying system info.
106
		 *
107
		 * This action is primarily for adding extra content in System Info.
108
		 */
109
		do_action( 'bd_system_info_before' );
110
?>
111
112
Multisite:                <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
113
114
SITE_URL:                 <?php echo site_url() . "\n"; ?>
115
HOME_URL:                 <?php echo home_url() . "\n"; ?>
116
Browser:                  <?php echo esc_html( $_SERVER['HTTP_USER_AGENT'] ), "\n"; ?>
117
118
Permalink Structure:      <?php echo get_option( 'permalink_structure' ) . "\n"; ?>
119
Active Theme:             <?php echo bd_get_current_theme_name() . "\n"; ?>
120
<?php
121
		$host = bd_identify_host();
122
		if ( '' !== $host ) : ?>
123
Host:                     <?php echo $host . "\n\n"; ?>
124
<?php endif; ?>
125
126
<?php $post_types = get_post_types(); ?>
127
Registered Post types:    <?php echo implode( ', ', $post_types ) . "\n"; ?>
128
<?php
129
		foreach ( $post_types as $post_type ) {
130
			echo $post_type;
131
			if ( strlen( $post_type ) < 26 ) {
132
				echo str_repeat( ' ', 26 - strlen( $post_type ) );
133
			}
134
			$post_count = wp_count_posts( $post_type );
135
			foreach ( $post_count as $key => $value ) {
136
				echo $key, '=', $value, ', ';
137
			}
138
			echo "\n";
139
		}
140
?>
141
142
<?php $taxonomies = get_taxonomies(); ?>
143
Registered Taxonomies:    <?php echo implode( ', ', $taxonomies ) . "\n"; ?>
144
145
Bulk Delete Version:      <?php echo Bulk_Delete::VERSION . "\n"; ?>
146
WordPress Version:        <?php echo get_bloginfo( 'version' ) . "\n"; ?>
147
PHP Version:              <?php echo PHP_VERSION . "\n"; ?>
148
MySQL Version:            <?php echo $wpdb->db_version() . "\n"; ?>
149
Web Server Info:          <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
150
151
WordPress Memory Limit:   <?php echo WP_MEMORY_LIMIT; ?><?php echo "\n"; ?>
152
WordPress Max Limit:      <?php echo WP_MAX_MEMORY_LIMIT; ?><?php echo "\n"; ?>
153
PHP Memory Limit:         <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
154
155
SAVEQUERIES:              <?php echo defined( 'SAVEQUERIES' ) ? SAVEQUERIES ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
156
WP_DEBUG:                 <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
157
WP_SCRIPT_DEBUG:          <?php echo defined( 'WP_SCRIPT_DEBUG' ) ? WP_SCRIPT_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
158
159
GMT Offset:               <?php echo esc_html( get_option( 'gmt_offset' ) ), "\n\n"; ?>
160
DISABLE_WP_CRON:          <?php echo defined( 'DISABLE_WP_CRON' ) ? DISABLE_WP_CRON ? 'Yes' . "\n" : 'No' . "\n" : 'Not set' . "\n" ?>
161
WP_CRON_LOCK_TIMEOUT:     <?php echo defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 'Not set', "\n" ?>
162
EMPTY_TRASH_DAYS:         <?php echo defined( 'EMPTY_TRASH_DAYS' ) ? EMPTY_TRASH_DAYS : 'Not set', "\n" ?>
163
164
PHP Safe Mode:            <?php echo ini_get( 'safe_mode' ) ? 'Yes' : 'No', "\n"; // phpcs:ignore PHPCompatibility.PHP.DeprecatedIniDirectives.safe_modeDeprecatedRemoved?>
165
PHP Upload Max Size:      <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
166
PHP Post Max Size:        <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
167
PHP Upload Max Filesize:  <?php echo ini_get( 'upload_max_filesize' ) . "\n"; ?>
168
PHP Time Limit:           <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
169
PHP Max Input Vars:       <?php echo ini_get( 'max_input_vars' ) . "\n"; // phpcs:ignore PHPCompatibility.PHP.NewIniDirectives.max_input_varsFound?>
170
PHP Arg Separator:        <?php echo ini_get( 'arg_separator.output' ) . "\n"; ?>
171
PHP Allow URL File Open:  <?php echo ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No', "\n"; ?>
172
173
WP Table Prefix:          <?php echo $wpdb->prefix, "\n";?>
174
175
Session:                  <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
176
Session Name:             <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
177
Cookie Path:              <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
178
Save Path:                <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
179
Use Cookies:              <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
180
Use Only Cookies:         <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
181
182
DISPLAY ERRORS:           <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
183
FSOCKOPEN:                <?php echo ( function_exists( 'fsockopen' ) ) ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.'; ?><?php echo "\n"; ?>
184
cURL:                     <?php echo ( function_exists( 'curl_init' ) ) ? 'Your server supports cURL.' : 'Your server does not support cURL.'; ?><?php echo "\n"; ?>
185
SOAP Client:              <?php echo ( class_exists( 'SoapClient' ) ) ? 'Your server has the SOAP Client enabled.' : 'Your server does not have the SOAP Client enabled.'; ?><?php echo "\n"; ?>
186
SUHOSIN:                  <?php echo ( extension_loaded( 'suhosin' ) ) ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.'; ?><?php echo "\n"; ?>
187
188
ACTIVE PLUGINS:
189
190
<?php bd_print_current_plugins(); ?>
191
192
<?php
193
		if ( is_multisite() ) : ?>
194
NETWORK ACTIVE PLUGINS:
195
196
<?php
197
			bd_print_network_active_plugins();
198
		endif;
199
?>
200
201
<?php do_action( 'bd_system_info_after' );?>
202
### End System Info ###</textarea>
203
204
		<p class="submit">
205
			<input type="hidden" name="bd_action" value="download_sysinfo">
206
			<?php submit_button( 'Download System Info File', 'primary', 'bulk-delete-download-sysinfo', false ); ?>
207
		</p>
208
<?php
209
	}
210
211
	/**
212
	 * Generates the System Info Download File.
213
	 *
214
	 * @since 5.0
215
	 *
216
	 * @return void
217
	 */
218
	public function generate_sysinfo_download() {
219
		nocache_headers();
220
221
		header( 'Content-type: text/plain' );
222
		header( 'Content-Disposition: attachment; filename="bulk-delete-system-info.txt"' );
223
224
		echo wp_strip_all_tags( $_POST['bulk-delete-sysinfo'] );
225
		die();
1 ignored issue
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
226
	}
227
}
228
229
BD_System_Info_page::factory();
230