Completed
Pull Request — develop (#1347)
by Gennady
17:14
created
includes/fields/class-gravityview-field-unsubscribe.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
 	public function __construct() {
20 20
 		$this->label = esc_html__( 'Unsubscribe', 'gravityview' );
21
-		$this->description =  esc_attr__( 'Unsubscribe from a Payment-based entry.', 'gravityview' );
21
+		$this->description = esc_attr__( 'Unsubscribe from a Payment-based entry.', 'gravityview' );
22 22
 		
23 23
 		$this->add_hooks();
24 24
 		
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 
36 36
 	public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {
37 37
 
38
-		unset( $field_options['only_loggedin'] );
38
+		unset( $field_options[ 'only_loggedin' ] );
39 39
 
40
-		unset( $field_options['new_window'] );
40
+		unset( $field_options[ 'new_window' ] );
41 41
 
42
-		unset( $field_options['show_as_link'] );
42
+		unset( $field_options[ 'show_as_link' ] );
43 43
 
44
-		$add_options['unsub_all'] = array(
44
+		$add_options[ 'unsub_all' ] = array(
45 45
 			'type'       => 'checkbox',
46 46
 			'label'      => __( 'Allow admins to unsubscribe', 'gravityview' ),
47 47
 			'desc'       => __( 'Allow users with `gravityforms_edit_entries` to cancel subscriptions', 'gravityview' ),
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 
75 75
 		foreach ( $feeds as $feed ) {
76
-			if ( isset( $subscription_addons[ $feed['addon_slug'] ] ) && \GV\Utils::get( $feed, 'meta/transactionType' ) == 'subscription' ) {
77
-				if ( ! isset( $entry_default_fields["{$this->name}"] ) && 'edit' !== $context ) {
78
-					$entry_default_fields["{$this->name}"] = array(
76
+			if ( isset( $subscription_addons[ $feed[ 'addon_slug' ] ] ) && \GV\Utils::get( $feed, 'meta/transactionType' ) == 'subscription' ) {
77
+				if ( ! isset( $entry_default_fields[ "{$this->name}" ] ) && 'edit' !== $context ) {
78
+					$entry_default_fields[ "{$this->name}" ] = array(
79 79
 						'label' => $this->label,
80 80
 						'desc'  => $this->description,
81 81
 						'type'  => $this->name,
@@ -94,42 +94,42 @@  discard block
 block discarded – undo
94 94
 			return $output;
95 95
 		}
96 96
 
97
-		$can_current_user_edit = wp_get_current_user()->ID == $entry['created_by'];
97
+		$can_current_user_edit = wp_get_current_user()->ID == $entry[ 'created_by' ];
98 98
 
99 99
 		if ( ! $can_current_user_edit ) {
100
-			if ( empty( $field_settings['unsub_all'] ) || ! \GVCommon::has_cap( 'gravityforms_edit_entries', $entry['id'] ) ) {
100
+			if ( empty( $field_settings[ 'unsub_all' ] ) || ! \GVCommon::has_cap( 'gravityforms_edit_entries', $entry[ 'id' ] ) ) {
101 101
 				return $output;
102 102
 			}
103 103
 		}
104 104
 
105
-		$status = $entry['payment_status'];
105
+		$status = $entry[ 'payment_status' ];
106 106
 		// @todo Move to init, or AJAXify, but make sure that the entry is in the View before allowing
107 107
 		if ( $entry = $this->maybe_unsubscribe( $entry ) ) {
108
-			if ( $entry['payment_status'] != $status ) {
108
+			if ( $entry[ 'payment_status' ] != $status ) {
109 109
 				// @todo Probably __( 'Unsubscribed', 'gravityview' );
110
-				return $entry['payment_status'];
110
+				return $entry[ 'payment_status' ];
111 111
 			}
112 112
 		}
113 113
 
114
-		if ( strtolower( $entry['payment_status'] ) != 'active' ) {
114
+		if ( strtolower( $entry[ 'payment_status' ] ) != 'active' ) {
115 115
 			return $output;
116 116
 		}
117 117
 
118 118
 		global $wp;
119 119
 		$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
120 120
 
121
-		$link = add_query_arg( 'unsubscribe', wp_create_nonce( 'unsubscribe_' . $entry['id'] ), $current_url );
122
-		$link = add_query_arg( 'uid', urlencode( $entry['id'] ), $link );
121
+		$link = add_query_arg( 'unsubscribe', wp_create_nonce( 'unsubscribe_' . $entry[ 'id' ] ), $current_url );
122
+		$link = add_query_arg( 'uid', urlencode( $entry[ 'id' ] ), $link );
123 123
 
124 124
 		return sprintf( '<a href="%s">%s</button>', $link, __( 'Unsubscribe', 'gravityview' ) );
125 125
 	}
126 126
 
127 127
 	private function maybe_unsubscribe( $entry ) {
128
-		if ( ! wp_verify_nonce( \GV\Utils::_REQUEST( 'unsubscribe' ), 'unsubscribe_' . $entry['id'] ) ) {
128
+		if ( ! wp_verify_nonce( \GV\Utils::_REQUEST( 'unsubscribe' ), 'unsubscribe_' . $entry[ 'id' ] ) ) {
129 129
 			return;
130 130
 		}
131 131
 
132
-		if ( ( ! $uid = \GV\Utils::_REQUEST( 'uid' ) ) || $uid != $entry['id'] ) {
132
+		if ( ( ! $uid = \GV\Utils::_REQUEST( 'uid' ) ) || $uid != $entry[ 'id' ] ) {
133 133
 			return;
134 134
 		}
135 135
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 				if ( ( $feed = $subscription_addons[ $slug ]->get_feed( $feed_id ) ) && \GV\Utils::get( $feed, 'meta/transactionType' ) == 'subscription' ) {
158 158
 					if ( $subscription_addons[ $slug ]->cancel( $entry, $feed ) ) {
159 159
 						$subscription_addons[ $slug ]->cancel_subscription( $entry, $feed );
160
-						return \GFAPI::get_entry( $entry['id'] );
160
+						return \GFAPI::get_entry( $entry[ 'id' ] );
161 161
 					}
162 162
 				}
163 163
 			}
Please login to merge, or discard this patch.