Completed
Pull Request — develop (#1523)
by
unknown
19:04
created
includes/class-gravityview-change-entry-creator.php 2 patches
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -5,307 +5,307 @@
 block discarded – undo
5 5
  */
6 6
 class GravityView_Change_Entry_Creator {
7 7
 
8
-    function __construct() {
9
-
10
-    	/**
11
-    	 * @since  1.5.1
12
-    	 */
13
-    	add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 );
14
-
15
-    	// ONLY ADMIN FROM HERE ON.
16
-    	if( !is_admin() ) { return; }
17
-
18
-	    /**
19
-         * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality
20
-	     * @since 1.7.4
21
-	     * @param boolean $disable Disable the Change Entry Creator functionality. Default: false.
22
-	     */
23
-	    if( apply_filters('gravityview_disable_change_entry_creator', false ) ) {
24
-		    return;
25
-	    }
26
-
27
-        /**
28
-         * Use `init` to fix bbPress warning
29
-         * @see https://bbpress.trac.wordpress.org/ticket/2309
30
-         */
31
-    	add_action('init', array( $this, 'load'), 100 );
32
-
33
-    	add_action('plugins_loaded', array( $this, 'prevent_conflicts') );
34
-
35
-        // Enqueues SelectWoo script and style.
36
-        add_action( 'admin_enqueue_scripts', array( $this, 'add_selectwoo_assets') );
37
-
38
-        // Ajax callback to get users to change entry creator.
39
-        add_action( 'wp_ajax_entry_creator_get_users', array( $this, 'entry_creator_get_users' ) );
40
-
41
-    }
42
-
43
-    /**
44
-     * Enqueues SelectWoo script and style.
45
-     *
46
-     * @since  2.9.1
47
-     *
48
-     */
49
-    function add_selectwoo_assets() {
50
-
51
-        $version      = GravityView_Plugin::version;
52
-        $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
53
-
54
-        wp_enqueue_script( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.full.min.js', GRAVITYVIEW_FILE ), array(), $version );
55
-        wp_enqueue_style( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.min.css', GRAVITYVIEW_FILE ), array(), $version );
56
-
57
-        wp_enqueue_script( 'gravityview_entry_creator', plugins_url( 'assets/js/admin-entry-creator' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'gravityview-selectWoo' ), $version );
58
-
59
-        wp_localize_script(
60
-            'gravityview_entry_creator',
61
-            'GVEntryCreator',
62
-            array(
63
-                'ajaxurl' => admin_url( 'admin-ajax.php' ),
64
-                'action'  => 'entry_creator_get_users',
65
-            ) 
66
-        );
67
-    }
68
-
69
-    /**
70
-     * Get users list for entry creator.
71
-     *
72
-     * @since  2.9.1
73
-     *
74
-     */
75
-    function entry_creator_get_users() {
76
-
77
-        $post_var = wp_parse_args(
78
-            wp_unslash( $_POST ),
79
-            array(
80
-                'q'        => '',
81
-                'gv_nonce' => '',
82
-                'on_load'  => '',
83
-            )
84
-        );
85
-
86
-        if( !wp_verify_nonce( $post_var['gv_nonce'], 'gv_entry_creator' )) {
87
-            die();
88
-        }
89
-
90
-        $search_string = $post_var['q'];
91
-
92
-        if( is_numeric( $search_string ) ) {
93
-            $user_args = array(
94
-                'search'         => $search_string . '*',
95
-                'search_columns' => array( 'ID' ),
96
-            );
97
-        } else {
98
-            $user_args = array(
99
-                'search'         => '*' . $search_string . '*',
100
-                'search_columns' => array( 'user_login', 'user_email', 'user_nicename', 'display_name' ),
101
-            );
102
-        }
103
-
104
-        if( 1 == $post_var['on_load'] ) {
105
-            $user_args[ 'number' ] = 100;
106
-        }
107
-
108
-        $users = GVCommon::get_users( 'change_entry_creator', $user_args );
109
-
110
-        echo wp_send_json( $users, 200 );
111
-
112
-        die();
113
-    }
114
-
115
-    /**
116
-     * When an user is created using the User Registration add-on, assign the entry to them
117
-     *
118
-     * @since  1.5.1
119
-     * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field
120
-     * @param  int $user_id  WordPress User ID
121
-     * @param  array $config   User registration feed configuration
122
-     * @param  array  $entry     GF Entry array
123
-     * @param  string $password User password
124
-     * @return void
125
-     */
126
-    function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) {
127
-
128
-    	/**
129
-    	 * Disable assigning the new user to the entry by returning false.
130
-    	 * @param  int $user_id  WordPress User ID
131
-	     * @param  array $config   User registration feed configuration
132
-	     * @param  array  $entry     GF Entry array
133
-    	 */
134
-    	$assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry );
135
-
136
-    	// If filter returns false, do not process
137
-    	if( empty( $assign_to_lead ) ) {
138
-    		return;
139
-    	}
140
-
141
-    	// Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing
142
-    	$result = RGFormsModel::update_entry_property( (int) $entry['id'], 'created_by', (int) $user_id, false, true );
143
-
144
-    	if ( false === $result ) {
145
-    		$status = __('Error', 'gravityview');
146
-    		global $wpdb;
147
-		    $note = sprintf( '%s: Failed to assign User ID #%d as the entry creator (Last database error: "%s")', $status, $user_id, $wpdb->last_error );
148
-    	} else {
149
-    		$status = __('Success', 'gravityview');
150
-    	    $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id );
151
-    	}
152
-
153
-    	gravityview()->log->debug( 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - {note}', array( 'note' => $note ) );
154
-
155
-	    /**
156
-	     * @filter `gravityview_disable_change_entry_creator_note` Disable adding a note when changing the entry creator
157
-	     * @since 1.21.5
158
-	     * @param boolean $disable Disable the Change Entry Creator note. Default: false.
159
-	     */
160
-	    if( apply_filters('gravityview_disable_change_entry_creator_note', false ) ) {
161
-		    return;
162
-	    }
163
-
164
-        GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' );
165
-
166
-    }
167
-
168
-    /**
169
-     * Disable previous functionality; use this one as the canonical.
170
-     * @return void
171
-     */
172
-    function prevent_conflicts() {
173
-
174
-    	// Plugin that was provided here:
175
-    	// @link https://gravityview.co/support/documentation/201991205/
176
-    	remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 );
177
-    	remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 );
178
-
179
-    }
180
-
181
-    /**
182
-     * @since  3.6.3
183
-     * @return void
184
-     */
185
-    function load() {
186
-
187
-    	// Does GF exist?
188
-        if( !class_exists('GFCommon') ) {
189
-            return;
190
-        }
191
-
192
-        // Can the user edit entries?
193
-        if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) {
194
-            return;
195
-        }
196
-
197
-        // If screen mode isn't set, then we're in the wrong place.
198
-        if( empty( $_REQUEST['screen_mode'] ) ) {
199
-            return;
200
-        }
201
-
202
-        // Now, no validation is required in the methods; let's hook in.
203
-        add_action('admin_init', array( &$this, 'set_screen_mode' ) );
204
-
205
-        add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2);
206
-
207
-        add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2);
208
-
209
-    }
210
-
211
-    /**
212
-     * Allows for edit links to work with a link instead of a form (GET instead of POST)
213
-     * @return void
214
-     */
215
-    function set_screen_mode() {
216
-
217
-    	if( 'view' === \GV\Utils::_POST( 'screen_mode' ) ) {
218
-    		return;
219
-	    }
220
-
221
-    	// If $_GET['screen_mode'] is set to edit, set $_POST value
222
-        if( \GV\Utils::_GET( 'screen_mode' ) === 'edit' ) {
223
-            $_POST["screen_mode"] = 'edit';
224
-        }
225
-
226
-    }
8
+	function __construct() {
9
+
10
+		/**
11
+		 * @since  1.5.1
12
+		 */
13
+		add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 );
14
+
15
+		// ONLY ADMIN FROM HERE ON.
16
+		if( !is_admin() ) { return; }
17
+
18
+		/**
19
+		 * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality
20
+		 * @since 1.7.4
21
+		 * @param boolean $disable Disable the Change Entry Creator functionality. Default: false.
22
+		 */
23
+		if( apply_filters('gravityview_disable_change_entry_creator', false ) ) {
24
+			return;
25
+		}
26
+
27
+		/**
28
+		 * Use `init` to fix bbPress warning
29
+		 * @see https://bbpress.trac.wordpress.org/ticket/2309
30
+		 */
31
+		add_action('init', array( $this, 'load'), 100 );
32
+
33
+		add_action('plugins_loaded', array( $this, 'prevent_conflicts') );
34
+
35
+		// Enqueues SelectWoo script and style.
36
+		add_action( 'admin_enqueue_scripts', array( $this, 'add_selectwoo_assets') );
37
+
38
+		// Ajax callback to get users to change entry creator.
39
+		add_action( 'wp_ajax_entry_creator_get_users', array( $this, 'entry_creator_get_users' ) );
40
+
41
+	}
42
+
43
+	/**
44
+	 * Enqueues SelectWoo script and style.
45
+	 *
46
+	 * @since  2.9.1
47
+	 *
48
+	 */
49
+	function add_selectwoo_assets() {
50
+
51
+		$version      = GravityView_Plugin::version;
52
+		$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
53
+
54
+		wp_enqueue_script( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.full.min.js', GRAVITYVIEW_FILE ), array(), $version );
55
+		wp_enqueue_style( 'gravityview-selectWoo', plugins_url( 'assets/lib/selectWoo/selectWoo.min.css', GRAVITYVIEW_FILE ), array(), $version );
56
+
57
+		wp_enqueue_script( 'gravityview_entry_creator', plugins_url( 'assets/js/admin-entry-creator' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'gravityview-selectWoo' ), $version );
58
+
59
+		wp_localize_script(
60
+			'gravityview_entry_creator',
61
+			'GVEntryCreator',
62
+			array(
63
+				'ajaxurl' => admin_url( 'admin-ajax.php' ),
64
+				'action'  => 'entry_creator_get_users',
65
+			) 
66
+		);
67
+	}
68
+
69
+	/**
70
+	 * Get users list for entry creator.
71
+	 *
72
+	 * @since  2.9.1
73
+	 *
74
+	 */
75
+	function entry_creator_get_users() {
76
+
77
+		$post_var = wp_parse_args(
78
+			wp_unslash( $_POST ),
79
+			array(
80
+				'q'        => '',
81
+				'gv_nonce' => '',
82
+				'on_load'  => '',
83
+			)
84
+		);
85
+
86
+		if( !wp_verify_nonce( $post_var['gv_nonce'], 'gv_entry_creator' )) {
87
+			die();
88
+		}
89
+
90
+		$search_string = $post_var['q'];
91
+
92
+		if( is_numeric( $search_string ) ) {
93
+			$user_args = array(
94
+				'search'         => $search_string . '*',
95
+				'search_columns' => array( 'ID' ),
96
+			);
97
+		} else {
98
+			$user_args = array(
99
+				'search'         => '*' . $search_string . '*',
100
+				'search_columns' => array( 'user_login', 'user_email', 'user_nicename', 'display_name' ),
101
+			);
102
+		}
103
+
104
+		if( 1 == $post_var['on_load'] ) {
105
+			$user_args[ 'number' ] = 100;
106
+		}
107
+
108
+		$users = GVCommon::get_users( 'change_entry_creator', $user_args );
109
+
110
+		echo wp_send_json( $users, 200 );
111
+
112
+		die();
113
+	}
114
+
115
+	/**
116
+	 * When an user is created using the User Registration add-on, assign the entry to them
117
+	 *
118
+	 * @since  1.5.1
119
+	 * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field
120
+	 * @param  int $user_id  WordPress User ID
121
+	 * @param  array $config   User registration feed configuration
122
+	 * @param  array  $entry     GF Entry array
123
+	 * @param  string $password User password
124
+	 * @return void
125
+	 */
126
+	function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) {
127
+
128
+		/**
129
+		 * Disable assigning the new user to the entry by returning false.
130
+		 * @param  int $user_id  WordPress User ID
131
+		 * @param  array $config   User registration feed configuration
132
+		 * @param  array  $entry     GF Entry array
133
+		 */
134
+		$assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry );
135
+
136
+		// If filter returns false, do not process
137
+		if( empty( $assign_to_lead ) ) {
138
+			return;
139
+		}
140
+
141
+		// Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing
142
+		$result = RGFormsModel::update_entry_property( (int) $entry['id'], 'created_by', (int) $user_id, false, true );
143
+
144
+		if ( false === $result ) {
145
+			$status = __('Error', 'gravityview');
146
+			global $wpdb;
147
+			$note = sprintf( '%s: Failed to assign User ID #%d as the entry creator (Last database error: "%s")', $status, $user_id, $wpdb->last_error );
148
+		} else {
149
+			$status = __('Success', 'gravityview');
150
+			$note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id );
151
+		}
152
+
153
+		gravityview()->log->debug( 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - {note}', array( 'note' => $note ) );
154
+
155
+		/**
156
+		 * @filter `gravityview_disable_change_entry_creator_note` Disable adding a note when changing the entry creator
157
+		 * @since 1.21.5
158
+		 * @param boolean $disable Disable the Change Entry Creator note. Default: false.
159
+		 */
160
+		if( apply_filters('gravityview_disable_change_entry_creator_note', false ) ) {
161
+			return;
162
+		}
163
+
164
+		GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' );
165
+
166
+	}
167
+
168
+	/**
169
+	 * Disable previous functionality; use this one as the canonical.
170
+	 * @return void
171
+	 */
172
+	function prevent_conflicts() {
173
+
174
+		// Plugin that was provided here:
175
+		// @link https://gravityview.co/support/documentation/201991205/
176
+		remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 );
177
+		remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 );
178
+
179
+	}
180
+
181
+	/**
182
+	 * @since  3.6.3
183
+	 * @return void
184
+	 */
185
+	function load() {
186
+
187
+		// Does GF exist?
188
+		if( !class_exists('GFCommon') ) {
189
+			return;
190
+		}
191
+
192
+		// Can the user edit entries?
193
+		if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) {
194
+			return;
195
+		}
196
+
197
+		// If screen mode isn't set, then we're in the wrong place.
198
+		if( empty( $_REQUEST['screen_mode'] ) ) {
199
+			return;
200
+		}
201
+
202
+		// Now, no validation is required in the methods; let's hook in.
203
+		add_action('admin_init', array( &$this, 'set_screen_mode' ) );
204
+
205
+		add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2);
206
+
207
+		add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2);
208
+
209
+	}
210
+
211
+	/**
212
+	 * Allows for edit links to work with a link instead of a form (GET instead of POST)
213
+	 * @return void
214
+	 */
215
+	function set_screen_mode() {
216
+
217
+		if( 'view' === \GV\Utils::_POST( 'screen_mode' ) ) {
218
+			return;
219
+		}
220
+
221
+		// If $_GET['screen_mode'] is set to edit, set $_POST value
222
+		if( \GV\Utils::_GET( 'screen_mode' ) === 'edit' ) {
223
+			$_POST["screen_mode"] = 'edit';
224
+		}
225
+
226
+	}
227 227
 
228
-    /**
229
-     * When the entry creator is changed, add a note to the entry
230
-     * @param  array $form   GF entry array
231
-     * @param  int $entry_id Entry ID
232
-     * @return void
233
-     */
234
-    function update_entry_creator($form, $entry_id) {
235
-            global $current_user;
228
+	/**
229
+	 * When the entry creator is changed, add a note to the entry
230
+	 * @param  array $form   GF entry array
231
+	 * @param  int $entry_id Entry ID
232
+	 * @return void
233
+	 */
234
+	function update_entry_creator($form, $entry_id) {
235
+			global $current_user;
236 236
 
237
-        // Update the entry
238
-        $created_by = absint( \GV\Utils::_POST( 'created_by') );
237
+		// Update the entry
238
+		$created_by = absint( \GV\Utils::_POST( 'created_by') );
239 239
 
240
-        RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by );
240
+		RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by );
241 241
 
242
-        // If the creator has changed, let's add a note about who it used to be.
243
-        $originally_created_by = \GV\Utils::_POST( 'originally_created_by' );
242
+		// If the creator has changed, let's add a note about who it used to be.
243
+		$originally_created_by = \GV\Utils::_POST( 'originally_created_by' );
244 244
 
245
-        // If there's no owner and there didn't used to be, keep going
246
-        if( empty( $originally_created_by ) && empty( $created_by ) ) {
247
-            return;
248
-        }
245
+		// If there's no owner and there didn't used to be, keep going
246
+		if( empty( $originally_created_by ) && empty( $created_by ) ) {
247
+			return;
248
+		}
249 249
 
250
-        // If the values have changed
251
-        if( absint( $originally_created_by ) !== absint( $created_by ) ) {
250
+		// If the values have changed
251
+		if( absint( $originally_created_by ) !== absint( $created_by ) ) {
252 252
 
253
-            $user_data = get_userdata($current_user->ID);
253
+			$user_data = get_userdata($current_user->ID);
254 254
 
255
-            $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview');
255
+			$user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview');
256 256
 
257
-            $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview');
257
+			$original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview');
258 258
 
259
-            if( !empty( $originally_created_by ) ) {
260
-                $originally_created_by_user_data = get_userdata($originally_created_by);
261
-                $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID );
262
-            }
259
+			if( !empty( $originally_created_by ) ) {
260
+				$originally_created_by_user_data = get_userdata($originally_created_by);
261
+				$original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID );
262
+			}
263 263
 
264
-            if( !empty( $created_by ) ) {
265
-                $created_by_user_data =  get_userdata($created_by);
266
-                $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID );
267
-            }
264
+			if( !empty( $created_by ) ) {
265
+				$created_by_user_data =  get_userdata($created_by);
266
+				$created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID );
267
+			}
268 268
 
269
-            GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' );
270
-        }
269
+			GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' );
270
+		}
271 271
 
272
-    }
272
+	}
273 273
 
274
-    /**
275
-     * Output the select to change the entry creator
276
-     * @param int $form_id GF Form ID
277
-     * @param array $entry    GF entry array
278
-     * @return void
279
-     */
280
-    function add_select($form_id, $entry ) {
274
+	/**
275
+	 * Output the select to change the entry creator
276
+	 * @param int $form_id GF Form ID
277
+	 * @param array $entry    GF entry array
278
+	 * @return void
279
+	 */
280
+	function add_select($form_id, $entry ) {
281 281
 
282
-        if( \GV\Utils::_POST( 'screen_mode' ) !== 'edit' ) {
283
-            return;
284
-        }
282
+		if( \GV\Utils::_POST( 'screen_mode' ) !== 'edit' ) {
283
+			return;
284
+		}
285 285
 
286 286
 
287
-        $output = '<label for="change_created_by">';
288
-        $output .= esc_html__('Change Entry Creator:', 'gravityview');
289
-        $output .= '</label>';
287
+		$output = '<label for="change_created_by">';
288
+		$output .= esc_html__('Change Entry Creator:', 'gravityview');
289
+		$output .= '</label>';
290 290
 
291
-	    $output .= '<select name="created_by" id="change_created_by" class="widefat">';
291
+		$output .= '<select name="created_by" id="change_created_by" class="widefat">';
292 292
 
293
-        $created_by_id = \GV\Utils::get( $entry, 'created_by' );
294
-        $created_by_user = GVCommon::get_users( 'change_entry_creator', array( 'include' => $created_by_id ) );
295
-        $created_by_user = isset($created_by_user[0]) ? $created_by_user[0] : array();
293
+		$created_by_id = \GV\Utils::get( $entry, 'created_by' );
294
+		$created_by_user = GVCommon::get_users( 'change_entry_creator', array( 'include' => $created_by_id ) );
295
+		$created_by_user = isset($created_by_user[0]) ? $created_by_user[0] : array();
296 296
 
297
-        if( empty( $created_by_user ) ) {
298
-            $output .= '<option value="0"> &mdash; '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' &mdash; </option>';
299
-        } else {
300
-            $output .= '<option value="'. $created_by_user->ID .'" "selected">'.esc_attr( $created_by_user->display_name.' ('.$created_by_user->user_nicename.')' ).'</option>';
301
-        }
297
+		if( empty( $created_by_user ) ) {
298
+			$output .= '<option value="0"> &mdash; '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' &mdash; </option>';
299
+		} else {
300
+			$output .= '<option value="'. $created_by_user->ID .'" "selected">'.esc_attr( $created_by_user->display_name.' ('.$created_by_user->user_nicename.')' ).'</option>';
301
+		}
302 302
 
303
-        $output .= '</select>';
304
-        $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />';
305
-        $output .= wp_nonce_field( 'gv_entry_creator', 'gv_entry_creator_nonce', false, false );
303
+		$output .= '</select>';
304
+		$output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />';
305
+		$output .= wp_nonce_field( 'gv_entry_creator', 'gv_entry_creator_nonce', false, false );
306 306
 
307
-        echo $output;
308
-    }
307
+		echo $output;
308
+	}
309 309
 
310 310
 }
311 311
 
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -10,17 +10,17 @@  discard block
 block discarded – undo
10 10
     	/**
11 11
     	 * @since  1.5.1
12 12
     	 */
13
-    	add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 );
13
+    	add_action( 'gform_user_registered', array( $this, 'assign_new_user_to_lead' ), 10, 4 );
14 14
 
15 15
     	// ONLY ADMIN FROM HERE ON.
16
-    	if( !is_admin() ) { return; }
16
+    	if ( ! is_admin() ) { return; }
17 17
 
18 18
 	    /**
19 19
          * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality
20 20
 	     * @since 1.7.4
21 21
 	     * @param boolean $disable Disable the Change Entry Creator functionality. Default: false.
22 22
 	     */
23
-	    if( apply_filters('gravityview_disable_change_entry_creator', false ) ) {
23
+	    if ( apply_filters( 'gravityview_disable_change_entry_creator', false ) ) {
24 24
 		    return;
25 25
 	    }
26 26
 
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
          * Use `init` to fix bbPress warning
29 29
          * @see https://bbpress.trac.wordpress.org/ticket/2309
30 30
          */
31
-    	add_action('init', array( $this, 'load'), 100 );
31
+    	add_action( 'init', array( $this, 'load' ), 100 );
32 32
 
33
-    	add_action('plugins_loaded', array( $this, 'prevent_conflicts') );
33
+    	add_action( 'plugins_loaded', array( $this, 'prevent_conflicts' ) );
34 34
 
35 35
         // Enqueues SelectWoo script and style.
36
-        add_action( 'admin_enqueue_scripts', array( $this, 'add_selectwoo_assets') );
36
+        add_action( 'admin_enqueue_scripts', array( $this, 'add_selectwoo_assets' ) );
37 37
 
38 38
         // Ajax callback to get users to change entry creator.
39 39
         add_action( 'wp_ajax_entry_creator_get_users', array( $this, 'entry_creator_get_users' ) );
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
             )
84 84
         );
85 85
 
86
-        if( !wp_verify_nonce( $post_var['gv_nonce'], 'gv_entry_creator' )) {
86
+        if ( ! wp_verify_nonce( $post_var[ 'gv_nonce' ], 'gv_entry_creator' ) ) {
87 87
             die();
88 88
         }
89 89
 
90
-        $search_string = $post_var['q'];
90
+        $search_string = $post_var[ 'q' ];
91 91
 
92
-        if( is_numeric( $search_string ) ) {
92
+        if ( is_numeric( $search_string ) ) {
93 93
             $user_args = array(
94 94
                 'search'         => $search_string . '*',
95 95
                 'search_columns' => array( 'ID' ),
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
             );
102 102
         }
103 103
 
104
-        if( 1 == $post_var['on_load'] ) {
104
+        if ( 1 == $post_var[ 'on_load' ] ) {
105 105
             $user_args[ 'number' ] = 100;
106 106
         }
107 107
 
@@ -134,20 +134,20 @@  discard block
 block discarded – undo
134 134
     	$assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry );
135 135
 
136 136
     	// If filter returns false, do not process
137
-    	if( empty( $assign_to_lead ) ) {
137
+    	if ( empty( $assign_to_lead ) ) {
138 138
     		return;
139 139
     	}
140 140
 
141 141
     	// Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing
142
-    	$result = RGFormsModel::update_entry_property( (int) $entry['id'], 'created_by', (int) $user_id, false, true );
142
+    	$result = RGFormsModel::update_entry_property( (int)$entry[ 'id' ], 'created_by', (int)$user_id, false, true );
143 143
 
144 144
     	if ( false === $result ) {
145
-    		$status = __('Error', 'gravityview');
145
+    		$status = __( 'Error', 'gravityview' );
146 146
     		global $wpdb;
147 147
 		    $note = sprintf( '%s: Failed to assign User ID #%d as the entry creator (Last database error: "%s")', $status, $user_id, $wpdb->last_error );
148 148
     	} else {
149
-    		$status = __('Success', 'gravityview');
150
-    	    $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id );
149
+    		$status = __( 'Success', 'gravityview' );
150
+    	    $note = sprintf( _x( '%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview' ), $status, $user_id );
151 151
     	}
152 152
 
153 153
     	gravityview()->log->debug( 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - {note}', array( 'note' => $note ) );
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
 	     * @since 1.21.5
158 158
 	     * @param boolean $disable Disable the Change Entry Creator note. Default: false.
159 159
 	     */
160
-	    if( apply_filters('gravityview_disable_change_entry_creator_note', false ) ) {
160
+	    if ( apply_filters( 'gravityview_disable_change_entry_creator_note', false ) ) {
161 161
 		    return;
162 162
 	    }
163 163
 
164
-        GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' );
164
+        GravityView_Entry_Notes::add_note( $entry[ 'id' ], -1, 'GravityView', $note, 'gravityview' );
165 165
 
166 166
     }
167 167
 
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 
174 174
     	// Plugin that was provided here:
175 175
     	// @link https://gravityview.co/support/documentation/201991205/
176
-    	remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 );
177
-    	remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 );
176
+    	remove_action( "gform_entry_info", 'gravityview_change_entry_creator_form', 10 );
177
+    	remove_action( "gform_after_update_entry", 'gravityview_update_entry_creator', 10 );
178 178
 
179 179
     }
180 180
 
@@ -185,26 +185,26 @@  discard block
 block discarded – undo
185 185
     function load() {
186 186
 
187 187
     	// Does GF exist?
188
-        if( !class_exists('GFCommon') ) {
188
+        if ( ! class_exists( 'GFCommon' ) ) {
189 189
             return;
190 190
         }
191 191
 
192 192
         // Can the user edit entries?
193
-        if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) {
193
+        if ( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) {
194 194
             return;
195 195
         }
196 196
 
197 197
         // If screen mode isn't set, then we're in the wrong place.
198
-        if( empty( $_REQUEST['screen_mode'] ) ) {
198
+        if ( empty( $_REQUEST[ 'screen_mode' ] ) ) {
199 199
             return;
200 200
         }
201 201
 
202 202
         // Now, no validation is required in the methods; let's hook in.
203
-        add_action('admin_init', array( &$this, 'set_screen_mode' ) );
203
+        add_action( 'admin_init', array( &$this, 'set_screen_mode' ) );
204 204
 
205
-        add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2);
205
+        add_action( "gform_entry_info", array( &$this, 'add_select' ), 10, 2 );
206 206
 
207
-        add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2);
207
+        add_action( "gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2 );
208 208
 
209 209
     }
210 210
 
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
      */
215 215
     function set_screen_mode() {
216 216
 
217
-    	if( 'view' === \GV\Utils::_POST( 'screen_mode' ) ) {
217
+    	if ( 'view' === \GV\Utils::_POST( 'screen_mode' ) ) {
218 218
     		return;
219 219
 	    }
220 220
 
221 221
     	// If $_GET['screen_mode'] is set to edit, set $_POST value
222
-        if( \GV\Utils::_GET( 'screen_mode' ) === 'edit' ) {
223
-            $_POST["screen_mode"] = 'edit';
222
+        if ( \GV\Utils::_GET( 'screen_mode' ) === 'edit' ) {
223
+            $_POST[ "screen_mode" ] = 'edit';
224 224
         }
225 225
 
226 226
     }
@@ -231,11 +231,11 @@  discard block
 block discarded – undo
231 231
      * @param  int $entry_id Entry ID
232 232
      * @return void
233 233
      */
234
-    function update_entry_creator($form, $entry_id) {
234
+    function update_entry_creator( $form, $entry_id ) {
235 235
             global $current_user;
236 236
 
237 237
         // Update the entry
238
-        $created_by = absint( \GV\Utils::_POST( 'created_by') );
238
+        $created_by = absint( \GV\Utils::_POST( 'created_by' ) );
239 239
 
240 240
         RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by );
241 241
 
@@ -243,30 +243,30 @@  discard block
 block discarded – undo
243 243
         $originally_created_by = \GV\Utils::_POST( 'originally_created_by' );
244 244
 
245 245
         // If there's no owner and there didn't used to be, keep going
246
-        if( empty( $originally_created_by ) && empty( $created_by ) ) {
246
+        if ( empty( $originally_created_by ) && empty( $created_by ) ) {
247 247
             return;
248 248
         }
249 249
 
250 250
         // If the values have changed
251
-        if( absint( $originally_created_by ) !== absint( $created_by ) ) {
251
+        if ( absint( $originally_created_by ) !== absint( $created_by ) ) {
252 252
 
253
-            $user_data = get_userdata($current_user->ID);
253
+            $user_data = get_userdata( $current_user->ID );
254 254
 
255
-            $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview');
255
+            $user_format = _x( '%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview' );
256 256
 
257
-            $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview');
257
+            $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview' );
258 258
 
259
-            if( !empty( $originally_created_by ) ) {
260
-                $originally_created_by_user_data = get_userdata($originally_created_by);
259
+            if ( ! empty( $originally_created_by ) ) {
260
+                $originally_created_by_user_data = get_userdata( $originally_created_by );
261 261
                 $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID );
262 262
             }
263 263
 
264
-            if( !empty( $created_by ) ) {
265
-                $created_by_user_data =  get_userdata($created_by);
264
+            if ( ! empty( $created_by ) ) {
265
+                $created_by_user_data = get_userdata( $created_by );
266 266
                 $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID );
267 267
             }
268 268
 
269
-            GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' );
269
+            GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __( 'Changed entry creator from %s to %s', 'gravityview' ), $original_name, $created_by_name ), 'note' );
270 270
         }
271 271
 
272 272
     }
@@ -277,31 +277,31 @@  discard block
 block discarded – undo
277 277
      * @param array $entry    GF entry array
278 278
      * @return void
279 279
      */
280
-    function add_select($form_id, $entry ) {
280
+    function add_select( $form_id, $entry ) {
281 281
 
282
-        if( \GV\Utils::_POST( 'screen_mode' ) !== 'edit' ) {
282
+        if ( \GV\Utils::_POST( 'screen_mode' ) !== 'edit' ) {
283 283
             return;
284 284
         }
285 285
 
286 286
 
287 287
         $output = '<label for="change_created_by">';
288
-        $output .= esc_html__('Change Entry Creator:', 'gravityview');
288
+        $output .= esc_html__( 'Change Entry Creator:', 'gravityview' );
289 289
         $output .= '</label>';
290 290
 
291 291
 	    $output .= '<select name="created_by" id="change_created_by" class="widefat">';
292 292
 
293 293
         $created_by_id = \GV\Utils::get( $entry, 'created_by' );
294 294
         $created_by_user = GVCommon::get_users( 'change_entry_creator', array( 'include' => $created_by_id ) );
295
-        $created_by_user = isset($created_by_user[0]) ? $created_by_user[0] : array();
295
+        $created_by_user = isset( $created_by_user[ 0 ] ) ? $created_by_user[ 0 ] : array();
296 296
 
297
-        if( empty( $created_by_user ) ) {
298
-            $output .= '<option value="0"> &mdash; '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' &mdash; </option>';
297
+        if ( empty( $created_by_user ) ) {
298
+            $output .= '<option value="0"> &mdash; ' . esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview' ) . ' &mdash; </option>';
299 299
         } else {
300
-            $output .= '<option value="'. $created_by_user->ID .'" "selected">'.esc_attr( $created_by_user->display_name.' ('.$created_by_user->user_nicename.')' ).'</option>';
300
+            $output .= '<option value="' . $created_by_user->ID . '" "selected">' . esc_attr( $created_by_user->display_name . ' (' . $created_by_user->user_nicename . ')' ) . '</option>';
301 301
         }
302 302
 
303 303
         $output .= '</select>';
304
-        $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />';
304
+        $output .= '<input name="originally_created_by" value="' . esc_attr( $entry[ 'created_by' ] ) . '" type="hidden" />';
305 305
         $output .= wp_nonce_field( 'gv_entry_creator', 'gv_entry_creator_nonce', false, false );
306 306
 
307 307
         echo $output;
Please login to merge, or discard this patch.