views
4 days ago
Dashboard.php
5 months ago
EditProfile.php
6 months ago
Login.php
5 months ago
PublicProfile.php
6 months ago
Register.php
6 months ago
User.php
2 months ago
UserController.php
4 months ago
EditProfile.php
114 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDM\User; |
| 4 | |
| 5 | use WPDM\__\__; |
| 6 | use WPDM\__\Crypt; |
| 7 | use WPDM\__\Email; |
| 8 | use WPDM\__\__MailUI; |
| 9 | use WPDM\__\Session; |
| 10 | use WPDM\__\Template; |
| 11 | use WPDM\Form\Form; |
| 12 | |
| 13 | if(!defined("ABSPATH")) die("Shit happens!"); |
| 14 | |
| 15 | class EditProfile |
| 16 | { |
| 17 | private static $instance; |
| 18 | |
| 19 | public static function getInstance() |
| 20 | { |
| 21 | if (self::$instance === null) { |
| 22 | self::$instance = new self; |
| 23 | } |
| 24 | return self::$instance; |
| 25 | } |
| 26 | |
| 27 | private function __construct() |
| 28 | { |
| 29 | add_action("init", [$this, 'logout']); |
| 30 | add_action('init', [$this, 'updateProfile']); |
| 31 | add_shortcode("wpdm_edit_profile", [$this, 'editProfile']); |
| 32 | } |
| 33 | |
| 34 | function editProfile() |
| 35 | { |
| 36 | ob_start(); |
| 37 | include Template::locate("dashboard/edit-profile.php", __DIR__ . '/views'); |
| 38 | return ob_get_clean(); |
| 39 | } |
| 40 | |
| 41 | function logout() |
| 42 | { |
| 43 | if (isset($_REQUEST['logout']) && wp_verify_nonce(wpdm_query_var('logout'), NONCE_KEY)) { |
| 44 | wp_logout(); |
| 45 | wp_safe_redirect(wpdm_login_url()); |
| 46 | die(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function updateProfile() |
| 51 | { |
| 52 | $current_user = wp_get_current_user(); |
| 53 | if (isset($_POST['wpdm_profile']) && is_user_logged_in() && wp_verify_nonce(wpdm_query_var('__wpdm_epnonce'), NONCE_KEY)) { |
| 54 | |
| 55 | $error = 0; |
| 56 | |
| 57 | $pfile_data['display_name'] = wpdm_sanitize_var($_POST['wpdm_profile']['display_name']); |
| 58 | $pfile_data['user_email'] = sanitize_email($_POST['wpdm_profile']['user_email']); |
| 59 | |
| 60 | |
| 61 | if ($_POST['password'] !== $_POST['cpassword']) { |
| 62 | Session::set('member_error', 'Password not matched'); |
| 63 | $error = 1; |
| 64 | } |
| 65 | if (!$error) { |
| 66 | $pfile_data['ID'] = $current_user->ID; |
| 67 | if ($_POST['password'] != '') |
| 68 | $pfile_data['user_pass'] = $_POST['password']; |
| 69 | |
| 70 | wp_update_user($pfile_data); |
| 71 | |
| 72 | update_user_meta($current_user->ID, '__wpdm_title', __::query_var('wpdm_profile/title', 'txt')); |
| 73 | update_user_meta($current_user->ID, 'description', __::query_var('wpdm_profile/description', 'txt')); |
| 74 | |
| 75 | if(isset($_POST['payment_account'])) |
| 76 | update_user_meta($current_user->ID, 'payment_account', $_POST['payment_account']); |
| 77 | |
| 78 | Session::set('member_success', 'Profile data updated successfully.'); |
| 79 | } |
| 80 | |
| 81 | if(__::query_var('__wpdm_profile_pic')) { |
| 82 | $profile = maybe_unserialize(get_user_meta(get_current_user_id(), '__wpdm_public_profile', true)); |
| 83 | if(!is_array($profile)) $profile = []; |
| 84 | $profile['logo'] = __::query_var('__wpdm_profile_pic', 'url'); |
| 85 | update_user_meta(get_current_user_id(), '__wpdm_public_profile', $profile); |
| 86 | } |
| 87 | |
| 88 | do_action("wpdm_update_profile", $current_user->ID); |
| 89 | |
| 90 | if (wpdm_is_ajax()) { |
| 91 | if (ob_get_length() > 0) @ob_clean(); |
| 92 | if ($error == 1) { |
| 93 | $msg['type'] = 'danger'; |
| 94 | $msg['title'] = 'ERROR!'; |
| 95 | $msg['msg'] = Session::get('member_error'); |
| 96 | Session::clear('member_error'); |
| 97 | wp_send_json($msg); |
| 98 | die(); |
| 99 | } else { |
| 100 | $msg['type'] = 'success'; |
| 101 | $msg['title'] = 'DONE!'; |
| 102 | $msg['msg'] = Session::get('member_success'); |
| 103 | Session::clear('member_success'); |
| 104 | $msg['data'] = $pfile_data; |
| 105 | wp_send_json($msg); |
| 106 | die(); |
| 107 | } |
| 108 | } |
| 109 | header("location: " . $_SERVER['HTTP_REFERER']); |
| 110 | die(); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 |