Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuddyPress. Send feedback on user deletion. #528

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function doPublicWork()
if (!empty($apbct->data['bp_feedback_message'])) {
add_action('admin_notices', array($this, 'userFeedbackShowAdminNotice'), 998);
}

//add ct_hash to meta on user registartion BEFORE user created
add_action('bp_core_signups_after_add', array($this, 'updateCTHashOnUserRegistration'), 10, 3);
//add ct_hash to meta on user registartion AFTER user created
add_action('bp_core_activated_user', array($this, 'updateCTHashOnUserActivation'), 10, 3);
}

public function doAdminWork()
Expand Down Expand Up @@ -315,4 +320,57 @@ public function sendFeedback($user_id)
// this will be sent by cron task within an hour
ct_feedback($ct_hash, $feedback_flag);
}

/**
* Fires on BP Signup process after user is in activation await stage.
* Adds a ct_hash to signup meta.
* This is not a user creation process!
* @param $_retval - unused
* @param $_r - unused
* @param $args - args of signup data
*
* @return void
*/
public function updateCTHashOnUserRegistration($_retval, $_r, $args)
{
if (
class_exists('\BP_Signup') &&
! empty($args['activation_key'])
) {
try {
/** @psalm-suppress UndefinedClass */
$object_usage = \BP_Signup::get(array('activation_key' => $args['activation_key']));
$the_signup = isset($object_usage['signups'][0]) ? $object_usage['signups'][0] : null;
$signup_meta = is_object($the_signup) && property_exists($the_signup, 'meta')
? $the_signup->meta
: null;
$id = is_object($the_signup) && property_exists($the_signup, 'id')
? $the_signup->id
: null;
$hash = ct_hash();
if ( is_array($signup_meta) && !empty($hash) && !empty($id)) {
$signup_meta['ct_hash'] = $hash;
/** @psalm-suppress UndefinedClass */
\BP_Signup::update(array('signup_id' => $id, 'meta' => $signup_meta));
}
} catch (\Exception $e) {
//does nothing
}
}
}

/**
* Fires if user created after signup process verified
* @param $user_id - user id
* @param $_key - unused
* @param $user - user data
*
* @return void
*/
public function updateCTHashOnUserActivation($user_id, $_key, $user)
{
if (!empty($user['meta']) && !empty($user['meta']['ct_hash']) && $user_id) {
update_user_meta($user_id, 'ct_hash', $user['meta']['ct_hash']);
}
}
}
4 changes: 4 additions & 0 deletions lib/Cleantalk/ApbctWP/RemoteCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public static function action__debug() // phpcs:ignore PSR1.Methods.CamelCapsMet
{
global $apbct, $wpdb;

if (Get::get('run_send_feedback') === '1') {
$out['send_feedback'] = array('result' => ct_send_feedback() ? 'true' : 'false');
}

$sfw_table_name = !empty($apbct->data['sfw_common_table_name']) ? $apbct->data['sfw_common_table_name'] : APBCT_TBL_FIREWALL_DATA;

$out['sfw_data_base_size'] = $wpdb->get_var('SELECT COUNT(*) FROM ' . $sfw_table_name);
Expand Down
Loading