/** * Email login credentials to a newly registered user. * A new user registration notification is also sent to admin email if enabled. * * @since 1.1.0 * @param string $user_id user id number of the newly registered user. * @param string $plaintext_pass password of the newly registered user. * @return void */ function wpaam_new_user_notification($user_id, $plaintext_pass) { $user = get_userdata($user_id); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // Send notification to admin if not disabled. if (!wpaam_get_option('disable_admin_register_email')) { $message = sprintf(esc_html__('New user registration on your site %s:', 'wpaam'), $blogname) . "\r\n\r\n"; $message .= sprintf(esc_html__('Username: %s', 'wpaam'), $user->user_login) . "\r\n\r\n"; $message .= sprintf(esc_html__('E-mail: %s', 'wpaam'), $user->user_email) . "\r\n"; wp_mail(get_option('admin_email'), sprintf(esc_html__('[%s] New User Registration', 'wpaam'), $blogname), $message); } // Send notification to the user now. if (empty($plaintext_pass)) { return; } // a custom mail code for registered user's $message = sprintf(esc_html__('Hello %s', 'wpaam'), $user->user_login) . "\r\n\r\n"; $message .= sprintf(esc_html__('Welcome to %s', 'wpaam'), $blogname) . "\r\n\r\n"; $message .= sprintf(esc_html__('These are your account details', 'wpaam')) . "\r\n\r\n"; $message .= sprintf(esc_html__('Username: %s', 'wpaam'), $user->user_login) . "\r\n"; $message .= sprintf(esc_html__('Password: %s', 'wpaam'), $plaintext_pass) . "\r\n"; wp_mail($user->user_email, sprintf(esc_html__('[%s] Your Account', 'wpaam'), $blogname), $message); // Check if email exists first. // if ( wpaam_email_exists( 'register' ) ) { // //Retrieve the email from the database // $register_email = wpaam_get_email( 'register' ); // $message = wpautop( $register_email['message'] ); // $message = wpaam_do_email_tags( $message, $user_id, $plaintext_pass ); // WPAAM()->emails->__set( 'heading', esc_html__( 'Your account', 'wpaam' ) ); // WPAAM()->emails->send( $user->user_email, $register_email['subject'], $message ); // } }
/** * Validate the password field. * * @access public * @since 1.0.0 * @return void */ public static function validate_password_field($passed, $fields, $values) { $pwd = $values['password_update']['password']; $pwd_strenght = wpaam_get_option('password_strength'); if (empty($pwd)) { return new WP_Error('password-validation-error', __('Enter a password.', 'wpaam')); } // Check strenght $containsLetter = preg_match('/[A-Z]/', $pwd); $containsDigit = preg_match('/\\d/', $pwd); $containsSpecial = preg_match('/[^a-zA-Z\\d]/', $pwd); if ($pwd_strenght == 'weak') { if (strlen($pwd) < 8) { return new WP_Error('password-validation-error', __('Password must be at least 8 characters long.', 'wpaam')); } } if ($pwd_strenght == 'medium') { if (!$containsLetter || !$containsDigit || strlen($pwd) < 8) { return new WP_Error('password-validation-error', __('Password must be at least 8 characters long and contain at least 1 number and 1 uppercase letter.', 'wpaam')); } } if ($pwd_strenght == 'strong') { if (!$containsLetter || !$containsDigit || !$containsSpecial || strlen($pwd) < 8) { return new WP_Error('password-validation-error', __('Password must be at least 8 characters long and contain at least 1 number and 1 uppercase letter and 1 special character.', 'wpaam')); } } // Check if matches repeated password if ($pwd !== $values['password_update']['password_repeat']) { return new WP_Error('password-validation-error', __('Passwords do not match.', 'wpaam')); } return $passed; }
/** * Admin Messages * * @since 1.0 * @global $wpaam_options Array of all the wpaam Options * @return void */ function wpaam_admin_messages() { global $wpaam_options; $screen = get_current_screen(); if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == true && !wpaam_get_option('custom_passwords') && wpaam_get_option('password_strength')) { add_settings_error('wpaam-notices', 'custom-passwords-disabled', __('You have enabled the "Minimum Password Strength" option, the "Users custom passwords" is currently disabled and must be enabled for custom passwords to work.', 'wpaam'), 'error'); } if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == true && !wpaam_get_option('custom_passwords') && wpaam_get_option('login_after_registration')) { add_settings_error('wpaam-notices', 'custom-passwords-disabled', __('Error: the option "Login after registration" can only work when the option "Users custom passwords" is enabled too.', 'wpaam'), 'error'); } if (isset($_GET['emails-updated']) && $_GET['emails-updated'] == true) { add_settings_error('wpaam-notices', 'emails-updated', __('Email successfully updated.', 'wpaam'), 'updated'); } // Display Errors in plugin settings page if ($screen->base == 'users_page_wpaam-settings') { // Display error if no core page is setup if (!wpaam_get_option('login_page') || !wpaam_get_option('registration_page') || !wpaam_get_option('account_page') || !wpaam_get_option('profile_page') || !wpaam_get_option('clients_page') || !wpaam_get_option('products_page') || !wpaam_get_option('quotations_page') || !wpaam_get_option('invoices_page') || !wpaam_get_option('creditmemos_page')) { add_settings_error('wpaam-notices', 'page-missing', __('One or more wpaam pages are not configured.', 'wpaam') . ' ' . sprintf(__('<a href="%s" class="button-primary">Click here to setup your pages</a>', 'wpaam'), admin_url('users.php?page=wpaam-settings&tab=general&wpaam_action=install_pages')), 'error'); } // Display error if wrong permalinks if (get_option('permalink_structure') == '') { add_settings_error('wpaam-notices', 'permalink-wrong', sprintf(__('You must <a href="%s">change your permalinks</a> to anything else other than "default" for profiles to work.', 'wpaam'), admin_url('options-permalink.php')), 'error'); } if (isset($_GET['setup_done']) && $_GET['setup_done'] == 'true') { add_settings_error('wpaam-notices', 'pages-updated', __('Pages setup completed.', 'wpaam'), 'updated'); } } // Verify if upload folder is writable if (isset($_GET['wpaam_action']) && $_GET['wpaam_action'] == 'check_folder_permission') { $upload_dir = wp_upload_dir(); if (!wp_is_writable($upload_dir['path'])) { add_settings_error('wpaam-notices', 'permission-error', sprintf(__('Your uploads folder in "%s" is not writable. <br/>Avatar uploads will not work, please adjust folder permission.<br/><br/> <a href="%s" class="button" target="_blank">Read More</a>', 'wpaam'), $upload_dir['basedir'], 'http://www.wpbeginner.com/wp-tutorials/how-to-fix-image-upload-issue-in-wordpress/'), 'error'); } else { add_settings_error('wpaam-notices', 'permission-success', sprintf(__('No issues detected.', 'wpaam'), admin_url('users.php?page=wpaam-settings&tab=profile')), 'updated notice is-dismissible'); } } // messages for the groups and fields pages if ($screen->base == 'users_page_wpaam-profile-fields') { if (isset($_GET['message']) && $_GET['message'] == 'group_success') { add_settings_error('wpaam-notices', 'group-updated', __('Field group successfully updated.', 'wpaam'), 'updated'); } if (isset($_GET['message']) && $_GET['message'] == 'group_delete_success') { add_settings_error('wpaam-notices', 'group-deleted', __('Field group successfully deleted.', 'wpaam'), 'updated'); } if (isset($_GET['message']) && $_GET['message'] == 'field_saved') { add_settings_error('wpaam-notices', 'field-saved', __('Field successfully updated.', 'wpaam'), 'updated'); } } // messages for tools page if ($screen->base == 'users_page_wpaam-tools') { if (isset($_GET['message']) && $_GET['message'] == 'settings_imported') { add_settings_error('wpaam-notices', 'settings-imported', __('Settings successfully imported.', 'wpaam'), 'updated'); } } settings_errors('wpaam-notices'); }
/** * A simple wrapper function for the wp_logout_url function * * The function checks whether a custom url has been passed, * if not, looks for the settings panel option, * defaults to wp_logout_url * * @since 1.0.0 * @access public * @return string */ function wpaam_logout_url($custom_redirect = null) { $redirect = null; if (!empty($custom_redirect)) { $redirect = esc_url($custom_redirect); } else { if (wpaam_get_option('logout_redirect')) { $redirect = esc_url(get_permalink(wpaam_get_option('logout_redirect'))); } } return wp_logout_url(apply_filters('wpaam_logout_url', $redirect, $custom_redirect)); }
/** * Init the form. * * @access public * @since 1.0.0 * @return void */ public static function init() { add_action('wp', array(__CLASS__, 'process')); // Set values to the fields if (!is_admin()) { self::$user = wp_get_current_user(); } // Store uploaded avatar if (wpaam_get_option('custom_avatars')) { //add_action( 'wpaam_after_user_update', array( __CLASS__, 'add_avatar' ), 10, 3 ); } }
/** * Construction function. * * @param string $file file path. * @param string $item_name item name. * @param string $version version of the addon. * @param string $author author of the addon. */ public function __construct($file, $item_name, $version, $author, $_api_url = null) { $this->file = $file; $this->item_name = $item_name; $this->version = $version; $this->author = $author; if (!empty($_api_url)) { $this->api_url = $_api_url; } $this->item_shortname = 'wpaam_' . preg_replace('/[^a-zA-Z0-9_\\s]/', '', str_replace(' ', '_', strtolower($this->item_name))); $this->license = trim(wpaam_get_option($this->item_shortname . '_license_key', '')); $this->includes(); $this->hooks(); }
/** * Allows login form to redirect to an url specified into a query string. * * @since 1.1.0 * @param string $url url * @return string url specified into the query string */ function wpaam_login_redirect_detection($url) { if (isset($_GET['redirect_to']) && $_GET['redirect_to'] !== '') { $url = urldecode($_GET['redirect_to']); } elseif (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] !== '' && !wpaam_get_option('always_redirect')) { $url = $_SERVER['HTTP_REFERER']; } elseif (wpaam_get_option('login_redirect')) { $url = get_permalink(wpaam_get_option('login_redirect')); } return esc_url($url); }
* Email Header * @version 1.1.0 */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly // For gmail compatibility, including CSS styles in head/body are stripped out therefore styles need to be inline. These variables contain rules which are added to the template inline. !important; is a gmail hack to prevent styles being stripped if it doesn't like something. $body = "\n\tbackground-color: #f6f6f6;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n"; $wrapper = "\n\twidth:100%;\n\t-webkit-text-size-adjust:none !important;\n\tmargin:0;\n\tpadding: 70px 0 70px 0;\n"; $template_container = "\n\tbox-shadow:0 0 0 1px #f3f3f3 !important;\n\tborder-radius:3px !important;\n\tbackground-color: #ffffff;\n\tborder: 1px solid #e9e9e9;\n\tborder-radius:3px !important;\n\tpadding: 20px;\n"; $template_header = "\n\tcolor: #00000;\n\tborder-top-left-radius:3px !important;\n\tborder-top-right-radius:3px !important;\n\tborder-bottom: 0;\n\tfont-weight:bold;\n\tline-height:100%;\n\ttext-align: center;\n\tvertical-align:middle;\n"; $body_content = "\n\tborder-radius:3px !important;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n"; $body_content_inner = "\n\tcolor: #000000;\n\tfont-size:14px;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n\tline-height:150%;\n\ttext-align:left;\n"; $header_content_h1 = "\n\tcolor: #000000;\n\tmargin:0;\n\tpadding: 28px 24px;\n\tdisplay:block;\n\tfont-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;\n\tfont-size:32px;\n\tfont-weight: 500;\n\tline-height: 1.2;\n"; $header_img = wpaam_get_option('email_logo', ''); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo get_bloginfo('name'); ?> </title> </head> <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="<?php echo $body; ?> "> <div style="<?php
<?php if ($register == 'yes') { ?> <p class="wpaam-register-url"> <?php echo apply_filters('wpaam_registration_link_label', sprintf(__('Don\'t have an account? <a href="%s">Signup Now »</a>', 'wpaam'), esc_url(get_permalink(wpaam_get_option('registration_page'))))); ?> </p> <?php } ?> <?php if ($password == 'yes') { ?> <p class="wpaam-password-recovery-url"> <a href="<?php echo esc_url(get_permalink(wpaam_get_option('password_recovery_page'))); ?> "> <?php echo apply_filters('wpaam_password_link_label', __('Lost your password?', 'wpaam')); ?> </a> </p> <?php } ?> </div>
/** * Validate username field. * * @access public * @since 1.0.0 * @return void */ public static function validate_username($passed, $fields, $values) { $nickname = $values['register']['username']; if (wpaam_get_option('exclude_usernames') && array_key_exists($nickname, wpaam_get_disabled_usernames())) { return new WP_Error('nickname-validation-error', __('This nickname cannot be used.', 'wpaam')); } // Check for nicknames if permalink structure requires unique nicknames. if (get_option('wpaam_permalink') == 'nickname') { $current_user = wp_get_current_user(); if ($username !== $current_user->user_nicename && wpaam_nickname_exists($username)) { return new WP_Error('username-validation-error', __('This nickname cannot be used.', 'wpaam')); } } return $passed; }
/** * Get the enabled email template * * @since 1.0.0 */ public function get_template() { if (!$this->template) { $this->template = wpaam_get_option('email_template', 'none'); } return apply_filters('wpaam_email_template', $this->template); }
/** * Returns the url where users are redirected after a successfull registration. * * @since 1.1.0 * @return string redirect url */ function wpaam_registration_redirect_url() { $url = false; if (wpaam_get_option('registration_redirect')) { $url = get_permalink(wpaam_get_option('registration_redirect')); } return apply_filters('wpaam_registration_redirect_url', $url); }
/** * Handles resetting the user's password. * * @access public * @param object $user The user * @param string $new_pass New password for the user in plaintext * @return void */ public static function change_password($user, $new_pass) { do_action('password_reset', $user, $new_pass); wp_set_password($new_pass, $user->ID); if (!wpaam_get_option('disable_admin_password_recovery_email')) { wp_password_change_notification($user); } }
/** * Get the list of account fields formatted into an array. * The format of the array is used by the forms. * * @since 1.0.0 * @return array - list of fields. */ function wpaam_get_account_fields() { // Get fields from the database $primary_group = wpaam()->field_groups->get_group_by('primary'); $args = array('id' => $primary_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) { // Adjust field type parameter if no field type template is defined. switch ($field['type']) { case 'username': case 'nickname': case 'url': $field['type'] = 'text'; break; case 'display_name': $field['type'] = 'text'; break; case 'avatar': $field['type'] = 'file'; 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'], 'placeholder' => apply_filters('wpaam_profile_field_placeholder', null, $field), 'options' => apply_filters('wpaam_profile_field_options', null, $field), 'value' => apply_filters('wpaam_profile_field_value', null, $field)), $field['options']); } // Remove password field from here unset($fields['password']); // The username cannot be changed, let's remove that field since it's useless unset($fields['username']); // Remove the user avatar field if not enabled if (!wpaam_get_option('custom_avatars')) { unset($fields['user_avatar']); } return apply_filters('wpaam_get_account_fields', $fields); }
/** * Loads the plugin frontend assets files * * @since 1.0.0 * @return void */ function wpaam_frontend_cssjs() { $js_dir = WPAAM_PLUGIN_URL . 'assets/js/'; $css_dir = WPAAM_PLUGIN_URL . 'assets/css/'; // Use minified libraries if SCRIPT_DEBUG is turned off $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // Default URL $url = $css_dir . 'wp_user_manager_frontend' . $suffix . '.css'; $file = 'wp_user_manager_frontend' . $suffix . '.css'; $templates_dir = 'wpaam/'; $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()) . $templates_dir . $file; $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()) . $templates_dir . 'wp_user_manager_frontend.css'; $parent_theme_style_sheet = trailingslashit(get_template_directory()) . $templates_dir . $file; $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()) . $templates_dir . 'wp_user_manager_frontend.css'; $wpaam_plugin_style_sheet = trailingslashit(wpaam_get_templates_dir()) . $file; // Look in the child theme directory first, followed by the parent theme, followed by the wpaam core templates directory // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled. // This allows users to copy just wp_user_manager_frontend.css to their theme if (file_exists($child_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2))) { if (!empty($nonmin)) { $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . 'wp_user_manager_frontend.css'; } else { $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . $file; } } elseif (file_exists($parent_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2))) { if (!empty($nonmin)) { $url = trailingslashit(get_template_directory_uri()) . $templates_dir . 'wp_user_manager_frontend.css'; } else { $url = trailingslashit(get_template_directory_uri()) . $templates_dir . $file; } } elseif (file_exists($wpaam_plugin_style_sheet) || file_exists($wpaam_plugin_style_sheet)) { $url = trailingslashit(wpaam_get_templates_url()) . $file; } // Styles & scripts registration wp_register_script('wpaam-frontend-js', $js_dir . 'wp_user_manager' . $suffix . '.js', array('jquery'), WPAAM_VERSION, true); wp_register_style('wpaam-frontend-css', $url, WPAAM_VERSION); // Enqueue everything wp_enqueue_script('jQuery'); wp_enqueue_script('wpaam-frontend-js'); // Allows developers to disable the frontend css in case own file is needed. if (!defined('wpaam_DISABLE_CSS')) { wp_enqueue_style('wpaam-frontend-css'); } // Display password meter only if enabled if (wpaam_get_option('display_password_meter_registration')) { wp_enqueue_script('password-strength-meter'); wp_localize_script('password-strength-meter', 'pwsL10n', array('empty' => __('Strength indicator', 'wpaam'), 'short' => __('Very weak', 'wpaam'), 'bad' => __('Weak', 'wpaam'), 'good' => _x('Medium', 'password strength', 'wpaam'), 'strong' => __('Strong', 'wpaam'))); } // Frontend jS Settings wp_localize_script('wpaam-frontend-js', 'wpaam_frontend_js', array('ajax' => admin_url('admin-ajax.php'), 'checking_credentials' => __('Checking credentials...', 'wpaam'), 'pwd_meter' => wpaam_get_option('display_password_meter_registration'), 'disable_ajax' => wpaam_get_option('disable_ajax'))); }
/** * Email template tag: recovery_url * * @param int $user_id * @param int $private_key * @return string url */ function wpaam_email_tag_recovery_url($user_id, $private_key) { $username = get_userdata($user_id); $username = esc_attr($username->user_login); $url = add_query_arg(array('password-reset' => true, 'key' => $private_key, 'login' => $username), get_permalink(wpaam_get_option('password_recovery_page'))); return esc_url_raw($url); }
/** * Authenticate the user and decide which login method to use. * * @since 1.0.3 * @param string $user user object * @param string $username typed username * @param string $password typed password * @return void Results of autheticating via wp_authenticate_username_password(), using the username found when looking up via email. */ function wpaam_authenticate_login_method($user, $username, $password) { // Get default login method $login_method = wpaam_get_option('login_method', 'username'); // Authenticate via email only if ($login_method == 'email') { if (is_a($user, 'WP_User')) { return $user; } if (!empty($username) && is_email($username)) { $user = get_user_by('email', $username); if (isset($user, $user->user_login, $user->user_status) && 0 == (int) $user->user_status) { $username = $user->user_login; } return wp_authenticate_username_password(null, $username, $password); } } else { if ($login_method == 'username_email') { if (is_a($user, 'WP_User')) { return $user; } $username = sanitize_user($username); if (!empty($username) && is_email($username)) { $user = get_user_by('email', $username); if (isset($user, $user->user_login, $user->user_status) && 0 == (int) $user->user_status) { $username = $user->user_login; } return wp_authenticate_username_password(null, $username, $password); } else { return wp_authenticate_username_password(null, $username, $password); } } } }
/** * Checks if members can view profiles. * * @since 1.0.0 * @return bool */ function wpaam_members_can_view_profiles() { $pass = false; if (wpaam_get_option('members_can_view_profiles')) { $pass = true; } return $pass; }
</div> </fieldset> <fieldset class="fieldset-client_prefix"> <label for="client_prefix">Set Client Prefix </label> <div class="field"> <input type="text" value="<?php if ($client_prefix) { echo $client_prefix; } ?> " placeholder="" id="client_prefix" name="client_prefix" class="input-name"> </div> </fieldset> <?php if (wpaam_get_option('custom_avatars')) { ?> <fieldset class="fieldset-company_logo" data-type="file" data-label="Profile Picture" data-required="0" data-name="company_logo"> <label for="company_logo">Company Logo </label> <div class="field "> <div class="wpaam-uploaded-files"> </div> <input id="company_logo" class="input-upload" type="file" name="company_logo"> <small class="description"> Maximum file size: 2 MB.</small> </div> </fieldset> <?php } ?> <?php