Description
The “gform_activate_user” action fires after a user signup has been activated. This action is used in the User Registration plugin for Gravity Forms.
Usage
add_action( 'gform_activate_user', 'your_function_name', 10, 3 );
Parameters
Example
Add a Note
add_action( 'gform_activate_user', 'after_user_activate', 10, 3 );
function after_user_activate( $user_id, $user_data, $signup_meta ) {
// Add note to entry.
GFFormsModel::add_note( $signup_meta['entry_id'], $user_id, 'admin', 'The user signup has completed for ' . $user_data['display_name'] . '.');
}
Delete Entry
add_action( 'gform_activate_user', function( $user_id, $user_data, $signup_meta ) {
// Delete the entry.
GFAPI::delete_entry( $signup_meta['entry_id'] );
GFCommon::log_debug( __METHOD__ . '(): Entry deleted after user activation, ID: ' . $signup_meta['entry_id'] );
}, 10, 3 );
Update status for posts created by the user being activated
The following example shows how to change the post status for posts created, using the Advanced Post Creation add-on, by the user being activated.
add_action( 'gform_activate_user', function( $user_id, $user_data, $signup_meta ) {
$entry = GFAPI::get_entry( rgar( $signup_meta, 'entry_id' ) );
// Get the ID for posts created using the APC add-on.
$created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' );
// If there are no posts return without action.
if ( empty( $created_posts ) ){
gf_user_registration()->log_debug( "No posts founds for user ID {$user_id}" );
return;
}
// Change the post status for any posts created by this user using the APC add-on.
foreach ( $created_posts as $post ){
// Set the post status to publish.
$post_status = 'publish';
wp_update_post(
array(
'ID' => $post['post_id'],
'post_status' => $post_status,
)
);
gf_user_registration()->log_debug( "Changed post status for post ID {$post['post_id']} to {$post_status}" );
}
}, 10, 3 );
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Source Code
This action is located in GF_User_Registration::activate_signup() in gravityformsuserregistration/includes/signups.php.