Completed
Push — master ( ef04cf...199149 )
by Mike
02:19
created
includes/class-create-post.php 1 patch
Spacing   +51 added lines, -51 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,15 +95,15 @@  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
102
-		$title = apply_filters( "tc_{$slug}_post_title", TestContent::title() );
102
+		$title = apply_filters("tc_{$slug}_post_title", TestContent::title());
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,57 +111,57 @@  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 ){
120
-			$post['post_content'] = apply_filters( "tc_{$slug}_post_content", TestContent::paragraphs() );
119
+		if ($supports['editor'] === true) {
120
+			$post['post_content'] = apply_filters("tc_{$slug}_post_content", TestContent::paragraphs());
121 121
 		}
122 122
 
123 123
 		// Add excerpt content if supported
124
-		if ( $supports['excerpt'] === true ){
125
-			$post['post_excerpt'] = apply_filters( "tc_{$slug}_post_excerpt", TestContent::plain_text() );
124
+		if ($supports['excerpt'] === true) {
125
+			$post['post_excerpt'] = apply_filters("tc_{$slug}_post_excerpt", TestContent::plain_text());
126 126
 		}
127 127
 
128 128
 		// Insert then post object
129
-		$post_id = wp_insert_post( apply_filters( "tc_{$slug}_post_arguments", $post ) );
129
+		$post_id = wp_insert_post(apply_filters("tc_{$slug}_post_arguments", $post));
130 130
 
131 131
 		// Then, set a test content flag on the new post for later deletion
132
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
132
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
133 133
 
134 134
 		// Add thumbnail if supported
135
-		if ( $this->connected == true && ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ) ){
136
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
135
+		if ($this->connected == true && ($supports['thumbnail'] === true || in_array($slug, array('post', 'page')))) {
136
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
137 137
 		}
138 138
 
139
-		$taxonomies = get_object_taxonomies( $slug );
139
+		$taxonomies = get_object_taxonomies($slug);
140 140
 
141 141
 		// Assign the post to terms
142
-		if ( !empty( $taxonomies ) ){
143
-			$return .= $this->assign_terms( $post_id, $taxonomies );
142
+		if (!empty($taxonomies)) {
143
+			$return .= $this->assign_terms($post_id, $taxonomies);
144 144
 		}
145 145
 
146 146
 		// Spin up metaboxes
147
-		if ( !empty( $metaboxes ) ){
148
-			foreach ( $metaboxes as $cmb ) :
149
-				$return .= $this->metaboxes->random_metabox_content( $post_id, $cmb, $this->connected );
147
+		if (!empty($metaboxes)) {
148
+			foreach ($metaboxes as $cmb) :
149
+				$return .= $this->metaboxes->random_metabox_content($post_id, $cmb, $this->connected);
150 150
 			endforeach;
151 151
 		}
152 152
 
153 153
 		// Check if we have errors and return them or created message
154
-		if ( is_wp_error( $return ) ){
155
-			error_log( $return->get_error_message() );
154
+		if (is_wp_error($return)) {
155
+			error_log($return->get_error_message());
156 156
 			return $return;
157 157
 		} else {
158 158
 			return array(
159 159
 				'type'		=> 'created',
160 160
 				'object'	=> 'post',
161 161
 				'pid'		=> $post_id,
162
-				'post_type'	=> get_post_type( $post_id ),
163
-				'link_edit'	=> admin_url( '/post.php?post='.$post_id.'&action=edit' ),
164
-				'link_view'	=> get_permalink( $post_id ),
162
+				'post_type'	=> get_post_type($post_id),
163
+				'link_edit'	=> admin_url('/post.php?post='.$post_id.'&action=edit'),
164
+				'link_view'	=> get_permalink($post_id),
165 165
 			);
166 166
 		}
167 167
 
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 	 * @param string $slug a custom post type ID.
179 179
 	 * @return array Array of necessary supports booleans.
180 180
 	 */
181
-	private function get_cpt_supports( $slug ){
181
+	private function get_cpt_supports($slug) {
182 182
 
183 183
 		$supports = array(
184
-			'title'		=> post_type_supports( $slug, 'title' ),
185
-			'editor'	=> post_type_supports( $slug, 'editor' ),
186
-			'excerpt'	=> post_type_supports( $slug, 'excerpt' ),
187
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
184
+			'title'		=> post_type_supports($slug, 'title'),
185
+			'editor'	=> post_type_supports($slug, 'editor'),
186
+			'excerpt'	=> post_type_supports($slug, 'excerpt'),
187
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
188 188
 		);
189 189
 
190 190
 		return $supports;
@@ -205,26 +205,26 @@  discard block
 block discarded – undo
205 205
 	 * @param array $taxonomies taxonomies assigned to this cpt.
206 206
 	 * @return object WP Error if there is one.
207 207
 	 */
208
-	private function assign_terms( $post_id, $taxonomies ){
208
+	private function assign_terms($post_id, $taxonomies) {
209 209
 
210 210
 		// Make sure it's an array & has items
211
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
211
+		if (empty($taxonomies) || !is_array($taxonomies)) {
212 212
 			return;
213 213
 		}
214 214
 
215
-		foreach ( $taxonomies as $tax ){
215
+		foreach ($taxonomies as $tax) {
216 216
 
217 217
 			// Get the individual terms already existing
218
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
219
-			$count = count( $terms ) - 1;
218
+			$terms = get_terms($tax, array('hide_empty'	=> false));
219
+			$count = count($terms) - 1;
220 220
 
221 221
 			// If there are no terms, skip to the next taxonomy
222
-			if ( empty( $terms ) ){
222
+			if (empty($terms)) {
223 223
 				continue;
224 224
 			}
225 225
 
226 226
 			// Get a random index to use
227
-			$index = rand( 0, $count );
227
+			$index = rand(0, $count);
228 228
 
229 229
 			// Initialize our array
230 230
 			$post_data = array(
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 			);
233 233
 
234 234
 			// Set the term data to update
235
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
235
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
236 236
 
237 237
 			// Update the post with the taxonomy info
238
-			$return = wp_update_post( $post_data );
238
+			$return = wp_update_post($post_data);
239 239
 
240 240
 			// Return the error if it exists
241
-			if ( is_wp_error( $return ) ){
242
-				error_log( $return->get_error_messages() );
241
+			if (is_wp_error($return)) {
242
+				error_log($return->get_error_messages());
243 243
 				return $return->get_error_messages();
244 244
 			}
245 245
 
Please login to merge, or discard this patch.
includes/class-metaboxes.php 1 patch
Spacing   +77 added lines, -77 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,23 +22,23 @@  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
 		// Advanced Custom Fields (ACF Free)
40
-		if ( class_exists( 'acf', false ) ) {
41
-			$fields = $this->get_acf_free_metaboxes( $slug );
40
+		if (class_exists('acf', false)) {
41
+			$fields = $this->get_acf_free_metaboxes($slug);
42 42
 		}
43 43
 
44 44
 		// Return our array
@@ -47,25 +47,25 @@  discard block
 block discarded – undo
47 47
 	}
48 48
 
49 49
 
50
-	private function get_acf_free_metaboxes( $slug ){
50
+	private function get_acf_free_metaboxes($slug) {
51 51
 
52 52
 		// This damn plugin. Is. A. Freaking. Nightmare.
53 53
 		$fieldsets = $this->get_all_acf_field_groups();
54 54
 
55
-		if ( empty( $fieldsets ) ){
55
+		if (empty($fieldsets)) {
56 56
 			return true;
57 57
 		}
58 58
 
59
-		foreach ( $fieldsets as $fieldset ){
59
+		foreach ($fieldsets as $fieldset) {
60 60
 
61
-			if ( $this->is_acf_field_in_post_type( $slug, $fieldset ) ){
61
+			if ($this->is_acf_field_in_post_type($slug, $fieldset)) {
62 62
 
63 63
 				// If this is the first group of fields, simply set the value
64 64
 				// Else, merge this group with the previous one
65
-				if ( empty( $fields ) ){
65
+				if (empty($fields)) {
66 66
 					$fields = $fieldset->fields;
67 67
 				} else {
68
-					$fields = array_merge( $fields, $fieldset->fields );
68
+					$fields = array_merge($fields, $fieldset->fields);
69 69
 				}
70 70
 
71 71
 			}
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 	}
78 78
 
79 79
 
80
-	private function is_acf_field_in_post_type( $slug, $fieldset ){
80
+	private function is_acf_field_in_post_type($slug, $fieldset) {
81 81
 
82
-		if ( empty( $fieldset ) ){
82
+		if (empty($fieldset)) {
83 83
 			return;
84 84
 		}
85 85
 
86
-		foreach ( $fieldset->rules as $rule ){
87
-			if ( $rule['param'] === 'post_type' && $rule['value'] === $slug ){
86
+		foreach ($fieldset->rules as $rule) {
87
+			if ($rule['param'] === 'post_type' && $rule['value'] === $slug) {
88 88
 				return true;
89 89
 			}
90 90
 		}
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	}
95 95
 
96 96
 
97
-	private function get_all_acf_field_groups(){
97
+	private function get_all_acf_field_groups() {
98 98
 		$info = $rules = $fields = array();
99 99
 
100 100
 		$args = array(
@@ -102,20 +102,20 @@  discard block
 block discarded – undo
102 102
 			'posts_per_page'=> 500
103 103
 		);
104 104
 
105
-		$objects = new \WP_Query( $args );
105
+		$objects = new \WP_Query($args);
106 106
 
107
-		if ( $objects->have_posts() ) :
108
-			while ( $objects->have_posts() ) : $objects->the_post();
107
+		if ($objects->have_posts()) :
108
+			while ($objects->have_posts()) : $objects->the_post();
109 109
 
110
-				$data = get_metadata( 'post', get_the_id() );
110
+				$data = get_metadata('post', get_the_id());
111 111
 
112
-				foreach ( $data['rule'] as $rule ){
113
-					$rules[] = unserialize( $rule );
112
+				foreach ($data['rule'] as $rule) {
113
+					$rules[] = unserialize($rule);
114 114
 				}
115 115
 
116
-				foreach ( $data as $key => $value ){
117
-					if ( substr( $key, 0, 6 ) == 'field_' ) :
118
-						$field_detail = unserialize( $value[0] );
116
+				foreach ($data as $key => $value) {
117
+					if (substr($key, 0, 6) == 'field_') :
118
+						$field_detail = unserialize($value[0]);
119 119
 						$fields[] = array(
120 120
 							'key'	 => $field_detail['key'],
121 121
 							'type'	 => $field_detail['type'],
@@ -153,55 +153,55 @@  discard block
 block discarded – undo
153 153
 	 * @param string $slug a custom post type ID.
154 154
 	 * @return array Array of fields.
155 155
 	 */
156
-	private function get_cmb2_metaboxes( $slug ){
156
+	private function get_cmb2_metaboxes($slug) {
157 157
 
158 158
 		$fields = array();
159 159
 
160 160
 		// Get all metaboxes from CMB2 library
161
-		$all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() );
161
+		$all_metaboxes = apply_filters('cmb2_meta_boxes', array());
162 162
 
163 163
 		// Loop through all possible sets of metaboxes added the old way
164
-		foreach ( $all_metaboxes as $metabox_array ){
164
+		foreach ($all_metaboxes as $metabox_array) {
165 165
 
166 166
 			// If the custom post type ID matches this set of fields, set & stop
167
-			if ( in_array( $slug, $metabox_array['object_types'] ) ) {
167
+			if (in_array($slug, $metabox_array['object_types'])) {
168 168
 
169 169
 				// If this is the first group of fields, simply set the value
170 170
 				// Else, merge this group with the previous one
171
-				if ( empty( $fields ) ){
171
+				if (empty($fields)) {
172 172
 					$fields = $metabox_array['fields'];
173 173
 				} else {
174
-					$fields = array_merge( $fields, $metabox_array['fields'] );
174
+					$fields = array_merge($fields, $metabox_array['fields']);
175 175
 				}
176 176
 			}
177 177
 
178 178
 		}
179 179
 
180 180
 		// Loop through all metaboxes added the new way
181
-		foreach ( \CMB2_Boxes::get_all() as $cmb ) {
181
+		foreach (\CMB2_Boxes::get_all() as $cmb) {
182 182
 
183 183
 			// Create the default
184 184
 			$match = false;
185 185
 
186 186
 			// Establish correct cmb types
187
-			if ( is_string( $cmb->meta_box['object_types'] ) ){
188
-				if ( $cmb->meta_box['object_types'] == $slug ){
187
+			if (is_string($cmb->meta_box['object_types'])) {
188
+				if ($cmb->meta_box['object_types'] == $slug) {
189 189
 					$match = true;
190 190
 				}
191 191
 			} else {
192
-				if ( in_array( $slug, $cmb->meta_box['object_types'] ) ){
192
+				if (in_array($slug, $cmb->meta_box['object_types'])) {
193 193
 					$match = true;
194 194
 				}
195 195
 			}
196 196
 
197
-			if ( $match !== true ){
197
+			if ($match !== true) {
198 198
 				continue;
199 199
 			}
200 200
 
201
-			if ( empty( $fields ) ){
201
+			if (empty($fields)) {
202 202
 				$fields = $cmb->meta_box['fields'];
203 203
 			} else {
204
-				$fields = array_merge( $fields, $cmb->meta_box['fields'] );
204
+				$fields = array_merge($fields, $cmb->meta_box['fields']);
205 205
 			}
206 206
 
207 207
 		}
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 	 * @param string $slug a custom post type ID.
226 226
 	 * @return array Array of fields.
227 227
 	 */
228
-	private function get_cmb1_metaboxes( $slug ){
228
+	private function get_cmb1_metaboxes($slug) {
229 229
 
230 230
 		$fields = array();
231 231
 
232 232
 		// Get all metaboxes from CMB2 library
233
-		$all_metaboxes = apply_filters( 'cmb_meta_boxes', array() );
233
+		$all_metaboxes = apply_filters('cmb_meta_boxes', array());
234 234
 
235 235
 		// Loop through all possible sets of metaboxes
236
-		foreach ( $all_metaboxes as $metabox_array ){
236
+		foreach ($all_metaboxes as $metabox_array) {
237 237
 
238 238
 			// If the custom post type ID matches this set of fields, set & stop
239
-			if ( in_array( $slug, $metabox_array['pages'] ) ) {
239
+			if (in_array($slug, $metabox_array['pages'])) {
240 240
 
241 241
 				// If this is the first group of fields, simply set the value
242 242
 				// Else, merge this group with the previous one
243
-				if ( empty( $fields ) ){
243
+				if (empty($fields)) {
244 244
 					$fields = $metabox_array['fields'];
245 245
 				} else {
246
-					$fields = array_merge( $fields, $metabox_array['fields'] );
246
+					$fields = array_merge($fields, $metabox_array['fields']);
247 247
 				}
248 248
 			}
249 249
 
@@ -266,36 +266,36 @@  discard block
 block discarded – undo
266 266
 	 * @param int $post_id Single post ID.
267 267
 	 * @param array $cmb custom metabox array from CMB2.
268 268
 	 */
269
-	public function random_metabox_content( $post_id, $cmb, $connected ){
269
+	public function random_metabox_content($post_id, $cmb, $connected) {
270 270
 		$value = '';
271 271
 
272 272
 		// First check that our post ID & cmb array aren't empty
273
-		if ( empty( $cmb ) || empty( $post_id ) ){
273
+		if (empty($cmb) || empty($post_id)) {
274 274
 			return;
275 275
 		}
276 276
 
277 277
 		// Fetch the appropriate type of data and return
278
-		switch( $cmb['type'] ){
278
+		switch ($cmb['type']) {
279 279
 
280 280
 			case 'text':
281 281
 			case 'text_small':
282 282
 			case 'text_medium':
283 283
 
284 284
 				// If phone is in the id, fetch a phone #
285
-				if ( stripos( $cmb['id'], 'phone' ) ){
285
+				if (stripos($cmb['id'], 'phone')) {
286 286
 					$value = TestContent::phone();
287 287
 
288 288
 				// If email is in the id, fetch an email address
289
-				} elseif ( stripos( $cmb['id'], 'email' ) ){
289
+				} elseif (stripos($cmb['id'], 'email')) {
290 290
 					$value = TestContent::email();
291 291
 
292 292
 				// If time is in the id, fetch a time string
293
-				} elseif ( stripos( $cmb['id'], 'time' ) ){
293
+				} elseif (stripos($cmb['id'], 'time')) {
294 294
 					$value = TestContent::time();
295 295
 
296 296
 				// Otherwise, just a random text string
297 297
 				} else {
298
-					$value = TestContent::title( rand( 10, 50 ) );
298
+					$value = TestContent::title(rand(10, 50));
299 299
 				}
300 300
 
301 301
 				break;
@@ -326,14 +326,14 @@  discard block
 block discarded – undo
326 326
 
327 327
 			case 'text_date':
328 328
 
329
-				$value = TestContent::date( 'm/d/Y' );
329
+				$value = TestContent::date('m/d/Y');
330 330
 
331 331
 				break;
332 332
 
333 333
 			case 'text_date_timestamp':
334 334
 			case 'text_datetime_timestamp':
335 335
 
336
-				$value = TestContent::date( 'U' );
336
+				$value = TestContent::date('U');
337 337
 
338 338
 				break;
339 339
 
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
 
342 342
 			case 'text_money':
343 343
 
344
-				$value = rand( 0, 100000 );
344
+				$value = rand(0, 100000);
345 345
 
346 346
 				break;
347 347
 
348 348
 			case 'test_colorpicker':
349 349
 
350
-				$value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT );
350
+				$value = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
351 351
 
352 352
 				break;
353 353
 
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 			case 'radio':
365 365
 
366 366
 				// Grab a random item out of the array and return the key
367
-				$new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 );
368
-				$value = key( $new_val );
367
+				$new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1);
368
+				$value = key($new_val);
369 369
 
370 370
 				break;
371 371
 
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 			case 'checkbox':
377 377
 
378 378
 				// 50/50 odds of being turned on
379
-				if ( rand( 0, 1 ) == 1 ){
379
+				if (rand(0, 1) == 1) {
380 380
 					$value = 'on';
381 381
 				}
382 382
 
@@ -387,10 +387,10 @@  discard block
 block discarded – undo
387 387
 				$new_option = array();
388 388
 
389 389
 				// Loop through each of our options
390
-				foreach ( $cmb['options'] as $key => $value ){
390
+				foreach ($cmb['options'] as $key => $value) {
391 391
 
392 392
 					// 50/50 chance of being included
393
-					if ( rand( 0, 1 ) ){
393
+					if (rand(0, 1)) {
394 394
 						$new_option[] = $key;
395 395
 					}
396 396
 
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 
409 409
 			case 'file':
410 410
 
411
-				if ( true == $connected ){
412
-					$value = TestContent::image( $post_id );
411
+				if (true == $connected) {
412
+					$value = TestContent::image($post_id);
413 413
 				}
414 414
 
415 415
 				break;
@@ -425,29 +425,29 @@  discard block
 block discarded – undo
425 425
 		}
426 426
 
427 427
 		// Value must exist to attempt to insert
428
-		if ( !empty( $value ) && !is_wp_error( $value ) ){
428
+		if (!empty($value) && !is_wp_error($value)) {
429 429
 
430 430
 			$type 	= $cmb['type'];
431
-			$id		= $cmb['id'];
432
-			$value = apply_filters( "tc_{$type}_metabox", $value );	// Filter by metabox type
433
-			$value = apply_filters( "tc_{$id}_metabox", $value ); // Filter by metabox ID
431
+			$id = $cmb['id'];
432
+			$value = apply_filters("tc_{$type}_metabox", $value); // Filter by metabox type
433
+			$value = apply_filters("tc_{$id}_metabox", $value); // Filter by metabox ID
434 434
 
435 435
 			// Files must be treated separately - they use the attachment ID
436 436
 			// & url of media for separate cmb values
437
-			if ( $cmb['type'] != 'file' ){
438
-				add_post_meta( $post_id, $cmb['id'], $value, true );
437
+			if ($cmb['type'] != 'file') {
438
+				add_post_meta($post_id, $cmb['id'], $value, true);
439 439
 			} else {
440
-				add_post_meta( $post_id, $cmb['id'].'_id', $value, true );
441
-				add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true );
440
+				add_post_meta($post_id, $cmb['id'].'_id', $value, true);
441
+				add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true);
442 442
 			}
443 443
 
444
-			if ( $cmb['source'] === 'acf' ){
445
-				add_post_meta( $post_id, '_' . $cmb['id'], $cmb['key'], true );
444
+			if ($cmb['source'] === 'acf') {
445
+				add_post_meta($post_id, '_'.$cmb['id'], $cmb['key'], true);
446 446
 			}
447 447
 
448 448
 		// If we're dealing with a WP Error object, just return the message for debugging
449
-		} elseif ( is_wp_error( $value ) ){
450
-			error_log( $value->get_error_message() );
449
+		} elseif (is_wp_error($value)) {
450
+			error_log($value->get_error_message());
451 451
 			return $value->get_error_message();
452 452
 		}
453 453
 
Please login to merge, or discard this patch.
includes/class-test-content.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * @subpackage Evans
15 15
  * @author     Old Town Media
16 16
  */
17
-class TestContent{
17
+class TestContent {
18 18
 
19 19
 	/**
20 20
 	 * Title function.
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param int $num_words Number of words to return.
27 27
 	 * @return string Random title string.
28 28
 	 */
29
-	public static function title( $num_words = '' ){
29
+	public static function title($num_words = '') {
30 30
 
31 31
 		$title = '';
32 32
 
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
 		);
68 68
 
69 69
 		// If we didn't choose a count, make one
70
-		if ( empty( $num_words ) ){
71
-			$num_words = rand( 2, 10 );
70
+		if (empty($num_words)) {
71
+			$num_words = rand(2, 10);
72 72
 		}
73 73
 
74 74
 		// Pull random words
75
-		for( $i = 1; $i <= $num_words; $i++ ){
76
-			$title .= $random_words[ rand( 0, 31 ) ] . " ";
75
+		for ($i = 1; $i <= $num_words; $i++) {
76
+			$title .= $random_words[rand(0, 31)]." ";
77 77
 		}
78 78
 
79
-		return apply_filters( "tc_title_data", substr( $title, 0, -1 ) );
79
+		return apply_filters("tc_title_data", substr($title, 0, -1));
80 80
 
81 81
 	}
82 82
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return string Paragraph(s) of text.
91 91
 	 */
92
-	public static function paragraphs(){
92
+	public static function paragraphs() {
93 93
 
94 94
 		$content = '';
95 95
 
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 
351 351
 		);
352 352
 
353
-		for( $i = 1; $i < 6; $i++ ){
354
-			$content .= $random_content_types[rand( 0, 12 )];
353
+		for ($i = 1; $i < 6; $i++) {
354
+			$content .= $random_content_types[rand(0, 12)];
355 355
 		}
356 356
 
357
-		return apply_filters( "tc_paragraphs_data", $content );
357
+		return apply_filters("tc_paragraphs_data", $content);
358 358
 
359 359
 	}
360 360
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 *
367 367
 	 * @return string Plain text paragraphs.
368 368
 	 */
369
-	public static function plain_text(){
369
+	public static function plain_text() {
370 370
 
371 371
 		$paragraphs = array(
372 372
 			'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tincidunt luctus eros, a tincidunt massa aliquet sit amet. Sed faucibus, eros non lacinia porttitor, risus odio efficitur sapien, id porta urna massa ac est. Cras efficitur lacinia magna eget tempus. Fusce ex felis, finibus consectetur mi at, finibus rhoncus augue. In ut tortor lacinia, rutrum mauris vel, maximus tortor. Praesent ac arcu nec eros pharetra tristique. Morbi congue leo sed ipsum fermentum vulputate. Ut nulla eros, porta varius pulvinar eget, bibendum quis dolor. Morbi sed diam eu dui semper ornare nec quis nisl.',
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 			'Fusce semper erat tortor, at pulvinar risus luctus suscipit. Phasellus quis enim nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas semper dapibus odio, nec pellentesque sem laoreet sit amet. Maecenas ut enim tellus. Fusce malesuada mattis sem, porta interdum ex fermentum quis. Ut eget quam mi. In molestie volutpat feugiat. Nulla vel viverra nunc. Integer lobortis nisl vitae placerat egestas. Curabitur tristique nulla at libero blandit, a eleifend augue tempus.',
382 382
 		);
383 383
 
384
-		return apply_filters( "tc_plain_text_data", $paragraphs[ rand( 0, 9 ) ] );
384
+		return apply_filters("tc_plain_text_data", $paragraphs[rand(0, 9)]);
385 385
 
386 386
 	}
387 387
 
@@ -397,49 +397,49 @@  discard block
 block discarded – undo
397 397
 	 * @param int $post_id Post ID.
398 398
 	 * @return mixed Attachment ID or WP Error.
399 399
 	 */
400
-	public static function image( $post_id ){
400
+	public static function image($post_id) {
401 401
 		$file_array = array();
402 402
 
403 403
 		// Get the image from the API
404 404
 		$url = self::get_image_link();
405 405
 
406 406
 		// If the returned string is empty or it's not a string, try again.
407
-		if ( empty( $url ) || !is_string( $url ) ){
407
+		if (empty($url) || !is_string($url)) {
408 408
 
409 409
 			// Try again
410 410
 			$url = self::get_image_link();
411 411
 
412 412
 			// If it fails again, just give up
413
-			if ( empty( $url ) || !is_string( $url ) ){
413
+			if (empty($url) || !is_string($url)) {
414 414
 				return;
415 415
 			}
416 416
 
417 417
 		}
418 418
 
419 419
 		// Download the file
420
-	    $tmp = \download_url( $url );
420
+	    $tmp = \download_url($url);
421 421
 
422
-	    preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches );
422
+	    preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches);
423 423
 
424
-        $file_array['name'] = basename( $matches[0] );
424
+        $file_array['name'] = basename($matches[0]);
425 425
         $file_array['tmp_name'] = $tmp;
426 426
 
427 427
 	    // Check for download errors
428
-	    if ( is_wp_error( $tmp ) ) {
429
-	        unlink( $file_array[ 'tmp_name' ] );
430
-	        error_log( $tmp->get_error_message() );
428
+	    if (is_wp_error($tmp)) {
429
+	        unlink($file_array['tmp_name']);
430
+	        error_log($tmp->get_error_message());
431 431
 	    }
432 432
 
433 433
 		// Pull the image into the media library
434
-	    $image_id = media_handle_sideload( $file_array, $post_id );
434
+	    $image_id = media_handle_sideload($file_array, $post_id);
435 435
 
436 436
 	    // Check for handle sideload errors.
437
-	    if ( is_wp_error( $image_id ) ) {
438
-	        unlink( $file_array['tmp_name'] );
439
-	        error_log( $image_id->get_error_message() );
437
+	    if (is_wp_error($image_id)) {
438
+	        unlink($file_array['tmp_name']);
439
+	        error_log($image_id->get_error_message());
440 440
 	    }
441 441
 
442
-	    return apply_filters( "tc_image_data", $image_id );
442
+	    return apply_filters("tc_image_data", $image_id);
443 443
 
444 444
 	}
445 445
 
@@ -451,31 +451,31 @@  discard block
 block discarded – undo
451 451
 	 *
452 452
 	 * @return string Image URL.
453 453
 	 */
454
-	private static function get_image_link(){
454
+	private static function get_image_link() {
455 455
 
456 456
 		// cURL an image API for a completely random photo
457
-		$curl = curl_init( "http://www.splashbase.co/api/v1/images/random?images_only=true" );
457
+		$curl = curl_init("http://www.splashbase.co/api/v1/images/random?images_only=true");
458 458
 
459
-		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
459
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
460 460
 
461
-		$curl_response = curl_exec( $curl );
461
+		$curl_response = curl_exec($curl);
462 462
 
463 463
 		// If our cURL failed
464
-		if ( $curl_response === false ) {
465
-		    $info = curl_getinfo( $curl );
466
-		    curl_close( $curl );
467
-		    die( 'error occured during curl exec. Additional info: ' . var_export( $info ) );
464
+		if ($curl_response === false) {
465
+		    $info = curl_getinfo($curl);
466
+		    curl_close($curl);
467
+		    die('error occured during curl exec. Additional info: '.var_export($info));
468 468
 		}
469 469
 
470
-		curl_close( $curl );
470
+		curl_close($curl);
471 471
 
472 472
 		// Decode the data
473
-		$response = json_decode( $curl_response, true );
473
+		$response = json_decode($curl_response, true);
474 474
 
475 475
 		// Check to make sure that the return contains a valid image extensions
476 476
 		preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $response['url'], $matches);
477 477
 
478
-		if ( !empty( $matches ) ){
478
+		if (!empty($matches)) {
479 479
 			return $response['url'];
480 480
 		}
481 481
 
@@ -490,12 +490,12 @@  discard block
 block discarded – undo
490 490
 	 * @param string $format PHP Date format.
491 491
 	 * @return mixed Date in the format requested.
492 492
 	 */
493
-	public static function date( $format ){
493
+	public static function date($format) {
494 494
 
495
-		$num_days = rand( 1, 60 );
496
-		$date = date( $format, strtotime( " +$num_days days" ) );
495
+		$num_days = rand(1, 60);
496
+		$date = date($format, strtotime(" +$num_days days"));
497 497
 
498
-		return apply_filters( "tc_date_data", $date );
498
+		return apply_filters("tc_date_data", $date);
499 499
 
500 500
 	}
501 501
 
@@ -507,19 +507,19 @@  discard block
 block discarded – undo
507 507
 	 *
508 508
 	 * @return string Time string
509 509
 	 */
510
-	public static function time(){
510
+	public static function time() {
511 511
 
512 512
 		$times = array(
513 513
 			'8:00 am',
514 514
 			'5:00PM',
515 515
 			'13:00',
516 516
 			'2015',
517
-			date( 'G:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
518
-			date( 'g:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
519
-			date( 'G:i A', strtotime( " +".rand( 4, 24 )." hours" ) )
517
+			date('G:i', strtotime(" +".rand(4, 24)." hours")),
518
+			date('g:i', strtotime(" +".rand(4, 24)." hours")),
519
+			date('G:i A', strtotime(" +".rand(4, 24)." hours"))
520 520
 		);
521 521
 
522
-		return apply_filters( "tc_time_data", $times[ rand( 0, 6 ) ] );
522
+		return apply_filters("tc_time_data", $times[rand(0, 6)]);
523 523
 
524 524
 	}
525 525
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 *
532 532
 	 * @return string Timezone
533 533
 	 */
534
-	public static function timezone(){
534
+	public static function timezone() {
535 535
 
536 536
 		$timezones = array(
537 537
 			'America/Denver',
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 			'UTC'
550 550
 		);
551 551
 
552
-		return apply_filters( "tc_timezone_data", $timezones[ rand( 0, 12 ) ] );
552
+		return apply_filters("tc_timezone_data", $timezones[rand(0, 12)]);
553 553
 
554 554
 	}
555 555
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	 *
563 563
 	 * @return string Phone #.
564 564
 	 */
565
-	public static function phone(){
565
+	public static function phone() {
566 566
 
567 567
 		$phone_numbers = array(
568 568
 			'7203893101',
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 			'+43 780 0047112'
579 579
 		);
580 580
 
581
-		return apply_filters( "tc_phone_data", $phone_numbers[ rand( 0, 10 ) ] );
581
+		return apply_filters("tc_phone_data", $phone_numbers[rand(0, 10)]);
582 582
 
583 583
 	}
584 584
 
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 	 *
591 591
 	 * @return string Email address.
592 592
 	 */
593
-	public static function email(){
593
+	public static function email() {
594 594
 
595 595
 		$email_addresses = array(
596 596
 			'[email protected]',
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 			'[email protected]'
604 604
 		);
605 605
 
606
-		return apply_filters( "tc_email_data", $email_addresses[ rand( 0, 7 ) ] );
606
+		return apply_filters("tc_email_data", $email_addresses[rand(0, 7)]);
607 607
 
608 608
 	}
609 609
 
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
 	 *
618 618
 	 * @return string URL.
619 619
 	 */
620
-	public static function link(){
620
+	public static function link() {
621 621
 
622 622
 		$links = array(
623 623
 			'http://google.com',
624 624
 			'https://www.twitter.com',
625
-			site_url( '/?iam=anextravariable' ),
625
+			site_url('/?iam=anextravariable'),
626 626
 			'github.com',
627 627
 			'http://filebase.com',
628 628
 			'www.oldtownmediainc.com',
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 			'https://www.eff.org'
631 631
 		);
632 632
 
633
-		return apply_filters( "tc_link_data", $links[ rand( 0, 7 ) ] );
633
+		return apply_filters("tc_link_data", $links[rand(0, 7)]);
634 634
 
635 635
 	}
636 636
 
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 	 *
642 642
 	 * @return string URL.
643 643
 	 */
644
-	public static function oembed(){
644
+	public static function oembed() {
645 645
 
646 646
 		$links = array(
647 647
 			'https://www.youtube.com/watch?v=A85-YQsm6pY',
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 			'https://www.instagram.com/p/-eyLo0RMfX',
653 653
 		);
654 654
 
655
-		return apply_filters( "tc_oembed_data", $links[ rand( 0, 5 ) ] );
655
+		return apply_filters("tc_oembed_data", $links[rand(0, 5)]);
656 656
 
657 657
 	}
658 658
 
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
 	 * @param	string $type Video service to get link from
667 667
 	 * @return	string URL.
668 668
 	 */
669
-	public static function video( $type ){
669
+	public static function video($type) {
670 670
 
671 671
 		// Switch through our video types. Expecting to add more in the future
672
-		switch( $type ){
672
+		switch ($type) {
673 673
 
674 674
 			// YouTube videos
675 675
 			case 'youtube' :
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 
711 711
 		}
712 712
 
713
-		return apply_filters( "tc_video_data", $links[ rand( 0, 8 ) ] );
713
+		return apply_filters("tc_video_data", $links[rand(0, 8)]);
714 714
 
715 715
 	}
716 716
 
Please login to merge, or discard this patch.
includes/class-create-term.php 1 patch
Spacing   +18 added lines, -18 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 CreateTerm{
11
+class CreateTerm {
12 12
 
13 13
 	/**
14 14
 	 * Create test data posts.
@@ -25,25 +25,25 @@  discard block
 block discarded – undo
25 25
 	 * @param boolean $echo Whether or not to echo. Optional.
26 26
 	 * @param int $num Optional. Number of posts to create.
27 27
 	 */
28
-	public function create_terms( $slug, $echo = false, $num = '' ){
28
+	public function create_terms($slug, $echo = false, $num = '') {
29 29
 
30 30
 		// If we're missing a custom post type id - don't do anything
31
-		if ( empty( $slug ) ){
31
+		if (empty($slug)) {
32 32
 			return;
33 33
 		}
34 34
 
35 35
 		// If we forgot to put in a quantity, make one for us
36
-		if ( empty( $num ) ){
37
-			$num = rand( 5, 30 );
36
+		if (empty($num)) {
37
+			$num = rand(5, 30);
38 38
 		}
39 39
 
40 40
 		// Create test terms
41
-		for( $i = 0; $i < $num; $i++ ){
41
+		for ($i = 0; $i < $num; $i++) {
42 42
 
43
-			$return = $this->create_test_object( $slug );
43
+			$return = $this->create_test_object($slug);
44 44
 
45
-			if ( $echo === true ){
46
-				echo \json_encode( $return );
45
+			if ($echo === true) {
46
+				echo \json_encode($return);
47 47
 			}
48 48
 
49 49
 		}
@@ -64,27 +64,27 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @param string $slug a custom post type ID.
66 66
 	 */
67
-	private function create_test_object( $slug ){
67
+	private function create_test_object($slug) {
68 68
 
69 69
 		// Get a random title
70
-		$title = apply_filters( "tc_{$slug}_term_title", TestContent::title() );
70
+		$title = apply_filters("tc_{$slug}_term_title", TestContent::title());
71 71
 
72 72
 		$return = wp_insert_term(
73 73
 			$title,
74 74
 			$slug,
75
-			apply_filters( "tc_{$slug}_term_arguments", array(
75
+			apply_filters("tc_{$slug}_term_arguments", array(
76 76
 					'description'=> TestContent::title(),
77
-					'slug' => sanitize_title( $title ),
77
+					'slug' => sanitize_title($title),
78 78
 				)
79 79
 			)
80 80
 		);
81 81
 
82 82
 		// Then, set a test content flag on the new post for later deletion
83
-		add_term_meta( $return['term_id'], 'evans_test_content', '__test__', true );
83
+		add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
84 84
 
85 85
 		// Check if we have errors and return them or created message
86
-		if ( is_wp_error( $return ) ){
87
-			error_log( $return->get_error_message() );
86
+		if (is_wp_error($return)) {
87
+			error_log($return->get_error_message());
88 88
 			return $return;
89 89
 		} else {
90 90
 			return array(
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 				'object'	=> 'term',
93 93
 				'tid'		=> $return['term_id'],
94 94
 				'taxonomy'	=> $slug,
95
-				'link_edit'	=> admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] ),
96
-				'link_view'	=> get_term_link( $return['term_id'] )
95
+				'link_edit'	=> admin_url('/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id']),
96
+				'link_view'	=> get_term_link($return['term_id'])
97 97
 			);
98 98
 		}
99 99
 
Please login to merge, or discard this patch.