Completed
Pull Request — develop (#1134)
by Zack
18:29
created
future/includes/rest/class-gv-rest-views-route.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			'total' => wp_count_posts( 'gravityview' )->publish,
64 64
 		);
65 65
 		foreach ( $items as $item ) {
66
-			$data['views'][] = $this->prepare_view_for_response( $item, $request );
66
+			$data[ 'views' ][ ] = $this->prepare_view_for_response( $item, $request );
67 67
 		}
68 68
 
69 69
 		return new \WP_REST_Response( $data, 200 );
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
 		$url = $request->get_url_params();
84 84
 
85
-		$view_id = intval( $url['id'] );
85
+		$view_id = intval( $url[ 'id' ] );
86 86
 
87 87
 		$item = get_post( $view_id );
88 88
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		// Only output the fields that should be displayed.
112 112
 		$allowed = array();
113 113
 		foreach ( $view->fields->by_position( "{$context}_*" )->by_visible()->all() as $field ) {
114
-			$allowed[] = $field->ID;
114
+			$allowed[ ] = $field->ID;
115 115
 		}
116 116
 
117 117
 		/**
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
 	public function get_sub_items( $request ) {
157 157
 
158 158
 		$url     = $request->get_url_params();
159
-		$view_id = intval( $url['id'] );
159
+		$view_id = intval( $url[ 'id' ] );
160 160
 		$format  = \GV\Utils::get( $url, 'format', 'json' );
161 161
 
162
-		if( $post_id = $request->get_param('post_id') ) {
162
+		if ( $post_id = $request->get_param( 'post_id' ) ) {
163 163
 			global $post;
164 164
 
165 165
 			$post = get_post( $post_id );
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 
216 216
 		$data = array( 'entries' => $entries->all(), 'total' => $entries->total() );
217 217
 
218
-		foreach ( $data['entries'] as &$entry ) {
218
+		foreach ( $data[ 'entries' ] as &$entry ) {
219 219
 			$entry = $this->prepare_entry_for_response( $view, $entry, $request, 'directory' );
220 220
 		}
221 221
 
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 	 */
235 235
 	public function get_sub_item( $request ) {
236 236
 		$url      = $request->get_url_params();
237
-		$view_id  = intval( $url['id'] );
238
-		$entry_id = intval( $url['s_id'] );
237
+		$view_id  = intval( $url[ 'id' ] );
238
+		$entry_id = intval( $url[ 's_id' ] );
239 239
 		$format   = \GV\Utils::get( $url, 'format', 'json' );
240 240
 
241 241
 		$view  = \GV\View::by_id( $view_id );
@@ -270,32 +270,32 @@  discard block
 block discarded – undo
270 270
 		// Add all the WP_Post data
271 271
 		$view_post = $view_post->to_array();
272 272
 
273
-		unset( $view_post['to_ping'], $view_post['ping_status'], $view_post['pinged'], $view_post['post_type'], $view_post['filter'], $view_post['post_category'], $view_post['tags_input'], $view_post['post_content'], $view_post['post_content_filtered'] );
273
+		unset( $view_post[ 'to_ping' ], $view_post[ 'ping_status' ], $view_post[ 'pinged' ], $view_post[ 'post_type' ], $view_post[ 'filter' ], $view_post[ 'post_category' ], $view_post[ 'tags_input' ], $view_post[ 'post_content' ], $view_post[ 'post_content_filtered' ] );
274 274
 
275 275
 		$return = wp_parse_args( $item, $view_post );
276 276
 
277
-		$return['title'] = $return['post_title'];
277
+		$return[ 'title' ] = $return[ 'post_title' ];
278 278
 
279
-		$return['settings'] = isset( $return['atts'] ) ? $return['atts'] : array();
280
-		unset( $return['atts'], $return['view_id'] );
279
+		$return[ 'settings' ] = isset( $return[ 'atts' ] ) ? $return[ 'atts' ] : array();
280
+		unset( $return[ 'atts' ], $return[ 'view_id' ] );
281 281
 
282
-		$return['search_criteria'] = array(
282
+		$return[ 'search_criteria' ] = array(
283 283
 			'page_size' => rgars( $return, 'settings/page_size' ),
284 284
 			'sort_field' => rgars( $return, 'settings/sort_field' ),
285 285
 			'sort_direction' => rgars( $return, 'settings/sort_direction' ),
286 286
 			'offset' => rgars( $return, 'settings/offset' ),
287 287
 		);
288 288
 
289
-		unset( $return['settings']['page_size'], $return['settings']['sort_field'], $return['settings']['sort_direction'] );
289
+		unset( $return[ 'settings' ][ 'page_size' ], $return[ 'settings' ][ 'sort_field' ], $return[ 'settings' ][ 'sort_direction' ] );
290 290
 
291 291
 		// Redact for non-logged ins
292 292
 		if ( ! \GVCommon::has_cap( 'edit_others_gravityviews' ) ) {
293
-			unset( $return['settings'] );
294
-			unset( $return['search_criteria'] );
293
+			unset( $return[ 'settings' ] );
294
+			unset( $return[ 'search_criteria' ] );
295 295
 		}
296 296
 		
297 297
 		if ( ! \GFCommon::current_user_can_any( 'gravityforms_edit_forms' ) ) {
298
-			unset( $return['form'] );
298
+			unset( $return[ 'form' ] );
299 299
 		}
300 300
 
301 301
 		return $return;
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 			$view_id = func_get_arg( 1 ); // $view_id override
307 307
 		} else {
308 308
 			$url     = $request->get_url_params();
309
-			$view_id = intval( $url['id'] );
309
+			$view_id = intval( $url[ 'id' ] );
310 310
 		}
311 311
 
312 312
 		if ( ! $view = \GV\View::by_id( $view_id ) ) {
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
 		}
360 360
 
361 361
 		$url     = $request->get_url_params();
362
-		$view_id = intval( $url['id'] );
363
-		$entry_id = intval( $url['s_id'] );
362
+		$view_id = intval( $url[ 'id' ] );
363
+		$entry_id = intval( $url[ 's_id' ] );
364 364
 
365 365
 		$view = \GV\View::by_id( $view_id );
366 366
 
@@ -368,11 +368,11 @@  discard block
 block discarded – undo
368 368
 			return new \WP_Error( 'rest_forbidden', 'You are not allowed to view this content.', 'gravityview' );
369 369
 		}
370 370
 
371
-		if ( $entry['form_id'] != $view->form->ID ) {
371
+		if ( $entry[ 'form_id' ] != $view->form->ID ) {
372 372
 			return new \WP_Error( 'rest_forbidden', 'You are not allowed to view this content.', 'gravityview' );
373 373
 		}
374 374
 
375
-		if ( $entry['status'] != 'active' ) {
375
+		if ( $entry[ 'status' ] != 'active' ) {
376 376
 			return new \WP_Error( 'rest_forbidden', 'You are not allowed to view this content.', 'gravityview' );
377 377
 		}
378 378
 
@@ -380,10 +380,10 @@  discard block
 block discarded – undo
380 380
 			return new \WP_Error( 'rest_forbidden', 'You are not allowed to view this content.', 'gravityview' );
381 381
 		}
382 382
 
383
-		$is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID );
383
+		$is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap( 'gravityview_moderate_entries', $view->ID );
384 384
 
385 385
 		if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) {
386
-			if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) )  ) {
386
+			if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) {
387 387
 				return new \WP_Error( 'rest_forbidden', 'You are not allowed to view this content.', 'gravityview' );
388 388
 			}
389 389
 		}
Please login to merge, or discard this patch.