Completed
Push — master ( add22c...fb4c0b )
by Mike
02:33
created
types/post.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -276,7 +276,7 @@
 block discarded – undo
276 276
 		$post_types = get_post_types( array( 'public' => true ), 'objects' );
277 277
 		foreach ( $post_types as $post_type ) :
278 278
 
279
-		    return $this->delete( $post_type->name );
279
+			return $this->delete( $post_type->name );
280 280
 
281 281
 		endforeach;
282 282
 
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @subpackage Evans
14 14
  * @author     Old Town Media
15 15
  */
16
-class Post extends Abs\Type{
16
+class Post extends Abs\Type {
17 17
 
18 18
 	/**
19 19
 	 * metaboxes
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @see object
40 40
 	 */
41
-	public function __construct(){
41
+	public function __construct() {
42 42
 
43 43
 		$this->metaboxes = new Main\Metaboxes;
44 44
 
@@ -59,29 +59,29 @@  discard block
 block discarded – undo
59 59
 	 * @param boolean $connection Whether or not we're connected to the Internet.
60 60
 	 * @param int $num Optional. Number of posts to create.
61 61
 	 */
62
-	public function create_objects( $slug, $connection, $num = '' ){
62
+	public function create_objects($slug, $connection, $num = '') {
63 63
 
64 64
 		// If we're missing a custom post type id - don't do anything
65
-		if ( empty( $slug ) ){
65
+		if (empty($slug)) {
66 66
 			return;
67 67
 		}
68 68
 
69 69
 		// Gather the necessary data to create the posts
70
-		$supports 	= $this->get_cpt_supports( $slug );
71
-		$metaboxes	= $this->metaboxes->get_metaboxes( $slug );
70
+		$supports 	= $this->get_cpt_supports($slug);
71
+		$metaboxes	= $this->metaboxes->get_metaboxes($slug);
72 72
 
73 73
 		// Set our connection status for the rest of the methods
74 74
 		$this->connected = $connection;
75 75
 
76 76
 		// If we forgot to put in a quantity, make one for us
77
-		if ( empty( $num ) ){
78
-			$num = rand( 5, 30 );
77
+		if (empty($num)) {
78
+			$num = rand(5, 30);
79 79
 		}
80 80
 
81 81
 		// Create test posts
82
-		for( $i = 0; $i < $num; $i++ ){
82
+		for ($i = 0; $i < $num; $i++) {
83 83
 
84
-			$return = $this->create_test_object( $slug, $supports, $metaboxes );
84
+			$return = $this->create_test_object($slug, $supports, $metaboxes);
85 85
 
86 86
 			return $return;
87 87
 
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
 	 * @param array $supports Features that the post type supports.
106 106
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
107 107
 	 */
108
-	private function create_test_object( $slug, $supports, $metaboxes ){
108
+	private function create_test_object($slug, $supports, $metaboxes) {
109 109
 		$return = '';
110 110
 
111 111
 		// Get a random title
112
-		$title = apply_filters( "tc_{$slug}_post_title", TestContent::title() );
112
+		$title = apply_filters("tc_{$slug}_post_title", TestContent::title());
113 113
 
114 114
 		// First, insert our post
115 115
 		$post = array(
116
-		  'post_name'      => sanitize_title( $title ),
116
+		  'post_name'      => sanitize_title($title),
117 117
 		  'post_status'    => 'publish',
118 118
 		  'post_type'      => $slug,
119 119
 		  'ping_status'    => 'closed',
@@ -121,57 +121,57 @@  discard block
 block discarded – undo
121 121
 		);
122 122
 
123 123
 		// Add title if supported
124
-		if ( $supports['title'] === true ){
124
+		if ($supports['title'] === true) {
125 125
 			$post['post_title'] = $title;
126 126
 		}
127 127
 
128 128
 		// Add main content if supported
129
-		if ( $supports['editor'] === true ){
130
-			$post['post_content'] = apply_filters( "tc_{$slug}_post_content", TestContent::paragraphs() );
129
+		if ($supports['editor'] === true) {
130
+			$post['post_content'] = apply_filters("tc_{$slug}_post_content", TestContent::paragraphs());
131 131
 		}
132 132
 
133 133
 		// Add excerpt content if supported
134
-		if ( $supports['excerpt'] === true ){
135
-			$post['post_excerpt'] = apply_filters( "tc_{$slug}_post_excerpt", TestContent::plain_text() );
134
+		if ($supports['excerpt'] === true) {
135
+			$post['post_excerpt'] = apply_filters("tc_{$slug}_post_excerpt", TestContent::plain_text());
136 136
 		}
137 137
 
138 138
 		// Insert then post object
139
-		$post_id = wp_insert_post( apply_filters( "tc_{$slug}_post_arguments", $post ) );
139
+		$post_id = wp_insert_post(apply_filters("tc_{$slug}_post_arguments", $post));
140 140
 
141 141
 		// Then, set a test content flag on the new post for later deletion
142
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
142
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
143 143
 
144 144
 		// Add thumbnail if supported
145
-		if ( $this->connected == true && ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ) ){
146
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
145
+		if ($this->connected == true && ($supports['thumbnail'] === true || in_array($slug, array('post', 'page')))) {
146
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
147 147
 		}
148 148
 
149
-		$taxonomies = get_object_taxonomies( $slug );
149
+		$taxonomies = get_object_taxonomies($slug);
150 150
 
151 151
 		// Assign the post to terms
152
-		if ( !empty( $taxonomies ) ){
153
-			$return .= $this->assign_terms( $post_id, $taxonomies );
152
+		if (!empty($taxonomies)) {
153
+			$return .= $this->assign_terms($post_id, $taxonomies);
154 154
 		}
155 155
 
156 156
 		// Spin up metaboxes
157
-		if ( !empty( $metaboxes ) ){
158
-			foreach ( $metaboxes as $cmb ) :
159
-				$return .= $this->metaboxes->random_metabox_content( $post_id, $cmb, $this->connected );
157
+		if (!empty($metaboxes)) {
158
+			foreach ($metaboxes as $cmb) :
159
+				$return .= $this->metaboxes->random_metabox_content($post_id, $cmb, $this->connected);
160 160
 			endforeach;
161 161
 		}
162 162
 
163 163
 		// Check if we have errors and return them or created message
164
-		if ( is_wp_error( $post_id ) ){
165
-			error_log( $post_id->get_error_message() );
164
+		if (is_wp_error($post_id)) {
165
+			error_log($post_id->get_error_message());
166 166
 			return $post_id;
167 167
 		} else {
168 168
 			return array(
169 169
 				'action'	=> 'created',
170 170
 				'object'	=> 'post',
171 171
 				'oid'		=> $post_id,
172
-				'type'		=> get_post_type( $post_id ),
173
-				'link_edit'	=> admin_url( '/post.php?post='.$post_id.'&action=edit' ),
174
-				'link_view'	=> get_permalink( $post_id ),
172
+				'type'		=> get_post_type($post_id),
173
+				'link_edit'	=> admin_url('/post.php?post='.$post_id.'&action=edit'),
174
+				'link_view'	=> get_permalink($post_id),
175 175
 			);
176 176
 		}
177 177
 
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 	 * @param string $slug a custom post type ID.
189 189
 	 * @return array Array of necessary supports booleans.
190 190
 	 */
191
-	private function get_cpt_supports( $slug ){
191
+	private function get_cpt_supports($slug) {
192 192
 
193 193
 		$supports = array(
194
-			'title'		=> post_type_supports( $slug, 'title' ),
195
-			'editor'	=> post_type_supports( $slug, 'editor' ),
196
-			'excerpt'	=> post_type_supports( $slug, 'excerpt' ),
197
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
194
+			'title'		=> post_type_supports($slug, 'title'),
195
+			'editor'	=> post_type_supports($slug, 'editor'),
196
+			'excerpt'	=> post_type_supports($slug, 'excerpt'),
197
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
198 198
 		);
199 199
 
200 200
 		return $supports;
@@ -215,26 +215,26 @@  discard block
 block discarded – undo
215 215
 	 * @param array $taxonomies taxonomies assigned to this cpt.
216 216
 	 * @return object WP Error if there is one.
217 217
 	 */
218
-	private function assign_terms( $post_id, $taxonomies ){
218
+	private function assign_terms($post_id, $taxonomies) {
219 219
 
220 220
 		// Make sure it's an array & has items
221
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
221
+		if (empty($taxonomies) || !is_array($taxonomies)) {
222 222
 			return;
223 223
 		}
224 224
 
225
-		foreach ( $taxonomies as $tax ){
225
+		foreach ($taxonomies as $tax) {
226 226
 
227 227
 			// Get the individual terms already existing
228
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
229
-			$count = count( $terms ) - 1;
228
+			$terms = get_terms($tax, array('hide_empty'	=> false));
229
+			$count = count($terms) - 1;
230 230
 
231 231
 			// If there are no terms, skip to the next taxonomy
232
-			if ( empty( $terms ) ){
232
+			if (empty($terms)) {
233 233
 				continue;
234 234
 			}
235 235
 
236 236
 			// Get a random index to use
237
-			$index = rand( 0, $count );
237
+			$index = rand(0, $count);
238 238
 
239 239
 			// Initialize our array
240 240
 			$post_data = array(
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
 			);
243 243
 
244 244
 			// Set the term data to update
245
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
245
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
246 246
 
247 247
 			// Update the post with the taxonomy info
248
-			$return = wp_update_post( $post_data );
248
+			$return = wp_update_post($post_data);
249 249
 
250 250
 			// Return the error if it exists
251
-			if ( is_wp_error( $return ) ){
252
-				error_log( $return->get_error_messages() );
251
+			if (is_wp_error($return)) {
252
+				error_log($return->get_error_messages());
253 253
 				return $return->get_error_messages();
254 254
 			}
255 255
 
@@ -263,20 +263,20 @@  discard block
 block discarded – undo
263 263
 	 *
264 264
 	 * @see Delete
265 265
 	 */
266
-	public function delete_all(){
266
+	public function delete_all() {
267 267
 
268
-		$delete =  new Delete;
268
+		$delete = new Delete;
269 269
 
270 270
 		// Make sure that the current user is logged in & has full permissions.
271
-		if ( ! $delete->user_can_delete() ){
271
+		if (!$delete->user_can_delete()) {
272 272
 			return;
273 273
 		}
274 274
 
275 275
 		// Loop through all post types and remove any test data
276
-		$post_types = get_post_types( array( 'public' => true ), 'objects' );
277
-		foreach ( $post_types as $post_type ) :
276
+		$post_types = get_post_types(array('public' => true), 'objects');
277
+		foreach ($post_types as $post_type) :
278 278
 
279
-		    return $this->delete( $post_type->name );
279
+		    return $this->delete($post_type->name);
280 280
 
281 281
 		endforeach;
282 282
 
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
 	 *
295 295
 	 * @param string $slug a custom post type ID.
296 296
 	 */
297
-	public function delete( $slug ){
297
+	public function delete($slug) {
298 298
 
299
-		$delete =  new Delete;
299
+		$delete = new Delete;
300 300
 
301 301
 		// Make sure that the current user is logged in & has full permissions.
302
-		if ( ! $delete->user_can_delete() ){
302
+		if (!$delete->user_can_delete()) {
303 303
 			return;
304 304
 		}
305 305
 
306 306
 		// Check that $cptslg has a string.
307
-		if ( empty( $slug ) ){
307
+		if (empty($slug)) {
308 308
 			return;
309 309
 		}
310 310
 
@@ -321,34 +321,34 @@  discard block
 block discarded – undo
321 321
 			),
322 322
 		);
323 323
 
324
-		$objects = new \WP_Query( $query );
324
+		$objects = new \WP_Query($query);
325 325
 
326
-		if ( $objects->have_posts() ){
326
+		if ($objects->have_posts()) {
327 327
 
328 328
 			$events = array();
329 329
 
330
-			while ( $objects->have_posts() ) : $objects->the_post();
330
+			while ($objects->have_posts()) : $objects->the_post();
331 331
 
332 332
 				// Find any media associated with the test post and delete it as well
333
-				$this->delete_associated_media( get_the_id() );
333
+				$this->delete_associated_media(get_the_id());
334 334
 
335 335
 				$events[] = array(
336 336
 					'action'	=> 'deleted',
337 337
 					'oid'		=> get_the_id(),
338
-					'type'		=> get_post_type( get_the_id() ),
338
+					'type'		=> get_post_type(get_the_id()),
339 339
 					'link'		=> ''
340 340
 				);
341 341
 
342 342
 				// Force delete the post
343
-				wp_delete_post( get_the_id(), true );
343
+				wp_delete_post(get_the_id(), true);
344 344
 
345 345
 			endwhile;
346 346
 
347
-			$obj = get_post_type_object( $slug );
347
+			$obj = get_post_type_object($slug);
348 348
 
349 349
 			$events[] = array(
350 350
 				'action'	=> 'general',
351
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $obj->labels->all_items
351
+				'message'	=> __('Deleted', 'otm-test-content').' '.$obj->labels->all_items
352 352
 			);
353 353
 
354 354
 			return $events;
@@ -371,28 +371,28 @@  discard block
 block discarded – undo
371 371
 	 *
372 372
 	 * @param int $pid a custom post type ID.
373 373
 	 */
374
-	private function delete_associated_media( $pid ){
374
+	private function delete_associated_media($pid) {
375 375
 
376
-		$delete =  new Delete;
376
+		$delete = new Delete;
377 377
 
378 378
 		// Make sure that the current user is logged in & has full permissions.
379
-		if ( !$delete->user_can_delete() ){
379
+		if (!$delete->user_can_delete()) {
380 380
 			return;
381 381
 		}
382 382
 
383 383
 		// Make sure $pid is, in fact, an ID
384
-		if ( !is_int( $pid ) ){
384
+		if (!is_int($pid)) {
385 385
 			return;
386 386
 		}
387 387
 
388 388
 		// Get our images
389
-		$media = get_attached_media( 'image', $pid );
389
+		$media = get_attached_media('image', $pid);
390 390
 
391
-		if ( !empty( $media ) ){
391
+		if (!empty($media)) {
392 392
 
393 393
 			// Loop through the media & delete each one
394
-			foreach ( $media as $attachment ){
395
-				wp_delete_attachment( $attachment->ID, true );
394
+			foreach ($media as $attachment) {
395
+				wp_delete_attachment($attachment->ID, true);
396 396
 			}
397 397
 
398 398
 		}
Please login to merge, or discard this patch.
types/term.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @subpackage Evans
13 13
  * @author     Old Town Media
14 14
  */
15
-class Term extends Abs\Type{
15
+class Term extends Abs\Type {
16 16
 
17 17
 	/**
18 18
 	 * type
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 	 * @param string $slug a custom post type ID.
38 38
 	 * @param int $num Optional. Number of posts to create.
39 39
 	 */
40
-	public function create_objects( $slug, $connection, $num = '' ){
40
+	public function create_objects($slug, $connection, $num = '') {
41 41
 
42 42
 		// If we're missing a custom post type id - don't do anything
43
-		if ( empty( $slug ) ){
43
+		if (empty($slug)) {
44 44
 			return;
45 45
 		}
46 46
 
@@ -48,14 +48,14 @@  discard block
 block discarded – undo
48 48
 		$this->connected = $connection;
49 49
 
50 50
 		// If we forgot to put in a quantity, make one for us
51
-		if ( empty( $num ) ){
52
-			$num = rand( 5, 30 );
51
+		if (empty($num)) {
52
+			$num = rand(5, 30);
53 53
 		}
54 54
 
55 55
 		// Create test terms
56
-		for( $i = 0; $i < $num; $i++ ){
56
+		for ($i = 0; $i < $num; $i++) {
57 57
 
58
-			$return = $this->create_test_object( $slug );
58
+			$return = $this->create_test_object($slug);
59 59
 
60 60
 			return $return;
61 61
 
@@ -77,27 +77,27 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @param string $slug a custom post type ID.
79 79
 	 */
80
-	private function create_test_object( $slug ){
80
+	private function create_test_object($slug) {
81 81
 
82 82
 		// Get a random title
83
-		$title = apply_filters( "tc_{$slug}_term_title", TestContent::title() );
83
+		$title = apply_filters("tc_{$slug}_term_title", TestContent::title());
84 84
 
85 85
 		$return = wp_insert_term(
86 86
 			$title,
87 87
 			$slug,
88
-			apply_filters( "tc_{$slug}_term_arguments", array(
88
+			apply_filters("tc_{$slug}_term_arguments", array(
89 89
 					'description'=> TestContent::title(),
90
-					'slug' => sanitize_title( $title ),
90
+					'slug' => sanitize_title($title),
91 91
 				)
92 92
 			)
93 93
 		);
94 94
 
95 95
 		// Then, set a test content flag on the new post for later deletion
96
-		add_term_meta( $return['term_id'], 'evans_test_content', '__test__', true );
96
+		add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
97 97
 
98 98
 		// Check if we have errors and return them or created message
99
-		if ( is_wp_error( $return ) ){
100
-			error_log( $return->get_error_message() );
99
+		if (is_wp_error($return)) {
100
+			error_log($return->get_error_message());
101 101
 			return $return;
102 102
 		} else {
103 103
 			return array(
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 				'object'	=> 'term',
106 106
 				'oid'		=> $return['term_id'],
107 107
 				'type'		=> $slug,
108
-				'link_edit'	=> admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] ),
109
-				'link_view'	=> get_term_link( $return['term_id'] )
108
+				'link_edit'	=> admin_url('/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id']),
109
+				'link_view'	=> get_term_link($return['term_id'])
110 110
 			);
111 111
 		}
112 112
 
@@ -119,20 +119,20 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @see Delete
121 121
 	 */
122
-	public function delete_all(){
122
+	public function delete_all() {
123 123
 
124
-		$delete =  new Delete;
124
+		$delete = new Delete;
125 125
 
126 126
 		// Make sure that the current user is logged in & has full permissions.
127
-		if ( ! $delete->user_can_delete() ){
127
+		if (!$delete->user_can_delete()) {
128 128
 			return;
129 129
 		}
130 130
 
131 131
 		// Loop through all taxonomies and remove any data
132 132
 		$taxonomies = get_taxonomies();
133
-		foreach ( $taxonomies as $tax ) :
133
+		foreach ($taxonomies as $tax) :
134 134
 
135
-			$this->delete( $tax );
135
+			$this->delete($tax);
136 136
 
137 137
 		endforeach;
138 138
 
@@ -150,17 +150,17 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @param string $slug a custom post type ID.
152 152
 	 */
153
-	public function delete( $slug ){
153
+	public function delete($slug) {
154 154
 
155
-		$delete =  new Delete;
155
+		$delete = new Delete;
156 156
 
157 157
 		// Make sure that the current user is logged in & has full permissions.
158
-		if ( !$delete->user_can_delete() ){
158
+		if (!$delete->user_can_delete()) {
159 159
 			return;
160 160
 		}
161 161
 
162 162
 		// Check that $cptslg has a string.
163
-		if ( empty( $slug ) ){
163
+		if (empty($slug)) {
164 164
 			return;
165 165
 		}
166 166
 
@@ -176,13 +176,13 @@  discard block
 block discarded – undo
176 176
 		    )
177 177
 		);
178 178
 
179
-		$terms = get_terms( $slug, $args );
179
+		$terms = get_terms($slug, $args);
180 180
 
181
-		if ( !empty( $terms ) ){
181
+		if (!empty($terms)) {
182 182
 
183 183
 			$events = array();
184 184
 
185
-			foreach ( $terms as $term ){
185
+			foreach ($terms as $term) {
186 186
 
187 187
 				$events[] = array(
188 188
 					'action'	=> 'deleted',
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
 				);
193 193
 
194 194
 				// Delete our term
195
-				wp_delete_term( $term->term_id, $slug );
195
+				wp_delete_term($term->term_id, $slug);
196 196
 
197 197
 			}
198 198
 
199
-			$taxonomy = get_taxonomy( $slug );
199
+			$taxonomy = get_taxonomy($slug);
200 200
 
201 201
 			$events[] = array(
202 202
 				'action'	=> 'general',
203
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $taxonomy->labels->name
203
+				'message'	=> __('Deleted', 'otm-test-content').' '.$taxonomy->labels->name
204 204
 			);
205 205
 
206 206
 			return $events;
Please login to merge, or discard this patch.