13 if ( ! defined(
'WPINC' ) ) {
40 add_action(
'wp', array( $this,
'add_hooks' ), 10 );
55 if( apply_filters(
'gravityview/edit_entry/user_registration/trigger_update',
true ) ) {
57 add_action(
'gravityview/edit_entry/after_update' , array( $this,
'update_user' ), 10, 2 );
60 add_action(
'gform_user_updated', array( $this,
'restore_display_name' ), 10, 4 );
76 if ( ! class_exists(
'GF_User_Registration' ) ) {
80 if( ! class_exists(
'GFAPI' ) ) {
81 gravityview()->log->error(
'GFAPI class not found; not updating the user' );
85 if( empty( $entry_id ) ) {
86 gravityview()->log->error(
'Entry ID is empty [{entry_id}]; not updating the user', array(
'entry_id' => $entry_id ) );
90 $gf_user_registration = GF_User_Registration::get_instance();
92 $entry = GFAPI::get_entry( $entry_id );
100 $entry = apply_filters(
'gravityview/edit_entry/user_registration/entry',
$entry,
$form );
105 if ( ! \
GV\Utils::get( $config,
'is_active',
false ) ) {
110 if ( \
GV\Utils::get( $config,
'meta/feedType' ) ===
'update' ) {
111 if( ! $gf_user_registration->is_feed_condition_met( $config,
$form,
$entry ) ) {
118 if ( ! isset(
$entry[ $username ] ) || ! get_user_by(
'login',
$entry[ $username ] ) ) {
123 add_filter(
'send_password_change_email',
'__return_false', 3 );
124 add_filter(
'send_email_change_email',
'__return_false', 3 );
127 $gf_user_registration->update_user(
$entry,
$form, $config );
129 remove_filter(
'send_password_change_email',
'__return_false', 3 );
130 remove_filter(
'send_email_change_email',
'__return_false', 3 );
133 remove_action(
'gravityview/edit_entry/after_update' , array( $this,
'update_user' ), 10 );
151 $gf_user_registration = GF_User_Registration::get_instance();
153 $config = $gf_user_registration->get_single_submission_feed(
$entry,
$form );
163 $preserve_role = apply_filters(
'gravityview/edit_entry/user_registration/preserve_role',
true, $config,
$form,
$entry );
165 if( $preserve_role ) {
166 $config[
'meta'][
'role'] =
'gfur_preserve_role';
175 $config[
'meta'][
'displayname'] = $displayname ? $displayname : $config[
'meta'][
'displayname'];
184 $config = apply_filters(
'gravityview/edit_entry/user_registration/config', $config,
$form,
$entry );
200 $user = get_userdata( $user_id );
208 $format = array_search(
$user->display_name, $names,
true );
215 $this->_user_before_update =
$user;
231 $public_display = array();
232 $public_display[
'nickname'] = $profileuser->nickname;
233 $public_display[
'username'] = $profileuser->user_login;
235 if ( !empty($profileuser->first_name) ) {
236 $public_display[
'firstname'] = $profileuser->first_name;
239 if ( !empty($profileuser->last_name) ) {
240 $public_display[
'lastname'] = $profileuser->last_name;
243 if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
244 $public_display[
'firstlast'] = $profileuser->first_name .
' ' . $profileuser->last_name;
245 $public_display[
'lastfirst'] = $profileuser->last_name .
' ' . $profileuser->first_name;
248 $public_display = array_map(
'trim', $public_display );
249 $public_display = array_unique( $public_display );
251 return $public_display;
273 $restore_display_name = apply_filters(
'gravityview/edit_entry/restore_display_name',
true );
275 $is_update_feed = ( $config &&
\GV\Utils::get( $config,
'meta/feed_type' ) ===
'update' );
284 if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) {
288 $user_after_update = get_userdata( $user_id );
291 if ( ! $user_after_update ) {
292 gravityview()->log->error(
'User not found at $user_id #{user_id}', array(
'user_id' => $user_id ) );
296 $restored_user = $user_after_update;
299 $restored_user->display_name = $this->_user_before_update->display_name;
302 unset( $restored_user->data->user_pass, $restored_user->user_pass );
312 $restored_user = apply_filters(
'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update,
$entry );
314 $updated = wp_update_user( $restored_user );
316 if( is_wp_error( $updated ) ) {
317 gravityview()->log->error(
'There was an error updating user #{user_id} details', array(
'user_id' => $user_id,
'data' => $updated ) );
319 gravityview()->log->debug(
'User #{user_id} details restored', array(
'user_id' => $user_id ) );
322 $this->_user_before_update = null;
324 unset( $restored_user, $user_after_update );
if(gv_empty( $field['value'], false, false)) $format
get_feed_configuration( $entry, $form)
Get the User Registration feed configuration for the entry & form.
if(gravityview() ->plugin->is_GF_25()) $form
__construct(GravityView_Edit_Entry $loader)
update_user( $form=array(), $entry_id=0)
Update the WordPress user profile based on the GF User Registration create feed.
restore_display_name( $user_id=0, $config=array(), $entry=array(), $password='')
Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration A...
generate_display_names( $profileuser)
Generate an array of all the user display names possibilities.
add_hooks()
Add hooks to trigger updating the user.
match_current_display_name( $user_id)
Calculate the user display name format.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
GravityView Edit Entry - Sync User Registration (when using the GF User Registration Add-on) ...