Created
May 5, 2019 10:59
-
-
Save eto4detak/be2fd44494719c5d4a73ac64ea2056f5 to your computer and use it in GitHub Desktop.
wp php ajax reg form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $psych_form; | |
$psych_form = new PsychForm(); | |
class PsychForm | |
{ | |
public $current_user; | |
public $current_template; | |
public $templates = [ | |
'reg' => ['template' => 'page-psych-reg.php', 'url' => ''], | |
'personal' => ['template' => 'page-psych-personal.php', 'url' => ''], | |
'contact' => ['template' => 'page-psych-contact.php', 'url' => ''], | |
'prof' => ['template' => 'page-psych-prof.php', 'url' => ''], | |
'service' => ['template' => 'page-psych-service.php', 'url' => ''], | |
'edu' => ['template' => 'page-psych-edu.php', 'url' => ''], | |
'problem' => ['template' => 'page-psych-problem.php', 'url' => ''], | |
]; | |
public $form_structure = [ | |
'1' => ['val' => 'aaa', 'title' => 'bbbbb'], | |
'1.1' => ['val' => 'ccc', 'title' => 'ddd'], | |
]; | |
function __construct() | |
{ | |
$this->init(); | |
} | |
public function is_template($value='') | |
{ | |
return is_page_template($this->templates['reg']['template']) | |
|| is_page_template($this->templates['personal']['template']) | |
|| is_page_template($this->templates['contact']['template']) | |
|| is_page_template($this->templates['prof']['template']) | |
|| is_page_template($this->templates['service']['template']) | |
|| is_page_template($this->templates['edu']['template']); | |
} | |
public function init() | |
{ | |
$this->get_url_template_form(); | |
add_action( 'wp_enqueue_scripts', [$this,'psych_magazine_prime_scripts'] , 1); | |
add_action( 'wp_enqueue_scripts', [$this,'add_style'],100 ); | |
add_action( 'wp_head', [$this,'add_in_heder'] ); | |
add_action( 'wp_footer', [$this,'add_Footer'], 1); | |
add_action( 'wp_footer', [$this,'finish_add_footer'], 100); | |
$this->current_user = wp_get_current_user(); | |
add_action( 'personal_options_update', [$this,'save_extra_profile_fields' ]); | |
add_action( 'edit_user_profile_update', [$this,'save_extra_profile_fields'] ); | |
add_action( 'user_register', [$this,'user_registration'] ); | |
add_action( 'show_user_profile', [$this,'author_box']); | |
add_action( 'edit_user_profile', [$this,'author_box']); | |
//wp_enqueue_scripts | |
add_action( 'wp_enqueue_scripts', [$this,'construct_myajax_data' ],101); | |
if( wp_doing_ajax() ){ | |
add_action('wp_ajax_update_psych_data', [$this,'update_psych_data']); | |
add_action('wp_ajax_nopriv_update_psych_data', [$this,'update_psych_data']); | |
add_action('wp_ajax_ajax_upload_files', [$this,'ajax_upload_files']); | |
add_action('wp_ajax_nopriv_ajax_upload_files', [$this,'ajax_upload_files']); | |
} | |
} | |
public function send_email($fromEmail,$fromEmailName,$toEmail,$toEmailName,$subject,$message,$extra='') { | |
$headers = 'MIME-Version: 1.0' . "\r\n"; | |
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; | |
$headers .= 'To: '.$toEmailName.' <'.$toEmail.'>' . "\r\n"; | |
$headers .= 'From: '.$fromEmailName.' <'.$fromEmail.'>' . "\r\n"; | |
if(wp_mail($toEmail,$subject,$message,$headers)) { | |
}else { | |
@mail($toEmail,$subject,$message,$headers); | |
} | |
} | |
public function footer_for_reg($value='') | |
{ | |
?> | |
<script> | |
$(function(){ | |
$('.input').each(function(){ | |
changeState($(this)); | |
}); | |
$('.input').on('focusout', function(){ | |
changeState($(this)); | |
}); | |
function changeState($formControl){ | |
if($formControl.val().length > 0){ | |
$formControl.prev().addClass('labelup'); | |
} | |
else{ | |
$formControl.prev().removeClass('labelup'); | |
} | |
$('.input').on('focusin', function(){ | |
$(this).prev().addClass('labelup'); | |
}); | |
} | |
}); | |
</script> | |
<style> | |
.label { | |
pointer-events: none; | |
} | |
</style> | |
<?php | |
} | |
public function finish_add_footer() | |
{ | |
?> | |
<!-- [if lte IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/placeholders/3.0.2/placeholders.min.js"></script><![endif] --> | |
<script> | |
$(document).ready(function(){ | |
var $gallery = $('.quiz-form'); | |
var slideCount = null; | |
$gallery.on('init', function(event, slick){ | |
slideCount = slick.slideCount; | |
setSlideCount(); | |
setCurrentSlideNumber(slick.currentSlide); | |
}); | |
$('.quiz-form').slick({ | |
prevArrow: $('.backlink'), | |
nextArrow: $('.nextbtn'), | |
infinite: false, | |
draggable: false, | |
speed: 500, | |
swipe: false, | |
adaptiveHeight: true, | |
autoHeight: true | |
}); | |
var $slider = $('.quiz-form'); | |
var $progressBar = $('.progress'); | |
$slider.on('beforeChange', function(event, slick, currentSlide, nextSlide) { | |
var calc = ( (nextSlide) / (slick.slideCount-1) ) * 100; | |
$progressBar | |
.css('background-size', calc + '% 100%') | |
.attr('aria-valuenow', calc ); | |
}); | |
$gallery.on('beforeChange', function(event, slick, currentSlide, nextSlide){ | |
setCurrentSlideNumber(nextSlide); | |
}); | |
function setSlideCount() { | |
var $el = $('.carousel-status').find('.total'); | |
$el.text(slideCount); | |
} | |
function setCurrentSlideNumber(currentSlide) { | |
var $el = $('.carousel-status').find('.current'); | |
$el.text(currentSlide + 1); | |
} | |
}); | |
</script> | |
<!-- Checkboxes --> | |
<script> | |
$(document).ready(function () { | |
$('.check').each(function () { | |
if ($(this).hasClass('activated') && $(this).closest('.quizbox').find('input:radio').length !== 0) { | |
$(this).closest('.quizbox').find('input:radio').eq(0).prop('checked', true); | |
} | |
}); | |
$("input:radio, input:checkbox").each(function () { | |
if ($(this).prop('checked')) { | |
$(this).closest('.quizbox').find('.check').addClass('activated'); | |
} else { | |
$(this).closest('.quizbox').find('.check').removeClass('activated'); | |
} | |
}); | |
$('.quizbox').click(function () { | |
var radio = $(this).find('input[type="radio"]'); | |
var checkbox = $(this).find('input[type="checkbox"]'); | |
var check = $(this).find('.check'); | |
if (radio.length !== 0) { | |
$(".quiz-form").slick('slickNext'); | |
$('.remodal-wrapper').animate({ scrollTop: "0px" }); | |
radio.eq(0).prop('checked', true); | |
check.eq(0).addClass('activated'); | |
$("input:radio[name=" + radio.eq(0).attr('name') + "]").each(function () { | |
if (!$(this).prop('checked')) { | |
$(this).closest('.quizbox').find('.check').removeClass('activated'); | |
} | |
}); | |
} else if (checkbox.length !== 0) { | |
var checked = checkbox.eq(0).prop('checked'); | |
checkbox.eq(0).prop('checked', !checked); | |
check.eq(0).toggleClass('activated'); | |
} | |
}) | |
}) | |
$('.link').click(function () { | |
$('html, body').animate({ | |
scrollTop: $("#quizbox").offset().top | |
}, 500);}) | |
</script> | |
<script> | |
$('.consultbtn').click(function () { | |
setTimeout(function() { $('.quiz-form').slick('setPosition'); }, 50); | |
}) | |
</script> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/remodal/1.1.1/remodal.min.css" rel="stylesheet" type="text/css"> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/remodal/1.1.1/remodal-default-theme.min.css" rel="stylesheet" type="text/css"> | |
<style> | |
.remodal-overlay { | |
background: rgba(0, 0, 0, 0.8); | |
} | |
.remodal { | |
background: rgba(0, 0, 0, 0); | |
width:auto; | |
padding: 0px; | |
} | |
.for-photo{ | |
overflow: hidden; | |
} | |
</style> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/remodal/1.1.1/remodal.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$('.consultbtn-f').on('click', function(){ | |
$('div[data-w-id="c2a9d305-b516-3566-1224-b9fd4d67068e"]').css({'display': 'flex'}); | |
console.log(123); | |
}); | |
$("#qform .closelink").on('click', function(){ | |
$('div[data-w-id="c2a9d305-b516-3566-1224-b9fd4d67068e"]').css({'display': 'none'}); | |
}); | |
$("#w-node-43138c2680a3-948e224a").on('click', function(){ | |
$(".wrapper-psy-bg").css({'display': 'flex'}); | |
}); | |
$(".close, .wrapper-psy-bg .closelink").on('click', function(){ | |
$(".wrapper-psy-bg").css({'display': 'none'}); | |
}); | |
}); | |
</script> | |
<?php | |
if(is_page_template($this->templates['reg']['template'])){ | |
$this->footer_for_reg(); | |
} | |
if(is_page_template($this->templates['edu']['template'])){ | |
$this->footer_for_edu(); | |
} | |
} | |
public function add_Footer() | |
{ | |
// if(is_page_template($this->templates['problem']['template'])){ | |
$this->html_page_problem(); | |
// } | |
} | |
public function footer_for_edu($value='') | |
{ | |
} | |
function add_in_heder(){ | |
?> | |
<script type="text/javascript">WebFont.load({ google: { families: ["Lato:100,100italic,300,300italic,400,400italic,700,700italic,900,900italic","Merriweather:300,300italic,400,400italic,700,700italic,900,900italic"] }});</script> | |
<!-- [if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js" type="text/javascript"></script><![endif] --> | |
<script type="text/javascript">!function(o,c){var n=c.documentElement,t=" w-mod-";n.className+=t+"js",("ontouchstart"in o||o.DocumentTouch&&c instanceof DocumentTouch)&&(n.className+=t+"touch")}(window,document);</script> | |
<!-- checkbox --> | |
<style type="text/css"> | |
.checkbox-sign > img{ | |
display: none; | |
} | |
.checkbox-sign.check-yes > img { | |
display: inline-block; | |
} | |
</style> | |
<?php | |
if(is_page_template($this->templates['problem']['template'])){ | |
?> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css"> | |
<style> | |
.progress { | |
background-image: linear-gradient(to right, #F25A5A, #F25A5A); | |
background-repeat: no-repeat; | |
background-size: 0 100%; | |
transition: background-size .4s ease; | |
} | |
.check {opacity:0} | |
.check.activated {opacity:1} | |
*:focus {outline:none !important} | |
</style> | |
<?php | |
} | |
} | |
public function add_style() | |
{ | |
if($this->is_template()){ | |
wp_enqueue_style('normalize-psych-css', get_template_directory_uri() . '/assets/normalize.css'); | |
wp_enqueue_style('webflow-psych-css', get_template_directory_uri() . '/assets/webflow.css'); | |
wp_enqueue_style('faser-psych-css', get_template_directory_uri() . '/assets/faser.webflow.css'); | |
// if(!is_page_template($this->templates['edu']['template'])){ | |
wp_deregister_script( 'jquery-core' ); | |
wp_deregister_script( 'jquery' ); | |
wp_register_script( 'jquery-core', 'https://code.jquery.com/jquery-3.3.1.min.js', false, null, true ); | |
wp_register_script( 'jquery', false, array('jquery-core'), null, true ); | |
wp_enqueue_script( 'jquery' ); | |
// } | |
} | |
} | |
public function psych_magazine_prime_scripts() | |
{ | |
wp_enqueue_script( 'googleapis-psych', 'https://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js', '', '20181225' );//header | |
wp_enqueue_script( 'magazine-form-mask', get_template_directory_uri() . '/js/jquery.mask.min.js', array('jquery'), '20151215', true ); | |
wp_enqueue_script( 'magazine-form-webflow', get_template_directory_uri() . '/js/webflow.js', array('jquery'), '20151215', true ); | |
wp_enqueue_script( 'magazine-form-start', get_template_directory_uri() . '/js/form-start.js', array('jquery'), '20151215', true ); | |
} | |
function update_psych_data() { | |
global $post; | |
if( ! wp_verify_nonce( $_POST['nonce_code'], 'form-psych-nonce' ) ) die( 'Stop!'); | |
if(empty($this->current_user->ID)){ | |
die('no user'); | |
}elseif(!get_the_author_meta( '_is_psych', $this->current_user->ID)){ | |
// die('no psych'); | |
} | |
$json = wp_unslash( $_POST['dataForm']); | |
$form = json_decode($json); | |
if(isset($form->formName)){ //есть форма | |
if('personal' == $form->formName){ | |
update_user_meta($this->current_user->ID, '_psych_country', sanitize_text_field($form->country )); | |
update_user_meta($this->current_user->ID, '_psych_city', sanitize_text_field($form->city)); | |
$date = DateTime::createFromFormat('d.m.Y', sanitize_text_field($form->date)); | |
if(!$date){ | |
// wp_send_json_success( ['action' => 'warning','input' => 'date', 'message'=>'invalid date'] ); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_date', $date ); | |
} | |
wp_send_json_success( ['action' => 'redirect','url' => $this->templates['contact']['url'], 'message'=>''] ); | |
}elseif('contact' == $form->formName){ | |
update_user_meta($this->current_user->ID, '_psych_address_consul', sanitize_text_field($form->addressConsul )); | |
update_user_meta($this->current_user->ID, '_psych_tel', sanitize_text_field($form->tel )); | |
update_user_meta($this->current_user->ID, '_psych_skype', sanitize_text_field($form->skype )); | |
update_user_meta($this->current_user->ID, '_psych_messager', sanitize_text_field($form->messager )); | |
if(filter_var($form->social, FILTER_VALIDATE_URL)){ | |
update_user_meta($this->current_user->ID, '_psych_social', esc_attr($form->social )); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_social', ''); | |
} | |
if(filter_var($form->site, FILTER_VALIDATE_URL)){ | |
update_user_meta($this->current_user->ID, '_psych_site', esc_attr($form->site )); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_site', ''); | |
} | |
wp_send_json_success( ['action' => 'redirect','url' => $this->templates['prof']['url'], 'message'=>''] ); | |
}elseif('prof' == $form->formName){ | |
update_user_meta($this->current_user->ID, '_psych_year_consul', sanitize_text_field($form->yearConsul )); | |
update_user_meta($this->current_user->ID, '_psych_hours_consul', sanitize_text_field($form->hours )); | |
update_user_meta($this->current_user->ID, '_psych_specialization_consul', sanitize_text_field($form->specialization )); | |
update_user_meta($this->current_user->ID, '_psych_lang_consul', sanitize_text_field($form->lang )); | |
update_user_meta($this->current_user->ID, '_psych_child1', sanitize_text_field($form->child1 )); | |
update_user_meta($this->current_user->ID, '_psych_child2', sanitize_text_field($form->child2 )); | |
update_user_meta($this->current_user->ID, '_psych_child3', sanitize_text_field($form->child3 )); | |
$str = substr(sanitize_text_field($form->aboutMe ), 0, 190); | |
update_user_meta($this->current_user->ID, '_psych_about_me', sanitize_text_field($str) ); | |
if(is_array($form->catTitles)){ | |
foreach ($form->catTitles as $key => $value) { | |
$form->catTitles[$key] = sanitize_text_field($value ); | |
} | |
update_user_meta($this->current_user->ID, '_psych_cat_titles', $form->catTitles); | |
} | |
wp_send_json_success( ['action' => 'redirect','url' => $this->templates['service']['url'], 'message'=>''] ); | |
}elseif('service' == $form->formName){ | |
update_user_meta($this->current_user->ID, '_psych_promotion', sanitize_text_field($form->promotion )); | |
if(isset($form->time_peronal) && isset($form->cost_peronal)){ | |
update_user_meta($this->current_user->ID, '_psych_time_peronal', sanitize_text_field($form->time_peronal )); | |
update_user_meta($this->current_user->ID, '_psych_cost_peronal', intval($form->cost_peronal )); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_time_peronal', '' ); | |
update_user_meta($this->current_user->ID, '_psych_cost_peronal', '' ); | |
} | |
if(isset($form->time_online) && isset($form->cost_online)){ | |
update_user_meta($this->current_user->ID, '_psych_time_online', sanitize_text_field($form->time_online )); | |
update_user_meta($this->current_user->ID, '_psych_cost_online', intval($form->cost_online )); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_time_online', ''); | |
update_user_meta($this->current_user->ID, '_psych_cost_online', ''); | |
} | |
if(isset($form->time_tel) && isset($form->cost_tel)){ | |
update_user_meta($this->current_user->ID, '_psych_time_tel', sanitize_text_field($form->time_tel )); | |
update_user_meta($this->current_user->ID, '_psych_cost_tel', intval($form->cost_tel )); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_time_tel', ''); | |
update_user_meta($this->current_user->ID, '_psych_cost_tel', ''); | |
} | |
if(isset($form->time_online_chat) && isset($form->cost_online_chat)){ | |
update_user_meta($this->current_user->ID, '_psych_time_online_chat', sanitize_text_field($form->time_online_chat )); | |
update_user_meta($this->current_user->ID, '_psych_cost_online_chat', sanitize_text_field($form->cost_online_chat )); | |
}else{ | |
update_user_meta($this->current_user->ID, '_psych_time_online_chat', ''); | |
update_user_meta($this->current_user->ID, '_psych_cost_online_chat', ''); | |
} | |
wp_send_json_success( ['action' => 'redirect','url' => $this->templates['edu']['url'], 'message'=>''] ); | |
}elseif('edu' == $form->formName){ | |
update_user_meta($this->current_user->ID, '_psych_consults', sanitize_text_field($form->consults )); | |
update_user_meta($this->current_user->ID, '_psych_supervision', $form->supervision ); | |
if(is_array($form->comment_urls)){ | |
foreach ($form->comment_urls as $key => $value) { | |
if(filter_var($value, FILTER_VALIDATE_URL)){ | |
}else{ | |
unset($form->comment_urls[$key]); | |
} | |
} | |
update_user_meta($this->current_user->ID, '_psych_comment_urls', $form->comment_urls ); | |
} | |
if(is_array($form->archive_urls)){ | |
foreach ($form->archive_urls as $key => $value) { | |
if(filter_var($value, FILTER_VALIDATE_URL)){ | |
}else{ | |
unset($form->archive_urls[$key]); | |
} | |
} | |
update_user_meta($this->current_user->ID, '_psych_archive_urls', $form->archive_urls ); | |
} | |
$_is_psych_data_send = get_user_meta($this->current_user->ID, '_is_psych_data_send',1) ? get_user_meta($this->current_user->ID, '_is_psych_data_send',1) : ''; | |
if(empty($_is_psych_data_send)){ | |
$user = get_userdata($this->current_user->ID); | |
$this->send_email(get_bloginfo("admin_email"), get_bloginfo('name'), $user->data->user_email, get_bloginfo('name'),__("Обработка данных","test"),$this->html_email_register_user($this->current_user->ID)); | |
update_user_meta($this->current_user->ID, '_is_psych_data_send', 1); | |
} | |
wp_send_json_success( ['action' => 'saved', 'message'=>''] ); | |
} | |
}else{ | |
wp_die('no form'); | |
} | |
wp_send_json_success( $form ); | |
wp_die(); | |
} | |
function ajax_upload_files() | |
{ | |
check_ajax_referer( 'form-psych-nonce', 'nonce' ); // защита | |
if( empty($_FILES) ) | |
wp_send_json_error( 'Файлов нет...' ); | |
// ограничим размер загружаемой картинки | |
$sizedata = getimagesize( $_FILES['upfile']['tmp_name'] ); | |
$max_size = 2000; | |
if( $sizedata[0] > $max_size || $sizedata[1] > $max_size ) | |
wp_send_json_error( __('Картинка не может быть больше чем '. $max_size .'px в ширину или высоту...','test') ); | |
// обрабатываем загрузку файла | |
require_once ABSPATH . 'wp-admin/includes/image.php'; | |
require_once ABSPATH . 'wp-admin/includes/file.php'; | |
require_once ABSPATH . 'wp-admin/includes/media.php'; | |
// фильтр допустимых типов файлов - разрешим только картинки | |
add_filter( 'upload_mimes', function( $mimes ){ | |
return [ | |
'jpg|jpeg|jpe' => 'image/jpeg', | |
'gif' => 'image/gif', | |
'png' => 'image/png', | |
]; | |
} ); | |
$uploaded_imgs = array(); | |
$ids = []; | |
foreach( $_FILES as $file_id => $data ){ | |
$attach_id = media_handle_upload( $file_id, 0 ); | |
$ids[] = $attach_id; | |
// ошибка | |
if( is_wp_error( $attach_id ) ) | |
$uploaded_imgs[] = 'Ошибка загрузки файла `'. $data['name'] .'`: '. $attach_id->get_error_message(); | |
else | |
$uploaded_imgs[] = wp_get_attachment_url( $attach_id ); | |
} | |
if(isset($_POST['status']) && 'certificate' == $_POST['status']){ | |
update_user_meta($this->current_user->ID, '_psych_certificate', $ids); | |
foreach ($ids as $key => $id_image) { | |
if($id_image > 0 ){ | |
update_post_meta($id_image, '_is_psych_certificate', 1); | |
} | |
} | |
wp_send_json_success( $uploaded_imgs); | |
}elseif(isset($_POST['status']) && 'foto-review' == $_POST['status']){ | |
update_user_meta($this->current_user->ID, '_psych_foto_review', $ids); | |
foreach ($ids as $key => $id_image) { | |
if($id_image > 0 ){ | |
update_post_meta($id_image, '_is_psych_foto_review', 1); | |
} | |
} | |
wp_send_json_success( $uploaded_imgs ); | |
}elseif(isset($_POST['status']) && 'photo' == $_POST['status']){ | |
update_user_meta($this->current_user->ID, '_psych_photo', $ids[0]); | |
foreach ($ids as $key => $id_image) { | |
if($id_image > 0 ){ | |
update_post_meta($id_image, '_is_psych_photo', 1); | |
} | |
} | |
wp_send_json_success( $uploaded_imgs ); | |
} | |
} | |
function construct_myajax_data(){ | |
wp_localize_script( 'jquery', 'formPsych', | |
array( | |
'url' => admin_url('admin-ajax.php'), | |
'nonce' => wp_create_nonce('form-psych-nonce'), | |
'domen' => get_template_directory_uri(), | |
'questioтStructure' => $this->form_structure, | |
'htmlStructure' => $this->html_psych_users(), | |
) | |
); | |
} | |
public function get_url_template_form() | |
{ | |
foreach ($this->templates as $key => $template) { | |
$pages = null; | |
$pages = get_pages(array( | |
'meta_key' => '_wp_page_template', | |
'meta_value' => $template['template'] | |
)); | |
if(!empty($pages)){ | |
$this->templates[$key]['url'] = get_permalink($pages[0]->ID); | |
} | |
} | |
} | |
function save_extra_profile_fields( $user_id ) { | |
if ( !current_user_can( 'edit_user', $user_id ) ) | |
return false; | |
if(isset($_POST['_is_psych'])){ | |
update_user_meta( $user_id, '_is_psych', esc_attr($_POST['_is_psych']) ); | |
} | |
} | |
function user_registration( $user_id ) { | |
if(isset($_POST['_is_psych'])){ | |
update_user_meta( $user_id, '_is_psych', esc_attr( $_POST['_is_psych']) ); | |
update_user_meta( $user_id, 'first_name', esc_attr( $_POST['first_name']) ); | |
update_user_meta( $user_id, 'last_name', esc_attr( $_POST['last_name']) ); | |
$user = get_userdata($user_id); | |
$this->send_email(get_bloginfo("admin_email"),get_bloginfo('name'), $user->data->user_email, get_bloginfo('name'),__("Регистрация психолога","test"),$this->html_email_reg_psych($user_id)); | |
// $this->send_email(get_bloginfo("admin_email"),get_bloginfo('name'), $user->data->user_email, get_bloginfo('name'),__("Обработка данных","test"),$this->html_email_register_user($user_id)); | |
// $this->send_email(get_bloginfo("admin_email"),get_bloginfo('name'), $user->data->user_email, get_bloginfo('name'),__("Связались с психологом?","test"),$this->html_email_no_bond($user_id)); | |
// $this->send_email(get_bloginfo("admin_email"),get_bloginfo('name'), $user->data->user_email, get_bloginfo('name'),__("Заявка на консультацию","test"),$this->html_email_request_consultation($user_id)); | |
if(isset($_POST['password'])){ | |
wp_set_password(sanitize_text_field( $_POST['password'] ), $user_id ); | |
} | |
} | |
} | |
function view_field($field,$name,$user) | |
{ | |
?> | |
<tr> | |
<th><label for="<?php echo $field; ?>"><?php echo $name;?></label></th> | |
<td> | |
<input type="text" size="36" class="regular-text" value="<?php echo esc_attr( get_the_author_meta("$field", $user->ID ) ); ?>" id="<?php echo $field; ?>" name="<?php echo $field; ?>"> | |
</td> | |
</tr> | |
<?php | |
} | |
function view_field_date($field,$name,$user) | |
{ | |
$value = get_the_author_meta("$field", $user->ID ) ? get_the_author_meta("$field", $user->ID ) : ''; | |
if(!is_object($value)){ | |
return; | |
} | |
?> | |
<tr> | |
<th><label for="<?php echo $field; ?>"><?php echo $name;?></label></th> | |
<td> | |
<input type="text" size="36" class="regular-text" value="<?php echo $value->date ?>" id="<?php echo $field; ?>" > | |
</td> | |
</tr> | |
<?php | |
} | |
function view_field_array($field,$name,$user) | |
{ | |
?> | |
<tr> | |
<th><label for="<?php echo $field; ?>"><?php echo $name;?></label></th> | |
<td> | |
<?php | |
foreach ((array)get_the_author_meta("$field", $user->ID,1 ) as $key => $value) { | |
echo '<input type="text" size="36" class="regular-text" value="'.esc_attr( $value ).'" name="">'; | |
} | |
?> | |
</td> | |
</tr> | |
<?php | |
} | |
function author_box($user) { | |
$is_psych = get_the_author_meta( '_is_psych', $user->ID,1 ); | |
if (!empty($is_psych)) { | |
?> | |
<table class="form-table"> | |
<?php $this->view_field('_psych_country','country',$user); ?> | |
<?php $this->view_field('_psych_city','city',$user); ?> | |
<?php $this->view_field_date('_psych_date','date',$user); ?> | |
<?php $this->view_field('_psych_address_consul','address consul',$user); ?> | |
<?php $this->view_field('_psych_tel','tel',$user); ?> | |
<?php $this->view_field('_psych_skype','skype',$user); ?> | |
<?php $this->view_field('_psych_social','social',$user); ?> | |
<?php $this->view_field('_psych_messager','messager',$user); ?> | |
<?php $this->view_field('_psych_site','site',$user); ?> | |
<?php $this->view_field('_psych_year_consul','year',$user); ?> | |
<?php $this->view_field('_psych_hours_consul','hours',$user); ?> | |
<?php $this->view_field('_psych_specialization_consul','special',$user); ?> | |
<?php $this->view_field('_psych_lang_consul','lang',$user); ?> | |
<?php $this->view_field('_psych_child1','child1',$user); ?> | |
<?php $this->view_field('_psych_child2','child2',$user); ?> | |
<?php $this->view_field('_psych_child3','child3',$user); ?> | |
<?php $this->view_field('_psych_about_me','about_me',$user); ?> | |
<?php $this->view_field('_psych_time_peronal','time_peronal',$user); ?> | |
<?php $this->view_field('_psych_cost_peronal','cost_peronal',$user); ?> | |
<?php $this->view_field('_psych_time_online','time_online',$user); ?> | |
<?php $this->view_field('_psych_cost_online','cost_online',$user); ?> | |
<?php $this->view_field('_psych_time_tel','time_tel',$user); ?> | |
<?php $this->view_field('_psych_cost_tel','cost_tel',$user); ?> | |
<?php $this->view_field('_psych_time_online_chat','time_online_chat',$user); ?> | |
<?php $this->view_field('_psych_cost_online_chat','cost_online_chat',$user); ?> | |
<?php $this->view_field('_psych_promotion','promotion',$user); ?> | |
<?php $this->view_field('_psych_consults','_psych_consults',$user); ?> | |
<?php $this->view_field('_psych_supervision','_psych_supervision',$user); ?> | |
<?php $this->view_field('_psych_photo','_psych_photo',$user); ?> | |
<?php $this->view_field_array('_psych_comment_urls','_psych_comment_urls',$user); ?> | |
<?php $this->view_field_array('_psych_archive_urls','_psych_archive_urls',$user); ?> | |
<?php $this->view_field_array('_psych_foto_review','_psych_foto_review',$user); ?> | |
<?php $this->view_field_array('_psych_certificate','_psych_certificate',$user); ?> | |
<?php $this->view_field_array('_psych_cat_titles','_psych_cat_titles',$user); ?> | |
</table> | |
<?php | |
} | |
} | |
public function view_item_dropbox($title,$name, $id) | |
{ | |
?> | |
<div class="nesting-item nesting-item-input"> | |
<img alt="" class="nest-sign" src="images/nest-sign.svg"> | |
<div class="checkbox-sign"> | |
<img alt="" src="<?php echo get_template_directory_uri() ?>/images/Union_1.svg" width="12"/> | |
<input class="hidden" type="text" value="" name="<?php echo $name ?>" id="<?php echo $id; ?>"> | |
</div> | |
<div class="input-text"> | |
<?php echo $title; ?> | |
</div> | |
</img> | |
</div> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment