Skip to content
Open
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
245 changes: 3 additions & 242 deletions inc/cleantalk-public-integrations.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Cleantalk\Antispam\IntegrationsByClass\WPRegistrationErrors;
use Cleantalk\ApbctWP\Escape;
use Cleantalk\ApbctWP\Helper;
use Cleantalk\ApbctWP\Honeypot;
Expand Down Expand Up @@ -844,248 +845,8 @@ function ct_test_registration($nickname, $email, $ip = null)
*/
function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null)
{
global $ct_checkjs_register_form, $apbct_cookie_request_id_label, $apbct_cookie_register_ok_label, $apbct_cookie_request_id, $bp, $ct_signup_done, $ct_negative_comment, $apbct, $ct_registration_error_comment, $cleantalk_executed;
$reg_flag = true;

// Go out if a registered user action
if ( apbct_is_user_enable() === false ) {
do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

return $errors;
}

if ( $apbct->settings['forms__registrations_test'] == 0 ) {
do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

return $errors;
}

// The function already executed
// It happens when used ct_register_post();
if ( $ct_signup_done && is_object($errors) && count($errors->errors) > 0 ) {
do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

if ($errors instanceof WP_Error) {
return $errors;
} else {
return new WP_Error('registration_error', 'An unexpected error occurred.');
}
}

/**
* Exclusions
*/
if ( Post::get('wpmem_reg_page') && apbct_is_plugin_active('wp-members/wp-members.php') ) {
return $errors;
}
// BuddyBoss login form
if ( Post::getString('wp-submit') && Post::getString('log') && Post::getString('pwd') ) {
return $errors;
}

$facebook = false;
// Facebook registration
$fb_userdata = Post::get('FB_userdata');
if ( is_array($fb_userdata) ) {
if ( $sanitized_user_login === null && isset($fb_userdata['name']) ) {
$sanitized_user_login = Sanitize::cleanUser($fb_userdata['name']);
$facebook = true;
}
if ($user_email === null && isset($fb_userdata['email'])) {
$user_email = Sanitize::cleanEmail($fb_userdata['email']);
$facebook = true;
}
}

// BuddyPress actions
$buddypress = false;
if ( $sanitized_user_login === null && Post::get('signup_username') ) {
$sanitized_user_login = Sanitize::cleanUser(Post::get('signup_username'));
$buddypress = true;
}
if ( $user_email === null && Post::get('signup_email') ) {
$user_email = Sanitize::cleanEmail(Post::get('signup_email'));
$buddypress = true;
}

// Get BuddyPress core instance if available
$bp = function_exists('buddypress') ? buddypress() : null;

// Skip BuddyPress request already contained validation errors
if ( ! empty($bp->signup->errors) ) {
do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
return $errors;
}

// Break tests because we already have servers response
if ( $buddypress && $ct_signup_done ) {
if ( $ct_negative_comment ) {
$bp->signup->errors['signup_username'] = $ct_negative_comment;
}
do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);

return $errors;
}

if ( current_filter() === 'woocommerce_registration_errors' ) {
$checkjs = apbct_js_test(Sanitize::cleanTextField(Cookie::get('ct_checkjs')), true);
$checkjs_post = null;
$checkjs_cookie = $checkjs;
} else {
// This hack can be helpful when plugin uses with untested themes&signups plugins.
$checkjs_post = apbct_js_test(Sanitize::cleanTextField(Post::get($ct_checkjs_register_form)));
$checkjs_cookie = apbct_js_test(Sanitize::cleanTextField(Cookie::get('ct_checkjs')), true);
$checkjs = $checkjs_cookie ?: $checkjs_post;
}

// BuddyBoss Platform use rest api for registration from phone app
if ( apbct_is_plugin_active('buddyboss-app/buddyboss-app.php') && apbct_is_in_uri('/wp-json/buddyboss-app/v1/signup') ) {
$checkjs = Post::getString('checkjs') === 'true' ? 1 : 0;
}

$sender_info = array(
'post_checkjs_passed' => $checkjs_post,
'cookie_checkjs_passed' => $checkjs_cookie,
'form_validation' => ! empty($errors) && $errors instanceof \WP_Error
? json_encode(
array(
'validation_notice' => $errors->get_error_message(),
'page_url' => TT::toString(Server::get('HTTP_HOST')) . TT::toString(Server::get('REQUEST_URI')),
)
)
: null,
);

/**
* Changing the type of check for BuddyPress
*/
if ( Post::get('signup_username') && Post::get('signup_email') ) {
// if buddy press set up custom fields
$reg_flag = ! empty(Post::get('signup_profile_field_ids'));
}

/**
* Changing the type of check for Avada Fusion
*/
if ( Post::get('fusion_login_box') ) {
$reg_flag = true;
}

if (current_filter() === 'woocommerce_registration_errors') {
if (!is_null($sanitized_user_login) && strpos($sanitized_user_login, '.') !== false) {
$username_parts = explode('.', $sanitized_user_login);
$sanitized_user_login = implode(' ', $username_parts);
}
}

if (Post::getString('tutor_action') === 'tutor_register_student') {
$user_email = Post::getString('email');
$sanitized_user_login = Post::getString('user_login');
$reg_flag = true;
}

$base_call_array = array(
'sender_email' => $user_email,
'sender_nickname' => $sanitized_user_login,
'sender_info' => $sender_info,
'js_on' => $checkjs,
);

if ( !$reg_flag ) {
$field_values = '';
$fields_numbers_to_check = explode(',', TT::toString(Post::get('signup_profile_field_ids')));
foreach ( $fields_numbers_to_check as $field_number ) {
$field_name = 'field_' . $field_number;
$field_value = Post::get($field_name) ? Sanitize::cleanTextareaField(Post::get($field_name)) : '';
$field_values .= $field_value . "\n";
}
$base_call_array['message'] = $field_values;
}

$base_call_result = apbct_base_call(
$base_call_array,
$reg_flag
);

if ( ! isset($base_call_result['ct_result']) ) {
return $errors;
}

$ct_result = $base_call_result['ct_result'];
ct_hash($ct_result->id);

// Change mail notification if license is out of date
if ( $apbct->data['moderate'] == 0 &&
($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
) {
$apbct->sender_email = $user_email;
$apbct->sender_ip = Helper::ipGet('real');
add_filter(
'wp_new_user_notification_email_admin',
'apbct_registration__Wordpress__changeMailNotification',
100,
3
);
}

$ct_signup_done = true;
$cleantalk_executed = true;

if ( $ct_result->inactive != 0 ) {
ct_send_error_notice($ct_result->comment);
return $errors;
}

if ( $ct_result->allow != 0 ) {
if (current_filter() === 'woocommerce_registration_errors' && $apbct->settings['forms__wc_register_from_order']) {
$cleantalk_executed = false;
}
}

if ( $ct_result->allow == 0 ) {
$ct_negative_comment = $ct_result->comment;
$ct_registration_error_comment = $ct_result->comment;

if (current_filter() === 'woocommerce_registration_errors') {
add_action('woocommerce_store_api_checkout_order_processed', ['Cleantalk\Antispam\IntegrationsByClass\Woocommerce', 'storeApiCheckoutOrderProcessed'], 10, 2);
}

if ( $buddypress === true ) {
$bp->signup->errors['signup_username'] = $ct_result->comment;
}

if (apbct_is_plugin_active('buddyboss-app/buddyboss-app.php') && apbct_is_in_uri('/wp-json/buddyboss-app/v1/signup')) {
wp_send_json_error(['success' => false, 'message' => $ct_result->comment]);
}

if ( $facebook ) {
/** @psalm-suppress InvalidArrayOffset */
$_POST['FB_userdata']['email'] = '';
/** @psalm-suppress InvalidArrayOffset */
$_POST['FB_userdata']['name'] = '';
return;
}

if ((defined('MGM_PLUGIN_NAME') || apbct_is_plugin_active('bbpress/bbpress.php')) &&
current_filter() !== 'woocommerce_registration_errors'
) {
ct_die_extended($ct_result->comment);
}

if ( is_wp_error($errors) ) {
$errors->add('ct_error', $ct_result->comment);
}

return $errors;
}

if ( $ct_result->id !== null ) {
$apbct_cookie_request_id = $ct_result->id;
Cookie::set($apbct_cookie_register_ok_label, $ct_result->id, time() + 10, '/');
Cookie::set($apbct_cookie_request_id_label, $ct_result->id, time() + 10, '/');
}

return $errors;
$handler = new WPRegistrationErrors();
return $handler->handle($errors, $sanitized_user_login, $user_email);
}

/**
Expand Down
Loading
Loading