function hocwp_change_captcha_image_ajax_callback() { $result = array('success' => false); $captcha = new HOCWP_Captcha(); $url = $captcha->generate_image(); if (!empty($url)) { $result['success'] = true; $result['captcha_image_url'] = $url; } else { $result['message'] = __('Sorry, cannot generate captcha image, please try again or contact administrator!', 'hocwp-theme'); } echo json_encode($result); die; }
function hocwp_widget_subscribe_ajax_callback() { $use_captcha = (bool) hocwp_get_method_value('use_captcha'); $captcha_code = hocwp_get_method_value('captcha'); $email = hocwp_get_method_value('email'); $name = hocwp_get_method_value('name'); $phone = hocwp_get_method_value('phone'); $register = (bool) hocwp_get_method_value('register'); $result = array('success' => false, 'message' => hocwp_build_message(hocwp_text_error_default(), 'danger')); $captcha_valid = true; if ($use_captcha) { $captcha = new HOCWP_Captcha(); $captcha_valid = $captcha->check($captcha_code); } $re_verify = false; $query = hocwp_get_post_by_meta('subscriber_email', $email, array('post_type' => 'hocwp_subscriber')); if ($query->have_posts()) { $subscriber = array_shift($query->posts); $verified = hocwp_get_post_meta('subscriber_verified', $subscriber->ID); if (1 != $verified) { $re_verify = true; } } if ($captcha_valid) { if (is_email($email)) { $active_key = hocwp_generate_reset_key(); $verify_link = hocwp_generate_verify_link($active_key); if ($re_verify) { hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link); $result['success'] = true; $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success'); } else { if ($query->have_posts() || $register && email_exists($email)) { $result['message'] = hocwp_build_message(hocwp_text_error_email_exists(), 'danger'); } else { $post_title = ''; if (!empty($name)) { $post_title .= $name; } if (empty($post_title)) { $post_title = $email; } else { $post_title .= ' - ' . $email; } $post_data = array('post_type' => 'hocwp_subscriber', 'post_title' => $post_title, 'post_status' => 'publish'); $post_id = hocwp_insert_post($post_data); if (hocwp_id_number_valid($post_id)) { update_post_meta($post_id, 'subscriber_name', $name); update_post_meta($post_id, 'subscriber_email', $email); update_post_meta($post_id, 'subscriber_phone', $phone); update_post_meta($post_id, 'subscriber_verified', 0); update_post_meta($post_id, 'subscriber_active_key', $active_key); if ($register) { $password = wp_generate_password(); $user_data = array('username' => $email, 'email' => $email, 'password' => $password); $user_id = hocwp_add_user($user_data); if (hocwp_id_number_valid($user_id)) { wp_send_new_user_notifications($user_id); update_post_meta($post_id, 'subscriber_user', $user_id); update_user_meta($user_id, 'subscriber_id', $post_id); } } hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link); $result['success'] = true; $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success'); } } } } else { $result['message'] = hocwp_build_message(hocwp_text_error_email_not_valid(), 'danger'); } } else { $result['message'] = hocwp_build_message(hocwp_text_error_captcha_not_valid(), 'danger'); } wp_send_json($result); }
function hocwp_setup_theme_preprocess_comment($commentdata) { $disable_captcha_user = hocwp_user_not_use_comment_form_captcha(); if (hocwp_use_comment_form_captcha() && (!$disable_captcha_user || $disable_captcha_user && !is_user_logged_in())) { $lang = hocwp_get_language(); if (isset($_POST['captcha'])) { $captcha = $_POST['captcha']; if (empty($captcha)) { wp_die(__('To confirm you are not a computer, please enter the security code!', 'hocwp-theme'), __('Empty captcha code error', 'hocwp-theme')); exit; } else { $hw_captcha = new HOCWP_Captcha(); if (!$hw_captcha->check($captcha)) { wp_die(__('The security code you entered is incorrect, please try again!', 'hocwp-theme'), __('Invalid captcha code', 'hocwp-theme')); exit; } } } else { $commentdata = null; wp_die(__('Our systems have detected that you are not a human!', 'hocwp-theme'), __('Post comment error', 'hocwp-theme')); exit; } } return $commentdata; }
function hocwp_check_captcha($captcha_code = '') { if (empty($captcha_code)) { $captcha_code = hocwp_get_method_value('captcha', 'request'); } $captcha = new HOCWP_Captcha(); if ($captcha->check($captcha_code)) { return true; } return false; }
function hocwp_field_captcha($args = array()) { $lang = hocwp_get_language(); hocwp_sanitize_field_args($args); $captcha = new HOCWP_Captcha(); $id = isset($args['id']) ? $args['id'] : ''; if (hocwp_string_empty($id)) { $id = 'hocwp_captcha'; } $placeholder = isset($args['placeholder']) ? $args['placeholder'] : __('Enter captcha code', 'hocwp-theme'); $class = isset($args['class']) ? $args['class'] : ''; $input_width = isset($args['input_width']) ? absint($args['input_width']) : 125; if (is_numeric($input_width) && '%' !== hocwp_get_last_char($input_width)) { $input_width .= 'px'; } $name = hocwp_get_value_by_key($args, 'name', 'captcha'); if (empty($name)) { $name = 'captcha'; hocwp_transmit_id_and_name($id, $name); } hocwp_add_string_with_space_before($class, 'hocwp-captcha-code'); $args['id'] = $id; hocwp_field_before($args); $image_url = $captcha->generate_image(); ?> <input autocomplete="off" id="<?php echo esc_attr($id); ?> " name="<?php echo esc_attr($name); ?> " placeholder="<?php echo esc_attr($placeholder); ?> " class="<?php echo esc_attr($class); ?> " type="text" style="width: <?php echo $input_width; ?> ;" required> <img class="hocwp-captcha-image" src="<?php echo $image_url; ?> "> <img class="hocwp-captcha-reload" src="<?php echo HOCWP_URL . '/images/icon-refresh-captcha.png'; ?> "> <?php hocwp_field_after($args); }
function hocwp_execute_lostpassword() { $http_post = 'POST' == $_SERVER['REQUEST_METHOD']; $user = null; $user_login = ''; $user_id = ''; $user_email = ''; $error = false; $message = __('There was an error occurred, please try again.', 'hocwp-theme'); $redirect = hocwp_get_value_by_key($_REQUEST, 'redirect_to'); $redirect_to = apply_filters('lostpassword_redirect', $redirect); if (is_user_logged_in()) { if (empty($redirect_to)) { $redirect_to = home_url('/'); } wp_redirect($redirect_to); exit; } $transient = ''; $captcha = hocwp_get_method_value('captcha'); if ($http_post) { $action = hocwp_get_method_value('action'); if ('lostpassword' === $action || 'retrievepassword' === $action) { $user_login = hocwp_get_method_value('user_login'); $transient_name = hocwp_build_transient_name('hocwp_lostpassword_user_%s', $user_login); if ((isset($_POST['submit']) || isset($_POST['wp-submit'])) && false === ($transient = get_transient($transient_name))) { if (empty($user_login)) { $error = true; $message = __('Please enter your account name or email address.', 'hocwp-theme'); } else { if (isset($_POST['captcha'])) { $capt = new HOCWP_Captcha(); if (!$capt->check($captcha)) { $error = true; $message = __('The security code is incorrect.', 'hocwp-theme'); } } if (!$error) { $user = hocwp_return_user($user_login); if (!is_a($user, 'WP_User')) { $error = true; $message = __('Username or email is not exists.', 'hocwp-theme'); } else { $user_login = $user->user_login; $user_id = $user->ID; $user_email = $user->user_email; } } } if (!$error && is_a($user, 'WP_User')) { $key = get_password_reset_key($user); if (is_wp_error($key)) { $error = true; $message = __('There was an error occurred, please try again or contact the administrator.', 'hocwp-theme'); } else { $message = wpautop(__('Someone has requested a password reset for the following account:', 'hocwp-theme')); $message .= wpautop(network_home_url('/')); $message .= wpautop(sprintf(__('Username: %s', 'hocwp-theme'), $user_login)); $message .= wpautop(__('If this was a mistake, just ignore this email and nothing will happen.', 'hocwp-theme')); $message .= wpautop(__('To reset your password, visit the following address:', 'hocwp-theme')); $message .= wpautop(network_site_url("wp-login.php?action=rp&key={$key}&login=" . rawurlencode($user_login), 'login')); if (is_multisite()) { $blogname = $GLOBALS['current_site']->site_name; } else { $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); } $title = sprintf(__('[%s] Password Reset'), $blogname); $title = apply_filters('retrieve_password_title', $title, $user_login, $user); $message = apply_filters('retrieve_password_message', $message, $key, $user_login, $user); if (!is_email($user_email)) { $user_email = $user->user_email; } if ($message && !hocwp_send_html_mail($user_email, wp_specialchars_decode($title), $message)) { $error = true; $message = __('The email could not be sent. Possible reason: your host may have disabled the mail() function.', 'hocwp-theme'); } else { $error = false; $message = __('Password recovery information has been sent, please check your mailbox.', 'hocwp-theme'); set_transient($transient_name, $user_id, 15 * MINUTE_IN_SECONDS); } } } } else { if (hocwp_id_number_valid($transient)) { $error = false; $message = __('Password recovery information has been sent, please check your mailbox.', 'hocwp-theme'); } } } } $result = array('user_id' => $user_id, 'user_email' => $user_email, 'user_login' => $user_login, 'captcha' => $captcha, 'error' => $error, 'message' => $message, 'redirect_to' => $redirect_to, 'transient' => $transient); return $result; }