Created
February 17, 2018 15:02
-
-
Save harddy/d275856c003d190f0e13cdd5b077a65e to your computer and use it in GitHub Desktop.
functions.php
This file contains 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 | |
if (!defined('ABSPATH')) | |
exit; | |
// BEGIN ENQUEUE PARENT ACTION | |
// AUTO GENERATED - Do not modify or remove comment markers above or below: | |
if (!function_exists('chld_thm_cfg_parent_css')): | |
function chld_thm_cfg_parent_css() { | |
wp_enqueue_style('chld_thm_cfg_parent', trailingslashit(get_template_directory_uri()) . 'style.css', array()); | |
} | |
endif; | |
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10); | |
function theme_js() { | |
wp_enqueue_style('flexslider', get_stylesheet_directory_uri() . '/css/ionicons.css'); | |
wp_enqueue_style('style-menu', get_stylesheet_directory_uri() . '/css/style.css'); | |
wp_enqueue_style('flexslider', ' http://fonts.googleapis.com/css?family=Droid+Serif'); | |
wp_enqueue_style('responsive-menu', get_stylesheet_directory_uri() . '/css/responsive.css'); | |
wp_enqueue_script( | |
'custom-jqut', get_stylesheet_directory_uri() . '/js/jquery.min.js', array('jquery') | |
); | |
wp_enqueue_script('validate-js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js'); | |
wp_enqueue_script('jquery_validatation', 'https://cdn.jsdelivr.net/jquery.validation/1.15.0/additional-methods.min.js'); | |
wp_enqueue_script( | |
'custom-script', get_stylesheet_directory_uri() . '/js/ast-custom.js', array('jquery') | |
); | |
} | |
add_action('wp_enqueue_scripts', 'theme_js', 1, 1); | |
register_nav_menus(array( | |
'profile_menu' => esc_html__('Footer Menu', 'Divi'), | |
)); | |
/* Ajax call for user signup */ | |
add_action('wp_ajax_nopriv_user_signup', 'user_signup_callback'); | |
add_action('wp_ajax_user_signup', 'user_signup_callback'); | |
function user_signup_callback() { | |
$fname = $_POST['fname']; | |
$lname = $_POST['lname']; | |
$email = $_POST['uemail']; | |
$phone = $_POST['uphone']; | |
$pw = $_POST['upassword']; | |
if (email_exists($email)) { | |
echo '2'; | |
} else { | |
global $wpdb; | |
$prefix = $wpdb->prefix; | |
$table_name = 'wp_pending_users'; | |
$datetime = date('Y-m-d H:i:s'); | |
$timestamp = strtotime($datetime); | |
$wpdb->insert( | |
$table_name, array( | |
'fname' => $fname, | |
'lname' => $lname, | |
'email' => $email, | |
'phone' => $phone, | |
'password' => $pw, | |
'role' => 'customer', | |
'date' => $datetime, | |
'status' => 'active' | |
) | |
); | |
echo $err = $wpdb->last_error; | |
if ($wpdb->insert_id): | |
/* Email to user */ | |
$to = $email; | |
$encrypt_method = "AES-256-CBC"; | |
$secret_key = 'This is my secret key'; | |
$secret_iv = 'This is my secret iv'; | |
// hash | |
$key = hash('sha256', $secret_key); | |
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning | |
$iv = substr(hash('sha256', $secret_iv), 0, 16); | |
$output = openssl_encrypt($email, $encrypt_method, $key, 0, $iv); | |
$output = base64_encode($output); | |
$subject = '[Risk Specialty] User Verification Email'; | |
$msg = ''; | |
$msg = '<div style="width: 850px; margin: 0 auto"> | |
<div style="width: 250px; margin: 0 auto"> | |
<a style="margin: 0 15px 0px 0; width: 250px" href="' . get_site_url() . '" onclick="return false" rel="noreferrer"> | |
<img src="' . et_get_option('divi_logo', '') . '" alt="logo" style="width: 100%"> | |
</a> | |
</div> | |
<div style="background: #f2f0f1; padding: 20px; border-radius: 15px; margin: 20px 0; display: inline-block; width: 100%"> | |
<div style="width: 100%; display: inline-block; margin-bottom: 30px"> | |
<h2 style="color: #0071bd; font-size: 13px; text-transform: capitalize;"><p> Please verify your email on click of below url .</p></h2><br/> | |
<a href="' . get_permalink(849) . '?string=' . $output . '">' . get_permalink(849) . '?string=' . $output . '</a> | |
<div> | |
<span style=" color: #333; margin: 0; width: 100%; display: inline-block; padding: 8px 5px"> | |
' . $desc . ' | |
</span> | |
</div> | |
</div> | |
<div style="width: 100%; display: inline-block; margin-bottom: 30px"> | |
<h2 style="color: #0071bd; font-size: 13px;">Thank you!</h2> | |
<div style="width: 100%; "> | |
<span style=" color: #333; margin: 0; width: 100%; display: inline-block; padding: 0"> | |
' . get_bloginfo() . ' | |
</span> | |
</div> | |
</div> | |
<p style="font-size: 14px; color: #7c7c7c; line-height: 22px; text-align: center; ">' . et_get_option('copyright_text', '') . '</p> | |
</div> | |
</div>'; | |
$headers = "MIME-Version: 1.0" . "\r\n"; | |
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; | |
$headers .= 'From: Risk Specialty <info@riskspecialtygroup.com>' . "\r\n"; | |
wp_mail($to, $subject, $msg, $headers); | |
echo '1'; | |
else: | |
echo '0'; | |
endif; | |
} | |
die(0); | |
} | |
/* Ajax call for user signin */ | |
add_action('wp_ajax_nopriv_user_signin', 'user_signin_callback'); | |
add_action('wp_ajax_user_signin', 'user_signin_callback'); | |
function user_signin_callback() { | |
$email = $_POST['email']; | |
$password = $_POST['password']; | |
if ($email != "" && $password != "") { | |
$creds = array(); | |
$creds['user_login'] = $email; | |
$creds['user_password'] = $password; | |
$user = wp_signon($creds, false); | |
if (is_wp_error($user)) { | |
//echo $user->get_error_message(); | |
echo '0'; | |
} else { | |
echo '1'; | |
} | |
} | |
die(0); | |
} | |
/* End ajax call for user signin */ | |
/* Ajax call for Forgot Password */ | |
add_action('wp_ajax_nopriv_forgot_pass', 'forgot_pass_callback'); | |
add_action('wp_ajax_forgot_pass', 'forgot_pass_callback'); | |
function forgot_pass_callback() { | |
$email = $_POST['email']; | |
if (email_exists($email)) { | |
$to = $email; | |
$encrypt_method = "AES-256-CBC"; | |
$secret_key = 'This is my secret key'; | |
$secret_iv = 'This is my secret iv'; | |
// hash | |
$key = hash('sha256', $secret_key); | |
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning | |
$iv = substr(hash('sha256', $secret_iv), 0, 16); | |
$output = openssl_encrypt($email, $encrypt_method, $key, 0, $iv); | |
$output = base64_encode($output); | |
$subject = 'Reset Password Link for Risk Specialty'; | |
$msg = ''; | |
$msg = '<div style="width: 850px; margin: 0 auto"> | |
<div style="width: 250px; margin: 0 auto"> | |
<a style="margin: 0 15px 0px 0; width: 250px" href="' . get_site_url() . '" onclick="return false" rel="noreferrer"> | |
<img src="' . et_get_option('divi_logo', '') . '" alt="logo" style="width: 100%"> | |
</a> | |
</div> | |
<div style="background: #f2f0f1; padding: 20px; border-radius: 15px; margin: 20px 0; display: inline-block; width: 100%"> | |
<div style="width: 100%; display: inline-block; margin-bottom: 30px"> | |
<h2 style="color: #0071bd; font-size: 13px; text-transform: capitalize;">Please click on the below link to reset password </h2><br/> | |
<a href="' . get_permalink(856) . '/reset-password?string=' . $output . '">' . get_permalink(856) . '/reset-password?string=' . $output . '</a> | |
<div> | |
<span style=" color: #333; margin: 0; width: 100%; display: inline-block; padding: 8px 5px"> | |
' . $desc . ' | |
</span> | |
</div> | |
</div> | |
<div style="width: 100%; display: inline-block; margin-bottom: 30px"> | |
<h2 style="color: #0071bd; font-size: 13px;">Thank you!</h2> | |
<div style="width: 100%; "> | |
<span style=" color: #333; margin: 0; width: 100%; display: inline-block; padding: 0"> | |
' . get_bloginfo() . ' | |
</span> | |
</div> | |
</div> | |
<p style="font-size: 14px; color: #7c7c7c; line-height: 22px; text-align: center; ">' . et_get_option('copyright_text') . '</p> | |
</div> | |
</div>'; | |
//$msg .= 'Please click on the below link to reset password <br/>' . '<br/><br/>'; | |
//$msg .= '<a href="' . get_permalink(358) . '/reset-password?string=' . $output . '">' . get_permalink(358) . '/reset-password?string=' . $output . '</a>'; | |
$headers = "MIME-Version: 1.0" . "\r\n"; | |
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; | |
$headers .= 'From: Risk Specialty <info@riskspecialtygroup.com>' . "\r\n"; | |
wp_mail($to, $subject, $msg, $headers); | |
echo "1"; | |
} else { | |
echo "0"; | |
} | |
die(0); | |
} | |
/* End ajax call for Forgot Password */ | |
/* Ajax call for Reset Password */ | |
add_action('wp_ajax_nopriv_reset_pass', 'reset_pass_callback'); | |
add_action('wp_ajax_reset_pass', 'reset_pass_callback'); | |
function reset_pass_callback() { | |
$pass = $_POST['oldpass']; | |
$password = $_POST['password']; | |
$user_id = $_POST['user_id']; | |
$email = $_POST['email']; | |
$user_login = $_POST['uname']; | |
if ($password != '' && $user_id != '' && $email != '' && $user_login != '' && $pass != $password) { | |
wp_set_password($password, $user_id); | |
$subject = 'New Password for Risk Specialty'; | |
$message = '<div style="width: 850px; margin: 0 auto"> | |
<div style="width: 250px; margin: 0 auto"> | |
<a style="margin: 0 15px 0px 0; width: 250px" href="' . get_site_url() . '" onclick="return false" rel="noreferrer"> | |
<img src="' . et_get_option('divi_logo', '') . '" alt="logo" style="width: 100%"> | |
</a> | |
</div> | |
<div style="background: #f2f0f1; padding: 20px; border-radius: 15px; margin: 20px 0; display: inline-block; width: 100%"> | |
<div style="width: 100%; display: inline-block; margin-bottom: 30px"> | |
<div> | |
<span style=" color: #333; margin: 0; width: 100%; display: inline-block; padding: 8px 5px"> | |
<p>' . __('Your new password for the account at:') . '</p> | |
<p>' . get_option('siteurl') . '</p> | |
<p>' . sprintf(__('Username: %s'), $user_login) . '</p> | |
<p>' . sprintf(__('Password: %s'), $password) . '</p> | |
<p>' . __('You can now login with your new password at: ') . '</p> <a href="' . get_permalink(852) . '">' . get_permalink(852) . '</a> | |
</span> | |
</div> | |
</div> | |
<div style="width: 100%; display: inline-block; margin-bottom: 30px"> | |
<h2 style="color: #0071bd; font-size: 13px;">Thank you!</h2> | |
<div style="width: 100%; "> | |
<span style=" color: #333; margin: 0; width: 100%; display: inline-block; padding: 0"> | |
' . get_bloginfo() . ' | |
</span> | |
</div> | |
</div> | |
<p style="font-size: 14px; color: #7c7c7c; line-height: 22px; text-align: center; ">' . et_get_option('copyright_text') . '</p> | |
</div> | |
</div>'; | |
$headers = "MIME-Version: 1.0" . "\r\n"; | |
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; | |
$headers .= 'From: Risk Specialty <info@riskspecialtygroup.com>' . "\r\n"; | |
wp_mail($email, $subject, $message, $headers); | |
echo '1'; | |
} else { | |
echo '0'; | |
} | |
die(); | |
} | |
/* Ajax call for edit user profile */ | |
add_action('wp_ajax_nopriv_edit_user_account', 'edit_user_account_callback'); | |
add_action('wp_ajax_edit_user_account', 'edit_user_account_callback'); | |
function edit_user_account_callback() { | |
$fname = $_POST['efname']; | |
$lname = $_POST['elname']; | |
$phone = $_POST['u_phone']; | |
$user_id = get_current_user_id(); | |
if ($fname && $lname && $phone) { | |
update_user_meta($user_id, 'first_name', $fname); | |
update_user_meta($user_id, 'last_name', $lname); | |
update_user_meta($user_id, '_phone_number', $phone); | |
echo '1'; | |
} else { | |
echo '0'; | |
} | |
die(0); | |
} | |
/* Ajax call for Change Profile Password */ | |
add_action('wp_ajax_nopriv_change_password', 'change_password_callback'); | |
add_action('wp_ajax_change_password', 'change_password_callback'); | |
function change_password_callback() { | |
$old_password = $_POST["old_password"]; | |
$new_password = $_POST["new_password"]; | |
$user_id = $_POST["user_id"]; | |
$user_info = get_userdata($user_id); | |
if (wp_check_password($old_password, $user_info->user_pass, $user_id)) { | |
$user_data = array( | |
'ID' => $user_id, | |
'user_pass' => $new_password | |
); | |
wp_update_user($user_data); | |
// wp_clear_auth_cookie(); | |
wp_logout(); | |
ob_clean(); | |
echo "1"; | |
} else { | |
echo "0"; | |
} | |
die(0); | |
} | |
add_filter('wp_nav_menu_items', 'wti_loginout_menu_link', 10, 2); | |
function wti_loginout_menu_link($items, $args) { | |
if ($args->theme_location == 'profile_menu') { | |
if (is_user_logged_in()) { | |
$items .= '<li class="right"><a href="' . wp_logout_url(home_url()) . '">' . __("Log Out") . '</a></li>'; | |
} | |
} | |
return $items; | |
} | |
add_action('after_setup_theme', 'remove_admin_bar'); | |
function remove_admin_bar() { | |
if (!current_user_can('administrator') && !is_admin()) { | |
show_admin_bar(false); | |
} | |
} | |
//code to save step form 1 | |
function array_filter_recursive($input){ | |
foreach ($input as &$value){ | |
if (is_array($value)){ | |
$value = array_filter_recursive($value); | |
} | |
} | |
return array_filter($input); | |
} | |
/* Ajax call for Change Profile Password */ | |
add_action('wp_ajax_nopriv_save_step_form1', 'save_step_form1_callback'); | |
add_action('wp_ajax_save_step_form1', 'save_step_form1_callback'); | |
function save_step_form1_callback() { | |
// $alldata = array_map('array_filter', $_POST); | |
$alldata = array_filter_recursive($_POST); | |
print_r($alldata); | |
die(0); | |
$user_id = get_current_user_id(); | |
if ($_POST['sec1_company_name'] && $_POST['sec1_company_address']) { | |
$id = wp_insert_post(array('post_title' => $_POST['sec1_company_name'], 'post_author' => $user_id, 'post_type' => 'submitted_forms', 'post_content' => '', 'post_status' => 'draft')); | |
if ($id) { | |
foreach ($alldata as $key => $value) { | |
if (!empty($value)) { | |
update_post_meta($id, $key, $value); | |
} | |
} | |
echo "1"; | |
} | |
} else { | |
echo "0"; | |
} | |
die(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment