예제 #1
0
 function postInsertUser()
 {
     global $userMeta;
     //$userMeta->dump($_REQUEST);die();
     $userMeta->verifyNonce();
     $umUserInsert = new umUserInsert();
     return $umUserInsert->postInsertUserProcess();
     $errors = new WP_Error();
     $user_ID = get_current_user_id();
     /// Determine $userID
     $userID = $user_ID;
     if (isset($_REQUEST['user_id'])) {
         $user = new WP_User($user_ID);
         if ($user->has_cap('add_users') && $_REQUEST['user_id']) {
             $userID = esc_attr($_REQUEST['user_id']);
         }
     }
     $user = new WP_User($userID);
     /// $_REQUEST Validation
     $actionType = @$_REQUEST['action_type'];
     if (empty($actionType)) {
         $errors->add('empty_action_type', __('Action type is empty', $userMeta->name));
     }
     if (!isset($_REQUEST['form_key'])) {
         $errors->add('empty_form_name', __('Form name is empty', $userMeta->name));
     }
     /// Determine $actionType
     $actionType = strtolower($actionType);
     if ($actionType == 'profile-registration') {
         if ($user_ID) {
             $actionType = 'profile';
         } else {
             $actionType = 'registration';
         }
     }
     $formName = $_REQUEST['form_key'];
     $formBuilder = new umFormGenerate($formName, $actionType, $userID);
     if (!$formBuilder->isFound()) {
         $errors->add('not_found', sprintf(__('Form "%s" is not found.', $userMeta->name), $formName));
     }
     /// filter valid key for update
     //$validFields = $userMeta->formValidInputField( @$_REQUEST['form_key'] );
     $validFields = $formBuilder->validInputFields();
     if (!$validFields) {
         $errors->add('empty_field', __('No field to update', $userMeta->name));
     }
     /// Showing error
     if ($errors->get_error_code()) {
         return $userMeta->ShowError($errors);
     }
     // Free version limitation
     //if( ( $actionType <> 'profile' ) && ! ( $userMeta->isPro ) )
     //return $userMeta->showError( sprintf( __( 'type="%s" is not supported in free version', $userMeta->name ), $actionType ) );
     /// Assign $fieldName,$field to $userData. Also validating required and unique
     foreach ($validFields as $fieldName => $field) {
         $field = apply_filters('user_meta_field_config', $field, $field['id'], $formName, $userID);
         if ($actionType == 'profile') {
             if ($fieldName == 'user_login' || $fieldName == 'user_pass' && empty($_REQUEST['user_pass'])) {
                 continue;
             }
         }
         if ($field['field_type'] == 'custom' && isset($field['input_type']) && $field['input_type'] == 'password') {
             if (empty($_REQUEST[$fieldName])) {
                 continue;
             }
         }
         /// Assigning data to $userData
         $userData[$fieldName] = @$_REQUEST[$fieldName];
         if (is_array($userData[$fieldName]) && count($userData[$fieldName]) == 1 && !empty($userData[$fieldName])) {
             $userData[$fieldName] = $userData[$fieldName][0];
         }
         /// Handle non-ajax file upload
         if (in_array($field['field_type'], array('user_avatar', 'file'))) {
             if (isset($_FILES[$fieldName])) {
                 $extensions = !empty($field['allowed_extension']) ? $field['allowed_extension'] : "jpg,png,gif";
                 $maxSize = !empty($field['max_file_size']) ? $field['max_file_size'] * 1024 : 1024 * 1024;
                 $file = $userMeta->fileUpload($fieldName, $extensions, $maxSize);
                 if (is_wp_error($file)) {
                     if ($file->get_error_code() != 'no_file') {
                         $errors->add($file->get_error_code(), $file->get_error_message());
                     }
                 } else {
                     if (is_string($file)) {
                         $umFile = new umFile();
                         $umFile->initFile($field);
                         $userData[$fieldName] = $file;
                     }
                 }
             }
             $userMeta->removeFromFileCache($userData[$fieldName]);
         }
         /*
          * Using umField Class
          */
         if (!isset($field['field_value'])) {
             $field['field_value'] = $userData[$fieldName];
         }
         $umField = new umField($field['id'], $field, array('user_id' => $userID, 'insert_type' => $actionType));
         if ($fieldName == 'user_pass' && $actionType == 'registration') {
             $umField->addRule('required');
         }
         if ($fieldName == 'user_pass' && $actionType == 'profile') {
             if (!empty($field['required_current_password'])) {
                 $umField->addRule('current_password');
             }
         }
         if (isset($_REQUEST[$fieldName . "_retype"])) {
             $umField->addRule('equals');
         }
         if (!$umField->validate()) {
             foreach ($umField->getErrors() as $errKey => $errVal) {
                 $errors->add($errKey, $errVal);
             }
         }
         /*if( isset($_REQUEST[ $fieldName . "_retype" ]) && !empty($_REQUEST[$fieldName]) ){
               if( $_REQUEST[ $fieldName . "_retype" ] != $_REQUEST[$fieldName] )
                   $errors->add( 'retype_required', sprintf( __( '%s field is required to retype', $userMeta->name ), $fieldData['field_title'] ) );
           }
           
           if( $fieldData[ 'unique' ] ){
               $available = $userMeta->isUserFieldAvailable( $fieldName, $userData[ $fieldName ], $userID );
               if( ! $available )
                   $errors->add( 'existing_' . $fieldName, sprintf( __( '%1$s: "%2$s" already taken', $userMeta->name ), $fieldData[ 'field_title' ], $userData[ $fieldName ] ) );								
           }*/
     }
     // If add_user_to_blog set true in UserMeta settings panel
     if (is_multisite() && $actionType == 'registration') {
         $registrationSettings = $userMeta->getSettings('registration');
         if (!empty($registrationSettings['add_user_to_blog'])) {
             if (in_array('existing_user_login', $errors->get_error_codes())) {
                 unset($errors->errors['existing_user_login']);
             }
             if (in_array('existing_user_email', $errors->get_error_codes())) {
                 unset($errors->errors['existing_user_email']);
             }
         }
     }
     if (empty($userData)) {
         return $userMeta->ShowError(__('No data to update', $userMeta->name));
     }
     // Showing error
     if ($errors->get_error_code()) {
         return $userMeta->ShowError($errors);
     }
     /// Run Captcha validation after completed all other validation
     $captchaValidation = $userMeta->isInvalidateCaptcha();
     if ($captchaValidation) {
         $errors->add('invalid_captcha', $captchaValidation);
         return $userMeta->ShowError($errors);
     }
     /**
      * Check allowed role for security purpose
      */
     if (isset($userData['role'])) {
         $ignoreRole = true;
         //$fieldData = $userMeta->getFieldData( @$_REQUEST['role_field_id'] );
         $field = $formBuilder->getField(@$_REQUEST['role_field_id']);
         if (is_array(@$field['allowed_roles'])) {
             if (in_array($userData['role'], $field['allowed_roles'])) {
                 $ignoreRole = false;
             }
         }
         if ($ignoreRole) {
             unset($userData['role']);
         }
     }
     if ($actionType == 'registration') {
         return $userMeta->registerUser($userData, @$imageCache);
     }
     $html = null;
     if ($actionType == 'profile') {
         if (!$user_ID) {
             return $userMeta->showError(__('User must be logged in to update profile', $userMeta->name));
         }
         $userData = apply_filters('user_meta_pre_user_update', $userData, $userID, $formName);
         if (is_wp_error($userData)) {
             return $userMeta->showError($userData);
         }
         /**
          * Profile Update modified data
          */
         $modifiedData = array();
         foreach ($userData as $key => $val) {
             if ($user->{$key} != $val) {
                 $modifiedData[$key] = $user->{$key};
             }
         }
         $response = $userMeta->insertUser($userData, $userID);
         if (is_wp_error($response)) {
             return $userMeta->showError($response);
         }
         if (!empty($modifiedData)) {
             $storedData = get_transient($userMeta->prefix . 'user_modified_data');
             if (empty($storedData)) {
                 $storedData = array();
             }
             $storedData[$userID] = $modifiedData;
             set_transient($userMeta->prefix . 'user_modified_data', $storedData, 30);
         }
         /**
          * End Profile Update modified data
          */
         /// Allow to populate form data based on DB instead of $_REQUEST
         $userMeta->showDataFromDB = true;
         // Commented since 1.1.5rc3
         //if( isset( $imageCache ) )
         //$userMeta->removeCache( 'image_cache', $imageCache, false );
         do_action('user_meta_after_user_update', (object) $response, $formName);
         $message = $userMeta->getMsg('profile_updated');
         $html = "<div action_type='{$actionType}'>" . $userMeta->showMessage($message) . "</div>";
     }
     return $userMeta->printAjaxOutput($html);
 }
예제 #2
0
 function fileUploadExtensions($allowedExtensions)
 {
     global $userMeta;
     if (isset($_REQUEST['field_id'])) {
         if ($_REQUEST['field_id'] == 'csv_upload_user_import') {
             $allowedExtensions = array("csv");
         } elseif ($_REQUEST['field_id'] == 'txt_upload_ump_import') {
             $allowedExtensions = array("txt");
         } elseif (strpos($_REQUEST['field_id'], 'um_field_') !== false) {
             if (empty($_REQUEST['form_key'])) {
                 return $allowedExtensions;
             }
             $formName = esc_attr($_REQUEST['form_key']);
             if (!empty($formName)) {
                 $form = new umFormGenerate($formName, null, null);
                 $validFields = $form->validInputFields();
                 if (!empty($validFields[$_REQUEST['field_name']])) {
                     $field = $validFields[$_REQUEST['field_name']];
                     if (!empty($field['allowed_extension'])) {
                         $allowedExtensions = str_replace(' ', '', $field['allowed_extension']);
                         $allowedExtensions = explode(",", $allowedExtensions);
                     }
                 }
             }
             /*$fieldID = str_replace( "um_field_", "", $_REQUEST['field_id'] );
               $fields = $userMeta->getData( 'fields' );
               if ( isset( $fields[$fieldID]['allowed_extension'] ) ) {
                   $allowedExtensions = str_replace( ' ', '', $fields[$fieldID]['allowed_extension'] );
                   $allowedExtensions = explode( ",", $allowedExtensions );      
               }*/
         }
     }
     return $allowedExtensions;
 }
예제 #3
0
 public function ajaxUpload()
 {
     global $userMeta;
     if (isset($_REQUEST['form_key'])) {
         $formName = esc_attr($_REQUEST['form_key']);
     }
     if (!empty($formName)) {
         $form = new umFormGenerate($formName, null, null);
         $validFields = $form->validInputFields();
         if (empty($validFields[$_REQUEST['field_name']])) {
             return;
         }
         $field = $validFields[$_REQUEST['field_name']];
     } else {
         if (!empty($_REQUEST['field_id'])) {
             $id = trim(str_replace('um_field_', '', esc_attr($_REQUEST['field_id'])));
             $umField = new umField($id);
             $field = $umField->getData();
         }
     }
     if (!empty($field)) {
         if (!empty($_REQUEST['filepath'])) {
             $field['field_value'] = esc_attr($_REQUEST['filepath']);
         }
         $this->initFile($field);
         echo $this->showFile();
     }
 }
예제 #4
0
파일: umMethods.php 프로젝트: robbenz/plugs
 function userUpdateRegisterProcess($actionType, $formName, $rolesForms = null)
 {
     global $userMeta;
     $userMeta->enqueueScripts(array('user-meta', 'jquery-ui-all', 'fileuploader', 'wysiwyg', 'jquery-ui-datepicker', 'jquery-ui-slider', 'timepicker', 'validationEngine', 'password_strength', 'placeholder', 'multiple-select'));
     $userMeta->runLocalization();
     $actionType = strtolower($actionType);
     if (empty($actionType)) {
         return $userMeta->showError(__('Please provide a name of action type.', $userMeta->name));
     }
     if (!$userMeta->validActionType($actionType)) {
         return $userMeta->showError(sprintf(__('Sorry. type="%s" is not valid.', $userMeta->name), $actionType));
     }
     /*if ( ! $userMeta->isPro() ) {
           if ( ! in_array( $actionType, array('profile','public') ) )
               return $userMeta->showError( "type='$actionType' is only supported, in pro version. Get " . $userMeta->getProLink( 'User Meta Pro' ), "info", false );                                    
       }*/
     $user = wp_get_current_user();
     $userID = isset($user->ID) ? (int) $user->ID : 0;
     $isLoggedIn = !empty($userID);
     if ($actionType == 'profile-registration') {
         $actionType = $isLoggedIn ? 'profile' : 'registration';
     }
     // Checking Permission
     if ($actionType == 'profile') {
         if (!$isLoggedIn) {
             $msg = $userMeta->getMsg('profile_required_loggedin');
             return empty($msg) ? null : $userMeta->showMessage($msg, 'info');
         }
         if (!empty($_REQUEST['user_id'])) {
             if ($userID != esc_attr($_REQUEST['user_id'])) {
                 if ($user->has_cap('add_users')) {
                     $userID = esc_attr($_REQUEST['user_id']);
                     $user = get_user_by('id', $userID);
                     if (empty($user)) {
                         return $userMeta->showError(__('No user found!.', $userMeta->name));
                     }
                 } else {
                     return $userMeta->showError(__("You do not have permission to access user profile.", $userMeta->name));
                 }
             }
             /*if( $user->has_cap( 'add_users' ) ){
                   $userID =  esc_attr( $_REQUEST['user_id'] );
                   $user = get_user_by('id', $userID);
                   if( empty($user) )
                       return $userMeta->showError( __( 'No user found!.', $userMeta->name ) );
               }else
                   return $userMeta->showError( __( "You do not have permission to access user profile.", $userMeta->name ) );*/
         }
     } elseif ($actionType == 'registration') {
         if ($isLoggedIn && !$user->has_cap('add_users')) {
             return $userMeta->showMessage(sprintf(__('You have already registered. See your <a href="%s">profile</a>', $userMeta->name), $userMeta->getProfileLink()), 'info');
         } elseif (!apply_filters('user_meta_allow_registration', true)) {
             return $userMeta->showError(__('User registration is currently not allowed.', $userMeta->name));
         }
         //elseif ( ! get_option( 'users_can_register' ) )
     } elseif ($actionType == 'public') {
         if (!empty($_REQUEST['user_id'])) {
             $userID = esc_attr($_REQUEST['user_id']);
             $user = get_user_by('id', $userID);
             if (empty($user)) {
                 return $userMeta->showError(__('No user found!.', $userMeta->name));
             }
         } else {
             if (!$isLoggedIn) {
                 $msg = $userMeta->getMsg('public_non_lggedin_msg');
                 return empty($msg) ? null : $userMeta->showMessage($msg, 'info');
             }
         }
     }
     if (!empty($rolesForms)) {
         if (is_string($rolesForms)) {
             $rolesForms = $userMeta->toArray($rolesForms);
         }
         if ($userID && in_array($actionType, array('profile', 'public'))) {
             $role = $userMeta->getUserRole($userID);
             if (isset($rolesForms[$role])) {
                 $formName = $rolesForms[$role];
             }
         }
     }
     if (empty($formName)) {
         return $userMeta->showError(__('Please provide a form name.', $userMeta->name));
     }
     $formBuilder = new umFormGenerate($formName, $actionType, $userID);
     if (!$formBuilder->isFound()) {
         return $userMeta->ShowError(sprintf(__('Form "%s" is not found.', $userMeta->name), $formName));
     }
     //$savedValues = in_array( $actionType, array('profile','public') ) ? get_userdata( $userID ) : null;
     $form = $formBuilder->getForm();
     //$userMeta->dump($form);
     /*$form   = $userMeta->getFormData( $formName ); 
       if ( is_wp_error( $form ) )
           return $userMeta->ShowError( $form );*/
     $form['form_class'] = !empty($form['form_class']) ? $form['form_class'] : '';
     $form['form_class'] = 'um_user_form ' . $form['form_class'];
     if (empty($form['disable_ajax'])) {
         $form['onsubmit'] = "umInsertUser(this);";
     }
     $output = $userMeta->render('generateForm', array('form' => $form, 'actionType' => $actionType, 'userID' => $userID, 'methodName' => 'InsertUser'));
     return $output;
 }