예제 #1
0
 /**
  * Replaces the default wp_new_user_notification function of the core.
  *
  * Email login credentials to a newly-registered user.
  * A new user registration notification is also sent to admin email.
  *
  * @since 1.0.0
  * @access public
  * @return void
  */
 function wp_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 (!wpum_get_option('disable_admin_register_email')) {
         $message = sprintf(__('New user registration on your site %s:', 'wpum'), $blogname) . "\r\n\r\n";
         $message .= sprintf(__('Username: %s', 'wpum'), $user->user_login) . "\r\n\r\n";
         $message .= sprintf(__('E-mail: %s', 'wpum'), $user->user_email) . "\r\n";
         wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration', 'wpum'), $blogname), $message);
     }
     /* == Send notification to the user now == */
     if (empty($plaintext_pass)) {
         return;
     }
     // Check if email exists first
     if (wpum_email_exists('register')) {
         // Retrieve the email from the database
         $register_email = wpum_get_email('register');
         $message = wpautop($register_email['message']);
         $message = wpum_do_email_tags($message, $user_id, $plaintext_pass);
         WPUM()->emails->__set('heading', __('Your account', 'wpum'));
         WPUM()->emails->send($user->user_email, $register_email['subject'], $message);
     }
 }
예제 #2
0
 private function create_custom_fields()
 {
     // Get primary group id
     $primary_group = WPUM()->field_groups->get_group_by('primary');
     $fields = array(array('group_id' => $primary_group->id, 'type' => 'username', 'name' => 'Username', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => false, 'meta' => 'username'), array('group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Prénom', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => true, 'meta' => 'first_name'), array('group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Nom', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => true, 'meta' => 'last_name'), array('group_id' => $primary_group->id, 'type' => 'email', 'name' => 'Email', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => false, 'meta' => 'user_email'), array('group_id' => $primary_group->id, 'type' => 'password', 'name' => 'Password', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => false, 'meta' => 'password'), array('group_id' => $primary_group->id, 'type' => 'email', 'name' => 'Email responsable', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => true, 'meta' => 'responsable_email'), array('group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Adresse professionnel', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => true, 'meta' => 'address_pro'), array('group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Direction appartenance', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => true, 'meta' => 'direction_appartenance'), array('group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Téléphone', 'is_required' => false, 'show_on_registration' => true, 'can_delete' => true, 'meta' => 'user_phone'));
     foreach ($fields as $field) {
         WPUM()->fields->add($field);
     }
 }
 /**
  * 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 (wpum_get_option('custom_passwords')) {
         self::$random_password = false;
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_password'), 10, 3);
         if (wpum_get_option('display_password_meter_registration')) {
             add_action('wpum/form/register/after/field=password', 'wpum_psw_indicator', 10);
         }
         if (wpum_get_option('login_after_registration')) {
             add_action('wpum/form/register/success', array(__CLASS__, 'do_login'), 11, 3);
         }
     }
     // Make sure the submitted email is valid and not in use.
     add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_email'), 10, 3);
     // Add a very basic honeypot spam prevention field.
     if (wpum_get_option('enable_honeypot')) {
         add_action('wpum_get_registration_fields', array(__CLASS__, 'add_honeypot'));
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_honeypot'), 10, 3);
     }
     /**
      * Adds a "terms" checkbox field to the signup form.
      */
     if (wpum_get_option('enable_terms')) {
         add_action('wpum_get_registration_fields', array(__CLASS__, 'add_terms'));
     }
     // Allow user to select a user role upon registration.
     if (wpum_get_option('allow_role_select')) {
         add_action('wpum_get_registration_fields', array(__CLASS__, 'add_role'));
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_role'), 10, 3);
         add_action('wpum/form/register/success', array(__CLASS__, 'save_role'), 10, 10);
     }
     // Prevent users from using specific usernames if enabled.
     $exclude_usernames = wpum_get_option('exclude_usernames');
     if (!empty($exclude_usernames)) {
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_username'), 10, 3);
     }
     // Store uploaded avatars into the database.
     if (wpum_get_option('custom_avatars') && WPUM()->fields->show_on_registration('user_avatar')) {
         add_action('wpum/form/register/success', array(__CLASS__, 'save_avatar'), 10, 3);
     }
     // Redirect to a page after successfull registration.
     if (wpum_get_option('login_after_registration') && wpum_get_option('custom_passwords') && wpum_get_option('registration_redirect')) {
         add_filter('wpum_redirect_after_automatic_login', array(__CLASS__, 'adjust_redirect_url'), 10, 2);
     } elseif (!wpum_get_option('login_after_registration') || !wpum_get_option('custom_passwords')) {
         if (wpum_get_option('registration_redirect')) {
             add_action('wpum/form/register/success', array(__CLASS__, 'redirect_on_success'), 9999, 3);
         }
     }
 }
예제 #4
0
 /**
  * Display widget content.
  *
  * @access private
  * @since 1.0.0
  * @return void
  */
 public function widget($args, $instance)
 {
     $output = $args['before_widget'];
     $output .= $args['before_title'];
     $output .= $instance['title'];
     $output .= $args['after_title'];
     $atts = array('form_id' => $instance['form_id'], 'login_link' => $instance['login_link'], 'psw_link' => $instance['psw_link'], 'register_link' => $instance['register_link']);
     // Set default values
     if (!array_key_exists('form_id', $atts) || empty($atts['form_id'])) {
         $atts['form_id'] = 'default_registration_form';
     }
     $output .= WPUM()->forms->get_form('register', $atts);
     $output .= $args['after_widget'];
     echo $output;
 }
예제 #5
0
/**
 * Upgrade function required to fix bug in v1.2.0
 * The bug caused certain fields to set themselves as not required anymore.
 * This function fixes the must-required fields and sets them as required again.
 *
 * @since 1.2.1
 * @return void
 */
function wpum_upgrade_function_v121()
{
    if (get_option('wpum_did_121_update')) {
        return;
    }
    // Get fields from the database
    $primary_group = WPUM()->field_groups->get_group_by('primary');
    $args = array('id' => $primary_group->id, 'array' => true, 'number' => -1);
    $data = WPUM()->fields->get_by_group($args);
    foreach ($data as $key => $field) {
        if ($field['meta'] == 'username' || $field['meta'] == 'user_email' || $field['meta'] == 'password' || $field['meta'] == 'nickname' || $field['meta'] == 'display_name' || $field['meta'] == 'display_name') {
            WPUM()->fields->update($field['id'], array('is_required' => true));
        }
    }
    update_option('wpum_did_121_update', true);
}
 /**
  * Display widget content.
  *
  * @access private
  * @since 1.0.0
  * @return void
  */
 public function widget($args, $instance)
 {
     ob_start();
     echo $args['before_widget'];
     echo $args['before_title'];
     echo $instance['title'];
     echo $args['after_title'];
     $atts = array('form_id' => $instance['form_id'], 'login_link' => $instance['login_link'], 'psw_link' => $instance['psw_link'], 'register_link' => $instance['register_link']);
     // Set default values
     if (!array_key_exists('form_id', $atts) || empty($atts['form_id'])) {
         $atts['form_id'] = 'default_password_form';
     }
     echo WPUM()->forms->get_form('password', $atts);
     echo $args['after_widget'];
     $output = ob_get_clean();
     echo $output;
 }
 /**
  * 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('wpum_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.', 'wpum'));
         return;
     }
     if (is_multisite() && !is_user_member_of_blog($user_data->ID, get_current_blog_id())) {
         self::add_error(__('Invalid username or e-mail.', 'wpum'));
         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', 'wpum'));
         return;
     } elseif (is_wp_error($allow)) {
         self::add_error(__('Password reset is not allowed for this user', 'wpum'));
         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 (wpum_email_exists('password')) {
         // Retrieve the email from the database
         $password_email = wpum_get_email('password');
         $message = wpautop($password_email['message']);
         $message = wpum_do_email_tags($message, $user_data->ID, $key);
         WPUM()->emails->__set('heading', __('Password Recovery', 'wpum'));
         WPUM()->emails->send($user_email, $password_email['subject'], $message);
         self::add_confirmation(__('Check your e-mail for the confirmation link.', 'wpum'));
     } else {
         return;
     }
     return true;
 }
예제 #8
0
?>
">
						<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 WPUM()->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;
 /**
  * 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 = WPUM()->field_groups->get_group_by('primary');
         $which_group = $primary_group->id;
     }
     $data = WPUM()->fields->get_by_group(array('id' => $which_group, 'array' => true, 'orderby' => 'field_order', 'order' => 'ASC'));
     return $data;
 }
예제 #10
0
/**
 * 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 wpum_get_group_fields_for_form($group_id)
{
    $args = array('id' => $group_id, 'array' => true, 'number' => -1, 'orderby' => 'field_order', 'order' => 'ASC');
    $data = WPUM()->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('wpum_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('wpum_get_group_fields_for_form', $fields, $group_id);
}
/**
 * Search content for email tags and filter email tags through their hooks
 *
 * @param string $content Content to search for email tags
 * @param int $user_id The user id
 * @param string $private_key the password
 *
 * @since 1.0.0
 *
 * @return string Content with email tags filtered out.
 */
function wpum_do_email_tags($content, $user_id, $private_key)
{
    // Replace all tags
    $content = WPUM()->email_tags->do_tags($content, $user_id, $private_key);
    // Return content
    return $content;
}
예제 #12
0
/**
 * Wrapper function to install fields database table and install primary fields.
 *
 * @since 1.0.0
 * @return void
 */
function wpum_install_fields()
{
    if (!get_option('wpum_version_upgraded_from')) {
        // Create database table for field groups
        @WPUM()->fields->create_table();
        // Get primary group id
        $primary_group = WPUM()->field_groups->get_group_by('primary');
        // Install fields
        $fields = array(array('id' => 1, 'group_id' => $primary_group->id, 'type' => 'username', 'name' => 'Username', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => false, 'meta' => 'username'), array('id' => 2, 'group_id' => $primary_group->id, 'type' => 'email', 'name' => 'Email', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => false, 'meta' => 'user_email'), array('id' => 3, 'group_id' => $primary_group->id, 'type' => 'password', 'name' => 'Password', 'is_required' => true, 'show_on_registration' => true, 'can_delete' => false, 'meta' => 'password'), array('id' => 4, 'group_id' => $primary_group->id, 'type' => 'text', 'name' => 'First Name', 'is_required' => false, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'first_name'), array('id' => 5, 'group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Last Name', 'is_required' => false, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'last_name'), array('id' => 6, 'group_id' => $primary_group->id, 'type' => 'nickname', 'name' => 'Nickname', 'is_required' => true, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'nickname'), array('id' => 7, 'group_id' => $primary_group->id, 'type' => 'display_name', 'name' => 'Display Name', 'is_required' => true, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'display_name'), array('id' => 8, 'group_id' => $primary_group->id, 'type' => 'text', 'name' => 'Website', 'is_required' => false, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'user_url'), array('id' => 9, 'group_id' => $primary_group->id, 'type' => 'textarea', 'name' => 'Description', 'is_required' => false, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'description'), array('id' => 10, 'group_id' => $primary_group->id, 'type' => 'avatar', 'name' => 'Profile Picture', 'is_required' => false, 'show_on_registration' => false, 'can_delete' => false, 'meta' => 'user_avatar'));
        foreach ($fields as $field) {
            WPUM()->fields->add($field);
        }
    }
}
예제 #13
0
                // Look in global /wp-content/languages/wpum folder
                load_textdomain('wpum', $mofile_global);
            } elseif (file_exists($mofile_local)) {
                // Look in local /wp-content/plugins/wp-user-manager/languages/ folder
                load_textdomain('wpum', $mofile_local);
            } else {
                // Load the default language files
                load_plugin_textdomain('wpum', false, $wpum_lang_dir);
            }
        }
    }
}
/**
 * The main function responsible for returning WP_User_Manager
 * Instance to functions everywhere.
 *
 * Use this function like you would a global variable, except without needing
 * to declare the global.
 *
 * Example: <?php $wpum = WPUM(); ?>
 *
 * @since 1.0.0
 * @return object WP_User_Manager Instance
 */
function WPUM()
{
    return WP_User_Manager::instance();
}
// Get WPUM Running
WPUM();
예제 #14
0
/**
 * Display content of the first tab into the account page.
 *
 * @since 1.0.0
 * @access public
 * @return void
 */
function wpum_show_psw_update_form($current_tab, $all_tabs, $form, $fields, $user_id, $atts)
{
    echo WPUM()->forms->get_form('update-password');
}
예제 #15
0
<div class="wpum-directory-search-form-wrapper">

  <form action="#" method="post" id="wpum-directory-search-form-<?php 
echo $directory_args['directory_id'];
?>
" class="wpum-directory-search-form" name="wpum-directory-search-form">

    <div class="form-fields">

      <?php 
do_action('wpum_directory_search_form_top_fields', $directory_args);
?>

      <?php 
$search_input = array('name' => 'search_user', 'value' => isset($_POST['search_user']) ? sanitize_text_field($_POST['search_user']) : '', 'placeholder' => esc_html__('Search for users', 'wpum'));
echo WPUM()->html->text($search_input);
?>

      <?php 
do_action('wpum_directory_search_form_bottom_fields', $directory_args);
?>

    </div>

    <div class="form-submit">
      <input type="submit" name="wpum_submit_user_search" id="wpum-submit-user-search" class="button wpum-button" value="<?php 
esc_html_e('Search', 'wpum');
?>
">
    </div>
 /**
  * Save the field to the database
  *
  * @access public
  * @return void
  */
 public function process_field()
 {
     // Check whether the form has been submitted
     if (isset($_POST['wpum-action']) && $_POST['wpum-action'] == 'save_field') {
         // nonce verification
         if (!wp_verify_nonce($_POST['_wpnonce'], 'wpum_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;
         }
         // 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']);
         }
         // Dirty fix for always required/show on registration fields.
         if ($this->field->meta == 'user_email' || $this->field->meta == 'username' || $this->field->meta == 'password') {
             unset($args['is_required']);
             unset($args['show_on_registration']);
         }
         if ($this->field->meta == 'nickname' || $this->field->meta == 'display_name') {
             unset($args['is_required']);
         }
         // Save the field
         if (WPUM()->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) {
                     wpum_update_field_option($field_id, 'display_full_name', true);
                 } elseif ($display_full_name === false) {
                     wpum_delete_field_option($field_id, 'display_full_name');
                 }
             }
             // Allow plugins to extend the save process
             do_action('wpum/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=wpum-profile-fields'));
             wp_redirect($admin_url);
             exit;
         }
     }
 }
 /**
  * Init the form.
  *
  * @access public
  * @since 1.0.0
  * @return void
  */
 public static function init()
 {
     add_action('wp', array(__CLASS__, 'process'));
     /**
      * The following hooks validate and process passwords,
      * they also execute functions that are only available when
      * custom passwords are enabled.
      *
      * 1 - Validate password strength
      * 2 - Add meter after password field
      * 3 - Execute automatic login
      * 
      */
     if (wpum_get_option('custom_passwords')) {
         self::$random_password = false;
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_password'), 10, 3);
         if (wpum_get_option('display_password_meter_registration')) {
             add_action('wpum/form/register/after/field=password', array(__CLASS__, 'add_psw_meter'), 10);
         }
         if (wpum_get_option('login_after_registration')) {
             add_action('wpum/form/register/success', array(__CLASS__, 'do_login'), 11, 3);
         }
     }
     /**
      * Make sure the submitted email is valid and not in use.
      */
     add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_email'), 10, 3);
     /**
      * The following hooks add a very basic honeypot spam prevention field.
      *
      * 1 - Adds new field within the registration fields array through filter.
      * 2 - Adds a new validation method through filter.
      *
      */
     if (wpum_get_option('enable_honeypot')) {
         add_action('wpum_get_registration_fields', array(__CLASS__, 'add_honeypot'));
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_honeypot'), 10, 3);
     }
     /**
      * Adds a "terms" checkbox field to the signup form.
      */
     if (wpum_get_option('enable_terms')) {
         add_action('wpum_get_registration_fields', array(__CLASS__, 'add_terms'));
     }
     /**
      * Allow user to select a user role upon registration.
      *
      * 1 - Adds new field within the registration form.
      * 2 - Adds a new validation method through filter.
      * 3 - Saves the selected role upon registration
      *
      */
     if (wpum_get_option('allow_role_select')) {
         add_action('wpum_get_registration_fields', array(__CLASS__, 'add_role'));
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_role'), 10, 3);
         add_action('wpum/form/register/success', array(__CLASS__, 'save_role'), 10, 10);
     }
     /**
      * Prevent users from using specific usernames if enabled
      */
     $exclude_usernames = wpum_get_option('exclude_usernames');
     if (!empty($exclude_usernames)) {
         add_filter('wpum/form/validate=register', array(__CLASS__, 'validate_username'), 10, 3);
     }
     /**
      * Store uploaded avatars into the database.
      */
     if (wpum_get_option('custom_avatars') && WPUM()->fields->show_on_registration('user_avatar')) {
         add_action('wpum/form/register/success', array(__CLASS__, 'save_avatar'), 10, 3);
     }
 }
 /**
  * Profile Edit Form Shortcode
  *
  * @access public
  * @since  1.0.0
  * @return $output shortcode output
  */
 public function wpum_account($atts, $content = null)
 {
     return WPUM()->forms->get_form('profile', $atts);
 }
 /**
  * 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('wpum_fields_editor_nonce', 'wpum_editor_nonce');
     // Abort if something isn't right.
     if (!is_admin() || !current_user_can('manage_options')) {
         $return = array('message' => __('Error.', 'wpum'));
         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']);
             WPUM()->fields->update((int) $field['field_id'], $args);
         }
     } else {
         $return = array('message' => __('Error.', 'wpum'));
         wp_send_json_error($return);
     }
     // Send message
     $return = array('message' => __('Fields order successfully updated.', 'wpum'));
     wp_send_json_success($return);
 }
 /**
  * Save the field to the database
  *
  * @access public
  * @return void
  */
 public function process_field()
 {
     // Check whether the form has been submitted
     if (isset($_POST['wpum-action']) && $_POST['wpum-action'] == 'save_field') {
         // nonce verification
         if (!wp_verify_nonce($_POST['_wpnonce'], 'wpum_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;
         }
         // 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);
         // 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) {
             unset($args['is_required']);
         }
         // Allow plugins to extend the save process
         do_action('wpum/fields/editor/single/before_save', $field_id, $group_id, $this->field, $this->field_object);
         // Save the field
         if (WPUM()->fields->update($field_id, $args)) {
             // Redirect now
             $admin_url = add_query_arg(array('message' => 'field_saved'), admin_url('users.php?page=wpum-profile-fields'));
             wp_redirect($admin_url);
             exit;
         }
     }
 }
예제 #21
0
/**
 * Fix the broken fields into the previous update.
 *
 * @since 1.2.6
 * @return void
*/
function wpum_run_fields_fix()
{
    if (is_admin() && current_user_can('manage_options') && isset($_GET['tool']) && $_GET['tool'] == 'restore-fields') {
        $primary_group = WPUM()->field_groups->get_group_by('primary');
        $args = array('id' => $primary_group->id, 'array' => true, 'number' => -1, 'orderby' => 'field_order', 'order' => 'ASC');
        $data = WPUM()->fields->get_by_group($args);
        foreach ($data as $key => $field) {
            if ($field['meta'] == 'username' || $field['meta'] == 'user_email' || $field['meta'] == 'password' || $field['meta'] == 'password') {
                $field_args = array('show_on_registration' => true, 'is_required' => true);
                WPUM()->fields->update($field['id'], $field_args);
            }
        }
        $url = add_query_arg(array('message' => 'fields_fixed'), admin_url('users.php?page=wpum-settings&tab=tools'));
        wp_redirect($url);
        exit;
    }
}