Completed
Pull Request — develop (#1360)
by Gennady
15:19
created
includes/extensions/duplicate-entry/class-duplicate-entry.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -171,7 +171,6 @@
 block discarded – undo
171 171
 	 *
172 172
 	 * @since develop
173 173
 	 * @param  array 	   $visibility_caps        Array of capabilities to display in field dropdown.
174
-	 * @param  string      $field_type  Type of field options to render (`field` or `widget`)
175 174
 	 * @param  string      $template_id Table slug
176 175
 	 * @param  float       $field_id    GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
177 176
 	 * @param  string      $context     What context are we in? Example: `single` or `directory`
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	public static function get_duplicate_link( $entry, $view_id, $post_id = null ) {
238 238
 		self::getInstance()->set_entry( $entry );
239 239
 
240
-        $base = GravityView_API::directory_link( $post_id ? : $view_id, true );
240
+		$base = GravityView_API::directory_link( $post_id ? : $view_id, true );
241 241
 
242 242
 		if ( empty( $base ) ) {
243 243
 			gravityview()->log->error( 'Post ID does not exist: {post_id}', array( 'post_id' => $post_id ) );
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 			'action'	=> 'duplicate',
252 252
 			'entry_id'	=> $entry_slug,
253 253
 			'gvid' => $view_id,
254
-            'view_id' => $view_id,
254
+			'view_id' => $view_id,
255 255
 		), $base );
256 256
 
257 257
 		$url = wp_nonce_url( $actionurl, 'duplicate_'.$entry_slug, 'duplicate' );
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 		 * @since develop
443 443
 		 * @param  array $duplicated_entry The duplicated entry
444 444
 		 * @param  array $entry The original entry
445
-		*/
445
+		 */
446 446
 		do_action( 'gravityview/duplicate-entry/duplicated', $duplicated_entry, $entry );
447 447
 
448 448
 		gravityview()->log->debug( 'Duplicate response: {duplicate_response}', array( 'duplicate_response' => $duplicate_response ) );
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 	function duplicate_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
109 109
 
110 110
 		// Always a link, never a filter
111
-		unset( $field_options['show_as_link'], $field_options['search_filter'] );
111
+		unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] );
112 112
 
113 113
 
114 114
 		// Duplicate Entry link should only appear to visitors capable of editing entries
115
-		unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
115
+		unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] );
116 116
 
117
-		$add_option['duplicate_link'] = array(
117
+		$add_option[ 'duplicate_link' ] = array(
118 118
 			'type' => 'text',
119 119
 			'label' => __( 'Duplicate Link Text', 'gravityview' ),
120 120
 			'desc' => NULL,
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 			'merge_tags' => true,
123 123
 		);
124 124
 
125
-		$field_options['allow_duplicate_cap'] = array(
125
+		$field_options[ 'allow_duplicate_cap' ] = array(
126 126
 			'type' => 'select',
127 127
 			'label' => __( 'Allow the following users to duplicate the entry:', 'gravityview' ),
128 128
 			'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
147 147
 
148 148
 		if ( 'edit' !== $zone ) {
149
-			$entry_default_fields['duplicate_link'] = array(
149
+			$entry_default_fields[ 'duplicate_link' ] = array(
150 150
 				'label' => __( 'Duplicate Entry', 'gravityview' ),
151 151
 				'type'  => 'duplicate_link',
152 152
 				'desc'  => __( 'A link to duplicate the entry. Respects the Duplicate Entry permissions.', 'gravityview' ),
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	function add_available_field( $available_fields = array() ) {
165 165
 
166
-		$available_fields['duplicate_link'] = array(
166
+		$available_fields[ 'duplicate_link' ] = array(
167 167
 			'label_text' => __( 'Duplicate Entry', 'gravityview' ),
168 168
 			'field_id' => 'duplicate_link',
169 169
 			'label_type' => 'field',
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 		if ( 'duplicate_link' === $field_id ) {
195 195
 
196 196
 			// Remove other built-in caps.
197
-			unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['duplicate_others_posts'] );
197
+			unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'duplicate_others_posts' ] );
198 198
 
199
-			$caps['read'] = _x( 'Entry Creator', 'User capability', 'gravityview' );
199
+			$caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' );
200 200
 		}
201 201
 
202 202
 		return $caps;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	public static function get_duplicate_link( $entry, $view_id, $post_id = null ) {
238 238
 		self::getInstance()->set_entry( $entry );
239 239
 
240
-        $base = GravityView_API::directory_link( $post_id ? : $view_id, true );
240
+        $base = GravityView_API::directory_link( $post_id ?: $view_id, true );
241 241
 
242 242
 		if ( empty( $base ) ) {
243 243
 			gravityview()->log->error( 'Post ID does not exist: {post_id}', array( 'post_id' => $post_id ) );
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 		}
246 246
 
247 247
 		// Use the slug instead of the ID for consistent security
248
-		$entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry );
248
+		$entry_slug = GravityView_API::get_entry_slug( $entry[ 'id' ], $entry );
249 249
 
250 250
 		$actionurl = add_query_arg( array(
251 251
 			'action'	=> 'duplicate',
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             'view_id' => $view_id,
255 255
 		), $base );
256 256
 
257
-		$url = wp_nonce_url( $actionurl, 'duplicate_'.$entry_slug, 'duplicate' );
257
+		$url = wp_nonce_url( $actionurl, 'duplicate_' . $entry_slug, 'duplicate' );
258 258
 
259 259
 		return $url;
260 260
 	}
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 	function process_duplicate() {
276 276
 
277 277
 		// If the form is submitted
278
-		if ( ! isset( $_GET['action'] ) || 'duplicate' !== $_GET['action'] || ! isset( $_GET['entry_id'] ) ) {
278
+		if ( ! isset( $_GET[ 'action' ] ) || 'duplicate' !== $_GET[ 'action' ] || ! isset( $_GET[ 'entry_id' ] ) ) {
279 279
 			return;
280 280
 		}
281 281
 
282 282
 		// Make sure it's a GravityView request
283
-		$valid_nonce_key = wp_verify_nonce( $_GET['duplicate'], self::get_nonce_key( $_GET['entry_id'] ) );
283
+		$valid_nonce_key = wp_verify_nonce( $_GET[ 'duplicate' ], self::get_nonce_key( $_GET[ 'entry_id' ] ) );
284 284
 
285 285
 		if ( ! $valid_nonce_key ) {
286 286
 			gravityview()->log->debug( 'Duplicate entry not processed: nonce validation failed.' );
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 		}
289 289
 
290 290
 		// Get the entry slug
291
-		$entry_slug = esc_attr( $_GET['entry_id'] );
291
+		$entry_slug = esc_attr( $_GET[ 'entry_id' ] );
292 292
 
293 293
 		// See if there's an entry there
294 294
 		$entry = gravityview_get_entry( $entry_slug, true, false );
@@ -371,15 +371,15 @@  discard block
 block discarded – undo
371 371
 			return new WP_Error( 'gravityview-duplicate-entry-missing', __( 'No such entry ID', 'gravityview' ) );
372 372
 		}
373 373
 
374
-		$row['id'] = null;
375
-		$row['date_created'] = date( 'Y-m-d H:i:s', time() );
376
-		$row['date_updated'] = $row['date_created'];
377
-		$row['is_starred'] = false;
378
-		$row['is_read'] = false;
379
-		$row['ip'] = GFFormsModel::get_ip();
380
-		$row['source_url'] = esc_url_raw( remove_query_arg( array( 'action', 'gvid' ) ) );
381
-		$row['user_agent'] = \GV\Utils::_SERVER( 'HTTP_USER_AGENT' );
382
-		$row['created_by'] = wp_get_current_user()->ID;
374
+		$row[ 'id' ] = null;
375
+		$row[ 'date_created' ] = date( 'Y-m-d H:i:s', time() );
376
+		$row[ 'date_updated' ] = $row[ 'date_created' ];
377
+		$row[ 'is_starred' ] = false;
378
+		$row[ 'is_read' ] = false;
379
+		$row[ 'ip' ] = GFFormsModel::get_ip();
380
+		$row[ 'source_url' ] = esc_url_raw( remove_query_arg( array( 'action', 'gvid' ) ) );
381
+		$row[ 'user_agent' ] = \GV\Utils::_SERVER( 'HTTP_USER_AGENT' );
382
+		$row[ 'created_by' ] = wp_get_current_user()->ID;
383 383
 
384 384
 		/**
385 385
 		 * @filter `gravityview/entry/duplicate/details` Modify the new entry details before it's created.
@@ -406,15 +406,15 @@  discard block
 block discarded – undo
406 406
 
407 407
 		$save_this_meta = array();
408 408
 		foreach ( $duplicate_meta->get_output() as $m ) {
409
-			$save_this_meta[] = array(
410
-				'meta_key' => $m['meta_key'],
411
-				'meta_value' => $m['meta_value'],
412
-				'item_index' => $m['item_index'],
409
+			$save_this_meta[ ] = array(
410
+				'meta_key' => $m[ 'meta_key' ],
411
+				'meta_value' => $m[ 'meta_value' ],
412
+				'item_index' => $m[ 'item_index' ],
413 413
 			);
414 414
 		}
415 415
 
416 416
 		// Update the row ID for later usage
417
-		$row['id'] = $duplicated_id;
417
+		$row[ 'id' ] = $duplicated_id;
418 418
 
419 419
 		/**
420 420
 		 * @filter `gravityview/entry/duplicate/meta` Modify the new entry meta details.
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
 		$save_this_meta = apply_filters( 'gravityview/entry/duplicate/meta', $save_this_meta, $row, $entry );
426 426
 
427 427
 		foreach ( $save_this_meta as $data ) {
428
-			$data['form_id'] = $entry['form_id'];
429
-			$data['entry_id'] = $duplicated_id;
428
+			$data[ 'form_id' ] = $entry[ 'form_id' ];
429
+			$data[ 'entry_id' ] = $duplicated_id;
430 430
 
431 431
 			if ( ! $wpdb->insert( $entry_meta_table, $data ) ) {
432 432
 				return new WP_Error( 'gravityview-duplicate-entry-db', __( 'Database error', 'gravityview' ) );
@@ -459,13 +459,13 @@  discard block
 block discarded – undo
459 459
 	public function verify_nonce() {
460 460
 
461 461
 		// No duplicate entry request was made
462
-		if ( empty( $_GET['entry_id'] ) || empty( $_GET['duplicate'] ) ) {
462
+		if ( empty( $_GET[ 'entry_id' ] ) || empty( $_GET[ 'duplicate' ] ) ) {
463 463
 			return false;
464 464
 		}
465 465
 
466
-		$nonce_key = self::get_nonce_key( $_GET['entry_id'] );
466
+		$nonce_key = self::get_nonce_key( $_GET[ 'entry_id' ] );
467 467
 
468
-		$valid = wp_verify_nonce( $_GET['duplicate'], $nonce_key );
468
+		$valid = wp_verify_nonce( $_GET[ 'duplicate' ], $nonce_key );
469 469
 
470 470
 		/**
471 471
 		 * @filter `gravityview/duplicate-entry/verify_nonce` Override Duplicate Entry nonce validation. Return true to declare nonce valid.
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 		 */
496 496
 		$confirm = apply_filters( 'gravityview/duplicate-entry/confirm-text', $confirm );
497 497
 
498
-		return 'return window.confirm(\''. esc_js( $confirm ) .'\');';
498
+		return 'return window.confirm(\'' . esc_js( $confirm ) . '\');';
499 499
 	}
500 500
 
501 501
 	/**
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	public static function check_user_cap_duplicate_entry( $entry, $field, $view_id ) {
546 546
 		$current_user = wp_get_current_user();
547 547
 
548
-		$entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL;
548
+		$entry_id = isset( $entry[ 'id' ] ) ? $entry[ 'id' ] : NULL;
549 549
 
550 550
 		// Or if they can duplicate any entries (as defined in Gravity Forms), we're good.
551 551
 		if ( GVCommon::has_cap( array( 'gravityforms_edit_entries' ), $entry_id ) ) {
@@ -560,17 +560,17 @@  discard block
 block discarded – undo
560 560
 		if ( ! empty( $field ) ) {
561 561
 
562 562
 			// If capability is not defined, something is not right!
563
-			if ( empty( $field['allow_duplicate_cap'] ) ) {
563
+			if ( empty( $field[ 'allow_duplicate_cap' ] ) ) {
564 564
 
565 565
 				gravityview()->log->error( 'Cannot read duplicate entry field caps', array( 'data' => $field ) );
566 566
 
567 567
 				return false;
568 568
 			}
569 569
 
570
-			if ( GVCommon::has_cap( $field['allow_duplicate_cap'] ) ) {
570
+			if ( GVCommon::has_cap( $field[ 'allow_duplicate_cap' ] ) ) {
571 571
 
572 572
 				// Do not return true if cap is read, as we need to check if the current user created the entry
573
-				if ( 'read' !== $field['allow_duplicate_cap'] ) {
573
+				if ( 'read' !== $field[ 'allow_duplicate_cap' ] ) {
574 574
 					return true;
575 575
 				}
576 576
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 
584 584
 		}
585 585
 
586
-		if ( ! isset( $entry['created_by'] ) ) {
586
+		if ( ! isset( $entry[ 'created_by' ] ) ) {
587 587
 
588 588
 			gravityview()->log->error( 'Entry `created_by` doesn\'t exist.' );
589 589
 
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 
596 596
 			$current_view = gravityview_get_current_view_data( $view_id );
597 597
 
598
-			$user_duplicate = isset( $current_view['atts']['user_duplicate'] ) ? $current_view['atts']['user_duplicate'] : false;
598
+			$user_duplicate = isset( $current_view[ 'atts' ][ 'user_duplicate' ] ) ? $current_view[ 'atts' ][ 'user_duplicate' ] : false;
599 599
 
600 600
 			if ( empty( $user_duplicate ) ) {
601 601
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 		}
607 607
 
608 608
 		// If the logged-in user is the same as the user who created the entry, we're good.
609
-		if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) {
609
+		if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) {
610 610
 
611 611
 			gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id' => $current_user->ID ) );
612 612
 
@@ -630,16 +630,16 @@  discard block
 block discarded – undo
630 630
 	 */
631 631
 	public function display_message( $current_view_id = 0 ) {
632 632
 
633
-		if ( empty( $_GET['status'] ) || ! self::verify_nonce() ) {
633
+		if ( empty( $_GET[ 'status' ] ) || ! self::verify_nonce() ) {
634 634
 			return;
635 635
 		}
636 636
 
637 637
 		// Entry wasn't duplicateded from current View
638
-		if ( isset( $_GET['view_id'] ) && ( intval( $_GET['view_id'] ) !== intval( $current_view_id ) ) ) {
638
+		if ( isset( $_GET[ 'view_id' ] ) && ( intval( $_GET[ 'view_id' ] ) !== intval( $current_view_id ) ) ) {
639 639
 			return;
640 640
 		}
641 641
 
642
-		$status = esc_attr( $_GET['status'] );
642
+		$status = esc_attr( $_GET[ 'status' ] );
643 643
 		$message_from_url = \GV\Utils::_GET( 'message' );
644 644
 		$message_from_url = rawurldecode( stripslashes_deep( $message_from_url ) );
645 645
 		$class = '';
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 		$message = apply_filters( 'gravityview/duplicate-entry/message', esc_attr( $message ), $status, $message_from_url );
666 666
 
667 667
 		// DISPLAY ERROR/SUCCESS MESSAGE
668
-		echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>';
668
+		echo '<div class="gv-notice' . esc_attr( $class ) . '">' . $message . '</div>';
669 669
 	}
670 670
 
671 671
 
Please login to merge, or discard this patch.