Completed
Push — master ( 01ce3b...15af58 )
by Mike
02:35
created
includes/class-create-post.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class CreatePost{
11
+class CreatePost {
12 12
 
13 13
 	/**
14 14
 	 * metaboxes
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @see Metaboxes
27 27
 	 */
28
-	public function __construct(){
28
+	public function __construct() {
29 29
 
30 30
 		$this->metaboxes = new Metaboxes;
31 31
 
@@ -47,32 +47,32 @@  discard block
 block discarded – undo
47 47
 	 * @param boolean $echo Whether or not to echo. Optional.
48 48
 	 * @param int $num Optional. Number of posts to create.
49 49
 	 */
50
-	public function create_post_type_content( $slug, $connection, $echo = false, $num = '' ){
50
+	public function create_post_type_content($slug, $connection, $echo = false, $num = '') {
51 51
 
52 52
 		// If we're missing a custom post type id - don't do anything
53
-		if ( empty( $slug ) ){
53
+		if (empty($slug)) {
54 54
 			return;
55 55
 		}
56 56
 
57 57
 		// Gather the necessary data to create the posts
58
-		$supports 	= $this->get_cpt_supports( $slug );
59
-		$metaboxes	= $this->metaboxes->get_metaboxes( $slug );
58
+		$supports 	= $this->get_cpt_supports($slug);
59
+		$metaboxes	= $this->metaboxes->get_metaboxes($slug);
60 60
 
61 61
 		// Set our connection status for the rest of the methods
62 62
 		$this->connected = $connection;
63 63
 
64 64
 		// If we forgot to put in a quantity, make one for us
65
-		if ( empty( $num ) ){
66
-			$num = rand( 5, 30 );
65
+		if (empty($num)) {
66
+			$num = rand(5, 30);
67 67
 		}
68 68
 
69 69
 		// Create test posts
70
-		for( $i = 0; $i < $num; $i++ ){
70
+		for ($i = 0; $i < $num; $i++) {
71 71
 
72
-			$return = $this->create_test_object( $slug, $supports, $metaboxes );
72
+			$return = $this->create_test_object($slug, $supports, $metaboxes);
73 73
 
74
-			if ( $echo === true ){
75
-				echo \json_encode( $return );
74
+			if ($echo === true) {
75
+				echo \json_encode($return);
76 76
 			}
77 77
 
78 78
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @param array $supports Features that the post type supports.
96 96
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
97 97
 	 */
98
-	private function create_test_object( $slug, $supports, $metaboxes ){
98
+	private function create_test_object($slug, $supports, $metaboxes) {
99 99
 		$return = '';
100 100
 
101 101
 		// Get a random title
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
 		// First, insert our post
105 105
 		$post = array(
106
-		  'post_name'      => sanitize_title( $title ),
106
+		  'post_name'      => sanitize_title($title),
107 107
 		  'post_status'    => 'publish',
108 108
 		  'post_type'      => $slug,
109 109
 		  'ping_status'    => 'closed',
@@ -111,52 +111,52 @@  discard block
 block discarded – undo
111 111
 		);
112 112
 
113 113
 		// Add title if supported
114
-		if ( $supports['title'] === true ){
114
+		if ($supports['title'] === true) {
115 115
 			$post['post_title'] = $title;
116 116
 		}
117 117
 
118 118
 		// Add main content if supported
119
-		if ( $supports['editor'] === true ){
119
+		if ($supports['editor'] === true) {
120 120
 			$post['post_content'] = TestContent::paragraphs();
121 121
 		}
122 122
 
123 123
 		// Insert then post object
124
-		$post_id = wp_insert_post( $post );
124
+		$post_id = wp_insert_post($post);
125 125
 
126 126
 		// Then, set a test content flag on the new post for later deletion
127
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
127
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
128 128
 
129 129
 		// Add thumbnail if supported
130
-		if ( $this->connected == true && ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ) ){
131
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
130
+		if ($this->connected == true && ($supports['thumbnail'] === true || in_array($slug, array('post', 'page')))) {
131
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
132 132
 		}
133 133
 
134
-		$taxonomies = get_object_taxonomies( $slug );
134
+		$taxonomies = get_object_taxonomies($slug);
135 135
 
136 136
 		// Assign the post to terms
137
-		if ( !empty( $taxonomies ) ){
138
-			$return .= $this->assign_terms( $post_id, $taxonomies );
137
+		if (!empty($taxonomies)) {
138
+			$return .= $this->assign_terms($post_id, $taxonomies);
139 139
 		}
140 140
 
141 141
 		// Spin up metaboxes
142
-		if ( !empty( $metaboxes ) ){
143
-			foreach ( $metaboxes as $cmb ) :
144
-				$return .= $this->metaboxes->random_metabox_content( $post_id, $cmb, $this->connected );
142
+		if (!empty($metaboxes)) {
143
+			foreach ($metaboxes as $cmb) :
144
+				$return .= $this->metaboxes->random_metabox_content($post_id, $cmb, $this->connected);
145 145
 			endforeach;
146 146
 		}
147 147
 
148 148
 		// Check if we have errors and return them or created message
149
-		if ( is_wp_error( $return ) ){
150
-			error_log( $return->get_error_message() );
149
+		if (is_wp_error($return)) {
150
+			error_log($return->get_error_message());
151 151
 			return $return;
152 152
 		} else {
153 153
 			return array(
154 154
 				'type'		=> 'created',
155 155
 				'object'	=> 'post',
156 156
 				'pid'		=> $post_id,
157
-				'post_type'	=> get_post_type( $post_id ),
158
-				'link_edit'	=> admin_url( '/post.php?post='.$post_id.'&action=edit' ),
159
-				'link_view'	=> get_permalink( $post_id ),
157
+				'post_type'	=> get_post_type($post_id),
158
+				'link_edit'	=> admin_url('/post.php?post='.$post_id.'&action=edit'),
159
+				'link_view'	=> get_permalink($post_id),
160 160
 			);
161 161
 		}
162 162
 
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
 	 * @param string $slug a custom post type ID.
174 174
 	 * @return array Array of necessary supports booleans.
175 175
 	 */
176
-	private function get_cpt_supports( $slug ){
176
+	private function get_cpt_supports($slug) {
177 177
 
178 178
 		$supports = array(
179
-			'title'		=> post_type_supports( $slug, 'title' ),
180
-			'editor'	=> post_type_supports( $slug, 'editor' ),
181
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
179
+			'title'		=> post_type_supports($slug, 'title'),
180
+			'editor'	=> post_type_supports($slug, 'editor'),
181
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
182 182
 		);
183 183
 
184 184
 		return $supports;
@@ -199,26 +199,26 @@  discard block
 block discarded – undo
199 199
 	 * @param array $taxonomies taxonomies assigned to this cpt.
200 200
 	 * @return object WP Error if there is one.
201 201
 	 */
202
-	private function assign_terms( $post_id, $taxonomies ){
202
+	private function assign_terms($post_id, $taxonomies) {
203 203
 
204 204
 		// Make sure it's an array & has items
205
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
205
+		if (empty($taxonomies) || !is_array($taxonomies)) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		foreach ( $taxonomies as $tax ){
209
+		foreach ($taxonomies as $tax) {
210 210
 
211 211
 			// Get the individual terms already existing
212
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
213
-			$count = count( $terms ) - 1;
212
+			$terms = get_terms($tax, array('hide_empty'	=> false));
213
+			$count = count($terms) - 1;
214 214
 
215 215
 			// If there are no terms, skip to the next taxonomy
216
-			if ( empty( $terms ) ){
216
+			if (empty($terms)) {
217 217
 				continue;
218 218
 			}
219 219
 
220 220
 			// Get a random index to use
221
-			$index = rand( 0, $count );
221
+			$index = rand(0, $count);
222 222
 
223 223
 			// Initialize our array
224 224
 			$post_data = array(
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
 			);
227 227
 
228 228
 			// Set the term data to update
229
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
229
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
230 230
 
231 231
 			// Update the post with the taxonomy info
232
-			$return = wp_update_post( $post_data );
232
+			$return = wp_update_post($post_data);
233 233
 
234 234
 			// Return the error if it exists
235
-			if ( is_wp_error( $return ) ){
236
-				error_log( $return->get_error_messages() );
235
+			if (is_wp_error($return)) {
236
+				error_log($return->get_error_messages());
237 237
 				return $return->get_error_messages();
238 238
 			}
239 239
 
Please login to merge, or discard this patch.
includes/class-metaboxes.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class Metaboxes{
11
+class Metaboxes {
12 12
 
13 13
 	/**
14 14
 	 * Decide which cmb library to try and loop to get our metaboxes.
@@ -22,18 +22,18 @@  discard block
 block discarded – undo
22 22
 	 * @param string $slug Post Type slug ID.
23 23
 	 * @return array Fields to fill in for our post object.
24 24
 	 */
25
-	public function get_metaboxes( $slug ){
25
+	public function get_metaboxes($slug) {
26 26
 
27 27
 		$fields = array();
28 28
 
29 29
 		// CMB2
30
-		if ( class_exists( 'CMB2', false ) ) {
31
-			$fields = $this->get_cmb2_metaboxes( $slug );
30
+		if (class_exists('CMB2', false)) {
31
+			$fields = $this->get_cmb2_metaboxes($slug);
32 32
 		}
33 33
 
34 34
 		// Custom Metaboxes and Fields (CMB1)
35
-		if ( class_exists( 'cmb_Meta_Box', false ) ) {
36
-			$fields = $this->get_cmb1_metaboxes( $slug );
35
+		if (class_exists('cmb_Meta_Box', false)) {
36
+			$fields = $this->get_cmb1_metaboxes($slug);
37 37
 		}
38 38
 
39 39
 		// Return our array
@@ -56,55 +56,55 @@  discard block
 block discarded – undo
56 56
 	 * @param string $slug a custom post type ID.
57 57
 	 * @return array Array of fields.
58 58
 	 */
59
-	private function get_cmb2_metaboxes( $slug ){
59
+	private function get_cmb2_metaboxes($slug) {
60 60
 
61 61
 		$fields = array();
62 62
 
63 63
 		// Get all metaboxes from CMB2 library
64
-		$all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() );
64
+		$all_metaboxes = apply_filters('cmb2_meta_boxes', array());
65 65
 
66 66
 		// Loop through all possible sets of metaboxes added the old way
67
-		foreach ( $all_metaboxes as $metabox_array ){
67
+		foreach ($all_metaboxes as $metabox_array) {
68 68
 
69 69
 			// If the custom post type ID matches this set of fields, set & stop
70
-			if ( in_array( $slug, $metabox_array['object_types'] ) ) {
70
+			if (in_array($slug, $metabox_array['object_types'])) {
71 71
 
72 72
 				// If this is the first group of fields, simply set the value
73 73
 				// Else, merge this group with the previous one
74
-				if ( empty( $fields ) ){
74
+				if (empty($fields)) {
75 75
 					$fields = $metabox_array['fields'];
76 76
 				} else {
77
-					$fields = array_merge( $fields, $metabox_array['fields'] );
77
+					$fields = array_merge($fields, $metabox_array['fields']);
78 78
 				}
79 79
 			}
80 80
 
81 81
 		}
82 82
 
83 83
 		// Loop through all metaboxes added the new way
84
-		foreach ( \CMB2_Boxes::get_all() as $cmb ) {
84
+		foreach (\CMB2_Boxes::get_all() as $cmb) {
85 85
 
86 86
 			// Create the default
87 87
 			$match = false;
88 88
 
89 89
 			// Establish correct cmb types
90
-			if ( is_string( $cmb->meta_box['object_types'] ) ){
91
-				if ( $cmb->meta_box['object_types'] == $slug ){
90
+			if (is_string($cmb->meta_box['object_types'])) {
91
+				if ($cmb->meta_box['object_types'] == $slug) {
92 92
 					$match = true;
93 93
 				}
94 94
 			} else {
95
-				if ( in_array( $slug, $cmb->meta_box['object_types'] ) ){
95
+				if (in_array($slug, $cmb->meta_box['object_types'])) {
96 96
 					$match = true;
97 97
 				}
98 98
 			}
99 99
 
100
-			if ( $match !== true ){
100
+			if ($match !== true) {
101 101
 				continue;
102 102
 			}
103 103
 
104
-			if ( empty( $fields ) ){
104
+			if (empty($fields)) {
105 105
 				$fields = $cmb->meta_box['fields'];
106 106
 			} else {
107
-				$fields = array_merge( $fields, $cmb->meta_box['fields'] );
107
+				$fields = array_merge($fields, $cmb->meta_box['fields']);
108 108
 			}
109 109
 
110 110
 		}
@@ -128,25 +128,25 @@  discard block
 block discarded – undo
128 128
 	 * @param string $slug a custom post type ID.
129 129
 	 * @return array Array of fields.
130 130
 	 */
131
-	private function get_cmb1_metaboxes( $slug ){
131
+	private function get_cmb1_metaboxes($slug) {
132 132
 
133 133
 		$fields = array();
134 134
 
135 135
 		// Get all metaboxes from CMB2 library
136
-		$all_metaboxes = apply_filters( 'cmb_meta_boxes', array() );
136
+		$all_metaboxes = apply_filters('cmb_meta_boxes', array());
137 137
 
138 138
 		// Loop through all possible sets of metaboxes
139
-		foreach ( $all_metaboxes as $metabox_array ){
139
+		foreach ($all_metaboxes as $metabox_array) {
140 140
 
141 141
 			// If the custom post type ID matches this set of fields, set & stop
142
-			if ( in_array( $slug, $metabox_array['pages'] ) ) {
142
+			if (in_array($slug, $metabox_array['pages'])) {
143 143
 
144 144
 				// If this is the first group of fields, simply set the value
145 145
 				// Else, merge this group with the previous one
146
-				if ( empty( $fields ) ){
146
+				if (empty($fields)) {
147 147
 					$fields = $metabox_array['fields'];
148 148
 				} else {
149
-					$fields = array_merge( $fields, $metabox_array['fields'] );
149
+					$fields = array_merge($fields, $metabox_array['fields']);
150 150
 				}
151 151
 			}
152 152
 
@@ -169,36 +169,36 @@  discard block
 block discarded – undo
169 169
 	 * @param int $post_id Single post ID.
170 170
 	 * @param array $cmb custom metabox array from CMB2.
171 171
 	 */
172
-	public function random_metabox_content( $post_id, $cmb, $connected ){
172
+	public function random_metabox_content($post_id, $cmb, $connected) {
173 173
 		$value = '';
174 174
 
175 175
 		// First check that our post ID & cmb array aren't empty
176
-		if ( empty( $cmb ) || empty( $post_id ) ){
176
+		if (empty($cmb) || empty($post_id)) {
177 177
 			return;
178 178
 		}
179 179
 
180 180
 		// Fetch the appropriate type of data and return
181
-		switch( $cmb['type'] ){
181
+		switch ($cmb['type']) {
182 182
 
183 183
 			case 'text':
184 184
 			case 'text_small':
185 185
 			case 'text_medium':
186 186
 
187 187
 				// If phone is in the id, fetch a phone #
188
-				if ( stripos( $cmb['id'], 'phone' ) ){
188
+				if (stripos($cmb['id'], 'phone')) {
189 189
 					$value = TestContent::phone();
190 190
 
191 191
 				// If email is in the id, fetch an email address
192
-				} elseif ( stripos( $cmb['id'], 'email' ) ){
192
+				} elseif (stripos($cmb['id'], 'email')) {
193 193
 					$value = TestContent::email();
194 194
 
195 195
 				// If time is in the id, fetch a time string
196
-				} elseif ( stripos( $cmb['id'], 'time' ) ){
196
+				} elseif (stripos($cmb['id'], 'time')) {
197 197
 					$value = TestContent::time();
198 198
 
199 199
 				// Otherwise, just a random text string
200 200
 				} else {
201
-					$value = TestContent::title( rand( 10, 50 ) );
201
+					$value = TestContent::title(rand(10, 50));
202 202
 				}
203 203
 
204 204
 				break;
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 229
 
230 230
 			case 'text_date':
231 231
 
232
-				$value = TestContent::date( 'm/d/Y' );
232
+				$value = TestContent::date('m/d/Y');
233 233
 
234 234
 				break;
235 235
 
236 236
 			case 'text_date_timestamp':
237 237
 			case 'text_datetime_timestamp':
238 238
 
239
-				$value = TestContent::date( 'U' );
239
+				$value = TestContent::date('U');
240 240
 
241 241
 				break;
242 242
 
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 
245 245
 			case 'text_money':
246 246
 
247
-				$value = rand( 0, 100000 );
247
+				$value = rand(0, 100000);
248 248
 
249 249
 				break;
250 250
 
251 251
 			case 'test_colorpicker':
252 252
 
253
-				$value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT );
253
+				$value = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
254 254
 
255 255
 				break;
256 256
 
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 			case 'radio':
268 268
 
269 269
 				// Grab a random item out of the array and return the key
270
-				$new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 );
271
-				$value = key( $new_val );
270
+				$new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1);
271
+				$value = key($new_val);
272 272
 
273 273
 				break;
274 274
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 			case 'checkbox':
280 280
 
281 281
 				// 50/50 odds of being turned on
282
-				if ( rand( 0, 1 ) == 1 ){
282
+				if (rand(0, 1) == 1) {
283 283
 					$value = 'on';
284 284
 				}
285 285
 
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 				$new_option = array();
291 291
 
292 292
 				// Loop through each of our options
293
-				foreach ( $cmb['options'] as $key => $value ){
293
+				foreach ($cmb['options'] as $key => $value) {
294 294
 
295 295
 					// 50/50 chance of being included
296
-					if ( rand( 0, 1 ) ){
296
+					if (rand(0, 1)) {
297 297
 						$new_option[] = $key;
298 298
 					}
299 299
 
@@ -311,8 +311,8 @@  discard block
 block discarded – undo
311 311
 
312 312
 			case 'file':
313 313
 
314
-				if ( true == $connected ){
315
-					$value = TestContent::image( $post_id );
314
+				if (true == $connected) {
315
+					$value = TestContent::image($post_id);
316 316
 				}
317 317
 
318 318
 				break;
@@ -328,20 +328,20 @@  discard block
 block discarded – undo
328 328
 		}
329 329
 
330 330
 		// Value must exist to attempt to insert
331
-		if ( !empty( $value ) && !is_wp_error( $value ) ){
331
+		if (!empty($value) && !is_wp_error($value)) {
332 332
 
333 333
 			// Files must be treated separately - they use the attachment ID
334 334
 			// & url of media for separate cmb values
335
-			if ( $cmb['type'] != 'file' ){
336
-				add_post_meta( $post_id, $cmb['id'], $value, true );
335
+			if ($cmb['type'] != 'file') {
336
+				add_post_meta($post_id, $cmb['id'], $value, true);
337 337
 			} else {
338
-				add_post_meta( $post_id, $cmb['id'].'_id', $value, true );
339
-				add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true );
338
+				add_post_meta($post_id, $cmb['id'].'_id', $value, true);
339
+				add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true);
340 340
 			}
341 341
 
342 342
 		// If we're dealing with a WP Error object, just return the message for debugging
343
-		} elseif ( is_wp_error( $value ) ){
344
-			error_log( $value->get_error_message() );
343
+		} elseif (is_wp_error($value)) {
344
+			error_log($value->get_error_message());
345 345
 			return $value->get_error_message();
346 346
 		}
347 347
 
Please login to merge, or discard this patch.
includes/class-connection-test.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  * @subpackage Evans
18 18
  * @author     Old Town Media
19 19
  */
20
-class ConnectionTest{
20
+class ConnectionTest {
21 21
 
22 22
 	/**
23 23
 	 * Run all of our connection tests.
@@ -26,33 +26,33 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return boolean Status of connection to Internet/Splashbase.
28 28
 	 */
29
-	public function test(){
29
+	public function test() {
30 30
 
31 31
 		/*
32 32
 		 * Make sure that we're looking at the correct admin page
33 33
 		 */
34
-		if ( ! $this->check_admin_page() ){
34
+		if (!$this->check_admin_page()) {
35 35
 			return;
36 36
 		}
37 37
 
38 38
 		/*
39 39
 		 * Test #1 - Check for Airplane Mode plugin status
40 40
 		 */
41
-		if ( ! $this->check_airplane_mode() ){
41
+		if (!$this->check_airplane_mode()) {
42 42
 			return false;
43 43
 		}
44 44
 
45 45
 		/*
46 46
 		 * Test #2 - Check Internet connection in general
47 47
 		 */
48
-		if ( ! $this->check_internet() ){
48
+		if (!$this->check_internet()) {
49 49
 			return false;
50 50
 		}
51 51
 
52 52
 		/*
53 53
 		 * Test #3 - Check External URL itself (Splashbase here)
54 54
 		 */
55
-		if ( ! $this->check_external_url( 'http://www.splashbase.co/api/v1/images/' ) ){
55
+		if (!$this->check_external_url('http://www.splashbase.co/api/v1/images/')) {
56 56
 			return false;
57 57
 		}
58 58
 
@@ -75,22 +75,22 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return boolean Whether or not we're in the right place.
77 77
 	 */
78
-	private function check_admin_page(){
78
+	private function check_admin_page() {
79 79
 		global $current_screen;
80 80
 
81 81
 		// Only run if we're in the admin page
82
-		if ( !is_admin() ){
82
+		if (!is_admin()) {
83 83
 			return false;
84 84
 		}
85 85
 
86 86
 		// Get the current admin screen & verify that we're on the right one
87 87
 		// before continuing.
88
-		if ( isset ( $current_screen ) && 'tools_page_create-test-data' != $current_screen->base ){
88
+		if (isset ($current_screen) && 'tools_page_create-test-data' != $current_screen->base) {
89 89
 			return false;
90 90
 		}
91 91
 
92
-		$last_uri_bit = explode( '=', $_SERVER['REQUEST_URI'] );
93
-		if ( 'create-test-data' != end( $last_uri_bit ) ){
92
+		$last_uri_bit = explode('=', $_SERVER['REQUEST_URI']);
93
+		if ('create-test-data' != end($last_uri_bit)) {
94 94
 			return false;
95 95
 		}
96 96
 
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return boolean Connected or not.
110 110
 	 */
111
-	private function check_airplane_mode(){
111
+	private function check_airplane_mode() {
112 112
 
113
-		if ( class_exists( 'Airplane_Mode_Core' ) ){
113
+		if (class_exists('Airplane_Mode_Core')) {
114 114
 			// Is airplane mode active?
115
-			$airplane_mode = get_site_option( 'airplane-mode' );
115
+			$airplane_mode = get_site_option('airplane-mode');
116 116
 
117
-			if ( $airplane_mode === 'on' ){
117
+			if ($airplane_mode === 'on') {
118 118
 				return false;
119 119
 			}
120 120
 		}
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return boolean Connected or not.
135 135
 	 */
136
-	private function check_internet(){
136
+	private function check_internet() {
137 137
 
138 138
 		// Attempt to open a socket connection to Google
139
-		$connected = @fsockopen( "www.google.com", 80 );
139
+		$connected = @fsockopen("www.google.com", 80);
140 140
 
141
-		if ( !$connected ){
141
+		if (!$connected) {
142 142
 			return false;
143 143
 		}
144 144
 
145 145
 		// Close out our 1st test
146
-		fclose( $connected );
146
+		fclose($connected);
147 147
 
148 148
 		return true;
149 149
 
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 	 * @param string $url External URL to attempt to reach.
161 161
 	 * @return boolean Connected or not.
162 162
 	 */
163
-	private function check_external_url( $url ){
163
+	private function check_external_url($url) {
164 164
 
165
-		$test_url = esc_url( $url );
166
-		$response = wp_remote_get( $test_url );
165
+		$test_url = esc_url($url);
166
+		$response = wp_remote_get($test_url);
167 167
 
168
-		if ( !is_array( $response ) ){
168
+		if (!is_array($response)) {
169 169
 			return false;
170 170
 		}
171 171
 
Please login to merge, or discard this patch.
includes/class-admin-page.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class AdminPage{
11
+class AdminPage {
12 12
 
13 13
 	/**
14 14
 	 * plugin
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @see admin_menu, wp_ajax actions
47 47
 	 */
48
-	public function hooks(){
48
+	public function hooks() {
49 49
 
50 50
 		$connection = new ConnectionTest;
51
-		$this->definitions	= $this->plugin->get_definitions();
52
-		$this->connected	= $connection->test();
51
+		$this->definitions = $this->plugin->get_definitions();
52
+		$this->connected = $connection->test();
53 53
 
54
-		add_action( 'admin_menu' , array( $this, 'add_menu_item' ) );
55
-		add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) );
56
-		add_filter( 'plugin_action_links_' . $this->definitions->basename , array( $this, 'add_settings_link' ) );
57
-		add_action( 'admin_notices', array( $this, 'internet_connected_admin_notice' ) );
54
+		add_action('admin_menu', array($this, 'add_menu_item'));
55
+		add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback'));
56
+		add_filter('plugin_action_links_'.$this->definitions->basename, array($this, 'add_settings_link'));
57
+		add_action('admin_notices', array($this, 'internet_connected_admin_notice'));
58 58
 
59 59
 	}
60 60
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @param Plugin $plugin Main plugin instance.
66 66
 	 */
67
-	public function set_plugin( $plugin ) {
67
+	public function set_plugin($plugin) {
68 68
 
69 69
 		$this->plugin = $plugin;
70 70
 		return $this;
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
 
82 82
 		$page = add_submenu_page(
83 83
 			'tools.php',
84
-			__( 'Create Test Content', 'otm-test-content' ),
85
-			__( 'Test Content', 'otm-test-content' ),
84
+			__('Create Test Content', 'otm-test-content'),
85
+			__('Test Content', 'otm-test-content'),
86 86
 			'manage_options',
87 87
 			'create-test-data',
88
-			array( $this, 'admin_page' )
88
+			array($this, 'admin_page')
89 89
 		);
90 90
 
91
-		add_action( 'admin_print_styles-' . $page, array( $this, 'load_scripts' ) );
91
+		add_action('admin_print_styles-'.$page, array($this, 'load_scripts'));
92 92
 
93 93
 	}
94 94
 
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
 	 * @param  array $links Existing links
99 99
 	 * @return array 		Modified links
100 100
 	 */
101
-	public function add_settings_link( $links ) {
101
+	public function add_settings_link($links) {
102 102
 
103
-		$settings_link = '<a href="tools.php?page=create-test-data">' . __( 'Build Test Content', 'otm-test-content' ) . '</a>';
104
-  		array_push( $links, $settings_link );
103
+		$settings_link = '<a href="tools.php?page=create-test-data">'.__('Build Test Content', 'otm-test-content').'</a>';
104
+  		array_push($links, $settings_link);
105 105
   		return $links;
106 106
 
107 107
 	}
@@ -114,24 +114,24 @@  discard block
 block discarded – undo
114 114
 	 * Internet, and the test fails displays a notice informing the user that
115 115
 	 * images will not pull into test data.
116 116
 	 */
117
-	public function internet_connected_admin_notice(){
117
+	public function internet_connected_admin_notice() {
118 118
 
119 119
 		// Get the current admin screen & verify that we're on the right one
120 120
 		// before continuing.
121 121
 		$screen = get_current_screen();
122 122
 
123
-		if ( $screen->base != 'tools_page_create-test-data' ){
123
+		if ($screen->base != 'tools_page_create-test-data') {
124 124
 			return;
125 125
 		}
126 126
 
127 127
 		// Check the response
128
-		if ( $this->connected ) {
128
+		if ($this->connected) {
129 129
 			// We got a response so early return
130 130
 			return;
131 131
 		} else {
132 132
 			// We didn't get a reponse so print the notice out
133 133
 			echo '<div class="notice notice-error">';
134
-		        echo '<p>'.__( 'WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content' ).'</p>';
134
+		        echo '<p>'.__('WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content').'</p>';
135 135
 		    echo '</div>';
136 136
 		}
137 137
 
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
 	/**
142 142
 	 * Load our script in the admin section and serve in data.
143 143
 	 */
144
-	public function load_scripts(){
144
+	public function load_scripts() {
145 145
 
146
-		wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) );
147
-		wp_enqueue_style( 'test-content-css', plugins_url( 'assets/admin.css' , dirname( __FILE__ ) ) );
146
+		wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__)));
147
+		wp_enqueue_style('test-content-css', plugins_url('assets/admin.css', dirname(__FILE__)));
148 148
 
149 149
 		$data = array(
150
-			'nonce'			=> wp_create_nonce( 'handle-test-data' ),
151
-			'createdStr'	=> __( 'Created', 'otm-test-content' ),
152
-			'deletedStr'	=> __( 'Deleting', 'otm-test-content' ),
153
-			'creatingStr'	=> __( 'Creating', 'otm-test-content' ),
150
+			'nonce'			=> wp_create_nonce('handle-test-data'),
151
+			'createdStr'	=> __('Created', 'otm-test-content'),
152
+			'deletedStr'	=> __('Deleting', 'otm-test-content'),
153
+			'creatingStr'	=> __('Creating', 'otm-test-content'),
154 154
 		);
155 155
 
156
-		wp_localize_script( 'test-content-js', 'test_content', $data );
156
+		wp_localize_script('test-content-js', 'test_content', $data);
157 157
 
158 158
 	}
159 159
 
@@ -165,21 +165,21 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function handle_test_data_callback() {
167 167
 
168
-		$action		= $_REQUEST['todo'];
169
-		$nonce		= $_REQUEST['nonce'];
168
+		$action = $_REQUEST['todo'];
169
+		$nonce = $_REQUEST['nonce'];
170 170
 
171 171
 		// Verify that we have a proper logged in user and it's the right person
172
-		if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){
172
+		if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) {
173 173
 			return;
174 174
 		}
175 175
 
176
-		if ( $action == 'delete' ){
176
+		if ($action == 'delete') {
177 177
 
178
-			$this->deletion_routing( $_REQUEST );
178
+			$this->deletion_routing($_REQUEST);
179 179
 
180
-		} elseif ( $action == 'create' ){
180
+		} elseif ($action == 'create') {
181 181
 
182
-			$this->creation_routing( $_REQUEST );
182
+			$this->creation_routing($_REQUEST);
183 183
 
184 184
 		}
185 185
 
@@ -192,17 +192,17 @@  discard block
 block discarded – undo
192 192
 	 * Choose which type of creation needs to be accomplished and route through
193 193
 	 * the correct class.
194 194
 	 */
195
-	private function creation_routing( $data ){
195
+	private function creation_routing($data) {
196 196
 
197
-		if ( $data['type'] == 'post' ){
197
+		if ($data['type'] == 'post') {
198 198
 
199 199
 			$create_content = new CreatePost;
200
-			$create_content->create_post_type_content( $data['slug'], $data['connection'], true, 1 );
200
+			$create_content->create_post_type_content($data['slug'], $data['connection'], true, 1);
201 201
 
202
-		} elseif( $data['type'] == 'term' ){
202
+		} elseif ($data['type'] == 'term') {
203 203
 
204 204
 			$create_content = new CreateTerm;
205
-			$create_content->create_terms( $data['slug'], true, 1 );
205
+			$create_content->create_terms($data['slug'], true, 1);
206 206
 
207 207
 		}
208 208
 
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 	 * Choose which type of deletion needs to be accomplished and route through
214 214
 	 * the correct method of Delete.
215 215
 	 */
216
-	private function deletion_routing( $data ){
216
+	private function deletion_routing($data) {
217 217
 
218 218
 		$delete_content = new Delete;
219 219
 
220
-		if ( $data['type'] == 'post' ){
220
+		if ($data['type'] == 'post') {
221 221
 
222
-			$delete_content->delete_posts( $data['slug'], true );
222
+			$delete_content->delete_posts($data['slug'], true);
223 223
 
224
-		} elseif ( $data['type'] == 'term' ){
224
+		} elseif ($data['type'] == 'term') {
225 225
 
226
-			$delete_content->delete_terms( $data['slug'], true );
226
+			$delete_content->delete_terms($data['slug'], true);
227 227
 
228 228
 		}
229 229
 
@@ -233,36 +233,36 @@  discard block
 block discarded – undo
233 233
 	/**
234 234
 	 * Print out our admin page to control test data.
235 235
 	 */
236
-	public function admin_page(){
236
+	public function admin_page() {
237 237
 
238 238
 		$html = "";
239 239
 
240
-		$html .= '<div class="wrap" id="options_editor">' . "\n";
240
+		$html .= '<div class="wrap" id="options_editor">'."\n";
241 241
 
242
-			$html .= '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n";
242
+			$html .= '<h2>'.__('Create Test Data', 'otm-test-content').'</h2>'."\n";
243 243
 
244 244
 			$html .= "<div>";
245 245
 
246 246
 			$html .= "<div class='test-data-cpt'>";
247 247
 				$html .= "<h3>";
248
-					$html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>";
249
-					$html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>".__( 'Set to 0 to keep random', 'otm-test-content' )."</i></small>";
248
+					$html .= "<span class='label'>".__('Quantity', 'otm-test-content')."</span>";
249
+					$html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>".__('Set to 0 to keep random', 'otm-test-content')."</i></small>";
250 250
 				$html .= "</h3>";
251 251
 			$html .= "</div>";
252 252
 
253 253
 			$html .= "<input type='hidden' id='connection-status' value='".$this->connected."'>";
254 254
 
255 255
 			// Loop through every post type available on the site
256
-			$post_types = get_post_types( array( 'public' => true ), 'objects' );
256
+			$post_types = get_post_types(array('public' => true), 'objects');
257 257
 
258
-			foreach ( $post_types as $post_type ) {
258
+			foreach ($post_types as $post_type) {
259 259
 
260 260
 				$skipped_cpts = array(
261 261
 					'attachment'
262 262
 				);
263 263
 
264 264
 				// Skip banned cpts
265
-				if ( in_array( $post_type->name, $skipped_cpts ) ){
265
+				if (in_array($post_type->name, $skipped_cpts)) {
266 266
 					continue;
267 267
 				}
268 268
 
@@ -271,38 +271,38 @@  discard block
 block discarded – undo
271 271
 					// Create row for the post/page/cpt
272 272
 					$html .= "<h3>";
273 273
 
274
-						$html .= "<span class='label'>" . $post_type->labels->name . "</span>";
275
-						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> ".__( 'Create Test Data', 'otm-test-content' )."</a>";
276
-						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete Test Data', 'otm-test-content' )."</a>";
274
+						$html .= "<span class='label'>".$post_type->labels->name."</span>";
275
+						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> ".__('Create Test Data', 'otm-test-content')."</a>";
276
+						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__('Delete Test Data', 'otm-test-content')."</a>";
277 277
 
278 278
 					$html .= "</h3>";
279 279
 
280 280
 					// Create row for each taxonomy associated with the post/page/cpt
281
-					$taxonomies = get_object_taxonomies( $post_type->name );
281
+					$taxonomies = get_object_taxonomies($post_type->name);
282 282
 
283
-						if ( !empty( $taxonomies ) ){
283
+						if (!empty($taxonomies)) {
284 284
 
285
-							foreach( $taxonomies as $tax ){
285
+							foreach ($taxonomies as $tax) {
286 286
 
287 287
 								$html .= "<h3 class='term-box'>";
288 288
 
289 289
 								$skipped_taxonomies = array(
290
-									'post_format',				// We shouldn't be making random post format classes
290
+									'post_format', // We shouldn't be making random post format classes
291 291
 									'product_shipping_class'	// These aren't used visually and are therefore skipped
292 292
 								);
293 293
 
294 294
 								// Skip banned taxonomies
295
-								if ( in_array( $tax, $skipped_taxonomies ) ){
295
+								if (in_array($tax, $skipped_taxonomies)) {
296 296
 									continue;
297 297
 								}
298 298
 
299
-								$taxonomy = get_taxonomy( $tax );
299
+								$taxonomy = get_taxonomy($tax);
300 300
 
301 301
 								$html .= "<span class='label'>".$taxonomy->labels->name."</span>";
302 302
 
303
-								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> ".__( 'Create', 'otm-test-content' )." ".$taxonomy->labels->name."</a>";
303
+								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> ".__('Create', 'otm-test-content')." ".$taxonomy->labels->name."</a>";
304 304
 
305
-								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete', 'otm-test-content' )." ".$taxonomy->labels->name."</a>";
305
+								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__('Delete', 'otm-test-content')." ".$taxonomy->labels->name."</a>";
306 306
 
307 307
 								$html .= "</h3>";
308 308
 
Please login to merge, or discard this patch.