| 1 |
<?php |
| 2 |
/****************************************************************************************** |
| 3 |
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License |
| 4 |
* Unauthorized copying of this file, via any medium is strictly prohibited |
| 5 |
* Proprietary and confidential |
| 6 |
* You can contact Smackcoders at email address info@smackcoders.com. |
| 7 |
*******************************************************************************************/ |
| 8 |
namespace Smackcoders\SMUSERS; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) |
| 11 |
exit; // Exit if accessed directly |
| 12 |
|
| 13 |
/** |
| 14 |
* Class SendPassword |
| 15 |
* @package Smackcoders\SMUSERS |
| 16 |
*/ |
| 17 |
class SendPassword { |
| 18 |
|
| 19 |
protected static $instance = null; |
| 20 |
|
| 21 |
public static function getInstance() { |
| 22 |
if ( null == self::$instance ) { |
| 23 |
self::$instance = new self; |
| 24 |
self::$instance->doHooks(); |
| 25 |
} |
| 26 |
return self::$instance; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* SendPassword constructor. |
| 31 |
*/ |
| 32 |
public function __construct() { |
| 33 |
$this->plugin = Plugin::getInstance(); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* SendPassword hooks. |
| 38 |
*/ |
| 39 |
public function doHooks(){ |
| 40 |
add_action('wp_ajax_settings_options', array($this,'settingsOptions')); |
| 41 |
add_action('wp_ajax_send_login_credentials_to_users', array($this,'send_login_credentials_to_users')); |
| 42 |
add_action('wp_ajax_get_options', array($this,'showOptions')); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Function for save settings options |
| 47 |
* |
| 48 |
*/ |
| 49 |
public function settingsOptions() { |
| 50 |
$ucisettings = get_option('sm_uci_pro_settings'); |
| 51 |
$option = sanitize_text_field($_POST['option']); |
| 52 |
$value = sanitize_text_field($_POST['value']); |
| 53 |
foreach ($ucisettings as $key => $val) { |
| 54 |
$settings[$key] = $val; |
| 55 |
} |
| 56 |
$settings[$option] = $value; |
| 57 |
update_option('sm_uci_pro_settings', $settings); |
| 58 |
$result['success'] = true; |
| 59 |
echo wp_json_encode($result); |
| 60 |
wp_die(); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Function for show settings options |
| 65 |
* |
| 66 |
*/ |
| 67 |
public function showOptions() { |
| 68 |
$ucisettings = get_option('sm_uci_pro_settings'); |
| 69 |
foreach ($ucisettings as $key => $val) { |
| 70 |
$settings[$key] = json_decode($val); |
| 71 |
} |
| 72 |
$result['options'] = $settings; |
| 73 |
echo wp_json_encode($result); |
| 74 |
wp_die(); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* send login credential to user |
| 79 |
* |
| 80 |
*/ |
| 81 |
public function send_login_credentials_to_users() { |
| 82 |
require_once(ABSPATH . "wp-includes/pluggable.php"); |
| 83 |
global $wpdb; |
| 84 |
$ucisettings = get_option('sm_uci_pro_settings'); |
| 85 |
if($ucisettings['send_user_password'] == "true") { |
| 86 |
$get_user_meta_info = $wpdb->get_results( $wpdb->prepare("select *from {$wpdb->prefix}usermeta where meta_key like %s", '%' . 'smack_uci_import' . '%') ); |
| 87 |
if(!empty($get_user_meta_info)) { |
| 88 |
foreach($get_user_meta_info as $key => $value) { |
| 89 |
$data_array = maybe_unserialize($value->meta_value); |
| 90 |
$currentUser = wp_get_current_user(); |
| 91 |
$admin_email = $currentUser->user_email; |
| 92 |
$em_headers = "From: Administrator <$admin_email>"; # . "\r\n"; |
| 93 |
$message = "Hi,You've been invited with the role of " . $data_array['role'] . ". Here, your login details." . "\n" . "username: " . $data_array['user_login'] . "\n" . "userpass: " . $data_array['user_pass'] . "\n" . "Please click here to login " . wp_login_url(); |
| 94 |
$emailaddress = $data_array['user_email']; |
| 95 |
$subject = 'Login Details'; |
| 96 |
if( wp_mail( $emailaddress, $subject, $message) ){ |
| 97 |
delete_user_meta($value->user_id, 'smack_uci_import'); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|