예제 #1
0
 public static function set_user_fields()
 {
     if (!isset(StaticClass::$_password_generated) && isset($_POST['user_pass'])) {
         StaticClass::$_password_generated = $_POST['user_pass'];
     }
     if (!isset(StaticClass::$_username_generated) && isset($_POST['user_login'])) {
         StaticClass::$_username_generated = sanitize_text_field($_POST['user_login']);
     }
     if (!isset(StaticClass::$_nickname_generated) && isset($_POST['nickname'])) {
         StaticClass::$_nickname_generated = sanitize_text_field($_POST['nickname']);
     }
 }
예제 #2
0
 public function CRED_extractUserFields($user_id, $user_role, $track = false)
 {
     global $user_ID;
     // reference to the form submission method
     global ${'_' . StaticClass::METHOD};
     $method =& ${'_' . StaticClass::METHOD};
     // get refs here
     $form =& $this->friendGet($this->_formBuilder, '&_formData');
     $out_ =& $this->friendGet($this->_formBuilder, '&out_');
     $form_id = $form->getForm()->ID;
     $zebraForm = $this->friendGet($this->_formBuilder, '_zebraForm');
     $_fields = $form->getFields();
     $form_type = $_fields['form_settings']->form['type'];
     $autogenerate_user = (bool) $_fields['form_settings']->form['autogenerate_username_scaffold'] ? true : false;
     $autogenerate_nick = (bool) $_fields['form_settings']->form['autogenerate_nickname_scaffold'] ? true : false;
     $autogenerate_pass = (bool) $_fields['form_settings']->form['autogenerate_password_scaffold'] ? true : false;
     $u = get_user_by('ID', $user_id);
     //user
     $post_type = $_fields['form_settings']->post['post_type'];
     $fields = $out_['fields'];
     $form_fields = $out_['form_fields'];
     // author
     //        if ('new' == $form_type)
     //            $post->post_author = $user_ID;
     // extract main post fields
     $user = array();
     $user['ID'] = $user_id;
     $user['user_role'] = $user_role;
     foreach ($form_fields as $name => $field) {
         if (array_key_exists($name, $method)) {
             $user[$name] = stripslashes($method[$name]);
         }
     }
     //###################################################################
     //# AUTOGENERATION EMAIL MESSAGE
     //###################################################################
     if ($form_type == 'new' && isset($user['user_email']) && ($autogenerate_user || $autogenerate_nick || $autogenerate_pass)) {
         $settings_model = CRED_Loader::get('MODEL/Settings');
         $settings = $settings_model->getSettings();
         //by default use notification for autogeneration email
         $use_notification_for_autogeneration = defined('CRED_NOTIFICATION_4_AUTOGENERATION') ? CRED_NOTIFICATION_4_AUTOGENERATION : true;
         $subject = "";
         $body = "";
         if (!$use_notification_for_autogeneration) {
             $subject = apply_filters('cuf_autogeneration_email_subject', $settings['autogeneration_email']['subject']);
             $body = apply_filters('cuf_autogeneration_email_body', $settings['autogeneration_email']['body']);
         }
         if ($autogenerate_pass && !isset($_POST['user_pass'])) {
             $password_generated = wp_generate_password(10, false);
             StaticClass::$_password_generated = $password_generated;
             $user["user_pass"] = $password_generated;
             //$message[] .= "Your password is: $password_generated";
             if (!$use_notification_for_autogeneration) {
                 $body = str_replace("%cuf_password%", $password_generated, $body);
             }
         }
         $username_generated = StaticClass::generateUsername($user['user_email']);
         if ($autogenerate_nick && !isset($_POST['nickname'])) {
             $nick_generated = $username_generated;
             StaticClass::$_nickname_generated = $nick_generated;
             $user["nickname"] = $nick_generated;
             //$message[] .= "Your password is: $password_generated";
             if (!$use_notification_for_autogeneration) {
                 $body = str_replace("%cuf_nickname%", $nick_generated, $body);
             }
         }
         if ($autogenerate_user && !isset($_POST['user_login'])) {
             $username_generated = $username_generated;
             StaticClass::$_username_generated = $username_generated;
             $user["user_login"] = $username_generated;
             //$message[] .= "Your username is: $username_generated";
             if (!$use_notification_for_autogeneration) {
                 $body = str_replace("%cuf_username%", $username_generated, $body);
             }
         }
         if ($autogenerate_pass && $autogenerate_user && $autogenerate_nick) {
             //nothing to do
         } else {
             if ($autogenerate_pass && !$autogenerate_user && !$autogenerate_nick) {
                 //Removing username not needed
                 if (!$use_notification_for_autogeneration) {
                     $body = preg_replace('#\\[username(.*)\\].*?\\[/username(.*)\\]#', '', $body);
                 }
             } else {
                 if (!$autogenerate_pass && $autogenerate_user && !$autogenerate_nick) {
                     //Removing password not needed
                     if (!$use_notification_for_autogeneration) {
                         $body = preg_replace('#\\[password(.*)\\].*?\\[/password(.*)\\]#', '', $body);
                     }
                 } else {
                     if (!$autogenerate_pass && !$autogenerate_user && $autogenerate_nick) {
                         if (!$use_notification_for_autogeneration) {
                             $body = preg_replace('#\\[nickname(.*)\\].*?\\[/nickname(.*)\\]#', '', $body);
                         }
                     }
                 }
             }
         }
         if (!$use_notification_for_autogeneration) {
             $body = str_replace(array("[username]", "[/username]", "[password]", "[/password]", "[nickname]", "[/nickname]"), "", $body);
             $mailer = CRED_Loader::get('CLASS/Mail_Handler');
             $mailer->reset();
             $mailer->setHTML(true, false);
             $recipients = $user['user_email'];
             $mailer->addRecipients($recipients);
             $mailer->setSubject($subject);
             $mailer->setBody($body);
             $mailer->setFrom("*****@*****.**");
             $_send_result = $mailer->send();
         }
     }
     //###################################################################
     //# AUTOGENERATION EMAIL MESSAGE
     //###################################################################
     if ($track) {
         // track the data, eg for notifications
         if (isset($user['name'])) {
             $this->trackData(array('name' => $user['name']));
         }
     }
     // return them
     return $user;
 }