gform_user_registration_update_user_id

gform_user_registration_update_user_id

DescriptionUsageParametersExampleExample 1Example 2Source

Description
This filter can be used to override which user is used to populate the form and updated when the form is submitted.
Usage
The following would apply to all forms with an update type feed.
add_filter( 'gform_user_registration_update_user_id', 'your_function_name', 10, 4 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_user_registration_update_user_id_FORMID)
add_filter( 'gform_user_registration_update_user_id_6', 'your_function_name', 10, 4 );

Parameters

$user_id integer
The ID of the user being used to populate the form and being updated on form submission.

$entry Entry Object
The entry currently being processed or an empty array when the form is being rendered.

$form Form Object
The form currently being processed.

$feed Feed Object
The feed currently being processed.

Example
Example 1
The following example shows how you can override the user id with a specific id.
add_filter( 'gform_user_registration_update_user_id_6', 'override_user_id', 10, 4 );
function override_user_id( $user_id, $entry, $form, $feed ) {

return is_user_logged_in() ? 13 : false;
}

Example 2
The following example overrides the user id form id 7 with the id of the user for the email address supplied in the URL query string when accessing the page containing the form or entered into field id 1 during submission.
add_filter( 'gform_user_registration_update_user_id_7', 'override_user_id', 10, 4 );
function override_user_id( $user_id, $entry, $form, $feed ) {
// Get email address from URL query string on form display or field ID 1 during submission.
$email = rgar( $entry, '1', rgget( 'the_URL_param_here' ) );

return email_exists( $email );
}

Source
return (int) gf_apply_filters( array( 'gform_user_registration_update_user_id', (int) rgar( $form, 'id' ) ), $user_id, $entry, $form, $feed );

Since version 4.7 this filter is located in GF_User_Registration::get_update_user_id() in class-gf-user-registration.php:
In previous versions the filter was located in the following methods:

GF_User_Registration::update_user() since 3.0.beta1.
GF_User_Registration::maybe_prepopulate_form() since 3.0.beta1.3.
GF_User_Registration::handle_existing_images_submission() since 3.0.beta1.3.
GF_User_Registration::validate() since 3.0.beta1.3.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注