Completed
Push — master ( 8cb23d...695170 )
by Mike
02:04
created
includes/class-admin-page.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class AdminPage{
11
+class AdminPage {
12 12
 
13 13
 	/**
14 14
 	 * Hooks function.
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @see admin_menu, wp_ajax actions
19 19
 	 */
20
-	public function hooks(){
20
+	public function hooks() {
21 21
 
22
-		add_action( 'admin_menu' , array( $this, 'add_menu_item' ) );
23
-		add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) );
24
-		add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) );
22
+		add_action('admin_menu', array($this, 'add_menu_item'));
23
+		add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback'));
24
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts'));
25 25
 
26 26
 	}
27 27
 
@@ -35,11 +35,11 @@  discard block
 block discarded – undo
35 35
 
36 36
 		add_submenu_page(
37 37
 			'tools.php',
38
-			__( 'Create Test Data', 'evans-mu' ),
39
-			__( 'Test Data', 'evans-mu' ),
38
+			__('Create Test Data', 'evans-mu'),
39
+			__('Test Data', 'evans-mu'),
40 40
 			'manage_options',
41 41
 			'create-test-data',
42
-			array( $this, 'admin_page' )
42
+			array($this, 'admin_page')
43 43
 		);
44 44
 
45 45
 	}
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @param string $hook Specific hook for the admin page that we're dealing with.
52 52
 	 */
53
-	public function load_scripts( $hook ){
53
+	public function load_scripts($hook) {
54 54
 
55
-		wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) );
55
+		wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__)));
56 56
 
57 57
 		$data = array(
58
-			'nonce'	=> wp_create_nonce( 'handle-test-data' )
58
+			'nonce'	=> wp_create_nonce('handle-test-data')
59 59
 		);
60 60
 
61
-		wp_localize_script( 'test-content-js', 'test_content', $data );
61
+		wp_localize_script('test-content-js', 'test_content', $data);
62 62
 
63 63
 	}
64 64
 
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function handle_test_data_callback() {
72 72
 
73
-		$action		= $_REQUEST['todo'];
74
-		$nonce		= $_REQUEST['nonce'];
73
+		$action = $_REQUEST['todo'];
74
+		$nonce = $_REQUEST['nonce'];
75 75
 
76 76
 		// Verify that we have a proper logged in user and it's the right person
77
-		if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){
77
+		if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) {
78 78
 			return;
79 79
 		}
80 80
 
81
-		if ( $action == 'delete' ){
81
+		if ($action == 'delete') {
82 82
 
83
-			$this->deletion_routing( $_REQUEST );
83
+			$this->deletion_routing($_REQUEST);
84 84
 
85
-		} elseif ( $action == 'create' ){
85
+		} elseif ($action == 'create') {
86 86
 
87
-			$this->creation_routing( $_REQUEST );
87
+			$this->creation_routing($_REQUEST);
88 88
 
89 89
 		}
90 90
 
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 	 * Choose which type of creation needs to be accomplished and route through
98 98
 	 * the correct class.
99 99
 	 */
100
-	private function creation_routing( $data ){
100
+	private function creation_routing($data) {
101 101
 
102
-		if ( $data['type'] == 'post' ){
102
+		if ($data['type'] == 'post') {
103 103
 
104 104
 			$create_content = new CreatePost;
105
-			$create_content->create_post_type_content( $data['slug'], true, 1 );
105
+			$create_content->create_post_type_content($data['slug'], true, 1);
106 106
 
107
-		} elseif( $data['type'] == 'term' ){
107
+		} elseif ($data['type'] == 'term') {
108 108
 
109 109
 			$create_content = new CreateTerm;
110
-			$create_content->create_terms( $data['slug'], true, 1 );
110
+			$create_content->create_terms($data['slug'], true, 1);
111 111
 
112 112
 		}
113 113
 
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
 	 * Choose which type of deletion needs to be accomplished and route through
119 119
 	 * the correct method of Delete.
120 120
 	 */
121
-	private function deletion_routing( $data ){
121
+	private function deletion_routing($data) {
122 122
 
123 123
 		$delete_content = new Delete;
124 124
 
125
-		if ( $data['type'] == 'post' ){
125
+		if ($data['type'] == 'post') {
126 126
 
127
-			$delete_content->delete_post( $data['slug'], true );
127
+			$delete_content->delete_post($data['slug'], true);
128 128
 
129 129
 		}
130 130
 
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
 	/**
135 135
 	 * Print out our admin page to control test data.
136 136
 	 */
137
-	public function admin_page(){
137
+	public function admin_page() {
138 138
 
139 139
 		$html = "";
140 140
 
141 141
 		$html .= '<div class="wrap" id="options_editor">' . "\n";
142 142
 
143
-			$html .= '<h2>' . __( 'Create Test Data' , 'evans-mu' ) . '</h2>' . "\n";
143
+			$html .= '<h2>' . __('Create Test Data', 'evans-mu') . '</h2>' . "\n";
144 144
 
145 145
 			// Loop through all other cpts
146
-			$post_types = get_post_types( array( 'public' => true ), 'objects' );
146
+			$post_types = get_post_types(array('public' => true), 'objects');
147 147
 
148
-			foreach ( $post_types as $post_type ) {
148
+			foreach ($post_types as $post_type) {
149 149
 
150 150
 				// Skip Attachments
151
-				if ( $post_type->name == 'attachment' ){
151
+				if ($post_type->name == 'attachment') {
152 152
 					continue;
153 153
 				}
154 154
 
@@ -157,21 +157,21 @@  discard block
 block discarded – undo
157 157
 					$html .= "<h3>";
158 158
 
159 159
 						$html .= "<span style='width: 20%; display: inline-block;'>" . $post_type->labels->name . "</span>";
160
-						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus' style='margin-top: 6px; font-size: 1.2em'></span> Create Test Data</a>";
161
-						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> Delete Test Data</a>";
160
+						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='" . $post_type->name . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus' style='margin-top: 6px; font-size: 1.2em'></span> Create Test Data</a>";
161
+						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='" . $post_type->name . "' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash' style='margin-top: 4px; font-size: 1.2em'></span> Delete Test Data</a>";
162 162
 
163
-						$taxonomies = get_object_taxonomies( $post_type->name );
163
+						$taxonomies = get_object_taxonomies($post_type->name);
164 164
 
165
-						if ( !empty( $taxonomies ) ){
166
-							foreach( $taxonomies as $tax ){
165
+						if (!empty($taxonomies)) {
166
+							foreach ($taxonomies as $tax) {
167 167
 
168
-								if ( $tax == 'post_format' ){
168
+								if ($tax == 'post_format') {
169 169
 									continue;
170 170
 								}
171 171
 
172
-								$taxonomy = get_taxonomy( $tax );
172
+								$taxonomy = get_taxonomy($tax);
173 173
 
174
-								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category' style='margin-top: 4px; font-size: 1.2em'></span> Create ".$taxonomy->labels->name."</a>";
174
+								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='" . $tax . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category' style='margin-top: 4px; font-size: 1.2em'></span> Create " . $taxonomy->labels->name . "</a>";
175 175
 							}
176 176
 						}
177 177
 
Please login to merge, or discard this patch.
includes/class-delete.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 Delete{
11
+class Delete {
12 12
 
13 13
 	/**
14 14
 	 * Delete test data posts.
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param string $slug a custom post type ID.
25 25
 	 */
26
-	public function delete_post( $slug, $echo = false ){
26
+	public function delete_post($slug, $echo = false) {
27 27
 
28 28
 		// Check that $cptslg has a string.
29 29
 		// Also make sure that the current user is logged in & has full permissions.
30
-		if ( empty( $slug ) || !is_user_logged_in() || !current_user_can( 'delete_posts' ) ){
30
+		if (empty($slug) || !is_user_logged_in() || !current_user_can('delete_posts')) {
31 31
 			return;
32 32
 		}
33 33
 
@@ -44,39 +44,39 @@  discard block
 block discarded – undo
44 44
 			),
45 45
 		);
46 46
 
47
-		$objects = new \WP_Query( $query );
47
+		$objects = new \WP_Query($query);
48 48
 
49
-		if ( $objects->have_posts() ){
49
+		if ($objects->have_posts()) {
50 50
 
51 51
 			$events = array();
52 52
 
53
-			while ( $objects->have_posts() ) : $objects->the_post();
53
+			while ($objects->have_posts()) : $objects->the_post();
54 54
 
55 55
 				// Find any media associated with the test post and delete it as well
56
-				$this->delete_associated_media( get_the_id() );
56
+				$this->delete_associated_media(get_the_id());
57 57
 
58
-				if ( $echo === true ){
58
+				if ($echo === true) {
59 59
 					$events[] = array(
60 60
 						'type'		=> 'deleted',
61 61
 						'pid'		=> get_the_id(),
62
-						'post_type'	=> get_post_type( get_the_id() ),
62
+						'post_type'	=> get_post_type(get_the_id()),
63 63
 						'link'		=> ''
64 64
 					);
65 65
 				}
66 66
 
67 67
 				// Force delete the post
68
-				wp_delete_post( get_the_id(), true );
68
+				wp_delete_post(get_the_id(), true);
69 69
 
70 70
 			endwhile;
71 71
 
72
-			$obj = get_post_type_object( $slug );
72
+			$obj = get_post_type_object($slug);
73 73
 
74 74
 			$events[] = array(
75 75
 				'type'		=> 'general',
76 76
 				'message'	=> 'Deleted ' . $obj->labels->all_items
77 77
 			);
78 78
 
79
-			echo \json_encode( $events );
79
+			echo \json_encode($events);
80 80
 
81 81
 		}
82 82
 
@@ -96,20 +96,20 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @param int $pid a custom post type ID.
98 98
 	 */
99
-	private function delete_associated_media( $pid ){
99
+	private function delete_associated_media($pid) {
100 100
 
101
-		if ( !is_int( $pid ) ){
101
+		if (!is_int($pid)) {
102 102
 			return;
103 103
 		}
104 104
 
105 105
 		// Get our images
106
-		$media = get_attached_media( 'image', $pid );
106
+		$media = get_attached_media('image', $pid);
107 107
 
108
-		if ( !empty( $media ) ){
108
+		if (!empty($media)) {
109 109
 
110 110
 			// Loop through the media & delete each one
111
-			foreach ( $media as $attachment ){
112
-				wp_delete_attachment( $attachment->ID, true );
111
+			foreach ($media as $attachment) {
112
+				wp_delete_attachment($attachment->ID, true);
113 113
 			}
114 114
 
115 115
 		}
Please login to merge, or discard this patch.
includes/class-create-post.php 1 patch
Spacing   +82 added lines, -82 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
 	 * Create test data posts.
@@ -25,29 +25,29 @@  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_post_type_content( $slug, $echo = false, $num = '' ){
28
+	public function create_post_type_content($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
 		// Gather the necessary data to create the posts
36
-		$supports 	= $this->get_cpt_supports( $slug );
37
-		$metaboxes	= $this->get_metaboxes( $slug );
36
+		$supports 	= $this->get_cpt_supports($slug);
37
+		$metaboxes	= $this->get_metaboxes($slug);
38 38
 
39 39
 		// If we forgot to put in a quantity, make one for us
40
-		if ( empty( $num ) ){
41
-			$num = rand( 5, 30 );
40
+		if (empty($num)) {
41
+			$num = rand(5, 30);
42 42
 		}
43 43
 
44 44
 		// Create test posts
45
-		for( $i = 0; $i < $num; $i++ ){
45
+		for ($i = 0; $i < $num; $i++) {
46 46
 
47
-			$return = $this->create_test_object( $slug, $supports, $metaboxes );
47
+			$return = $this->create_test_object($slug, $supports, $metaboxes);
48 48
 
49
-			if ( $echo === true ){
50
-				echo \json_encode( $return );
49
+			if ($echo === true) {
50
+				echo \json_encode($return);
51 51
 			}
52 52
 
53 53
 		}
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * @param array $supports Features that the post type supports.
71 71
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
72 72
 	 */
73
-	private function create_test_object( $slug, $supports, $metaboxes ){
73
+	private function create_test_object($slug, $supports, $metaboxes) {
74 74
 		$return = '';
75 75
 
76 76
 		// Get a random title
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		// First, insert our post
80 80
 		$post = array(
81
-		  'post_name'      => sanitize_title( $title ),
81
+		  'post_name'      => sanitize_title($title),
82 82
 		  'post_status'    => 'publish',
83 83
 		  'post_type'      => $slug,
84 84
 		  'ping_status'    => 'closed',
@@ -86,50 +86,50 @@  discard block
 block discarded – undo
86 86
 		);
87 87
 
88 88
 		// Add title if supported
89
-		if ( $supports['title'] === true ){
89
+		if ($supports['title'] === true) {
90 90
 			$post['post_title'] = $title;
91 91
 		}
92 92
 
93 93
 		// Add main content if supported
94
-		if ( $supports['editor'] === true ){
94
+		if ($supports['editor'] === true) {
95 95
 			$post['post_content'] = TestContent::paragraphs();
96 96
 		}
97 97
 
98 98
 		// Insert then post object
99
-		$post_id = wp_insert_post( $post );
99
+		$post_id = wp_insert_post($post);
100 100
 
101 101
 		// Then, set a test content flag on the new post for later deletion
102
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
102
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
103 103
 
104 104
 		// Add thumbnail if supported
105
-		if ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ){
106
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
105
+		if ($supports['thumbnail'] === true || in_array($slug, array('post', 'page'))) {
106
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
107 107
 		}
108 108
 
109
-		$taxonomies = get_object_taxonomies( $slug );
109
+		$taxonomies = get_object_taxonomies($slug);
110 110
 
111 111
 		// Assign the post to terms
112
-		if ( !empty( $taxonomies ) ){
113
-			$return .= $this->assign_terms( $post_id, $taxonomies );
112
+		if (!empty($taxonomies)) {
113
+			$return .= $this->assign_terms($post_id, $taxonomies);
114 114
 		}
115 115
 
116 116
 		// Spin up metaboxes
117
-		if ( !empty( $metaboxes ) ){
118
-			foreach ( $metaboxes as $cmb ) :
119
-				$return .= $this->random_metabox_content( $post_id, $cmb );
117
+		if (!empty($metaboxes)) {
118
+			foreach ($metaboxes as $cmb) :
119
+				$return .= $this->random_metabox_content($post_id, $cmb);
120 120
 			endforeach;
121 121
 		}
122 122
 
123 123
 		// Check if we have errors and return them or created message
124
-		if ( is_wp_error( $return ) ){
124
+		if (is_wp_error($return)) {
125 125
 			return $return;
126 126
 		} else {
127 127
 			return array(
128 128
 				'type'		=> 'created',
129 129
 				'object'	=> 'post',
130 130
 				'pid'		=> $post_id,
131
-				'post_type'	=> get_post_type( $post_id ),
132
-				'link'		=> admin_url( '/post.php?post='.$post_id.'&action=edit' )
131
+				'post_type'	=> get_post_type($post_id),
132
+				'link'		=> admin_url('/post.php?post=' . $post_id . '&action=edit')
133 133
 			);
134 134
 		}
135 135
 
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 	 * @param string $slug a custom post type ID.
147 147
 	 * @return array Array of necessary supports booleans.
148 148
 	 */
149
-	private function get_cpt_supports( $slug ){
149
+	private function get_cpt_supports($slug) {
150 150
 
151 151
 		$supports = array(
152
-			'title'		=> post_type_supports( $slug, 'title' ),
153
-			'editor'	=> post_type_supports( $slug, 'editor' ),
154
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
152
+			'title'		=> post_type_supports($slug, 'title'),
153
+			'editor'	=> post_type_supports($slug, 'editor'),
154
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
155 155
 		);
156 156
 
157 157
 		return $supports;
@@ -172,26 +172,26 @@  discard block
 block discarded – undo
172 172
 	 * @param array $taxonomies taxonomies assigned to this cpt.
173 173
 	 * @return object WP Error if there is one.
174 174
 	 */
175
-	private function assign_terms( $post_id, $taxonomies ){
175
+	private function assign_terms($post_id, $taxonomies) {
176 176
 
177 177
 		// Make sure it's an array & has items
178
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
178
+		if (empty($taxonomies) || !is_array($taxonomies)) {
179 179
 			return;
180 180
 		}
181 181
 
182
-		foreach ( $taxonomies as $tax ){
182
+		foreach ($taxonomies as $tax) {
183 183
 
184 184
 			// Get the individual terms already existing
185
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
186
-			$count = count( $terms ) - 1;
185
+			$terms = get_terms($tax, array('hide_empty'	=> false));
186
+			$count = count($terms) - 1;
187 187
 
188 188
 			// If there are no terms, skip to the next taxonomy
189
-			if ( empty( $terms ) ){
189
+			if (empty($terms)) {
190 190
 				continue;
191 191
 			}
192 192
 
193 193
 			// Get a random index to use
194
-			$index = rand( 0, $count );
194
+			$index = rand(0, $count);
195 195
 
196 196
 			// Initialize our array
197 197
 			$post_data = array(
@@ -199,13 +199,13 @@  discard block
 block discarded – undo
199 199
 			);
200 200
 
201 201
 			// Set the term data to update
202
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
202
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
203 203
 
204 204
 			// Update the post with the taxonomy info
205
-			$return = wp_update_post( $post_data );
205
+			$return = wp_update_post($post_data);
206 206
 
207 207
 			// Return the error if it exists
208
-			if ( is_wp_error( $return ) ){
208
+			if (is_wp_error($return)) {
209 209
 				return $return->get_error_messages();
210 210
 			}
211 211
 
@@ -228,18 +228,18 @@  discard block
 block discarded – undo
228 228
 	 * @param string $slug Post Type slug ID.
229 229
 	 * @return array Fields to fill in for our post object.
230 230
 	 */
231
-	private function get_metaboxes( $slug ){
231
+	private function get_metaboxes($slug) {
232 232
 
233 233
 		$fields = array();
234 234
 
235 235
 		// CMB2
236
-		if ( class_exists( 'CMB2_Bootstrap_212', false ) ) {
237
-			$fields = $this->get_cmb2_metaboxes( $slug );
236
+		if (class_exists('CMB2_Bootstrap_212', false)) {
237
+			$fields = $this->get_cmb2_metaboxes($slug);
238 238
 		}
239 239
 
240 240
 		// Custom Metaboxes and Fields (CMB1)
241
-		if ( class_exists( 'cmb_Meta_Box', false ) ) {
242
-			$fields = $this->get_cmb1_metaboxes( $slug );
241
+		if (class_exists('cmb_Meta_Box', false)) {
242
+			$fields = $this->get_cmb1_metaboxes($slug);
243 243
 		}
244 244
 
245 245
 		// Return our array
@@ -262,25 +262,25 @@  discard block
 block discarded – undo
262 262
 	 * @param string $slug a custom post type ID.
263 263
 	 * @return array Array of fields.
264 264
 	 */
265
-	private function get_cmb2_metaboxes( $slug ){
265
+	private function get_cmb2_metaboxes($slug) {
266 266
 
267 267
 		$fields = array();
268 268
 
269 269
 		// Get all metaboxes from CMB2 library
270
-		$all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() );
270
+		$all_metaboxes = apply_filters('cmb2_meta_boxes', array());
271 271
 
272 272
 		// Loop through all possible sets of metaboxes
273
-		foreach ( $all_metaboxes as $metabox_array ){
273
+		foreach ($all_metaboxes as $metabox_array) {
274 274
 
275 275
 			// If the custom post type ID matches this set of fields, set & stop
276
-			if ( in_array( $slug, $metabox_array['object_types'] ) ) {
276
+			if (in_array($slug, $metabox_array['object_types'])) {
277 277
 
278 278
 				// If this is the first group of fields, simply set the value
279 279
 				// Else, merge this group with the previous one
280
-				if ( empty( $fields ) ){
280
+				if (empty($fields)) {
281 281
 					$fields = $metabox_array['fields'];
282 282
 				} else {
283
-					$fields = array_merge( $fields, $metabox_array['fields'] );
283
+					$fields = array_merge($fields, $metabox_array['fields']);
284 284
 				}
285 285
 			}
286 286
 
@@ -305,25 +305,25 @@  discard block
 block discarded – undo
305 305
 	 * @param string $slug a custom post type ID.
306 306
 	 * @return array Array of fields.
307 307
 	 */
308
-	private function get_cmb1_metaboxes( $slug ){
308
+	private function get_cmb1_metaboxes($slug) {
309 309
 
310 310
 		$fields = array();
311 311
 
312 312
 		// Get all metaboxes from CMB2 library
313
-		$all_metaboxes = apply_filters( 'cmb_meta_boxes', array() );
313
+		$all_metaboxes = apply_filters('cmb_meta_boxes', array());
314 314
 
315 315
 		// Loop through all possible sets of metaboxes
316
-		foreach ( $all_metaboxes as $metabox_array ){
316
+		foreach ($all_metaboxes as $metabox_array) {
317 317
 
318 318
 			// If the custom post type ID matches this set of fields, set & stop
319
-			if ( in_array( $slug, $metabox_array['pages'] ) ) {
319
+			if (in_array($slug, $metabox_array['pages'])) {
320 320
 
321 321
 				// If this is the first group of fields, simply set the value
322 322
 				// Else, merge this group with the previous one
323
-				if ( empty( $fields ) ){
323
+				if (empty($fields)) {
324 324
 					$fields = $metabox_array['fields'];
325 325
 				} else {
326
-					$fields = array_merge( $fields, $metabox_array['fields'] );
326
+					$fields = array_merge($fields, $metabox_array['fields']);
327 327
 				}
328 328
 			}
329 329
 
@@ -348,35 +348,35 @@  discard block
 block discarded – undo
348 348
 	 * @param int $post_id Single post ID.
349 349
 	 * @param array $cmb custom metabox array from CMB2.
350 350
 	 */
351
-	private function random_metabox_content( $post_id, $cmb ){
351
+	private function random_metabox_content($post_id, $cmb) {
352 352
 		$value = '';
353 353
 
354 354
 		// First check that our post ID & cmb array aren't empty
355
-		if ( empty( $cmb ) || empty( $post_id ) ){
355
+		if (empty($cmb) || empty($post_id)) {
356 356
 			return;
357 357
 		}
358 358
 
359
-		switch( $cmb['type'] ){
359
+		switch ($cmb['type']) {
360 360
 
361 361
 			case 'text':
362 362
 			case 'text_small':
363 363
 			case 'text_medium':
364 364
 
365 365
 				// If phone is in the id, fetch a phone #
366
-				if ( stripos( $cmb['id'], 'phone' ) ){
366
+				if (stripos($cmb['id'], 'phone')) {
367 367
 					$value = TestContent::phone();
368 368
 
369 369
 				// If email is in the id, fetch an email address
370
-				} elseif ( stripos( $cmb['id'], 'email' ) ){
370
+				} elseif (stripos($cmb['id'], 'email')) {
371 371
 					$value = TestContent::email();
372 372
 
373 373
 				// If time is in the id, fetch a time string
374
-				} elseif ( stripos( $cmb['id'], 'time' ) ){
374
+				} elseif (stripos($cmb['id'], 'time')) {
375 375
 					$value = TestContent::time();
376 376
 
377 377
 				// Otherwise, just a random text string
378 378
 				} else {
379
-					$value = TestContent::title( rand( 10, 50 ) );
379
+					$value = TestContent::title(rand(10, 50));
380 380
 				}
381 381
 
382 382
 				break;
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
 
404 404
 			case 'text_date':
405 405
 
406
-				$value = TestContent::date( 'm/d/Y' );
406
+				$value = TestContent::date('m/d/Y');
407 407
 
408 408
 				break;
409 409
 
410 410
 			case 'text_date_timestamp':
411 411
 			case 'text_datetime_timestamp':
412 412
 
413
-				$value = TestContent::date( 'U' );
413
+				$value = TestContent::date('U');
414 414
 
415 415
 				break;
416 416
 
@@ -418,13 +418,13 @@  discard block
 block discarded – undo
418 418
 
419 419
 			case 'text_money':
420 420
 
421
-				$value = rand( 0, 100000 );
421
+				$value = rand(0, 100000);
422 422
 
423 423
 				break;
424 424
 
425 425
 			case 'test_colorpicker':
426 426
 
427
-				$value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT );
427
+				$value = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
428 428
 
429 429
 				break;
430 430
 
@@ -441,8 +441,8 @@  discard block
 block discarded – undo
441 441
 			case 'radio':
442 442
 
443 443
 				// Grab a random item out of the array and return the key
444
-				$new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 );
445
-				$value = key( $new_val );
444
+				$new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1);
445
+				$value = key($new_val);
446 446
 
447 447
 				break;
448 448
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 			case 'checkbox':
454 454
 
455 455
 				// 50/50 odds of being turned on
456
-				if ( rand( 0, 1 ) == 1 ){
456
+				if (rand(0, 1) == 1) {
457 457
 					$value = 'on';
458 458
 				}
459 459
 
@@ -464,10 +464,10 @@  discard block
 block discarded – undo
464 464
 				$new_option = array();
465 465
 
466 466
 				// Loop through each of our options
467
-				foreach ( $cmb['options'] as $key => $value ){
467
+				foreach ($cmb['options'] as $key => $value) {
468 468
 
469 469
 					// 50/50 chance of being included
470
-					if ( rand( 0, 1 ) ){
470
+					if (rand(0, 1)) {
471 471
 						$new_option[] = $key;
472 472
 					}
473 473
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
 			case 'file':
487 487
 
488
-				$value = TestContent::image( $post_id );
488
+				$value = TestContent::image($post_id);
489 489
 
490 490
 				break;
491 491
 
@@ -500,19 +500,19 @@  discard block
 block discarded – undo
500 500
 		}
501 501
 
502 502
 		// Value must exist to attempt to insert
503
-		if ( !empty( $value ) && !is_wp_error( $value ) ){
503
+		if (!empty($value) && !is_wp_error($value)) {
504 504
 
505 505
 			// Files must be treated separately - they use the attachment ID
506 506
 			// & url of media for separate cmb values
507
-			if ( $cmb['type'] != 'file' ){
508
-				add_post_meta( $post_id, $cmb['id'], $value, true );
507
+			if ($cmb['type'] != 'file') {
508
+				add_post_meta($post_id, $cmb['id'], $value, true);
509 509
 			} else {
510
-				add_post_meta( $post_id, $cmb['id'].'_id', $value, true );
511
-				add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true );
510
+				add_post_meta($post_id, $cmb['id'] . '_id', $value, true);
511
+				add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true);
512 512
 			}
513 513
 
514 514
 		// If we're dealing with a WP Error object, just return the message for debugging
515
-		} elseif ( is_wp_error( $value ) ){
515
+		} elseif (is_wp_error($value)) {
516 516
 			return $value->get_error_message();
517 517
 		}
518 518
 
Please login to merge, or discard this patch.
includes/class-create-term.php 1 patch
Spacing   +14 added lines, -14 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 posts
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,7 +64,7 @@  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
 		$return = '';
69 69
 
70 70
 		// Get a random title
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
 			$slug,
76 76
 			array(
77 77
 				'description'=> TestContent::title(),
78
-				'slug' => sanitize_title( $title ),
78
+				'slug' => sanitize_title($title),
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
 
86 86
 		// Check if we have errors and return them or created message
87
-		if ( is_wp_error( $return ) ){
87
+		if (is_wp_error($return)) {
88 88
 			return $return;
89 89
 		} else {
90 90
 			return array(
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 				'object'	=> 'term',
93 93
 				'tid'		=> $return['term_id'],
94 94
 				'taxonomy'	=> $slug,
95
-				'link'		=> admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] )
95
+				'link'		=> admin_url('/edit-tags.php?action=edit&taxonomy=' . $slug . '&tag_ID=' . $return['term_id'])
96 96
 			);
97 97
 		}
98 98
 
Please login to merge, or discard this patch.