Completed
Pull Request — master (#5)
by
unknown
01:34
created
src/wp-requirements.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  * @license GPL-2.0-or-later
12 12
  */
13 13
 
14
-if ( ! class_exists( 'WP_Requirements' ) ) {
14
+if ( ! class_exists('WP_Requirements')) {
15 15
 
16 16
 	class WP_Requirements {
17 17
 
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 		 * @param string $theme        Output of `plugin_basename( __FILE__ )`.
89 89
 		 * @param array  $requirements Associative array with requirements.
90 90
 		 */
91
-		public function __construct( $name, $theme, $requirements ) {
91
+		public function __construct($name, $theme, $requirements) {
92 92
 
93
-			$this->name = esc_html( wp_strip_all_tags( $name ) );
93
+			$this->name = esc_html(wp_strip_all_tags($name));
94 94
 			$this->plugin = $theme;
95 95
 			$this->requirements = $requirements;
96 96
 
97
-			if ( ! empty( $requirements ) && is_array( $requirements ) ) {
97
+			if ( ! empty($requirements) && is_array($requirements)) {
98 98
 
99 99
 				$failures = $extensions = array();
100 100
 
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 				);
108 108
 
109 109
 				// Check for WordPress version.
110
-				if ( $requirements['WordPress'] && is_string( $requirements['WordPress'] ) ) {
111
-					if ( function_exists( 'get_bloginfo' ) ) {
112
-						$wp_version = get_bloginfo( 'version' );
113
-						if ( version_compare( $wp_version, $requirements['WordPress'] ) === - 1 ) {
110
+				if ($requirements['WordPress'] && is_string($requirements['WordPress'])) {
111
+					if (function_exists('get_bloginfo')) {
112
+						$wp_version = get_bloginfo('version');
113
+						if (version_compare($wp_version, $requirements['WordPress']) === - 1) {
114 114
 							$failures['WordPress'] = $wp_version;
115 115
 							$this->wp = false;
116 116
 						}
@@ -118,24 +118,24 @@  discard block
 block discarded – undo
118 118
 				}
119 119
 
120 120
 				// Check for PHP version.
121
-				if ( $requirements['PHP'] && is_string( $requirements['PHP'] ) ) {
122
-					if ( version_compare( PHP_VERSION, $requirements['PHP'] ) === -1 ) {
121
+				if ($requirements['PHP'] && is_string($requirements['PHP'])) {
122
+					if (version_compare(PHP_VERSION, $requirements['PHP']) === -1) {
123 123
 						$failures['PHP'] = PHP_VERSION;
124 124
 						$this->php = false;
125 125
 					}
126 126
 				}
127 127
 
128 128
 				// Check for PHP Extensions.
129
-				if ( $requirements['Extensions'] && is_array( $requirements['Extensions'] ) ) {
130
-					foreach ( $requirements['Extensions'] as $extension ) {
131
-						if ( $extension && is_string( $extension ) ) {
132
-							$extensions[ $extension ] = extension_loaded( $extension );
129
+				if ($requirements['Extensions'] && is_array($requirements['Extensions'])) {
130
+					foreach ($requirements['Extensions'] as $extension) {
131
+						if ($extension && is_string($extension)) {
132
+							$extensions[$extension] = extension_loaded($extension);
133 133
 						}
134 134
 					}
135
-					if ( in_array( false, $extensions ) ) {
136
-						foreach ( $extensions as $extension_name => $found  ) {
137
-							if ( $found === false ) {
138
-								$failures['Extensions'][ $extension_name ] = $extension_name;
135
+					if (in_array(false, $extensions)) {
136
+						foreach ($extensions as $extension_name => $found) {
137
+							if ($found === false) {
138
+								$failures['Extensions'][$extension_name] = $extension_name;
139 139
 							}
140 140
 						}
141 141
 						$this->extensions = false;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
 			} else {
148 148
 
149
-				trigger_error( 'WP Requirements: the requirements are invalid.', E_USER_ERROR );
149
+				trigger_error('WP Requirements: the requirements are invalid.', E_USER_ERROR);
150 150
 
151 151
 			}
152 152
 		}
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 		 * @return bool
167 167
 		 */
168 168
 		public function pass() {
169
-			if ( in_array( false, array(
169
+			if (in_array(false, array(
170 170
 				$this->wp,
171 171
 				$this->php,
172 172
 				$this->extensions,
173
-			) ) ) {
173
+			))) {
174 174
 				return false;
175 175
 			}
176 176
 			return true;
@@ -183,27 +183,27 @@  discard block
 block discarded – undo
183 183
 		 *
184 184
 		 * @return string
185 185
 		 */
186
-		public function get_notice( $message = '' ) {
186
+		public function get_notice($message = '') {
187 187
 
188 188
 			$notice   = '';
189 189
 			$name     = $this->name;
190 190
 			$failures = $this->failures;
191 191
 
192
-			if ( ! empty( $failures ) && is_array( $failures ) ) {
192
+			if ( ! empty($failures) && is_array($failures)) {
193 193
 
194 194
 				$notice  = '<div class="error">' . "\n";
195 195
 				$notice .= "\t" . '<p>' . "\n";
196
-				$notice .= '<strong>' . sprintf( '%s could not be activated.', $name ) . '</strong><br>';
196
+				$notice .= '<strong>' . sprintf('%s could not be activated.', $name) . '</strong><br>';
197 197
 
198
-				foreach ( $failures as $requirement => $found ) {
198
+				foreach ($failures as $requirement => $found) {
199 199
 
200
-					$required = $this->requirements[ $requirement ];
200
+					$required = $this->requirements[$requirement];
201 201
 
202
-					if ( 'Extensions' == $requirement ) {
203
-						if ( is_array( $found ) ) {
202
+					if ('Extensions' == $requirement) {
203
+						if (is_array($found)) {
204 204
 							$notice .= sprintf(
205 205
 									'Required PHP Extension(s) not found: %s.',
206
-									join( ', ', $found )
206
+									join(', ', $found)
207 207
 								) . '';
208 208
 						}
209 209
 					} else {
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 
218 218
 				}
219 219
 
220
-				$notice .= '<em>' . sprintf( 'Please update to meet %s requirements.', $name ) . '</em>' . "\n";
220
+				$notice .= '<em>' . sprintf('Please update to meet %s requirements.', $name) . '</em>' . "\n";
221 221
 				$notice .= "\t" . '</p>' . "\n";
222
-				if ( $message ) {
222
+				if ($message) {
223 223
 					$notice .= $message;
224 224
 				}
225 225
 				$notice .= '</div>';
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 		 * Deactivate plugin.
240 240
 		 */
241 241
 		public function deactivate_plugin() {
242
-			if ( function_exists( 'deactivate_plugins' ) && function_exists( 'plugin_basename' ) ) {
243
-				deactivate_plugins( $this->plugin );
242
+			if (function_exists('deactivate_plugins') && function_exists('plugin_basename')) {
243
+				deactivate_plugins($this->plugin);
244 244
 			}
245 245
 		}
246 246
 
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
 		 *
250 250
 		 * @param string $message An additional message in notice.
251 251
 		 */
252
-		public function halt( $message = '' ) {
252
+		public function halt($message = '') {
253 253
 
254
-			$this->notice = $this->get_notice( $message );
254
+			$this->notice = $this->get_notice($message);
255 255
 
256
-			if ( $this->notice && function_exists( 'add_action' ) ) {
256
+			if ($this->notice && function_exists('add_action')) {
257 257
 
258
-				add_action( 'admin_notices', array( $this, 'print_notice' ) );
259
-				add_action( 'admin_init', array( $this, 'deactivate_plugin' ) );
258
+				add_action('admin_notices', array($this, 'print_notice'));
259
+				add_action('admin_init', array($this, 'deactivate_plugin'));
260 260
 
261
-				if ( isset( $_GET['activate'] ) ) {
262
-					unset( $_GET['activate'] );
261
+				if (isset($_GET['activate'])) {
262
+					unset($_GET['activate']);
263 263
 				}
264 264
 			}
265 265
 		}
Please login to merge, or discard this patch.