Forum Replies Created
-
AuthorPosts
-
May 15, 2025 at 8:36 am in reply to: Suggestion: Adding Action Hook from core also to Form Builder #30410
saschapi
ParticipantThank you. That works perfectly! 🙂
May 14, 2025 at 11:57 am in reply to: Any way to automatically delete accounts that have status “activation needed”? #30399saschapi
ParticipantAs others mentioned before, this setting will not delete accounts that did not manually validated their email. In case that others are looking for a way to auto delete accounts that registered and did not manually validated their email after a certain period of time, this function added to the functions.php or a custom plugin might help:
// Delete not activated members after three days add_action('swpm_delete_pending_account_event', 'delete_not_activated_accounts'); function delete_not_activated_accounts() { global $wpdb; $query = $wpdb->prepare("SELECT member_id,user_name FROM {$wpdb->prefix}swpm_members_tbl WHERE account_state='activation_required' AND subscription_starts < DATE_SUB(NOW(), INTERVAL 3 DAY) LIMIT %d, 100", $counter); $results = $wpdb->get_results($query); if (empty($results)) { //No more records to process. Break out of the loop. return false; } $to_delete = array(); foreach ($results as $result) { //Delete SM member $query = "DELETE FROM {$wpdb->prefix}swpm_members_tbl WHERE member_id ='".$result->member_id."'"; $wpdb->query($query); //Delete WP user $queryWP = "DELETE FROM {$wpdb->prefix}users WHERE user_login = '".$result->user_name."'"; $wpdb->query($queryWP); } }It uses the same hook as the pending account deletion. In this case it deletes those users after 3 days if they did not click the link in their email and activated their account. It is necessary to ALSO delete the WP account which this function does for you.
Hope this helps others. Sascha
saschapi
ParticipantThe URL looks like this:
your-domain.com/?swpm_email_activation=1&swpm_member_id=13&swpm_token=232d462c32a2a2e1c848d14c7e29efd1
And the Text is in German for me. But the text is something to the likes of:
Sucess! Your Account has been activated succesfully.
You will be redirected in a few seconds. If not, please click here.
saschapi
Participant@all I found the hook that I need in the code. It is already there. 🙂
For anybody else that is looking for something like this. I implemented the following action in a plugin to send out an email automatically if the status from a member switches from “pending” to “active”. It uses the subject and body text from the bulk status update emails.
// Add Action Hook to Account status change add_action('swpm_admin_account_status_updated','send_email_at_status_change', 10, 1 ); function send_email_at_status_change($info_array) { $member_id = $info_array['member_id']; $from_status = $info_array['from_status']; $to_status = $info_array['to_status']; if($from_status == 'pending' && $to_status == 'active') { $settings = SwpmSettings::get_instance(); $to_email = SwpmMemberUtils::get_member_field_by_id($member_id,'email'); $subject = $settings->get_value( 'bulk-activate-notify-mail-subject' ); if ( empty( $subject ) ) { $subject = 'Account Activated!'; } $body = $settings->get_value( 'bulk-activate-notify-mail-body' ); if ( empty( $body ) ) { $body = 'Hi, Your account has been activated successfully!'; } $from_address = $settings->get_value( 'email-from' ); $headers = 'From: ' . $from_address . "\r\n"; //Send the activation email one by one to all the selected members. $subject = apply_filters( 'swpm_email_bulk_set_status_subject', $subject ); $body = apply_filters( 'swpm_email_bulk_set_status_body', $body ).' ID/from/to: '; $to_email = trim($to_email); SwpmMiscUtils::mail( $to_email, $subject, $body, $headers ); SwpmLog::log_simple_debug( 'Bulk activation email notification sent. Activation email sent to the following email: ' . $to_email, true ); } }saschapi
ParticipantHi again. Thank you for your answer. I understand that.
That’s why I asked this specific question. So it is NOT possible to send out mail automatically when the account status changes? The answer you gave per the developer tackles the use case, but not my original question if there are any hooks that can be used to send out mails if the account status changes.
saschapi
ParticipantThanks for your reply.
Not exactly. In fact I am trying to have both email verification AND manual approval. For our region and the specific task at hand it is a must by some regulation. I got it to work just fine by filtering the status after email approval.
Everything works as it should, I would just love to have an automatic email send out when the account goes to active. Everything else is already working as it should.
-
AuthorPosts