/** * Init the form. * * @access public * @since 1.0.0 * @return void */ public static function init() { add_action('wp', array(__CLASS__, 'process')); // Validate and process passwords. if (wpaam_get_option('custom_passwords')) { self::$random_password = false; add_filter('wpaam/form/validate=register', array(__CLASS__, 'validate_password'), 10, 3); if (wpaam_get_option('display_password_meter_registration')) { add_action('wpaam/form/register/after/field=password', 'wpaam_psw_indicator', 10); } if (wpaam_get_option('login_after_registration')) { add_action('wpaam/form/register/success', array(__CLASS__, 'do_login'), 11, 3); } } // Make sure the submitted email is valid and not in use. add_filter('wpaam/form/validate=register', array(__CLASS__, 'validate_email'), 10, 3); // Add a very basic honeypot spam prevention field. if (wpaam_get_option('enable_honeypot')) { add_action('wpaam_get_registration_fields', array(__CLASS__, 'add_honeypot')); add_filter('wpaam/form/validate=register', array(__CLASS__, 'validate_honeypot'), 10, 3); } /** * Adds a "terms" checkbox field to the signup form. */ if (wpaam_get_option('enable_terms')) { add_action('wpaam_get_registration_fields', array(__CLASS__, 'add_terms')); } // Allow user to select a user role upon registration. if (wpaam_get_option('allow_role_select')) { add_action('wpaam_get_registration_fields', array(__CLASS__, 'add_role')); add_filter('wpaam/form/validate=register', array(__CLASS__, 'validate_role'), 10, 3); add_action('wpaam/form/register/success', array(__CLASS__, 'save_role'), 10, 10); } // Prevent users from using specific usernames if enabled. $exclude_usernames = wpaam_get_option('exclude_usernames'); if (!empty($exclude_usernames)) { add_filter('wpaam/form/validate=register', array(__CLASS__, 'validate_username'), 10, 3); } // Store uploaded avatars into the database. if (wpaam_get_option('custom_avatars') && wpaam()->fields->show_on_registration('user_avatar')) { add_action('wpaam/form/register/success', array(__CLASS__, 'save_avatar'), 10, 3); } // Redirect to a page after successfull registration. if (wpaam_get_option('login_after_registration') && wpaam_get_option('custom_passwords') && wpaam_get_option('registration_redirect')) { add_filter('wpaam_redirect_after_automatic_login', array(__CLASS__, 'adjust_redirect_url'), 10, 2); } elseif (!wpaam_get_option('login_after_registration') || !wpaam_get_option('custom_passwords')) { if (wpaam_get_option('registration_redirect')) { add_action('wpaam/form/register/success', array(__CLASS__, 'redirect_on_success'), 9999, 3); } } }
/** * Updates custom fields order. * * @access public * @since 1.0.0 * @return void */ public function update_fields_order() { // Check our nonce and make sure it's correct. check_ajax_referer('wpaam_fields_editor_nonce', 'wpaam_editor_nonce'); // Abort if something isn't right. if (!is_admin() || !current_user_can('manage_options')) { $return = array('message' => __('Error.', 'wpaam')); wp_send_json_error($return); } // Prepare the array. $fields = $_POST['items']; if (is_array($fields)) { foreach ($fields as $field) { $args = array('field_order' => (int) $field['priority']); wpaam()->fields->update((int) $field['field_id'], $args); } } else { $return = array('message' => __('Error.', 'wpaam')); wp_send_json_error($return); } // Send message $return = array('message' => __('Fields order successfully updated.', 'wpaam')); wp_send_json_success($return); }
/** * Get the list of fields formatted into an array. * The format of the array is used by the forms. * * @since 1.2.0 * @param string $group_id the id number of the group. * @return array - list of fields. */ function wpaam_get_group_fields_for_form($group_id) { $args = array('id' => $group_id, 'array' => true, 'number' => -1, 'orderby' => 'field_order', 'order' => 'ASC'); $data = wpaam()->fields->get_by_group($args); // Manipulate fields list into a list formatted for the forms API. $fields = array(); // Loop through the found fields. foreach ($data as $key => $field) { switch ($field['type']) { case 'url': $field['type'] = 'text'; break; } $fields[$field['meta']] = apply_filters('wpaam_form_field', array('priority' => $field['field_order'], 'label' => $field['name'], 'type' => $field['type'], 'meta' => $field['meta'], 'required' => $field['is_required'], 'description' => $field['description'], 'value' => maybe_unserialize(get_user_meta(get_current_user_id(), $field['meta'], true))), $field['options']); } return apply_filters('wpaam_get_group_fields_for_form', $fields, $group_id); }
/** * Save the field to the database * * @access public * @return void */ public function process_field() { // Check whether the form has been submitted if (isset($_POST['wpaam-action']) && $_POST['wpaam-action'] == 'save_field') { // nonce verification if (!wp_verify_nonce($_POST['_wpnonce'], 'wpaam_save_field')) { return; } // bail if something is wrong if (!isset($_POST['from_group']) || !isset($_POST['which_field']) || !is_admin() || !current_user_can('manage_options')) { return; } die("we are on the save process"); // store information into variable $field_id = (int) $_POST['which_field']; $group_id = (int) $_POST['from_group']; // Prepare array $args = array('name' => sanitize_text_field($_POST['name']), 'description' => wp_kses_post($_POST['field_description']), 'is_required' => isset($_POST['set_as_required']) ? (bool) $_POST['set_as_required'] : false, 'show_on_registration' => isset($_POST['show_on_registration']) ? (bool) $_POST['show_on_registration'] : false, 'default_visibility' => isset($_POST['field_visibility']) ? sanitize_key($_POST['field_visibility']) : 'public'); // Unset options from being saved if field type doesn't support them if (!$this->field_object->set_registration) { unset($args['show_on_registration']); } if (!$this->field_object->set_requirement || $this->field->meta == 'user_email') { unset($args['is_required']); } // Save the field if (wpaam()->fields->update($field_id, $args)) { // Verify whether the "display full name" option has been checked or not. // If it's checked, then we store the value into the field options. if ($this->field->meta == 'first_name' || $this->field->meta == 'last_name') { $display_full_name = isset($_POST['display_full_name']) ? (bool) $_POST['display_full_name'] : false; if ($display_full_name) { wpaam_update_field_option($field_id, 'display_full_name', true); } elseif ($display_full_name === false) { wpaam_delete_field_option($field_id, 'display_full_name'); } } // Allow plugins to extend the save process do_action('wpaam/fields/editor/single/before_save', $field_id, $group_id, $this->field, $this->field_object); // Redirect now $admin_url = add_query_arg(array('message' => 'field_saved', 'action' => 'edit', 'group' => $group_id), admin_url('users.php?page=wpaam-profile-fields')); wp_redirect($admin_url); exit; } } }
/** * Get the table data * * @since 1.0.0 * @return Array */ private function table_data() { $which_group = null; // Detect if a group is selected - // if not get the primary group ID. if (isset($_GET['group'])) { $which_group = (int) $_GET['group']; } else { $primary_group = wpaam()->field_groups->get_group_by('primary'); $which_group = $primary_group->id; } $data = wpaam()->fields->get_by_group(array('id' => $which_group, 'array' => true, 'orderby' => 'field_order', 'order' => 'ASC')); return $data; }
?> "> <tr> <td align="center" valign="top"> <!-- Header --> <table border="0" cellpadding="0" cellspacing="0" width="520" id="template_header" style="<?php echo $template_header; ?> " bgcolor="#ffffff"> <tr> <td> <h1 style="<?php echo $header_content_h1; ?> "><?php echo wpaam()->emails->get_heading(); ?> </h1> </td> </tr> </table> <!-- End Header --> </td> </tr> <tr> <td align="center" valign="top"> <!-- Body --> <table border="0" cellpadding="0" cellspacing="0" width="520" id="template_body"> <tr> <td valign="top" style="<?php echo $body_content;
/** * Handles sending password retrieval email to user. * Based on retrieve_password() in core wp-login.php * * @access public * @param string $username contains the username of the user. * @uses $wpdb WordPress Database object * @return bool True: when finish. False: on error */ public static function retrieve_password($username) { global $wpdb, $wp_hasher; // Check on username first, as users can use emails as usernames. $login = trim($username); $user_data = get_user_by('login', $login); // If no user found, check if it login is email and lookup user based on email. if (!$user_data && is_email($username) && apply_filters('wpaam_get_username_from_email', true)) { $user_data = get_user_by('email', trim($username)); } do_action('lostpassword_post'); if (!$user_data) { self::add_error(__('Invalid username or e-mail.', 'wpaam')); return; } if (is_multisite() && !is_user_member_of_blog($user_data->ID, get_current_blog_id())) { self::add_error(__('Invalid username or e-mail.', 'wpaam')); return; } // redefining user_login ensures we return the right case in the email $user_login = $user_data->user_login; $user_email = $user_data->user_email; do_action('retrieve_password', $user_login); $allow = apply_filters('allow_password_reset', true, $user_data->ID); if (!$allow) { self::add_error(__('Password reset is not allowed for this user', 'wpaam')); return; } elseif (is_wp_error($allow)) { self::add_error(__('Password reset is not allowed for this user', 'wpaam')); return; } $key = wp_generate_password(20, false); do_action('retrieve_password_key', $user_login, $key); // Now insert the key, hashed, into the DB. if (empty($wp_hasher)) { require_once ABSPATH . 'wp-includes/class-phpass.php'; $wp_hasher = new PasswordHash(8, true); } $hashed = $wp_hasher->HashPassword($key); $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user_login)); /* == Send Email == */ // Check if email exists first if (wpaam_email_exists('password')) { // Retrieve the email from the database $password_email = wpaam_get_email('password'); $message = wpautop($password_email['message']); $message = wpaam_do_email_tags($message, $user_data->ID, $key); wpaam()->emails->__set('heading', __('Password Recovery', 'wpaam')); wpaam()->emails->send($user_email, $password_email['subject'], $message); self::add_confirmation(__('Check your e-mail for the confirmation link.', 'wpaam')); } else { return; } return true; }