/** * Checking WP Admin access * * @return void */ public static function moove_check_redirect() { $moove_user = new Moove_User(); $u = $moove_user->moove_check(); if ($u['logged_in'] === true) { if ($u['wp_admin'] === true || $u['editor'] === true) { wp_redirect(site_url('/wp-admin/')); } else { $redirect_to = esc_url_raw(wp_unslash($_GET['redirect_to'])); if (isset($redirect_to) && $redirect_to !== '') { wp_redirect(esc_url($redirect_to)); } else { wp_redirect(site_url('/')); // /my-account } } } }
/** * New user registration * * @param array $userData Form data. * @param array $customFields Extra fields from register form. * @return array Created and updated user data */ public function moove_register($userData, $customFields) { $user_id = wp_create_user($userData['username'], $userData['password'], $userData['email']); if (is_wp_error($user_id)) { return $user_id; } $userdata = array('ID' => $user_id, 'first_name' => esc_attr($userData['name']), 'last_name' => esc_attr($userData['surname']), 'display_name' => esc_attr($userData['name'] . ' ' . esc_attr($userData['surname'])), 'user_nicename' => esc_attr($userData['name'] . ' ' . esc_attr($userData['surname'])), 'role' => 'free_registration'); $x = wp_update_user($userdata); if (!is_wp_error($x)) { $maildata = array('username' => esc_attr($userData['name'] . ' ' . esc_attr($userData['surname'])), 'user_email' => esc_attr($userData['email'])); $_mailcontent = Moove_View::load('moove.mail.confirm'); $mailcontent = Moove_User::moove_register_mail_content(array('mail' => $_mailcontent, 'view_data' => $maildata)); wp_mail($userData['email'], 'Welcome to ' . get_option('blogname'), $mailcontent, 'Content-type: text/html' . "\r\n" . ''); do_action('moove_user_normal_registration_complete', $user_id); } return $x; }
/** * Password reset * * @param array $atts User attributes. * @return string Error message */ function moove_reset_password($atts) { $validation_messages = get_option('moove_protection-validation'); if (is_user_logged_in()) { return '<p>' . __('Cannot reset password for a logged in user.', 'moove') . '</p>'; } $errors = array(); $token = sanitize_key(wp_unslash($_GET['token'])); $reset_token = sanitize_key(wp_unslash($_POST['reset_token'])); if (trim($token) === '' && !isset($reset_token)) { return '<p>' . __('No token has been specified.', 'moove') . '</p>'; } if (isset($reset_token)) { if (!wp_verify_nonce(sanitize_key(wp_unslash($_POST['moove_reset'])), 'moove_reset_action')) { $errors['error'] = true; $errors['nonce'] = 'Remote check failed'; } $token = $reset_token; $password = sanitize_text_field(wp_unslash($_POST['password'])); $password2 = sanitize_text_field(wp_unslash($_POST['password2'])); if (trim($password) === '') { $errors['error'] = true; $errors['password'] = $validation_messages['Reset_password_required']; } if (mb_strlen($password) < 8) { $errors['error'] = true; $errors['password'] = $validation_messages['Reset_password_min-length']; } if ($password !== $password2) { $errors['error'] = true; $errors['password2'] = $validation_messages['Reset_password_equal-to']; } } if (!isset($errors['error']) && isset($reset_token)) { $user = new Moove_User(); $result = $user->moove_update_password($token, sanitize_text_field(wp_unslash($_POST['password']))); if ($result === false) { $errors['error'] = true; $errors['fail'] = __('An error occurred. Please try again', 'moove'); } } if (!isset($errors['error']) && isset($reset_token)) { echo Moove_View::load('moove.reset-completed', false); } else { echo Moove_View::load('moove.reset', array('token' => esc_attr($token), 'errors' => $errors)); } }
/** * Sending the password reset e-mail with token * * @return void */ function moove_password_reset_request() { $email_address = sanitize_email($_POST['email']); if (is_email($email_address)) { $user = get_user_by('email', $email_address); } else { $user = false; } if ($user === false) { echo json_encode(array('success' => false)); } else { $token = sha1($email_address . substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1, 20))), 1, 20)); $model = new Moove_User(); $model->moove_set_activation_key($token, $user->user_login); $subject = get_option('blogname') . ' - Reset your password'; $view_data = array('name' => $user->display_name, 'email' => $email_address, 'link' => site_url('/reset-password/?token=' . $token)); $_mailcontent = Moove_View::load('moove.mail.remind'); $mailcontent = Moove_User_Custom_Settings::moove_password_reset_content(array('mail' => $_mailcontent, 'view_data' => $view_data)); wp_mail($email_address, $subject, $mailcontent, 'Content-type: text/html' . "\r\n"); echo json_encode(array('success' => true)); } die; }
/** * Content protection, returns the trimmed content if is protected. * * @param string $content Content string. */ function moove_protect_content($content) { $moove_user = new Moove_User(); $u = $moove_user->moove_check(); $post = $GLOBALS['post']; $protection_selected = get_post_meta($post->ID, 'moove_post_protect_data', true); if (empty($protection_selected)) { $post_type = $post->post_type; $options = get_option('moove_post_protect'); if (isset($options[$post_type])) { $protection_selected = $options[$post_type]; } } if (!$u['wp_admin'] || !$u['editor']) { if (!is_admin() && !current_user_can('edit_posts')) { $post_level = moove_post_protection_level($post); if (!is_user_logged_in() && !moove_is_public($post) && !moove_is_premium($post)) { $trimmed = wp_trim_words($post->post_content, $num_words = 55, $more = null); $content = $trimmed; $content .= Moove_View::load('moove.protected.truncated.free_membership_restriction'); } if (moove_is_premium($post)) { $trimmed = wp_trim_words($post->post_content, $num_words = 55, $more = null); $content = $trimmed; $content .= Moove_View::load('moove.protected.truncated.premium_membership_restriction'); } } } return $content; }