Completed
Push — master ( e3ebdf...e1139d )
by Mike
02:28
created
test-content.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
  */
22 22
 foreach ( $dirs as $dir ){
23 23
 	foreach ( glob( plugin_dir_path( __FILE__ ) . "/$dir/*.php", GLOB_NOSORT ) as $filename ){
24
-	    require_once $filename;
24
+		require_once $filename;
25 25
 	}
26 26
 }
27 27
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@
 block discarded – undo
22 22
  *
23 23
  * Loop through our directory array and require any PHP files without individual calls.
24 24
  */
25
-foreach ( $dirs as $dir ){
26
-	foreach ( glob( plugin_dir_path( __FILE__ ) . "/$dir/*.php", GLOB_NOSORT ) as $filename ){
25
+foreach ($dirs as $dir) {
26
+	foreach (glob(plugin_dir_path(__FILE__)."/$dir/*.php", GLOB_NOSORT) as $filename) {
27 27
 	    require_once $filename;
28 28
 	}
29 29
 }
30 30
 
31 31
 $admin_page = new testContent\AdminPage;
32
-$admin_page->hooks( __FILE__ );
33 32
\ No newline at end of file
33
+$admin_page->hooks(__FILE__);
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-delete.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   +28 added lines, -28 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_posts( $slug, $echo = false ){
26
+	public function delete_posts($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
-				'message'	=> __( 'Deleted', 'otm-test-content' ) . ' ' . $obj->labels->all_items
76
+				'message'	=> __('Deleted', 'otm-test-content').' '.$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
 		}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @param string $slug a custom post type ID.
131 131
 	 */
132
-	public function delete_terms( $slug, $echo = false ){
132
+	public function delete_terms($slug, $echo = false) {
133 133
 
134 134
 		// Query for our terms
135 135
 		$args = array(
@@ -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.
includes/class-admin-page.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @see load_plugin_textdomain
46 46
 	 */
47 47
 	function load_textdomain() {
48
-	    load_plugin_textdomain( 'otm-test-content', FALSE, basename( dirname( $this->file ) ) . '/languages/' );
48
+		load_plugin_textdomain( 'otm-test-content', FALSE, basename( dirname( $this->file ) ) . '/languages/' );
49 49
 	}
50 50
 
51 51
 
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		} else {
109 109
 			// We didn't get a reponse so print the notice out
110 110
 			echo '<div class="notice notice-error is-dismissible">';
111
-		        echo '<p>'.__( 'WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content' ).'</p>';
112
-		    echo '</div>';
111
+				echo '<p>'.__( 'WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content' ).'</p>';
112
+			echo '</div>';
113 113
 		}
114 114
 
115 115
 	}
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 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
 	 * file
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @see admin_menu, wp_ajax actions
28 28
 	 */
29
-	public function hooks( $file ){
29
+	public function hooks($file) {
30 30
 
31 31
 		$this->file = $file;
32 32
 
33
-		add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
34
-		add_action( 'admin_menu' , array( $this, 'add_menu_item' ) );
35
-		add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) );
36
-		add_filter( 'plugin_action_links_' . plugin_basename( $file ) , array( $this, 'add_settings_link' ) );
37
-		add_action( 'admin_notices', array( $this, 'internet_connected_admin_notice' ) );
33
+		add_action('plugins_loaded', array($this, 'load_textdomain'));
34
+		add_action('admin_menu', array($this, 'add_menu_item'));
35
+		add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback'));
36
+		add_filter('plugin_action_links_'.plugin_basename($file), array($this, 'add_settings_link'));
37
+		add_action('admin_notices', array($this, 'internet_connected_admin_notice'));
38 38
 
39 39
 	}
40 40
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @see load_plugin_textdomain
46 46
 	 */
47 47
 	public function load_textdomain() {
48
-	    load_plugin_textdomain( 'otm-test-content', FALSE, basename( dirname( $this->file ) ) . '/languages/' );
48
+	    load_plugin_textdomain('otm-test-content', FALSE, basename(dirname($this->file)).'/languages/');
49 49
 	}
50 50
 
51 51
 
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 
59 59
 		$page = add_submenu_page(
60 60
 			'tools.php',
61
-			__( 'Create Test Content', 'otm-test-content' ),
62
-			__( 'Test Content', 'otm-test-content' ),
61
+			__('Create Test Content', 'otm-test-content'),
62
+			__('Test Content', 'otm-test-content'),
63 63
 			'manage_options',
64 64
 			'create-test-data',
65
-			array( $this, 'admin_page' )
65
+			array($this, 'admin_page')
66 66
 		);
67 67
 
68
-		add_action( 'admin_print_styles-' . $page, array( $this, 'load_scripts' ) );
68
+		add_action('admin_print_styles-'.$page, array($this, 'load_scripts'));
69 69
 
70 70
 	}
71 71
 
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
 	 * @param  array $links Existing links
76 76
 	 * @return array 		Modified links
77 77
 	 */
78
-	public function add_settings_link( $links ) {
78
+	public function add_settings_link($links) {
79 79
 
80
-		$settings_link = '<a href="tools.php?page=create-test-data">' . __( 'Build Test Content', 'otm-test-content' ) . '</a>';
81
-  		array_push( $links, $settings_link );
80
+		$settings_link = '<a href="tools.php?page=create-test-data">'.__('Build Test Content', 'otm-test-content').'</a>';
81
+  		array_push($links, $settings_link);
82 82
   		return $links;
83 83
 
84 84
 	}
@@ -91,24 +91,24 @@  discard block
 block discarded – undo
91 91
 	 * Internet, and the test fails displays a notice informing the user that
92 92
 	 * images will not pull into test data.
93 93
 	 */
94
-	public function internet_connected_admin_notice(){
94
+	public function internet_connected_admin_notice() {
95 95
 
96 96
 		// Get the current admin screen & verify that we're on the right one
97 97
 		// before continuing.
98 98
 		$screen = get_current_screen();
99 99
 
100
-		if ( $screen->base != 'tools_page_create-test-data' ){
100
+		if ($screen->base != 'tools_page_create-test-data') {
101 101
 			return;
102 102
 		}
103 103
 
104 104
 		// Check the response
105
-		if ( $this->test_splashbase_api() ) {
105
+		if ($this->test_splashbase_api()) {
106 106
 			// We got a response so early return
107 107
 			return;
108 108
 		} else {
109 109
 			// We didn't get a reponse so print the notice out
110 110
 			echo '<div class="notice notice-error is-dismissible">';
111
-		        echo '<p>'.__( 'WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content' ).'</p>';
111
+		        echo '<p>'.__('WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content').'</p>';
112 112
 		    echo '</div>';
113 113
 		}
114 114
 
@@ -131,30 +131,30 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @return boolean Status of connection to Splashbase.
133 133
 	 */
134
-	private function test_splashbase_api(){
134
+	private function test_splashbase_api() {
135 135
 
136 136
 		/*
137 137
 		 * Test #1 - Check Internet connection in general
138 138
 		 */
139 139
 		// Attempt to open a socket connection to Google
140
-		$connected = @fsockopen( "www.google.com", 80 );
140
+		$connected = @fsockopen("www.google.com", 80);
141 141
 
142
-		if ( !$connected ){
142
+		if (!$connected) {
143 143
 			return false;
144 144
 		}
145 145
 
146 146
 		// Close out our 1st test
147
-		fclose( $connected );
147
+		fclose($connected);
148 148
 
149 149
 
150 150
 		/*
151 151
 		 * Test #2 - Check for Airplane Mode plugin status
152 152
 		 */
153
-		if ( class_exists( 'Airplane_Mode_Core' ) ){
153
+		if (class_exists('Airplane_Mode_Core')) {
154 154
 			// Is airplane mode active?
155
-			$airplane_mode = get_site_option( 'airplane-mode' );
155
+			$airplane_mode = get_site_option('airplane-mode');
156 156
 
157
-			if ( $airplane_mode === 'on' ){
157
+			if ($airplane_mode === 'on') {
158 158
 				return false;
159 159
 			}
160 160
 		}
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
 		 * Test #3 - Check Splashbase itself
165 165
 		 */
166 166
 		$test_url = 'http://www.splashbase.co/api/v1/images/';
167
-		$response = wp_remote_get( $test_url );
167
+		$response = wp_remote_get($test_url);
168 168
 
169
-		if ( !is_array( $response ) ){
169
+		if (!is_array($response)) {
170 170
 			return false;
171 171
 		}
172 172
 
@@ -179,19 +179,19 @@  discard block
 block discarded – undo
179 179
 	/**
180 180
 	 * Load our script in the admin section and serve in data.
181 181
 	 */
182
-	public function load_scripts(){
182
+	public function load_scripts() {
183 183
 
184
-		wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) );
185
-		wp_enqueue_style( 'test-content-css', plugins_url( 'assets/admin.css' , dirname( __FILE__ ) ) );
184
+		wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__)));
185
+		wp_enqueue_style('test-content-css', plugins_url('assets/admin.css', dirname(__FILE__)));
186 186
 
187 187
 		$data = array(
188
-			'nonce'			=> wp_create_nonce( 'handle-test-data' ),
189
-			'createdStr'	=> __( 'Created', 'otm-test-content' ),
190
-			'deletedStr'	=> __( 'Deleting', 'otm-test-content' ),
191
-			'creatingStr'	=> __( 'Creating', 'otm-test-content' ),
188
+			'nonce'			=> wp_create_nonce('handle-test-data'),
189
+			'createdStr'	=> __('Created', 'otm-test-content'),
190
+			'deletedStr'	=> __('Deleting', 'otm-test-content'),
191
+			'creatingStr'	=> __('Creating', 'otm-test-content'),
192 192
 		);
193 193
 
194
-		wp_localize_script( 'test-content-js', 'test_content', $data );
194
+		wp_localize_script('test-content-js', 'test_content', $data);
195 195
 
196 196
 	}
197 197
 
@@ -203,21 +203,21 @@  discard block
 block discarded – undo
203 203
 	 */
204 204
 	public function handle_test_data_callback() {
205 205
 
206
-		$action		= $_REQUEST['todo'];
207
-		$nonce		= $_REQUEST['nonce'];
206
+		$action = $_REQUEST['todo'];
207
+		$nonce = $_REQUEST['nonce'];
208 208
 
209 209
 		// Verify that we have a proper logged in user and it's the right person
210
-		if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){
210
+		if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) {
211 211
 			return;
212 212
 		}
213 213
 
214
-		if ( $action == 'delete' ){
214
+		if ($action == 'delete') {
215 215
 
216
-			$this->deletion_routing( $_REQUEST );
216
+			$this->deletion_routing($_REQUEST);
217 217
 
218
-		} elseif ( $action == 'create' ){
218
+		} elseif ($action == 'create') {
219 219
 
220
-			$this->creation_routing( $_REQUEST );
220
+			$this->creation_routing($_REQUEST);
221 221
 
222 222
 		}
223 223
 
@@ -230,17 +230,17 @@  discard block
 block discarded – undo
230 230
 	 * Choose which type of creation needs to be accomplished and route through
231 231
 	 * the correct class.
232 232
 	 */
233
-	private function creation_routing( $data ){
233
+	private function creation_routing($data) {
234 234
 
235
-		if ( $data['type'] == 'post' ){
235
+		if ($data['type'] == 'post') {
236 236
 
237 237
 			$create_content = new CreatePost;
238
-			$create_content->create_post_type_content( $data['slug'], true, 1 );
238
+			$create_content->create_post_type_content($data['slug'], true, 1);
239 239
 
240
-		} elseif( $data['type'] == 'term' ){
240
+		} elseif ($data['type'] == 'term') {
241 241
 
242 242
 			$create_content = new CreateTerm;
243
-			$create_content->create_terms( $data['slug'], true, 1 );
243
+			$create_content->create_terms($data['slug'], true, 1);
244 244
 
245 245
 		}
246 246
 
@@ -251,17 +251,17 @@  discard block
 block discarded – undo
251 251
 	 * Choose which type of deletion needs to be accomplished and route through
252 252
 	 * the correct method of Delete.
253 253
 	 */
254
-	private function deletion_routing( $data ){
254
+	private function deletion_routing($data) {
255 255
 
256 256
 		$delete_content = new Delete;
257 257
 
258
-		if ( $data['type'] == 'post' ){
258
+		if ($data['type'] == 'post') {
259 259
 
260
-			$delete_content->delete_posts( $data['slug'], true );
260
+			$delete_content->delete_posts($data['slug'], true);
261 261
 
262
-		} elseif ( $data['type'] == 'term' ){
262
+		} elseif ($data['type'] == 'term') {
263 263
 
264
-			$delete_content->delete_terms( $data['slug'], true );
264
+			$delete_content->delete_terms($data['slug'], true);
265 265
 
266 266
 		}
267 267
 
@@ -271,35 +271,35 @@  discard block
 block discarded – undo
271 271
 	/**
272 272
 	 * Print out our admin page to control test data.
273 273
 	 */
274
-	public function admin_page(){
274
+	public function admin_page() {
275 275
 
276 276
 		$html = "";
277 277
 
278
-		$html .= '<div class="wrap" id="options_editor">' . "\n";
278
+		$html .= '<div class="wrap" id="options_editor">'."\n";
279 279
 
280
-			$html .= '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n";
280
+			$html .= '<h2>'.__('Create Test Data', 'otm-test-content').'</h2>'."\n";
281 281
 
282 282
 			// Loop through all other cpts
283
-			$post_types = get_post_types( array( 'public' => true ), 'objects' );
283
+			$post_types = get_post_types(array('public' => true), 'objects');
284 284
 
285 285
 			$html .= "<div>";
286 286
 
287 287
 			$html .= "<div class='test-data-cpt'>";
288 288
 				$html .= "<h3>";
289
-					$html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>";
290
-					$html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>".__( 'Set to 0 to keep random', 'otm-test-content' )."</i></small>";
289
+					$html .= "<span class='label'>".__('Quantity', 'otm-test-content')."</span>";
290
+					$html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>".__('Set to 0 to keep random', 'otm-test-content')."</i></small>";
291 291
 				$html .= "</h3>";
292 292
 			$html .= "</div>";
293 293
 
294 294
 			// Loop through every post type available on the site
295
-			foreach ( $post_types as $post_type ) {
295
+			foreach ($post_types as $post_type) {
296 296
 
297 297
 				$skipped_cpts = array(
298 298
 					'attachment'
299 299
 				);
300 300
 
301 301
 				// Skip banned cpts
302
-				if ( in_array( $post_type->name, $skipped_cpts ) ){
302
+				if (in_array($post_type->name, $skipped_cpts)) {
303 303
 					continue;
304 304
 				}
305 305
 
@@ -308,38 +308,38 @@  discard block
 block discarded – undo
308 308
 					// Create row for the post/page/cpt
309 309
 					$html .= "<h3>";
310 310
 
311
-						$html .= "<span class='label'>" . $post_type->labels->name . "</span>";
312
-						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> ".__( 'Create Test Data', 'otm-test-content' )."</a>";
313
-						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete Test Data', 'otm-test-content' )."</a>";
311
+						$html .= "<span class='label'>".$post_type->labels->name."</span>";
312
+						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> ".__('Create Test Data', 'otm-test-content')."</a>";
313
+						$html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__('Delete Test Data', 'otm-test-content')."</a>";
314 314
 
315 315
 					$html .= "</h3>";
316 316
 
317 317
 					// Create row for each taxonomy associated with the post/page/cpt
318
-					$taxonomies = get_object_taxonomies( $post_type->name );
318
+					$taxonomies = get_object_taxonomies($post_type->name);
319 319
 
320
-						if ( !empty( $taxonomies ) ){
320
+						if (!empty($taxonomies)) {
321 321
 
322
-							foreach( $taxonomies as $tax ){
322
+							foreach ($taxonomies as $tax) {
323 323
 
324 324
 								$html .= "<h3 class='term-box'>";
325 325
 
326 326
 								$skipped_taxonomies = array(
327
-									'post_format',				// We shouldn't be making random post format classes
327
+									'post_format', // We shouldn't be making random post format classes
328 328
 									'product_shipping_class'	// These aren't used visually and are therefore skipped
329 329
 								);
330 330
 
331 331
 								// Skip banned taxonomies
332
-								if ( in_array( $tax, $skipped_taxonomies ) ){
332
+								if (in_array($tax, $skipped_taxonomies)) {
333 333
 									continue;
334 334
 								}
335 335
 
336
-								$taxonomy = get_taxonomy( $tax );
336
+								$taxonomy = get_taxonomy($tax);
337 337
 
338 338
 								$html .= "<span class='label'>".$taxonomy->labels->name."</span>";
339 339
 
340
-								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> ".__( 'Create', 'otm-test-content' )." ".$taxonomy->labels->name."</a>";
340
+								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> ".__('Create', 'otm-test-content')." ".$taxonomy->labels->name."</a>";
341 341
 
342
-								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete', 'otm-test-content' )." ".$taxonomy->labels->name."</a>";
342
+								$html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__('Delete', 'otm-test-content')." ".$taxonomy->labels->name."</a>";
343 343
 
344 344
 								$html .= "</h3>";
345 345
 
Please login to merge, or discard this patch.
includes/class-test-content.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -417,29 +417,29 @@  discard block
 block discarded – undo
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] );
425
-        $file_array['tmp_name'] = $tmp;
424
+		$file_array['name'] = basename( $matches[0] );
425
+		$file_array['tmp_name'] = $tmp;
426 426
 
427
-	    // Check for download errors
428
-	    if ( is_wp_error( $tmp ) ) {
429
-	        unlink( $file_array[ 'tmp_name' ] );
430
-	        error_log( $tmp->get_error_message() );
431
-	    }
427
+		// Check for download errors
428
+		if ( is_wp_error( $tmp ) ) {
429
+			unlink( $file_array[ 'tmp_name' ] );
430
+			error_log( $tmp->get_error_message() );
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
-	    // 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() );
440
-	    }
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() );
440
+		}
441 441
 
442
-	    return $image_id;
442
+		return $image_id;
443 443
 
444 444
 	}
445 445
 
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
 
463 463
 		// If our cURL failed
464 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 ) );
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 470
 		curl_close( $curl );
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 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 substr( $title, 0, -1 );
79
+		return 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,8 +350,8 @@  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 357
 		return $content;
@@ -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 $paragraphs[ rand( 0, 9 ) ];
384
+		return $paragraphs[rand(0, 9)];
385 385
 
386 386
 	}
387 387
 
@@ -397,46 +397,46 @@  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 442
 	    return $image_id;
@@ -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,10 +490,10 @@  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
-		return date( $format, strtotime( " +$num_days days" ) );
495
+		$num_days = rand(1, 60);
496
+		return date($format, strtotime(" +$num_days days"));
497 497
 
498 498
 	}
499 499
 
@@ -505,19 +505,19 @@  discard block
 block discarded – undo
505 505
 	 *
506 506
 	 * @return string Time string
507 507
 	 */
508
-	public static function time(){
508
+	public static function time() {
509 509
 
510 510
 		$times = array(
511 511
 			'8:00 am',
512 512
 			'5:00PM',
513 513
 			'13:00',
514 514
 			'2015',
515
-			date( 'G:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
516
-			date( 'g:i', strtotime( " +".rand( 4, 24 )." hours" ) ),
517
-			date( 'G:i A', strtotime( " +".rand( 4, 24 )." hours" ) )
515
+			date('G:i', strtotime(" +".rand(4, 24)." hours")),
516
+			date('g:i', strtotime(" +".rand(4, 24)." hours")),
517
+			date('G:i A', strtotime(" +".rand(4, 24)." hours"))
518 518
 		);
519 519
 
520
-		return $times[ rand( 0, 6 ) ];
520
+		return $times[rand(0, 6)];
521 521
 
522 522
 	}
523 523
 
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 	 *
530 530
 	 * @return string Timezone
531 531
 	 */
532
-	public static function timezone(){
532
+	public static function timezone() {
533 533
 
534 534
 		$timezones = array(
535 535
 			'America/Denver',
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 			'UTC'
548 548
 		);
549 549
 
550
-		return $timezones[ rand( 0, 12 ) ];
550
+		return $timezones[rand(0, 12)];
551 551
 
552 552
 	}
553 553
 
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 	 *
561 561
 	 * @return string Phone #.
562 562
 	 */
563
-	public static function phone(){
563
+	public static function phone() {
564 564
 
565 565
 		$phone_numbers = array(
566 566
 			'7203893101',
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 			'+43 780 0047112'
577 577
 		);
578 578
 
579
-		return $phone_numbers[ rand( 0, 10 ) ];
579
+		return $phone_numbers[rand(0, 10)];
580 580
 
581 581
 	}
582 582
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 	 *
589 589
 	 * @return string Email address.
590 590
 	 */
591
-	public static function email(){
591
+	public static function email() {
592 592
 
593 593
 		$email_addresses = array(
594 594
 			'[email protected]',
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 			'[email protected]'
602 602
 		);
603 603
 
604
-		return $email_addresses[ rand( 0, 7 ) ];
604
+		return $email_addresses[rand(0, 7)];
605 605
 
606 606
 	}
607 607
 
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
 	 *
616 616
 	 * @return string URL.
617 617
 	 */
618
-	public static function link(){
618
+	public static function link() {
619 619
 
620 620
 		$links = array(
621 621
 			'http://google.com',
622 622
 			'https://www.twitter.com',
623
-			site_url( '/?iam=anextravariable' ),
623
+			site_url('/?iam=anextravariable'),
624 624
 			'github.com',
625 625
 			'http://filebase.com',
626 626
 			'www.oldtownmediainc.com',
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
 			'https://www.eff.org'
629 629
 		);
630 630
 
631
-		return $links[ rand( 0, 7 ) ];
631
+		return $links[rand(0, 7)];
632 632
 
633 633
 	}
634 634
 
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 	 *
640 640
 	 * @return string URL.
641 641
 	 */
642
-	public static function oembed(){
642
+	public static function oembed() {
643 643
 
644 644
 		$links = array(
645 645
 			'https://www.youtube.com/watch?v=A85-YQsm6pY',
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 			'https://www.instagram.com/p/-eyLo0RMfX',
651 651
 		);
652 652
 
653
-		return $links[ rand( 0, 5 ) ];
653
+		return $links[rand(0, 5)];
654 654
 
655 655
 	}
656 656
 
@@ -664,10 +664,10 @@  discard block
 block discarded – undo
664 664
 	 * @param	string $type Video service to get link from
665 665
 	 * @return	string URL.
666 666
 	 */
667
-	public static function video( $type ){
667
+	public static function video($type) {
668 668
 
669 669
 		// Switch through our video types. Expecting to add more in the future
670
-		switch( $type ){
670
+		switch ($type) {
671 671
 
672 672
 			// YouTube videos
673 673
 			case 'youtube' :
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 
709 709
 		}
710 710
 
711
-		return $links[ rand( 0, 8 ) ];
711
+		return $links[rand(0, 8)];
712 712
 
713 713
 	}
714 714
 
Please login to merge, or discard this patch.
includes/class-create-term.php 1 patch
Spacing   +16 added lines, -16 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,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
 
69 69
 		// Get a random title
70 70
 		$title = TestContent::title();
@@ -74,16 +74,16 @@  discard block
 block discarded – undo
74 74
 			$slug,
75 75
 			array(
76 76
 				'description'=> TestContent::title(),
77
-				'slug' => sanitize_title( $title ),
77
+				'slug' => sanitize_title($title),
78 78
 			)
79 79
 		);
80 80
 
81 81
 		// Then, set a test content flag on the new post for later deletion
82
-		add_term_meta( $return['term_id'], 'evans_test_content', '__test__', true );
82
+		add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
83 83
 
84 84
 		// Check if we have errors and return them or created message
85
-		if ( is_wp_error( $return ) ){
86
-			error_log( $return->get_error_message() );
85
+		if (is_wp_error($return)) {
86
+			error_log($return->get_error_message());
87 87
 			return $return;
88 88
 		} else {
89 89
 			return array(
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 				'object'	=> 'term',
92 92
 				'tid'		=> $return['term_id'],
93 93
 				'taxonomy'	=> $slug,
94
-				'link_edit'	=> admin_url( '/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id'] ),
95
-				'link_view'	=> get_term_link( $return['term_id'] )
94
+				'link_edit'	=> admin_url('/edit-tags.php?action=edit&taxonomy='.$slug.'&tag_ID='.$return['term_id']),
95
+				'link_view'	=> get_term_link($return['term_id'])
96 96
 			);
97 97
 		}
98 98
 
Please login to merge, or discard this patch.
includes/class-create-post.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class CreatePost{
11
+class CreatePost {
12 12
 
13 13
 	/**
14 14
 	 * metaboxes
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @see Metaboxes
27 27
 	 */
28
-	public function __construct(){
28
+	public function __construct() {
29 29
 
30 30
 		$this->metaboxes = new Metaboxes;
31 31
 
@@ -46,29 +46,29 @@  discard block
 block discarded – undo
46 46
 	 * @param boolean $echo Whether or not to echo. Optional.
47 47
 	 * @param int $num Optional. Number of posts to create.
48 48
 	 */
49
-	public function create_post_type_content( $slug, $echo = false, $num = '' ){
49
+	public function create_post_type_content($slug, $echo = false, $num = '') {
50 50
 
51 51
 		// If we're missing a custom post type id - don't do anything
52
-		if ( empty( $slug ) ){
52
+		if (empty($slug)) {
53 53
 			return;
54 54
 		}
55 55
 
56 56
 		// Gather the necessary data to create the posts
57
-		$supports 	= $this->get_cpt_supports( $slug );
58
-		$metaboxes	= $this->metaboxes->get_metaboxes( $slug );
57
+		$supports 	= $this->get_cpt_supports($slug);
58
+		$metaboxes	= $this->metaboxes->get_metaboxes($slug);
59 59
 
60 60
 		// If we forgot to put in a quantity, make one for us
61
-		if ( empty( $num ) ){
62
-			$num = rand( 5, 30 );
61
+		if (empty($num)) {
62
+			$num = rand(5, 30);
63 63
 		}
64 64
 
65 65
 		// Create test posts
66
-		for( $i = 0; $i < $num; $i++ ){
66
+		for ($i = 0; $i < $num; $i++) {
67 67
 
68
-			$return = $this->create_test_object( $slug, $supports, $metaboxes );
68
+			$return = $this->create_test_object($slug, $supports, $metaboxes);
69 69
 
70
-			if ( $echo === true ){
71
-				echo \json_encode( $return );
70
+			if ($echo === true) {
71
+				echo \json_encode($return);
72 72
 			}
73 73
 
74 74
 		}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @param array $supports Features that the post type supports.
92 92
 	 * @param array $supports All CMB2 metaboxes attached to the post type.
93 93
 	 */
94
-	private function create_test_object( $slug, $supports, $metaboxes ){
94
+	private function create_test_object($slug, $supports, $metaboxes) {
95 95
 		$return = '';
96 96
 
97 97
 		// Get a random title
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 		// First, insert our post
101 101
 		$post = array(
102
-		  'post_name'      => sanitize_title( $title ),
102
+		  'post_name'      => sanitize_title($title),
103 103
 		  'post_status'    => 'publish',
104 104
 		  'post_type'      => $slug,
105 105
 		  'ping_status'    => 'closed',
@@ -107,52 +107,52 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 
109 109
 		// Add title if supported
110
-		if ( $supports['title'] === true ){
110
+		if ($supports['title'] === true) {
111 111
 			$post['post_title'] = $title;
112 112
 		}
113 113
 
114 114
 		// Add main content if supported
115
-		if ( $supports['editor'] === true ){
115
+		if ($supports['editor'] === true) {
116 116
 			$post['post_content'] = TestContent::paragraphs();
117 117
 		}
118 118
 
119 119
 		// Insert then post object
120
-		$post_id = wp_insert_post( $post );
120
+		$post_id = wp_insert_post($post);
121 121
 
122 122
 		// Then, set a test content flag on the new post for later deletion
123
-		add_post_meta( $post_id, 'evans_test_content', '__test__', true );
123
+		add_post_meta($post_id, 'evans_test_content', '__test__', true);
124 124
 
125 125
 		// Add thumbnail if supported
126
-		if ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ){
127
-			 update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) );
126
+		if ($supports['thumbnail'] === true || in_array($slug, array('post', 'page'))) {
127
+			 update_post_meta($post_id, '_thumbnail_id', TestContent::image($post_id));
128 128
 		}
129 129
 
130
-		$taxonomies = get_object_taxonomies( $slug );
130
+		$taxonomies = get_object_taxonomies($slug);
131 131
 
132 132
 		// Assign the post to terms
133
-		if ( !empty( $taxonomies ) ){
134
-			$return .= $this->assign_terms( $post_id, $taxonomies );
133
+		if (!empty($taxonomies)) {
134
+			$return .= $this->assign_terms($post_id, $taxonomies);
135 135
 		}
136 136
 
137 137
 		// Spin up metaboxes
138
-		if ( !empty( $metaboxes ) ){
139
-			foreach ( $metaboxes as $cmb ) :
140
-				$return .= $this->metaboxes->random_metabox_content( $post_id, $cmb );
138
+		if (!empty($metaboxes)) {
139
+			foreach ($metaboxes as $cmb) :
140
+				$return .= $this->metaboxes->random_metabox_content($post_id, $cmb);
141 141
 			endforeach;
142 142
 		}
143 143
 
144 144
 		// Check if we have errors and return them or created message
145
-		if ( is_wp_error( $return ) ){
146
-			error_log( $return->get_error_message() );
145
+		if (is_wp_error($return)) {
146
+			error_log($return->get_error_message());
147 147
 			return $return;
148 148
 		} else {
149 149
 			return array(
150 150
 				'type'		=> 'created',
151 151
 				'object'	=> 'post',
152 152
 				'pid'		=> $post_id,
153
-				'post_type'	=> get_post_type( $post_id ),
154
-				'link_edit'	=> admin_url( '/post.php?post='.$post_id.'&action=edit' ),
155
-				'link_view'	=> get_permalink( $post_id ),
153
+				'post_type'	=> get_post_type($post_id),
154
+				'link_edit'	=> admin_url('/post.php?post='.$post_id.'&action=edit'),
155
+				'link_view'	=> get_permalink($post_id),
156 156
 			);
157 157
 		}
158 158
 
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 	 * @param string $slug a custom post type ID.
170 170
 	 * @return array Array of necessary supports booleans.
171 171
 	 */
172
-	private function get_cpt_supports( $slug ){
172
+	private function get_cpt_supports($slug) {
173 173
 
174 174
 		$supports = array(
175
-			'title'		=> post_type_supports( $slug, 'title' ),
176
-			'editor'	=> post_type_supports( $slug, 'editor' ),
177
-			'thumbnail'	=> post_type_supports( $slug, 'thumbnail' )
175
+			'title'		=> post_type_supports($slug, 'title'),
176
+			'editor'	=> post_type_supports($slug, 'editor'),
177
+			'thumbnail'	=> post_type_supports($slug, 'thumbnail')
178 178
 		);
179 179
 
180 180
 		return $supports;
@@ -195,26 +195,26 @@  discard block
 block discarded – undo
195 195
 	 * @param array $taxonomies taxonomies assigned to this cpt.
196 196
 	 * @return object WP Error if there is one.
197 197
 	 */
198
-	private function assign_terms( $post_id, $taxonomies ){
198
+	private function assign_terms($post_id, $taxonomies) {
199 199
 
200 200
 		// Make sure it's an array & has items
201
-		if ( empty( $taxonomies ) || !is_array( $taxonomies ) ){
201
+		if (empty($taxonomies) || !is_array($taxonomies)) {
202 202
 			return;
203 203
 		}
204 204
 
205
-		foreach ( $taxonomies as $tax ){
205
+		foreach ($taxonomies as $tax) {
206 206
 
207 207
 			// Get the individual terms already existing
208
-			$terms = get_terms( $tax, array( 'hide_empty'	=> false ) );
209
-			$count = count( $terms ) - 1;
208
+			$terms = get_terms($tax, array('hide_empty'	=> false));
209
+			$count = count($terms) - 1;
210 210
 
211 211
 			// If there are no terms, skip to the next taxonomy
212
-			if ( empty( $terms ) ){
212
+			if (empty($terms)) {
213 213
 				continue;
214 214
 			}
215 215
 
216 216
 			// Get a random index to use
217
-			$index = rand( 0, $count );
217
+			$index = rand(0, $count);
218 218
 
219 219
 			// Initialize our array
220 220
 			$post_data = array(
@@ -222,14 +222,14 @@  discard block
 block discarded – undo
222 222
 			);
223 223
 
224 224
 			// Set the term data to update
225
-			$post_data['tax_input'][ $tax ] = array( $terms[$index]->term_id );
225
+			$post_data['tax_input'][$tax] = array($terms[$index]->term_id);
226 226
 
227 227
 			// Update the post with the taxonomy info
228
-			$return = wp_update_post( $post_data );
228
+			$return = wp_update_post($post_data);
229 229
 
230 230
 			// Return the error if it exists
231
-			if ( is_wp_error( $return ) ){
232
-				error_log( $return->get_error_messages() );
231
+			if (is_wp_error($return)) {
232
+				error_log($return->get_error_messages());
233 233
 				return $return->get_error_messages();
234 234
 			}
235 235
 
Please login to merge, or discard this patch.
includes/class-metaboxes.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @subpackage Evans
9 9
  * @author     Old Town Media
10 10
  */
11
-class Metaboxes{
11
+class Metaboxes {
12 12
 
13 13
 	/**
14 14
 	 * Decide which cmb library to try and loop to get our metaboxes.
@@ -22,18 +22,18 @@  discard block
 block discarded – undo
22 22
 	 * @param string $slug Post Type slug ID.
23 23
 	 * @return array Fields to fill in for our post object.
24 24
 	 */
25
-	public function get_metaboxes( $slug ){
25
+	public function get_metaboxes($slug) {
26 26
 
27 27
 		$fields = array();
28 28
 
29 29
 		// CMB2
30
-		if ( class_exists( 'CMB2', false ) ) {
31
-			$fields = $this->get_cmb2_metaboxes( $slug );
30
+		if (class_exists('CMB2', false)) {
31
+			$fields = $this->get_cmb2_metaboxes($slug);
32 32
 		}
33 33
 
34 34
 		// Custom Metaboxes and Fields (CMB1)
35
-		if ( class_exists( 'cmb_Meta_Box', false ) ) {
36
-			$fields = $this->get_cmb1_metaboxes( $slug );
35
+		if (class_exists('cmb_Meta_Box', false)) {
36
+			$fields = $this->get_cmb1_metaboxes($slug);
37 37
 		}
38 38
 
39 39
 		// Return our array
@@ -56,55 +56,55 @@  discard block
 block discarded – undo
56 56
 	 * @param string $slug a custom post type ID.
57 57
 	 * @return array Array of fields.
58 58
 	 */
59
-	private function get_cmb2_metaboxes( $slug ){
59
+	private function get_cmb2_metaboxes($slug) {
60 60
 
61 61
 		$fields = array();
62 62
 
63 63
 		// Get all metaboxes from CMB2 library
64
-		$all_metaboxes = apply_filters( 'cmb2_meta_boxes', array() );
64
+		$all_metaboxes = apply_filters('cmb2_meta_boxes', array());
65 65
 
66 66
 		// Loop through all possible sets of metaboxes added the old way
67
-		foreach ( $all_metaboxes as $metabox_array ){
67
+		foreach ($all_metaboxes as $metabox_array) {
68 68
 
69 69
 			// If the custom post type ID matches this set of fields, set & stop
70
-			if ( in_array( $slug, $metabox_array['object_types'] ) ) {
70
+			if (in_array($slug, $metabox_array['object_types'])) {
71 71
 
72 72
 				// If this is the first group of fields, simply set the value
73 73
 				// Else, merge this group with the previous one
74
-				if ( empty( $fields ) ){
74
+				if (empty($fields)) {
75 75
 					$fields = $metabox_array['fields'];
76 76
 				} else {
77
-					$fields = array_merge( $fields, $metabox_array['fields'] );
77
+					$fields = array_merge($fields, $metabox_array['fields']);
78 78
 				}
79 79
 			}
80 80
 
81 81
 		}
82 82
 
83 83
 		// Loop through all metaboxes added the new way
84
-		foreach ( \CMB2_Boxes::get_all() as $cmb ) {
84
+		foreach (\CMB2_Boxes::get_all() as $cmb) {
85 85
 
86 86
 			// Create the default
87 87
 			$match = false;
88 88
 
89 89
 			// Establish correct cmb types
90
-			if ( is_string( $cmb->meta_box['object_types'] ) ){
91
-				if ( $cmb->meta_box['object_types'] == $slug ){
90
+			if (is_string($cmb->meta_box['object_types'])) {
91
+				if ($cmb->meta_box['object_types'] == $slug) {
92 92
 					$match = true;
93 93
 				}
94 94
 			} else {
95
-				if ( in_array( $slug, $cmb->meta_box['object_types'] ) ){
95
+				if (in_array($slug, $cmb->meta_box['object_types'])) {
96 96
 					$match = true;
97 97
 				}
98 98
 			}
99 99
 
100
-			if ( $match !== true ){
100
+			if ($match !== true) {
101 101
 				continue;
102 102
 			}
103 103
 
104
-			if ( empty( $fields ) ){
104
+			if (empty($fields)) {
105 105
 				$fields = $cmb->meta_box['fields'];
106 106
 			} else {
107
-				$fields = array_merge( $fields, $cmb->meta_box['fields'] );
107
+				$fields = array_merge($fields, $cmb->meta_box['fields']);
108 108
 			}
109 109
 
110 110
 		}
@@ -128,25 +128,25 @@  discard block
 block discarded – undo
128 128
 	 * @param string $slug a custom post type ID.
129 129
 	 * @return array Array of fields.
130 130
 	 */
131
-	private function get_cmb1_metaboxes( $slug ){
131
+	private function get_cmb1_metaboxes($slug) {
132 132
 
133 133
 		$fields = array();
134 134
 
135 135
 		// Get all metaboxes from CMB2 library
136
-		$all_metaboxes = apply_filters( 'cmb_meta_boxes', array() );
136
+		$all_metaboxes = apply_filters('cmb_meta_boxes', array());
137 137
 
138 138
 		// Loop through all possible sets of metaboxes
139
-		foreach ( $all_metaboxes as $metabox_array ){
139
+		foreach ($all_metaboxes as $metabox_array) {
140 140
 
141 141
 			// If the custom post type ID matches this set of fields, set & stop
142
-			if ( in_array( $slug, $metabox_array['pages'] ) ) {
142
+			if (in_array($slug, $metabox_array['pages'])) {
143 143
 
144 144
 				// If this is the first group of fields, simply set the value
145 145
 				// Else, merge this group with the previous one
146
-				if ( empty( $fields ) ){
146
+				if (empty($fields)) {
147 147
 					$fields = $metabox_array['fields'];
148 148
 				} else {
149
-					$fields = array_merge( $fields, $metabox_array['fields'] );
149
+					$fields = array_merge($fields, $metabox_array['fields']);
150 150
 				}
151 151
 			}
152 152
 
@@ -169,36 +169,36 @@  discard block
 block discarded – undo
169 169
 	 * @param int $post_id Single post ID.
170 170
 	 * @param array $cmb custom metabox array from CMB2.
171 171
 	 */
172
-	public function random_metabox_content( $post_id, $cmb ){
172
+	public function random_metabox_content($post_id, $cmb) {
173 173
 		$value = '';
174 174
 
175 175
 		// First check that our post ID & cmb array aren't empty
176
-		if ( empty( $cmb ) || empty( $post_id ) ){
176
+		if (empty($cmb) || empty($post_id)) {
177 177
 			return;
178 178
 		}
179 179
 
180 180
 		// Fetch the appropriate type of data and return
181
-		switch( $cmb['type'] ){
181
+		switch ($cmb['type']) {
182 182
 
183 183
 			case 'text':
184 184
 			case 'text_small':
185 185
 			case 'text_medium':
186 186
 
187 187
 				// If phone is in the id, fetch a phone #
188
-				if ( stripos( $cmb['id'], 'phone' ) ){
188
+				if (stripos($cmb['id'], 'phone')) {
189 189
 					$value = TestContent::phone();
190 190
 
191 191
 				// If email is in the id, fetch an email address
192
-				} elseif ( stripos( $cmb['id'], 'email' ) ){
192
+				} elseif (stripos($cmb['id'], 'email')) {
193 193
 					$value = TestContent::email();
194 194
 
195 195
 				// If time is in the id, fetch a time string
196
-				} elseif ( stripos( $cmb['id'], 'time' ) ){
196
+				} elseif (stripos($cmb['id'], 'time')) {
197 197
 					$value = TestContent::time();
198 198
 
199 199
 				// Otherwise, just a random text string
200 200
 				} else {
201
-					$value = TestContent::title( rand( 10, 50 ) );
201
+					$value = TestContent::title(rand(10, 50));
202 202
 				}
203 203
 
204 204
 				break;
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 229
 
230 230
 			case 'text_date':
231 231
 
232
-				$value = TestContent::date( 'm/d/Y' );
232
+				$value = TestContent::date('m/d/Y');
233 233
 
234 234
 				break;
235 235
 
236 236
 			case 'text_date_timestamp':
237 237
 			case 'text_datetime_timestamp':
238 238
 
239
-				$value = TestContent::date( 'U' );
239
+				$value = TestContent::date('U');
240 240
 
241 241
 				break;
242 242
 
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 
245 245
 			case 'text_money':
246 246
 
247
-				$value = rand( 0, 100000 );
247
+				$value = rand(0, 100000);
248 248
 
249 249
 				break;
250 250
 
251 251
 			case 'test_colorpicker':
252 252
 
253
-				$value = '#' . str_pad( dechex( mt_rand( 0, 0xFFFFFF ) ), 6, '0', STR_PAD_LEFT );
253
+				$value = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
254 254
 
255 255
 				break;
256 256
 
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 			case 'radio':
268 268
 
269 269
 				// Grab a random item out of the array and return the key
270
-				$new_val = array_slice( $cmb['options'], rand( 0, count( $cmb['options'] ) ), 1 );
271
-				$value = key( $new_val );
270
+				$new_val = array_slice($cmb['options'], rand(0, count($cmb['options'])), 1);
271
+				$value = key($new_val);
272 272
 
273 273
 				break;
274 274
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 			case 'checkbox':
280 280
 
281 281
 				// 50/50 odds of being turned on
282
-				if ( rand( 0, 1 ) == 1 ){
282
+				if (rand(0, 1) == 1) {
283 283
 					$value = 'on';
284 284
 				}
285 285
 
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 				$new_option = array();
291 291
 
292 292
 				// Loop through each of our options
293
-				foreach ( $cmb['options'] as $key => $value ){
293
+				foreach ($cmb['options'] as $key => $value) {
294 294
 
295 295
 					// 50/50 chance of being included
296
-					if ( rand( 0, 1 ) ){
296
+					if (rand(0, 1)) {
297 297
 						$new_option[] = $key;
298 298
 					}
299 299
 
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 
312 312
 			case 'file':
313 313
 
314
-				$value = TestContent::image( $post_id );
314
+				$value = TestContent::image($post_id);
315 315
 
316 316
 				break;
317 317
 
@@ -326,20 +326,20 @@  discard block
 block discarded – undo
326 326
 		}
327 327
 
328 328
 		// Value must exist to attempt to insert
329
-		if ( !empty( $value ) && !is_wp_error( $value ) ){
329
+		if (!empty($value) && !is_wp_error($value)) {
330 330
 
331 331
 			// Files must be treated separately - they use the attachment ID
332 332
 			// & url of media for separate cmb values
333
-			if ( $cmb['type'] != 'file' ){
334
-				add_post_meta( $post_id, $cmb['id'], $value, true );
333
+			if ($cmb['type'] != 'file') {
334
+				add_post_meta($post_id, $cmb['id'], $value, true);
335 335
 			} else {
336
-				add_post_meta( $post_id, $cmb['id'].'_id', $value, true );
337
-				add_post_meta( $post_id, $cmb['id'], wp_get_attachment_url( $value ), true );
336
+				add_post_meta($post_id, $cmb['id'].'_id', $value, true);
337
+				add_post_meta($post_id, $cmb['id'], wp_get_attachment_url($value), true);
338 338
 			}
339 339
 
340 340
 		// If we're dealing with a WP Error object, just return the message for debugging
341
-		} elseif ( is_wp_error( $value ) ){
342
-			error_log( $value->get_error_message() );
341
+		} elseif (is_wp_error($value)) {
342
+			error_log($value->get_error_message());
343 343
 			return $value->get_error_message();
344 344
 		}
345 345
 
Please login to merge, or discard this patch.