@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | private function add_hooks() { |
40 | 40 | |
41 | 41 | // in case entry is edited (on admin or frontend) |
42 | - add_action( 'gform_after_update_entry', array( $this, 'after_update_entry_update_approved_meta' ), 10, 2); |
|
42 | + add_action( 'gform_after_update_entry', array( $this, 'after_update_entry_update_approved_meta' ), 10, 2 ); |
|
43 | 43 | |
44 | 44 | // when using the User opt-in field, check on entry submission |
45 | 45 | add_action( 'gform_after_submission', array( $this, 'after_submission' ), 10, 2 ); |
46 | 46 | |
47 | 47 | // process ajax approve entry requests |
48 | - add_action('wp_ajax_gv_update_approved', array( $this, 'ajax_update_approved')); |
|
48 | + add_action( 'wp_ajax_gv_update_approved', array( $this, 'ajax_update_approved' ) ); |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public static function get_entry_status( $entry, $value_or_label = 'label' ) { |
64 | 64 | |
65 | - $entry_id = is_array( $entry ) ? $entry['id'] : GVCommon::get_entry_id( $entry ); |
|
65 | + $entry_id = is_array( $entry ) ? $entry[ 'id' ] : GVCommon::get_entry_id( $entry ); |
|
66 | 66 | |
67 | 67 | $status = gform_get_meta( $entry_id, self::meta_key ); |
68 | 68 | |
69 | 69 | $status = GravityView_Entry_Approval_Status::maybe_convert_status( $status ); |
70 | 70 | |
71 | - if( 'value' === $value_or_label ) { |
|
71 | + if ( 'value' === $value_or_label ) { |
|
72 | 72 | return $status; |
73 | 73 | } |
74 | 74 | |
@@ -93,16 +93,16 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function ajax_update_approved() { |
95 | 95 | |
96 | - $form_id = intval( rgpost('form_id') ); |
|
96 | + $form_id = intval( rgpost( 'form_id' ) ); |
|
97 | 97 | |
98 | - $entry_id = GVCommon::get_entry_id( rgpost('entry_slug'), true ); |
|
98 | + $entry_id = GVCommon::get_entry_id( rgpost( 'entry_slug' ), true ); |
|
99 | 99 | |
100 | - $approval_status = rgpost('approved'); |
|
100 | + $approval_status = rgpost( 'approved' ); |
|
101 | 101 | |
102 | - $nonce = rgpost('nonce'); |
|
102 | + $nonce = rgpost( 'nonce' ); |
|
103 | 103 | |
104 | 104 | // Valid status |
105 | - if( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) { |
|
105 | + if ( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) { |
|
106 | 106 | |
107 | 107 | do_action( 'gravityview_log_error', __METHOD__ . ': Invalid approval status', $_POST ); |
108 | 108 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | do_action( 'gravityview_log_error', __METHOD__ . ' User does not have the `gravityview_moderate_entries` capability.' ); |
135 | 135 | |
136 | - $result = new WP_Error( 'Missing Cap: gravityview_moderate_entries', __( 'You do not have permission to edit this entry.', 'gravityview') ); |
|
136 | + $result = new WP_Error( 'Missing Cap: gravityview_moderate_entries', __( 'You do not have permission to edit this entry.', 'gravityview' ) ); |
|
137 | 137 | |
138 | 138 | } |
139 | 139 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param $form array Gravity Forms form object |
167 | 167 | */ |
168 | 168 | public function after_submission( $entry, $form ) { |
169 | - $this->after_update_entry_update_approved_meta( $form , $entry['id'] ); |
|
169 | + $this->after_update_entry_update_approved_meta( $form, $entry[ 'id' ] ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -180,18 +180,18 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function after_update_entry_update_approved_meta( $form, $entry_id = NULL ) { |
182 | 182 | |
183 | - $approved_column = self::get_approved_column( $form['id'] ); |
|
183 | + $approved_column = self::get_approved_column( $form[ 'id' ] ); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * If the form doesn't contain the approve field, don't assume anything. |
187 | 187 | */ |
188 | - if( empty( $approved_column ) ) { |
|
188 | + if ( empty( $approved_column ) ) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $entry = GFAPI::get_entry( $entry_id ); |
193 | 193 | |
194 | - self::update_approved_meta( $entry_id, $entry[ (string)$approved_column ], $form['id'] ); |
|
194 | + self::update_approved_meta( $entry_id, $entry[ (string)$approved_column ], $form[ 'id' ] ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | $success = true; |
232 | 232 | foreach ( $entries as $entry_id ) { |
233 | - $update_success = self::update_approved( (int) $entry_id, $approved, $form_id, $approved_column_id ); |
|
233 | + $update_success = self::update_approved( (int)$entry_id, $approved, $form_id, $approved_column_id ); |
|
234 | 234 | |
235 | 235 | if ( ! $update_success ) { |
236 | 236 | $success = false; |
@@ -256,12 +256,12 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public static function update_approved( $entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0 ) { |
258 | 258 | |
259 | - if( !class_exists( 'GFAPI' ) ) { |
|
259 | + if ( ! class_exists( 'GFAPI' ) ) { |
|
260 | 260 | do_action( 'gravityview_log_error', __METHOD__ . 'GFAPI does not exist' ); |
261 | 261 | return false; |
262 | 262 | } |
263 | 263 | |
264 | - if( ! GravityView_Entry_Approval_Status::is_valid( $approved ) ) { |
|
264 | + if ( ! GravityView_Entry_Approval_Status::is_valid( $approved ) ) { |
|
265 | 265 | do_action( 'gravityview_log_error', __METHOD__ . ': Not a valid approval value.' ); |
266 | 266 | return false; |
267 | 267 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | // If the form has an Approve/Reject field, update that value |
279 | 279 | $result = self::update_approved_column( $entry_id, $approved, $form_id, $approvedcolumn ); |
280 | 280 | |
281 | - if( is_wp_error( $result ) ) { |
|
281 | + if ( is_wp_error( $result ) ) { |
|
282 | 282 | do_action( 'gravityview_log_error', __METHOD__ . sprintf( ' - Entry approval not updated: %s', $result->get_error_message() ) ); |
283 | 283 | return false; |
284 | 284 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | |
291 | 291 | // add note to entry if approval field updating worked or there was no approved field |
292 | 292 | // There's no validation for the meta |
293 | - if( true === $result ) { |
|
293 | + if ( true === $result ) { |
|
294 | 294 | |
295 | 295 | // Add an entry note |
296 | 296 | self::add_approval_status_updated_note( $entry_id, $approved ); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | |
344 | 344 | $note_id = false; |
345 | 345 | |
346 | - if( $add_note && class_exists( 'GravityView_Entry_Notes' ) ) { |
|
346 | + if ( $add_note && class_exists( 'GravityView_Entry_Notes' ) ) { |
|
347 | 347 | |
348 | 348 | $current_user = wp_get_current_user(); |
349 | 349 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | */ |
366 | 366 | private static function update_approved_column( $entry_id = 0, $status = '0', $form_id = 0, $approvedcolumn = 0 ) { |
367 | 367 | |
368 | - if( empty( $approvedcolumn ) ) { |
|
368 | + if ( empty( $approvedcolumn ) ) { |
|
369 | 369 | $approvedcolumn = self::get_approved_column( $form_id ); |
370 | 370 | } |
371 | 371 | |
@@ -413,16 +413,16 @@ discard block |
||
413 | 413 | private static function update_approved_meta( $entry_id, $status, $form_id = 0 ) { |
414 | 414 | |
415 | 415 | if ( ! GravityView_Entry_Approval_Status::is_valid( $status ) ) { |
416 | - do_action('gravityview_log_error', __METHOD__ . ': $is_approved not valid value', $status ); |
|
416 | + do_action( 'gravityview_log_error', __METHOD__ . ': $is_approved not valid value', $status ); |
|
417 | 417 | return; |
418 | 418 | } |
419 | 419 | |
420 | 420 | $status = GravityView_Entry_Approval_Status::maybe_convert_status( $status ); |
421 | 421 | |
422 | 422 | // update entry meta |
423 | - if( function_exists('gform_update_meta') ) { |
|
423 | + if ( function_exists( 'gform_update_meta' ) ) { |
|
424 | 424 | |
425 | - if( GravityView_Entry_Approval_Status::is_unapproved( $status ) ) { |
|
425 | + if ( GravityView_Entry_Approval_Status::is_unapproved( $status ) ) { |
|
426 | 426 | gform_delete_meta( $entry_id, self::meta_key ); |
427 | 427 | } else { |
428 | 428 | gform_update_meta( $entry_id, self::meta_key, $status, $form_id ); |
@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | * @since 1.18 Added "unapproved" |
446 | 446 | * @param int $entry_id ID of the Gravity Forms entry |
447 | 447 | */ |
448 | - do_action( 'gravityview/approve_entries/' . $action , $entry_id ); |
|
448 | + do_action( 'gravityview/approve_entries/' . $action, $entry_id ); |
|
449 | 449 | |
450 | 450 | } else { |
451 | 451 | |
452 | - do_action('gravityview_log_error', __METHOD__ . ' - `gform_update_meta` does not exist.' ); |
|
452 | + do_action( 'gravityview_log_error', __METHOD__ . ' - `gform_update_meta` does not exist.' ); |
|
453 | 453 | |
454 | 454 | } |
455 | 455 | } |
@@ -464,29 +464,29 @@ discard block |
||
464 | 464 | */ |
465 | 465 | static public function get_approved_column( $form ) { |
466 | 466 | |
467 | - if( empty( $form ) ) { |
|
467 | + if ( empty( $form ) ) { |
|
468 | 468 | return null; |
469 | 469 | } |
470 | 470 | |
471 | - if( !is_array( $form ) ) { |
|
471 | + if ( ! is_array( $form ) ) { |
|
472 | 472 | $form = GVCommon::get_form( $form ); |
473 | 473 | } |
474 | 474 | |
475 | - foreach( $form['fields'] as $key => $field ) { |
|
475 | + foreach ( $form[ 'fields' ] as $key => $field ) { |
|
476 | 476 | |
477 | - $field = (array) $field; |
|
477 | + $field = (array)$field; |
|
478 | 478 | |
479 | - if( !empty( $field['gravityview_approved'] ) ) { |
|
480 | - if( !empty($field['inputs'][0]['id']) ) { |
|
481 | - return $field['inputs'][0]['id']; |
|
479 | + if ( ! empty( $field[ 'gravityview_approved' ] ) ) { |
|
480 | + if ( ! empty( $field[ 'inputs' ][ 0 ][ 'id' ] ) ) { |
|
481 | + return $field[ 'inputs' ][ 0 ][ 'id' ]; |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | 485 | // Note: This is just for backward compatibility from GF Directory plugin and old GV versions - when using i18n it may not work.. |
486 | - if( 'checkbox' == $field['type'] && isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) { |
|
487 | - foreach ( $field['inputs'] as $key2 => $input ) { |
|
488 | - if ( strtolower( $input['label'] ) == 'approved' ) { |
|
489 | - return $input['id']; |
|
486 | + if ( 'checkbox' == $field[ 'type' ] && isset( $field[ 'inputs' ] ) && is_array( $field[ 'inputs' ] ) ) { |
|
487 | + foreach ( $field[ 'inputs' ] as $key2 => $input ) { |
|
488 | + if ( strtolower( $input[ 'label' ] ) == 'approved' ) { |
|
489 | + return $input[ 'id' ]; |
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | if ( ! defined( 'WPINC' ) ) { |
14 | - die; |
|
14 | + die; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -22,253 +22,253 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @var GravityView_Edit_Entry |
24 | 24 | */ |
25 | - protected $loader; |
|
25 | + protected $loader; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var WP_User|null Temporary storage used by restore_user_details() |
|
29 | - */ |
|
30 | - private $_user_before_update = null; |
|
27 | + /** |
|
28 | + * @var WP_User|null Temporary storage used by restore_user_details() |
|
29 | + */ |
|
30 | + private $_user_before_update = null; |
|
31 | 31 | |
32 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
33 | - $this->loader = $loader; |
|
34 | - } |
|
32 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
33 | + $this->loader = $loader; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @since 1.11 |
38 | 38 | */ |
39 | 39 | public function load() { |
40 | 40 | add_action( 'wp', array( $this, 'add_hooks' ), 10 ); |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Add hooks to trigger updating the user |
45 | 45 | * |
46 | 46 | * @since 1.18 |
47 | 47 | */ |
48 | - public function add_hooks() { |
|
49 | - |
|
50 | - /** |
|
51 | - * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
52 | - * @since 1.11 |
|
53 | - * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
54 | - */ |
|
55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
56 | - |
|
57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
58 | - |
|
59 | - // last resort in case the current user display name don't match any of the defaults |
|
60 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Update the WordPress user profile based on the GF User Registration create feed |
|
66 | - * |
|
67 | - * @since 1.11 |
|
68 | - * |
|
69 | - * @param array $form Gravity Forms form array |
|
70 | - * @param string $entry_id Gravity Forms entry ID |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function update_user( $form = array(), $entry_id = 0 ) { |
|
74 | - |
|
75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) || empty( $entry_id ) ) { |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - /** @var GF_User_Registration $gf_user_registration */ |
|
80 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
81 | - |
|
82 | - $entry = GFAPI::get_entry( $entry_id ); |
|
83 | - |
|
84 | - /** |
|
85 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
86 | - * @since 1.11 |
|
87 | - * @param array $entry Gravity Forms entry |
|
88 | - * @param array $form Gravity Forms form |
|
89 | - */ |
|
90 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
91 | - |
|
92 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
93 | - |
|
94 | - /** |
|
95 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
96 | - * @since 1.15 |
|
97 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
98 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
99 | - * @param[in] array $form Gravity Forms form array |
|
100 | - * @param[in] array $entry Gravity Forms entry being edited |
|
101 | - */ |
|
102 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
103 | - |
|
104 | - if( $preserve_role ) { |
|
105 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Make sure the current display name is not changed with the update user method. |
|
110 | - * @since 1.15 |
|
111 | - */ |
|
112 | - $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
117 | - * @since 1.14 |
|
118 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
119 | - * @param[in] array $form Gravity Forms form array |
|
120 | - * @param[in] array $entry Gravity Forms entry being edited |
|
121 | - */ |
|
122 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
123 | - |
|
124 | - |
|
125 | - // Make sure the feed is active |
|
126 | - if ( ! rgar( $config, 'is_active', false ) ) { |
|
48 | + public function add_hooks() { |
|
49 | + |
|
50 | + /** |
|
51 | + * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
52 | + * @since 1.11 |
|
53 | + * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
54 | + */ |
|
55 | + if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
56 | + |
|
57 | + add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
58 | + |
|
59 | + // last resort in case the current user display name don't match any of the defaults |
|
60 | + add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Update the WordPress user profile based on the GF User Registration create feed |
|
66 | + * |
|
67 | + * @since 1.11 |
|
68 | + * |
|
69 | + * @param array $form Gravity Forms form array |
|
70 | + * @param string $entry_id Gravity Forms entry ID |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function update_user( $form = array(), $entry_id = 0 ) { |
|
74 | + |
|
75 | + if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) || empty( $entry_id ) ) { |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + /** @var GF_User_Registration $gf_user_registration */ |
|
80 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
81 | + |
|
82 | + $entry = GFAPI::get_entry( $entry_id ); |
|
83 | + |
|
84 | + /** |
|
85 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
86 | + * @since 1.11 |
|
87 | + * @param array $entry Gravity Forms entry |
|
88 | + * @param array $form Gravity Forms form |
|
89 | + */ |
|
90 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
91 | + |
|
92 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
93 | + |
|
94 | + /** |
|
95 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
96 | + * @since 1.15 |
|
97 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
98 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
99 | + * @param[in] array $form Gravity Forms form array |
|
100 | + * @param[in] array $entry Gravity Forms entry being edited |
|
101 | + */ |
|
102 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
103 | + |
|
104 | + if( $preserve_role ) { |
|
105 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Make sure the current display name is not changed with the update user method. |
|
110 | + * @since 1.15 |
|
111 | + */ |
|
112 | + $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
117 | + * @since 1.14 |
|
118 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
119 | + * @param[in] array $form Gravity Forms form array |
|
120 | + * @param[in] array $entry Gravity Forms entry being edited |
|
121 | + */ |
|
122 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
123 | + |
|
124 | + |
|
125 | + // Make sure the feed is active |
|
126 | + if ( ! rgar( $config, 'is_active', false ) ) { |
|
127 | 127 | return; |
128 | - } |
|
129 | - |
|
130 | - // If an Update feed, make sure the conditions are met. |
|
131 | - if( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
132 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
133 | - return; |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - // The priority is set to 3 so that default priority (10) will still override it |
|
138 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
139 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
140 | - |
|
141 | - // Trigger the User Registration update user method |
|
142 | - $gf_user_registration->update_user( $entry, $form, $config ); |
|
143 | - |
|
144 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
145 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Calculate the user display name format |
|
151 | - * |
|
152 | - * @since 1.15 |
|
153 | - * |
|
154 | - * @param int $user_id WP User ID |
|
155 | - * @return string Display name format as used inside Gravity Forms User Registration |
|
156 | - */ |
|
157 | - public function match_current_display_name( $user_id ) { |
|
158 | - |
|
159 | - $user = get_userdata( $user_id ); |
|
160 | - |
|
161 | - $names = $this->generate_display_names( $user ); |
|
162 | - |
|
163 | - $format = array_search( $user->display_name, $names, true ); |
|
164 | - |
|
165 | - // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) |
|
166 | - // trigger last resort method at the 'gform_user_updated' hook |
|
167 | - if( false === $format || 'nickname' === $format ) { |
|
168 | - $this->_user_before_update = $user; |
|
169 | - $format = 'nickname'; |
|
170 | - } |
|
171 | - |
|
172 | - return $format; |
|
173 | - |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Generate an array of all the user display names possibilities |
|
178 | - * |
|
179 | - * @since 1.15 |
|
180 | - * |
|
181 | - * @param object $profileuser WP_User object |
|
182 | - * @return array List all the possible display names for a certain User object |
|
183 | - */ |
|
184 | - public function generate_display_names( $profileuser ) { |
|
185 | - |
|
186 | - $public_display = array(); |
|
187 | - $public_display['nickname'] = $profileuser->nickname; |
|
188 | - $public_display['username'] = $profileuser->user_login; |
|
189 | - |
|
190 | - if ( !empty($profileuser->first_name) ) |
|
191 | - $public_display['firstname'] = $profileuser->first_name; |
|
192 | - |
|
193 | - if ( !empty($profileuser->last_name) ) |
|
194 | - $public_display['lastname'] = $profileuser->last_name; |
|
195 | - |
|
196 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
197 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
198 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
199 | - } |
|
200 | - |
|
201 | - $public_display = array_map( 'trim', $public_display ); |
|
202 | - $public_display = array_unique( $public_display ); |
|
203 | - |
|
204 | - return $public_display; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
210 | - * |
|
211 | - * @see GFUser::update_user() |
|
212 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
213 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
214 | - * @param array $entry The Gravity Forms entry that was just updated |
|
215 | - * @param string $password User password |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
219 | - |
|
220 | - /** |
|
221 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
222 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
223 | - * @since 1.14.4 |
|
224 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
225 | - */ |
|
226 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
227 | - |
|
228 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
229 | - |
|
230 | - /** |
|
231 | - * Don't restore display name: |
|
232 | - * - either disabled, |
|
233 | - * - or it is an Update feed (we only care about Create feed) |
|
234 | - * - or we don't need as we found the correct format before updating user. |
|
235 | - * @since 1.14.4 |
|
236 | - */ |
|
237 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
238 | - return; |
|
239 | - } |
|
240 | - |
|
241 | - $user_after_update = get_userdata( $user_id ); |
|
242 | - |
|
243 | - $restored_user = $user_after_update; |
|
244 | - |
|
245 | - // Restore previous display_name |
|
246 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
247 | - |
|
248 | - // Don't have WP update the password. |
|
249 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
250 | - |
|
251 | - /** |
|
252 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
253 | - * @since 1.14 |
|
254 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
255 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
256 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
257 | - * @param array $entry The Gravity Forms entry that was just updated |
|
258 | - */ |
|
259 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
260 | - |
|
261 | - $updated = wp_update_user( $restored_user ); |
|
262 | - |
|
263 | - if( is_wp_error( $updated ) ) { |
|
264 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
265 | - } else { |
|
266 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
267 | - } |
|
268 | - |
|
269 | - $this->_user_before_update = null; |
|
270 | - |
|
271 | - unset( $updated, $restored_user, $user_after_update ); |
|
272 | - } |
|
128 | + } |
|
129 | + |
|
130 | + // If an Update feed, make sure the conditions are met. |
|
131 | + if( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
132 | + if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
133 | + return; |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + // The priority is set to 3 so that default priority (10) will still override it |
|
138 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
139 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
140 | + |
|
141 | + // Trigger the User Registration update user method |
|
142 | + $gf_user_registration->update_user( $entry, $form, $config ); |
|
143 | + |
|
144 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
145 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Calculate the user display name format |
|
151 | + * |
|
152 | + * @since 1.15 |
|
153 | + * |
|
154 | + * @param int $user_id WP User ID |
|
155 | + * @return string Display name format as used inside Gravity Forms User Registration |
|
156 | + */ |
|
157 | + public function match_current_display_name( $user_id ) { |
|
158 | + |
|
159 | + $user = get_userdata( $user_id ); |
|
160 | + |
|
161 | + $names = $this->generate_display_names( $user ); |
|
162 | + |
|
163 | + $format = array_search( $user->display_name, $names, true ); |
|
164 | + |
|
165 | + // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) |
|
166 | + // trigger last resort method at the 'gform_user_updated' hook |
|
167 | + if( false === $format || 'nickname' === $format ) { |
|
168 | + $this->_user_before_update = $user; |
|
169 | + $format = 'nickname'; |
|
170 | + } |
|
171 | + |
|
172 | + return $format; |
|
173 | + |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Generate an array of all the user display names possibilities |
|
178 | + * |
|
179 | + * @since 1.15 |
|
180 | + * |
|
181 | + * @param object $profileuser WP_User object |
|
182 | + * @return array List all the possible display names for a certain User object |
|
183 | + */ |
|
184 | + public function generate_display_names( $profileuser ) { |
|
185 | + |
|
186 | + $public_display = array(); |
|
187 | + $public_display['nickname'] = $profileuser->nickname; |
|
188 | + $public_display['username'] = $profileuser->user_login; |
|
189 | + |
|
190 | + if ( !empty($profileuser->first_name) ) |
|
191 | + $public_display['firstname'] = $profileuser->first_name; |
|
192 | + |
|
193 | + if ( !empty($profileuser->last_name) ) |
|
194 | + $public_display['lastname'] = $profileuser->last_name; |
|
195 | + |
|
196 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
197 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
198 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
199 | + } |
|
200 | + |
|
201 | + $public_display = array_map( 'trim', $public_display ); |
|
202 | + $public_display = array_unique( $public_display ); |
|
203 | + |
|
204 | + return $public_display; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
210 | + * |
|
211 | + * @see GFUser::update_user() |
|
212 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
213 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
214 | + * @param array $entry The Gravity Forms entry that was just updated |
|
215 | + * @param string $password User password |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
219 | + |
|
220 | + /** |
|
221 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
222 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
223 | + * @since 1.14.4 |
|
224 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
225 | + */ |
|
226 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
227 | + |
|
228 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
229 | + |
|
230 | + /** |
|
231 | + * Don't restore display name: |
|
232 | + * - either disabled, |
|
233 | + * - or it is an Update feed (we only care about Create feed) |
|
234 | + * - or we don't need as we found the correct format before updating user. |
|
235 | + * @since 1.14.4 |
|
236 | + */ |
|
237 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
238 | + return; |
|
239 | + } |
|
240 | + |
|
241 | + $user_after_update = get_userdata( $user_id ); |
|
242 | + |
|
243 | + $restored_user = $user_after_update; |
|
244 | + |
|
245 | + // Restore previous display_name |
|
246 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
247 | + |
|
248 | + // Don't have WP update the password. |
|
249 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
250 | + |
|
251 | + /** |
|
252 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
253 | + * @since 1.14 |
|
254 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
255 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
256 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
257 | + * @param array $entry The Gravity Forms entry that was just updated |
|
258 | + */ |
|
259 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
260 | + |
|
261 | + $updated = wp_update_user( $restored_user ); |
|
262 | + |
|
263 | + if( is_wp_error( $updated ) ) { |
|
264 | + do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
265 | + } else { |
|
266 | + do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
267 | + } |
|
268 | + |
|
269 | + $this->_user_before_update = null; |
|
270 | + |
|
271 | + unset( $updated, $restored_user, $user_after_update ); |
|
272 | + } |
|
273 | 273 | |
274 | 274 | } //end class |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @since 1.11 |
53 | 53 | * @param boolean $boolean Whether to trigger update on user registration (default: true) |
54 | 54 | */ |
55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
55 | + if ( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
56 | 56 | |
57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
57 | + add_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10, 2 ); |
|
58 | 58 | |
59 | 59 | // last resort in case the current user display name don't match any of the defaults |
60 | 60 | add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function update_user( $form = array(), $entry_id = 0 ) { |
74 | 74 | |
75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) || empty( $entry_id ) ) { |
|
75 | + if ( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) || empty( $entry_id ) ) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | */ |
102 | 102 | $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
103 | 103 | |
104 | - if( $preserve_role ) { |
|
105 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
104 | + if ( $preserve_role ) { |
|
105 | + $config[ 'meta' ][ 'role' ] = 'gfur_preserve_role'; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Make sure the current display name is not changed with the update user method. |
110 | 110 | * @since 1.15 |
111 | 111 | */ |
112 | - $config['meta']['displayname'] = $this->match_current_display_name( $entry['created_by'] ); |
|
112 | + $config[ 'meta' ][ 'displayname' ] = $this->match_current_display_name( $entry[ 'created_by' ] ); |
|
113 | 113 | |
114 | 114 | |
115 | 115 | /** |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | // If an Update feed, make sure the conditions are met. |
131 | - if( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
132 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
131 | + if ( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
132 | + if ( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | // In case we can't find the current display name format, or it is the 'nickname' format (which Gravity Forms doesn't support) |
166 | 166 | // trigger last resort method at the 'gform_user_updated' hook |
167 | - if( false === $format || 'nickname' === $format ) { |
|
167 | + if ( false === $format || 'nickname' === $format ) { |
|
168 | 168 | $this->_user_before_update = $user; |
169 | 169 | $format = 'nickname'; |
170 | 170 | } |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | public function generate_display_names( $profileuser ) { |
185 | 185 | |
186 | 186 | $public_display = array(); |
187 | - $public_display['nickname'] = $profileuser->nickname; |
|
188 | - $public_display['username'] = $profileuser->user_login; |
|
187 | + $public_display[ 'nickname' ] = $profileuser->nickname; |
|
188 | + $public_display[ 'username' ] = $profileuser->user_login; |
|
189 | 189 | |
190 | - if ( !empty($profileuser->first_name) ) |
|
191 | - $public_display['firstname'] = $profileuser->first_name; |
|
190 | + if ( ! empty( $profileuser->first_name ) ) |
|
191 | + $public_display[ 'firstname' ] = $profileuser->first_name; |
|
192 | 192 | |
193 | - if ( !empty($profileuser->last_name) ) |
|
194 | - $public_display['lastname'] = $profileuser->last_name; |
|
193 | + if ( ! empty( $profileuser->last_name ) ) |
|
194 | + $public_display[ 'lastname' ] = $profileuser->last_name; |
|
195 | 195 | |
196 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
197 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
198 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
196 | + if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) { |
|
197 | + $public_display[ 'firstlast' ] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
198 | + $public_display[ 'lastfirst' ] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $public_display = array_map( 'trim', $public_display ); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
227 | 227 | |
228 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
228 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type' ) === 'update' ); |
|
229 | 229 | |
230 | 230 | /** |
231 | 231 | * Don't restore display name: |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * - or we don't need as we found the correct format before updating user. |
235 | 235 | * @since 1.14.4 |
236 | 236 | */ |
237 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
237 | + if ( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | |
261 | 261 | $updated = wp_update_user( $restored_user ); |
262 | 262 | |
263 | - if( is_wp_error( $updated ) ) { |
|
264 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
263 | + if ( is_wp_error( $updated ) ) { |
|
264 | + do_action( 'gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
265 | 265 | } else { |
266 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
266 | + do_action( 'gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | $this->_user_before_update = null; |