Completed
Push — master ( 2b9d0a...add22c )
by Mike
02:39
created
types/term.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -133,14 +133,14 @@
 block discarded – undo
133 133
 
134 134
 		// Query for our terms
135 135
 		$args = array(
136
-		    'hide_empty' => false,
137
-		    'meta_query' => array(
138
-		        array(
139
-		           'key'       => 'evans_test_content',
140
-		           'value'     => '__test__',
141
-		           'compare'   => '='
142
-		        )
143
-		    )
136
+			'hide_empty' => false,
137
+			'meta_query' => array(
138
+				array(
139
+				   'key'       => 'evans_test_content',
140
+				   'value'     => '__test__',
141
+				   'compare'   => '='
142
+				)
143
+			)
144 144
 		);
145 145
 
146 146
 		$terms = get_terms( $slug, $args );
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 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
 	protected $type = 'term';
18 18
 
@@ -31,25 +31,25 @@  discard block
 block discarded – undo
31 31
 	 * @param boolean $echo Whether or not to echo. Optional.
32 32
 	 * @param int $num Optional. Number of posts to create.
33 33
 	 */
34
-	public function create_objects( $slug, $connection, $echo = false, $num = '' ){
34
+	public function create_objects($slug, $connection, $echo = false, $num = '') {
35 35
 
36 36
 		// If we're missing a custom post type id - don't do anything
37
-		if ( empty( $slug ) ){
37
+		if (empty($slug)) {
38 38
 			return;
39 39
 		}
40 40
 
41 41
 		// If we forgot to put in a quantity, make one for us
42
-		if ( empty( $num ) ){
43
-			$num = rand( 5, 30 );
42
+		if (empty($num)) {
43
+			$num = rand(5, 30);
44 44
 		}
45 45
 
46 46
 		// Create test terms
47
-		for( $i = 0; $i < $num; $i++ ){
47
+		for ($i = 0; $i < $num; $i++) {
48 48
 
49
-			$return = $this->create_test_object( $slug );
49
+			$return = $this->create_test_object($slug);
50 50
 
51
-			if ( $echo === true ){
52
-				echo \json_encode( $return );
51
+			if ($echo === true) {
52
+				echo \json_encode($return);
53 53
 			}
54 54
 
55 55
 		}
@@ -70,27 +70,27 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @param string $slug a custom post type ID.
72 72
 	 */
73
-	private function create_test_object( $slug ){
73
+	private function create_test_object($slug) {
74 74
 
75 75
 		// Get a random title
76
-		$title = apply_filters( "tc_{$slug}_term_title", TestContent::title() );
76
+		$title = apply_filters("tc_{$slug}_term_title", TestContent::title());
77 77
 
78 78
 		$return = wp_insert_term(
79 79
 			$title,
80 80
 			$slug,
81
-			apply_filters( "tc_{$slug}_term_arguments", array(
81
+			apply_filters("tc_{$slug}_term_arguments", array(
82 82
 					'description'=> TestContent::title(),
83
-					'slug' => sanitize_title( $title ),
83
+					'slug' => sanitize_title($title),
84 84
 				)
85 85
 			)
86 86
 		);
87 87
 
88 88
 		// Then, set a test content flag on the new post for later deletion
89
-		add_term_meta( $return['term_id'], 'evans_test_content', '__test__', true );
89
+		add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
90 90
 
91 91
 		// Check if we have errors and return them or created message
92
-		if ( is_wp_error( $return ) ){
93
-			error_log( $return->get_error_message() );
92
+		if (is_wp_error($return)) {
93
+			error_log($return->get_error_message());
94 94
 			return $return;
95 95
 		} else {
96 96
 			return array(
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 				'object'	=> 'term',
99 99
 				'tid'		=> $return['term_id'],
100 100
 				'taxonomy'	=> $slug,
101
-				'link_edit'	=> admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] ),
102
-				'link_view'	=> get_term_link( $return['term_id'] )
101
+				'link_edit'	=> admin_url('/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id']),
102
+				'link_view'	=> get_term_link($return['term_id'])
103 103
 			);
104 104
 		}
105 105
 
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
 	 * @param string $slug a custom post type ID.
118 118
 	 * @param boolean $echo Whether or not to echo the result
119 119
 	 */
120
-	public function delete( $slug, $echo = false ){
120
+	public function delete($slug, $echo = false) {
121 121
 
122
-		$delete =  new Delete;
122
+		$delete = new Delete;
123 123
 
124 124
 		// Make sure that the current user is logged in & has full permissions.
125
-		if ( !$delete->user_can_delete() ){
125
+		if (!$delete->user_can_delete()) {
126 126
 			return;
127 127
 		}
128 128
 
129 129
 		// Check that $cptslg has a string.
130
-		if ( empty( $slug ) ){
130
+		if (empty($slug)) {
131 131
 			return;
132 132
 		}
133 133
 
@@ -143,15 +143,15 @@  discard block
 block discarded – undo
143 143
 		    )
144 144
 		);
145 145
 
146
-		$terms = get_terms( $slug, $args );
146
+		$terms = get_terms($slug, $args);
147 147
 
148
-		if ( !empty( $terms ) ){
148
+		if (!empty($terms)) {
149 149
 
150 150
 			$events = array();
151 151
 
152
-			foreach ( $terms as $term ){
152
+			foreach ($terms as $term) {
153 153
 
154
-				if ( $echo === true ){
154
+				if ($echo === true) {
155 155
 					$events[] = array(
156 156
 						'type'		=> 'deleted',
157 157
 						'pid'		=> $term->term_id,
@@ -161,18 +161,18 @@  discard block
 block discarded – undo
161 161
 				}
162 162
 
163 163
 				// Delete our term
164
-				wp_delete_term( $term->term_id, $slug );
164
+				wp_delete_term($term->term_id, $slug);
165 165
 
166 166
 			}
167 167
 
168
-			$taxonomy = get_taxonomy( $slug );
168
+			$taxonomy = get_taxonomy($slug);
169 169
 
170 170
 			$events[] = array(
171 171
 				'type'		=> 'general',
172
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $taxonomy->labels->name
172
+				'message'	=> __('Deleted', 'otm-test-content').' '.$taxonomy->labels->name
173 173
 			);
174 174
 
175
-			echo \json_encode( $events );
175
+			echo \json_encode($events);
176 176
 
177 177
 		}
178 178
 
Please login to merge, or discard this patch.
types/post.php 1 patch
Spacing   +73 added lines, -73 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
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @see Metaboxes
33 33
 	 */
34
-	public function __construct(){
34
+	public function __construct() {
35 35
 
36 36
 		$this->metaboxes = new Main\Metaboxes;
37 37
 
@@ -53,32 +53,32 @@  discard block
 block discarded – undo
53 53
 	 * @param boolean $echo Whether or not to echo. Optional.
54 54
 	 * @param int $num Optional. Number of posts to create.
55 55
 	 */
56
-	public function create_objects( $slug, $connection, $echo = false, $num = '' ){
56
+	public function create_objects($slug, $connection, $echo = false, $num = '') {
57 57
 
58 58
 		// If we're missing a custom post type id - don't do anything
59
-		if ( empty( $slug ) ){
59
+		if (empty($slug)) {
60 60
 			return;
61 61
 		}
62 62
 
63 63
 		// Gather the necessary data to create the posts
64
-		$supports 	= $this->get_cpt_supports( $slug );
65
-		$metaboxes	= $this->metaboxes->get_metaboxes( $slug );
64
+		$supports 	= $this->get_cpt_supports($slug);
65
+		$metaboxes	= $this->metaboxes->get_metaboxes($slug);
66 66
 
67 67
 		// Set our connection status for the rest of the methods
68 68
 		$this->connected = $connection;
69 69
 
70 70
 		// If we forgot to put in a quantity, make one for us
71
-		if ( empty( $num ) ){
72
-			$num = rand( 5, 30 );
71
+		if (empty($num)) {
72
+			$num = rand(5, 30);
73 73
 		}
74 74
 
75 75
 		// Create test posts
76
-		for( $i = 0; $i < $num; $i++ ){
76
+		for ($i = 0; $i < $num; $i++) {
77 77
 
78
-			$return = $this->create_test_object( $slug, $supports, $metaboxes );
78
+			$return = $this->create_test_object($slug, $supports, $metaboxes);
79 79
 
80
-			if ( $echo === true ){
81
-				echo \json_encode( $return );
80
+			if ($echo === true) {
81
+				echo \json_encode($return);
82 82
 			}
83 83
 
84 84
 		}
@@ -101,15 +101,15 @@  discard block
 block discarded – undo
101 101
 	 * @param array $supports Features that the post type supports.
102 102
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
103 103
 	 */
104
-	private function create_test_object( $slug, $supports, $metaboxes ){
104
+	private function create_test_object($slug, $supports, $metaboxes) {
105 105
 		$return = '';
106 106
 
107 107
 		// Get a random title
108
-		$title = apply_filters( "tc_{$slug}_post_title", TestContent::title() );
108
+		$title = apply_filters("tc_{$slug}_post_title", TestContent::title());
109 109
 
110 110
 		// First, insert our post
111 111
 		$post = array(
112
-		  'post_name'      => sanitize_title( $title ),
112
+		  'post_name'      => sanitize_title($title),
113 113
 		  'post_status'    => 'publish',
114 114
 		  'post_type'      => $slug,
115 115
 		  'ping_status'    => 'closed',
@@ -117,57 +117,57 @@  discard block
 block discarded – undo
117 117
 		);
118 118
 
119 119
 		// Add title if supported
120
-		if ( $supports['title'] === true ){
120
+		if ($supports['title'] === true) {
121 121
 			$post['post_title'] = $title;
122 122
 		}
123 123
 
124 124
 		// Add main content if supported
125
-		if ( $supports['editor'] === true ){
126
-			$post['post_content'] = apply_filters( "tc_{$slug}_post_content", TestContent::paragraphs() );
125
+		if ($supports['editor'] === true) {
126
+			$post['post_content'] = apply_filters("tc_{$slug}_post_content", TestContent::paragraphs());
127 127
 		}
128 128
 
129 129
 		// Add excerpt content if supported
130
-		if ( $supports['excerpt'] === true ){
131
-			$post['post_excerpt'] = apply_filters( "tc_{$slug}_post_excerpt", TestContent::plain_text() );
130
+		if ($supports['excerpt'] === true) {
131
+			$post['post_excerpt'] = apply_filters("tc_{$slug}_post_excerpt", TestContent::plain_text());
132 132
 		}
133 133
 
134 134
 		// Insert then post object
135
-		$post_id = wp_insert_post( apply_filters( "tc_{$slug}_post_arguments", $post ) );
135
+		$post_id = wp_insert_post(apply_filters("tc_{$slug}_post_arguments", $post));
136 136
 
137 137
 		// Then, set a test content flag on the new post for later deletion
138
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
138
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
139 139
 
140 140
 		// Add thumbnail if supported
141
-		if ( $this->connected == true && ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ) ){
142
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
141
+		if ($this->connected == true && ($supports['thumbnail'] === true || in_array($slug, array('post', 'page')))) {
142
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
143 143
 		}
144 144
 
145
-		$taxonomies = get_object_taxonomies( $slug );
145
+		$taxonomies = get_object_taxonomies($slug);
146 146
 
147 147
 		// Assign the post to terms
148
-		if ( !empty( $taxonomies ) ){
149
-			$return .= $this->assign_terms( $post_id, $taxonomies );
148
+		if (!empty($taxonomies)) {
149
+			$return .= $this->assign_terms($post_id, $taxonomies);
150 150
 		}
151 151
 
152 152
 		// Spin up metaboxes
153
-		if ( !empty( $metaboxes ) ){
154
-			foreach ( $metaboxes as $cmb ) :
155
-				$return .= $this->metaboxes->random_metabox_content( $post_id, $cmb, $this->connected );
153
+		if (!empty($metaboxes)) {
154
+			foreach ($metaboxes as $cmb) :
155
+				$return .= $this->metaboxes->random_metabox_content($post_id, $cmb, $this->connected);
156 156
 			endforeach;
157 157
 		}
158 158
 
159 159
 		// Check if we have errors and return them or created message
160
-		if ( is_wp_error( $return ) ){
161
-			error_log( $return->get_error_message() );
160
+		if (is_wp_error($return)) {
161
+			error_log($return->get_error_message());
162 162
 			return $return;
163 163
 		} else {
164 164
 			return array(
165 165
 				'type'		=> 'created',
166 166
 				'object'	=> 'post',
167 167
 				'pid'		=> $post_id,
168
-				'post_type'	=> get_post_type( $post_id ),
169
-				'link_edit'	=> admin_url( '/post.php?post='.$post_id.'&action=edit' ),
170
-				'link_view'	=> get_permalink( $post_id ),
168
+				'post_type'	=> get_post_type($post_id),
169
+				'link_edit'	=> admin_url('/post.php?post='.$post_id.'&action=edit'),
170
+				'link_view'	=> get_permalink($post_id),
171 171
 			);
172 172
 		}
173 173
 
@@ -184,13 +184,13 @@  discard block
 block discarded – undo
184 184
 	 * @param string $slug a custom post type ID.
185 185
 	 * @return array Array of necessary supports booleans.
186 186
 	 */
187
-	private function get_cpt_supports( $slug ){
187
+	private function get_cpt_supports($slug) {
188 188
 
189 189
 		$supports = array(
190
-			'title'		=> post_type_supports( $slug, 'title' ),
191
-			'editor'	=> post_type_supports( $slug, 'editor' ),
192
-			'excerpt'	=> post_type_supports( $slug, 'excerpt' ),
193
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
190
+			'title'		=> post_type_supports($slug, 'title'),
191
+			'editor'	=> post_type_supports($slug, 'editor'),
192
+			'excerpt'	=> post_type_supports($slug, 'excerpt'),
193
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
194 194
 		);
195 195
 
196 196
 		return $supports;
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
 	 * @param array $taxonomies taxonomies assigned to this cpt.
212 212
 	 * @return object WP Error if there is one.
213 213
 	 */
214
-	private function assign_terms( $post_id, $taxonomies ){
214
+	private function assign_terms($post_id, $taxonomies) {
215 215
 
216 216
 		// Make sure it's an array & has items
217
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
217
+		if (empty($taxonomies) || !is_array($taxonomies)) {
218 218
 			return;
219 219
 		}
220 220
 
221
-		foreach ( $taxonomies as $tax ){
221
+		foreach ($taxonomies as $tax) {
222 222
 
223 223
 			// Get the individual terms already existing
224
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
225
-			$count = count( $terms ) - 1;
224
+			$terms = get_terms($tax, array('hide_empty'	=> false));
225
+			$count = count($terms) - 1;
226 226
 
227 227
 			// If there are no terms, skip to the next taxonomy
228
-			if ( empty( $terms ) ){
228
+			if (empty($terms)) {
229 229
 				continue;
230 230
 			}
231 231
 
232 232
 			// Get a random index to use
233
-			$index = rand( 0, $count );
233
+			$index = rand(0, $count);
234 234
 
235 235
 			// Initialize our array
236 236
 			$post_data = array(
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
 			);
239 239
 
240 240
 			// Set the term data to update
241
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
241
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
242 242
 
243 243
 			// Update the post with the taxonomy info
244
-			$return = wp_update_post( $post_data );
244
+			$return = wp_update_post($post_data);
245 245
 
246 246
 			// Return the error if it exists
247
-			if ( is_wp_error( $return ) ){
248
-				error_log( $return->get_error_messages() );
247
+			if (is_wp_error($return)) {
248
+				error_log($return->get_error_messages());
249 249
 				return $return->get_error_messages();
250 250
 			}
251 251
 
@@ -265,17 +265,17 @@  discard block
 block discarded – undo
265 265
 	 * @param string $slug a custom post type ID.
266 266
 	 * @param boolean $echo Whether or not to echo the result
267 267
 	 */
268
-	public function delete( $slug, $echo = false ){
268
+	public function delete($slug, $echo = false) {
269 269
 
270
-		$delete =  new Delete;
270
+		$delete = new Delete;
271 271
 
272 272
 		// Make sure that the current user is logged in & has full permissions.
273
-		if ( !$delete->user_can_delete() ){
273
+		if (!$delete->user_can_delete()) {
274 274
 			return;
275 275
 		}
276 276
 
277 277
 		// Check that $cptslg has a string.
278
-		if ( empty( $slug ) ){
278
+		if (empty($slug)) {
279 279
 			return;
280 280
 		}
281 281
 
@@ -292,39 +292,39 @@  discard block
 block discarded – undo
292 292
 			),
293 293
 		);
294 294
 
295
-		$objects = new \WP_Query( $query );
295
+		$objects = new \WP_Query($query);
296 296
 
297
-		if ( $objects->have_posts() ){
297
+		if ($objects->have_posts()) {
298 298
 
299 299
 			$events = array();
300 300
 
301
-			while ( $objects->have_posts() ) : $objects->the_post();
301
+			while ($objects->have_posts()) : $objects->the_post();
302 302
 
303 303
 				// Find any media associated with the test post and delete it as well
304
-				$this->delete_associated_media( get_the_id() );
304
+				$this->delete_associated_media(get_the_id());
305 305
 
306
-				if ( $echo === true ){
306
+				if ($echo === true) {
307 307
 					$events[] = array(
308 308
 						'type'		=> 'deleted',
309 309
 						'pid'		=> get_the_id(),
310
-						'post_type'	=> get_post_type( get_the_id() ),
310
+						'post_type'	=> get_post_type(get_the_id()),
311 311
 						'link'		=> ''
312 312
 					);
313 313
 				}
314 314
 
315 315
 				// Force delete the post
316
-				wp_delete_post( get_the_id(), true );
316
+				wp_delete_post(get_the_id(), true);
317 317
 
318 318
 			endwhile;
319 319
 
320
-			$obj = get_post_type_object( $slug );
320
+			$obj = get_post_type_object($slug);
321 321
 
322 322
 			$events[] = array(
323 323
 				'type'		=> 'general',
324
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $obj->labels->all_items
324
+				'message'	=> __('Deleted', 'otm-test-content').' '.$obj->labels->all_items
325 325
 			);
326 326
 
327
-			echo \json_encode( $events );
327
+			echo \json_encode($events);
328 328
 
329 329
 		}
330 330
 
@@ -344,28 +344,28 @@  discard block
 block discarded – undo
344 344
 	 *
345 345
 	 * @param int $pid a custom post type ID.
346 346
 	 */
347
-	private function delete_associated_media( $pid ){
347
+	private function delete_associated_media($pid) {
348 348
 
349
-		$delete =  new Delete;
349
+		$delete = new Delete;
350 350
 
351 351
 		// Make sure that the current user is logged in & has full permissions.
352
-		if ( !$delete->user_can_delete() ){
352
+		if (!$delete->user_can_delete()) {
353 353
 			return;
354 354
 		}
355 355
 
356 356
 		// Make sure $pid is, in fact, an ID
357
-		if ( !is_int( $pid ) ){
357
+		if (!is_int($pid)) {
358 358
 			return;
359 359
 		}
360 360
 
361 361
 		// Get our images
362
-		$media = get_attached_media( 'image', $pid );
362
+		$media = get_attached_media('image', $pid);
363 363
 
364
-		if ( !empty( $media ) ){
364
+		if (!empty($media)) {
365 365
 
366 366
 			// Loop through the media & delete each one
367
-			foreach ( $media as $attachment ){
368
-				wp_delete_attachment( $attachment->ID, true );
367
+			foreach ($media as $attachment) {
368
+				wp_delete_attachment($attachment->ID, true);
369 369
 			}
370 370
 
371 371
 		}
Please login to merge, or discard this patch.
abstracts/type.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @subpackage Test Content
11 11
  * @author     Old Town Media
12 12
  */
13
-abstract class Type{
13
+abstract class Type {
14 14
 
15 15
 	/**
16 16
 	 * type
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
 	protected $type;
23 23
 
24 24
 
25
-	public function register_type(){
25
+	public function register_type() {
26 26
 
27
-		add_action( 'tc_types', 'set_type' );
27
+		add_action('tc_types', 'set_type');
28 28
 
29 29
 	}
30 30
 
31
-	public function set_type( $types ){
31
+	public function set_type($types) {
32 32
 
33 33
 		$types[] = $this->type;
34 34
 
Please login to merge, or discard this patch.
includes/class-metaboxes.php 1 patch
Spacing   +80 added lines, -80 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,31 +22,31 @@  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
 		$cmb2_fields = $cmb_fields = $acf_fields = array();
27 27
 
28 28
 		// CMB2
29
-		if ( class_exists( 'CMB2', false ) ) {
30
-			$cmb2_fields = $this->get_cmb2_metaboxes( $slug );
29
+		if (class_exists('CMB2', false)) {
30
+			$cmb2_fields = $this->get_cmb2_metaboxes($slug);
31 31
 		}
32 32
 
33 33
 		// Custom Metaboxes and Fields (CMB1)
34
-		if ( class_exists( 'cmb_Meta_Box', false ) ) {
35
-			$cmb_fields = $this->get_cmb1_metaboxes( $slug );
34
+		if (class_exists('cmb_Meta_Box', false)) {
35
+			$cmb_fields = $this->get_cmb1_metaboxes($slug);
36 36
 		}
37 37
 
38 38
 		// Advanced Custom Fields (ACF Free)
39
-		if ( class_exists( 'acf', false ) ) {
40
-			$acf_fields = $this->get_acf_free_metaboxes( $slug );
39
+		if (class_exists('acf', false)) {
40
+			$acf_fields = $this->get_acf_free_metaboxes($slug);
41 41
 		}
42 42
 
43 43
 		// Return our array
44
-		return array_merge( $cmb2_fields, $cmb_fields, $acf_fields );
44
+		return array_merge($cmb2_fields, $cmb_fields, $acf_fields);
45 45
 
46 46
 	}
47 47
 
48 48
 
49
-	private function get_acf_free_metaboxes( $slug ){
49
+	private function get_acf_free_metaboxes($slug) {
50 50
 
51 51
 		$fields = array();
52 52
 
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
 		$fieldsets = $this->get_all_acf_field_groups();
55 55
 
56 56
 		// Return empty array if there are no fieldsets at all
57
-		if ( empty( $fieldsets ) ){
57
+		if (empty($fieldsets)) {
58 58
 			return $fields;
59 59
 		}
60 60
 
61 61
 		// Loop through each fieldset for possible matches
62
-		foreach ( $fieldsets as $fieldset ){
62
+		foreach ($fieldsets as $fieldset) {
63 63
 
64
-			if ( $this->is_acf_field_in_post_type( $slug, $fieldset ) ){
64
+			if ($this->is_acf_field_in_post_type($slug, $fieldset)) {
65 65
 
66 66
 				// If this is the first group of fields, simply set the value
67 67
 				// Else, merge this group with the previous one
68
-				if ( empty( $fields ) ){
68
+				if (empty($fields)) {
69 69
 					$fields = $fieldset->fields;
70 70
 				} else {
71
-					$fields = array_merge( $fields, $fieldset->fields );
71
+					$fields = array_merge($fields, $fieldset->fields);
72 72
 				}
73 73
 
74 74
 			}
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 
83
-	private function is_acf_field_in_post_type( $slug, $fieldset ){
83
+	private function is_acf_field_in_post_type($slug, $fieldset) {
84 84
 
85 85
 		// Make sure we have something to parse
86
-		if ( empty( $fieldset ) ){
86
+		if (empty($fieldset)) {
87 87
 			return false;
88 88
 		}
89 89
 
90 90
 		// Loop through the rules to check for post type matches
91
-		foreach ( $fieldset->rules as $rule ){
92
-			if ( $rule['param'] === 'post_type' && $rule['value'] === $slug ){
91
+		foreach ($fieldset->rules as $rule) {
92
+			if ($rule['param'] === 'post_type' && $rule['value'] === $slug) {
93 93
 				return true;
94 94
 			}
95 95
 		}
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	}
101 101
 
102 102
 
103
-	private function get_all_acf_field_groups(){
103
+	private function get_all_acf_field_groups() {
104 104
 		$info = $rules = $fields = array();
105 105
 
106 106
 		$args = array(
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 			'posts_per_page'=> 500
109 109
 		);
110 110
 
111
-		$objects = new \WP_Query( $args );
111
+		$objects = new \WP_Query($args);
112 112
 
113
-		if ( $objects->have_posts() ) :
114
-			while ( $objects->have_posts() ) : $objects->the_post();
113
+		if ($objects->have_posts()) :
114
+			while ($objects->have_posts()) : $objects->the_post();
115 115
 
116
-				$data = get_metadata( 'post', get_the_id() );
116
+				$data = get_metadata('post', get_the_id());
117 117
 
118
-				foreach ( $data['rule'] as $rule ){
119
-					$rules[] = unserialize( $rule );
118
+				foreach ($data['rule'] as $rule) {
119
+					$rules[] = unserialize($rule);
120 120
 				}
121 121
 
122
-				foreach ( $data as $key => $value ){
123
-					if ( substr( $key, 0, 6 ) == 'field_' ) :
124
-						$field_detail = unserialize( $value[0] );
122
+				foreach ($data as $key => $value) {
123
+					if (substr($key, 0, 6) == 'field_') :
124
+						$field_detail = unserialize($value[0]);
125 125
 						$fields[] = array(
126 126
 							'key'	 => $field_detail['key'],
127 127
 							'type'	 => $field_detail['type'],
@@ -159,55 +159,55 @@  discard block
 block discarded – undo
159 159
 	 * @param string $slug a custom post type ID.
160 160
 	 * @return array Array of fields.
161 161
 	 */
162
-	private function get_cmb2_metaboxes( $slug ){
162
+	private function get_cmb2_metaboxes($slug) {
163 163
 
164 164
 		$fields = array();
165 165
 
166 166
 		// Get all metaboxes from CMB2 library
167
-		$all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() );
167
+		$all_metaboxes = apply_filters('cmb2_meta_boxes', array());
168 168
 
169 169
 		// Loop through all possible sets of metaboxes added the old way
170
-		foreach ( $all_metaboxes as $metabox_array ){
170
+		foreach ($all_metaboxes as $metabox_array) {
171 171
 
172 172
 			// If the custom post type ID matches this set of fields, set & stop
173
-			if ( in_array( $slug, $metabox_array['object_types'] ) ) {
173
+			if (in_array($slug, $metabox_array['object_types'])) {
174 174
 
175 175
 				// If this is the first group of fields, simply set the value
176 176
 				// Else, merge this group with the previous one
177
-				if ( empty( $fields ) ){
177
+				if (empty($fields)) {
178 178
 					$fields = $metabox_array['fields'];
179 179
 				} else {
180
-					$fields = array_merge( $fields, $metabox_array['fields'] );
180
+					$fields = array_merge($fields, $metabox_array['fields']);
181 181
 				}
182 182
 			}
183 183
 
184 184
 		}
185 185
 
186 186
 		// Loop through all metaboxes added the new way
187
-		foreach ( \CMB2_Boxes::get_all() as $cmb ) {
187
+		foreach (\CMB2_Boxes::get_all() as $cmb) {
188 188
 
189 189
 			// Create the default
190 190
 			$match = false;
191 191
 
192 192
 			// Establish correct cmb types
193
-			if ( is_string( $cmb->meta_box['object_types'] ) ){
194
-				if ( $cmb->meta_box['object_types'] == $slug ){
193
+			if (is_string($cmb->meta_box['object_types'])) {
194
+				if ($cmb->meta_box['object_types'] == $slug) {
195 195
 					$match = true;
196 196
 				}
197 197
 			} else {
198
-				if ( in_array( $slug, $cmb->meta_box['object_types'] ) ){
198
+				if (in_array($slug, $cmb->meta_box['object_types'])) {
199 199
 					$match = true;
200 200
 				}
201 201
 			}
202 202
 
203
-			if ( $match !== true ){
203
+			if ($match !== true) {
204 204
 				continue;
205 205
 			}
206 206
 
207
-			if ( empty( $fields ) ){
207
+			if (empty($fields)) {
208 208
 				$fields = $cmb->meta_box['fields'];
209 209
 			} else {
210
-				$fields = array_merge( $fields, $cmb->meta_box['fields'] );
210
+				$fields = array_merge($fields, $cmb->meta_box['fields']);
211 211
 			}
212 212
 
213 213
 		}
@@ -231,25 +231,25 @@  discard block
 block discarded – undo
231 231
 	 * @param string $slug a custom post type ID.
232 232
 	 * @return array Array of fields.
233 233
 	 */
234
-	private function get_cmb1_metaboxes( $slug ){
234
+	private function get_cmb1_metaboxes($slug) {
235 235
 
236 236
 		$fields = array();
237 237
 
238 238
 		// Get all metaboxes from CMB2 library
239
-		$all_metaboxes = apply_filters( 'cmb_meta_boxes', array() );
239
+		$all_metaboxes = apply_filters('cmb_meta_boxes', array());
240 240
 
241 241
 		// Loop through all possible sets of metaboxes
242
-		foreach ( $all_metaboxes as $metabox_array ){
242
+		foreach ($all_metaboxes as $metabox_array) {
243 243
 
244 244
 			// If the custom post type ID matches this set of fields, set & stop
245
-			if ( in_array( $slug, $metabox_array['pages'] ) ) {
245
+			if (in_array($slug, $metabox_array['pages'])) {
246 246
 
247 247
 				// If this is the first group of fields, simply set the value
248 248
 				// Else, merge this group with the previous one
249
-				if ( empty( $fields ) ){
249
+				if (empty($fields)) {
250 250
 					$fields = $metabox_array['fields'];
251 251
 				} else {
252
-					$fields = array_merge( $fields, $metabox_array['fields'] );
252
+					$fields = array_merge($fields, $metabox_array['fields']);
253 253
 				}
254 254
 			}
255 255
 
@@ -272,36 +272,36 @@  discard block
 block discarded – undo
272 272
 	 * @param int $post_id Single post ID.
273 273
 	 * @param array $cmb custom metabox array from CMB2.
274 274
 	 */
275
-	public function random_metabox_content( $post_id, $cmb, $connected ){
275
+	public function random_metabox_content($post_id, $cmb, $connected) {
276 276
 		$value = '';
277 277
 
278 278
 		// First check that our post ID & cmb array aren't empty
279
-		if ( empty( $cmb ) || empty( $post_id ) ){
279
+		if (empty($cmb) || empty($post_id)) {
280 280
 			return;
281 281
 		}
282 282
 
283 283
 		// Fetch the appropriate type of data and return
284
-		switch( $cmb['type'] ){
284
+		switch ($cmb['type']) {
285 285
 
286 286
 			case 'text':
287 287
 			case 'text_small':
288 288
 			case 'text_medium':
289 289
 
290 290
 				// If phone is in the id, fetch a phone #
291
-				if ( stripos( $cmb['id'], 'phone' ) ){
291
+				if (stripos($cmb['id'], 'phone')) {
292 292
 					$value = TestContent::phone();
293 293
 
294 294
 				// If email is in the id, fetch an email address
295
-				} elseif ( stripos( $cmb['id'], 'email' ) ){
295
+				} elseif (stripos($cmb['id'], 'email')) {
296 296
 					$value = TestContent::email();
297 297
 
298 298
 				// If time is in the id, fetch a time string
299
-				} elseif ( stripos( $cmb['id'], 'time' ) ){
299
+				} elseif (stripos($cmb['id'], 'time')) {
300 300
 					$value = TestContent::time();
301 301
 
302 302
 				// Otherwise, just a random text string
303 303
 				} else {
304
-					$value = TestContent::title( rand( 10, 50 ) );
304
+					$value = TestContent::title(rand(10, 50));
305 305
 				}
306 306
 
307 307
 				break;
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
 
333 333
 			case 'text_date':
334 334
 
335
-				$value = TestContent::date( 'm/d/Y' );
335
+				$value = TestContent::date('m/d/Y');
336 336
 
337 337
 				break;
338 338
 
339 339
 			case 'text_date_timestamp':
340 340
 			case 'text_datetime_timestamp':
341 341
 
342
-				$value = TestContent::date( 'U' );
342
+				$value = TestContent::date('U');
343 343
 
344 344
 				break;
345 345
 
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
 
348 348
 			case 'text_money':
349 349
 
350
-				$value = rand( 0, 100000 );
350
+				$value = rand(0, 100000);
351 351
 
352 352
 				break;
353 353
 
354 354
 			case 'test_colorpicker':
355 355
 
356
-				$value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT );
356
+				$value = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
357 357
 
358 358
 				break;
359 359
 
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
 			case 'radio':
371 371
 
372 372
 				// Grab a random item out of the array and return the key
373
-				$new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 );
374
-				$value = key( $new_val );
373
+				$new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1);
374
+				$value = key($new_val);
375 375
 
376 376
 				break;
377 377
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 			case 'checkbox':
383 383
 
384 384
 				// 50/50 odds of being turned on
385
-				if ( rand( 0, 1 ) == 1 ){
385
+				if (rand(0, 1) == 1) {
386 386
 					$value = 'on';
387 387
 				}
388 388
 
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
 				$new_option = array();
394 394
 
395 395
 				// Loop through each of our options
396
-				foreach ( $cmb['options'] as $key => $value ){
396
+				foreach ($cmb['options'] as $key => $value) {
397 397
 
398 398
 					// 50/50 chance of being included
399
-					if ( rand( 0, 1 ) ){
399
+					if (rand(0, 1)) {
400 400
 						$new_option[] = $key;
401 401
 					}
402 402
 
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 
415 415
 			case 'file':
416 416
 
417
-				if ( true == $connected ){
418
-					$value = TestContent::image( $post_id );
417
+				if (true == $connected) {
418
+					$value = TestContent::image($post_id);
419 419
 				}
420 420
 
421 421
 				break;
@@ -431,38 +431,38 @@  discard block
 block discarded – undo
431 431
 		}
432 432
 
433 433
 		// Value must exist to attempt to insert
434
-		if ( ! empty( $value ) && ! is_wp_error( $value ) ){
434
+		if (!empty($value) && !is_wp_error($value)) {
435 435
 
436
-			$this->update_meta( $post_id, $value, $cmb );
436
+			$this->update_meta($post_id, $value, $cmb);
437 437
 
438 438
 		// If we're dealing with a WP Error object, just return the message for debugging
439
-		} elseif ( is_wp_error( $value ) ){
440
-			error_log( $value->get_error_message() );
439
+		} elseif (is_wp_error($value)) {
440
+			error_log($value->get_error_message());
441 441
 			return $value->get_error_message();
442 442
 		}
443 443
 
444 444
 	} // end random_metabox_content
445 445
 
446 446
 
447
-	private function update_meta( $post_id, $value, $cmb ){
447
+	private function update_meta($post_id, $value, $cmb) {
448 448
 
449 449
 		$type 	= $cmb['type'];
450
-		$id		= $cmb['id'];
451
-		$value = apply_filters( "tc_{$type}_metabox", $value );	// Filter by metabox type
452
-		$value = apply_filters( "tc_{$id}_metabox", $value ); // Filter by metabox ID
450
+		$id = $cmb['id'];
451
+		$value = apply_filters("tc_{$type}_metabox", $value); // Filter by metabox type
452
+		$value = apply_filters("tc_{$id}_metabox", $value); // Filter by metabox ID
453 453
 
454 454
 		// Files must be treated separately - they use the attachment ID
455 455
 		// & url of media for separate cmb values.
456
-		if ( $cmb['type'] != 'file' ){
457
-			add_post_meta( $post_id, $cmb['id'], $value, true );
456
+		if ($cmb['type'] != 'file') {
457
+			add_post_meta($post_id, $cmb['id'], $value, true);
458 458
 		} else {
459
-			add_post_meta( $post_id, $cmb['id'].'_id', $value, true );
460
-			add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true );
459
+			add_post_meta($post_id, $cmb['id'].'_id', $value, true);
460
+			add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true);
461 461
 		}
462 462
 
463 463
 		// Add extra, redundant meta. Because, why not have rows for the price of one?
464
-		if ( $cmb['source'] === 'acf' ){
465
-			add_post_meta( $post_id, '_' . $cmb['id'], $cmb['key'], true );
464
+		if ($cmb['source'] === 'acf') {
465
+			add_post_meta($post_id, '_'.$cmb['id'], $cmb['key'], true);
466 466
 		}
467 467
 
468 468
 	}
Please login to merge, or discard this patch.
abstracts/view.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @subpackage Test Content
11 11
  * @author     Old Town Media
12 12
  */
13
-abstract class View{
13
+abstract class View {
14 14
 
15 15
 	/**
16 16
 	 * title
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @see tab, view
46 46
 	 */
47
-	public function register_view(){
47
+	public function register_view() {
48 48
 
49
-		add_action( 'tc-admin-tabs', array( $this, 'tab' ), $this->priority );
50
-		add_action( 'tc-admin-sections', array( $this, 'view' ), $this->priority );
49
+		add_action('tc-admin-tabs', array($this, 'tab'), $this->priority);
50
+		add_action('tc-admin-sections', array($this, 'view'), $this->priority);
51 51
 
52 52
 	}
53 53
 
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 	 * Each view has a tab and tab navigation - this function compiles our
59 59
 	 * navigation tab. Rarely extended.
60 60
 	 */
61
-	public function tab(){
61
+	public function tab() {
62 62
 		$html = "";
63 63
 
64
-		$html .= "<a class='nav-tab' data-type='".sanitize_title( $this->title )."' href='javascript:void(0)'>";
64
+		$html .= "<a class='nav-tab' data-type='".sanitize_title($this->title)."' href='javascript:void(0)'>";
65 65
 			$html .= $this->title;
66 66
 		$html .= "</a>";
67 67
 
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @see actions_section, options_section
80 80
 	 */
81
-	public function view(){
81
+	public function view() {
82 82
 		$html = '';
83 83
 
84
-		$html .= "<section class='test-content-tab' data-type='".sanitize_title( $this->title )."'>";
84
+		$html .= "<section class='test-content-tab' data-type='".sanitize_title($this->title)."'>";
85 85
 			$html .= $this->actions_section();
86 86
 			$html .= $this->options_section();
87 87
 		$html .= "</section>";
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @return string HTML content.
100 100
 	 */
101
-	protected function actions_section(){
101
+	protected function actions_section() {
102 102
 		$html = '';
103 103
 		return $html;
104 104
 	}
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	 * @param string $html Existing HTML content.
116 116
 	 * @return string HTML section content.
117 117
 	 */
118
-	protected function options_section( $html = '' ){
118
+	protected function options_section($html = '') {
119 119
 		$html .= "<hr>";
120 120
 
121 121
 		$html .= "<div class='test-data-cpt'>";
122 122
 			$html .= "<h3>";
123
-				$html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>";
124
-				$html .= "<input type='number' value='0' class='quantity-adjustment' for='".$this->type."' placeholder='".__( '', 'otm-test-content' )."'> ";
123
+				$html .= "<span class='label'>".__('Quantity', 'otm-test-content')."</span>";
124
+				$html .= "<input type='number' value='0' class='quantity-adjustment' for='".$this->type."' placeholder='".__('', 'otm-test-content')."'> ";
125 125
 			$html .= "</h3>";
126 126
 		$html .= "</div>";
127 127
 
@@ -139,22 +139,22 @@  discard block
 block discarded – undo
139 139
 	 * @param string $text Text to display in the button.
140 140
 	 * @return string HTML.
141 141
 	 */
142
-	protected function build_button( $action, $slug, $text ){
142
+	protected function build_button($action, $slug, $text) {
143 143
 		$html = $dashicon = '';
144 144
 
145
-		if ( $action == 'create' ){
145
+		if ($action == 'create') {
146 146
 			$dashicon = 'dashicons-plus';
147
-		} elseif ( $action == 'delete' ){
147
+		} elseif ($action == 'delete') {
148 148
 			$dashicon = 'dashicons-trash';
149 149
 		}
150 150
 
151 151
 		$html .= "<a href='javascript:void(0);' ";
152
-			$html .= " data-type='" . $this->type . "'";
153
-			$html .= " data-slug='" . $slug . "'";
154
-			$html .= " data-todo='" . $action . "'";
152
+			$html .= " data-type='".$this->type."'";
153
+			$html .= " data-slug='".$slug."'";
154
+			$html .= " data-todo='".$action."'";
155 155
 			$html .= " class='button-primary handle-test-data'";
156 156
 		$html .= "/>";
157
-			$html .= "<span class='dashicons " . $dashicon . "'></span>";
157
+			$html .= "<span class='dashicons ".$dashicon."'></span>";
158 158
 			$html .= $text;
159 159
 		$html .= "</a>";
160 160
 
Please login to merge, or discard this patch.