elementor
3 years ago
admin-create-shortcode.php
7 years ago
admin-create-user.php
3 years ago
admin-custom-function.php
3 years ago
admin-rest-api.php
4 years ago
admin-settings.php
3 years ago
admin-social-button.php
3 years ago
admin-social-enque-script.php
5 years ago
counter-widget.php
3 years ago
counter.php
3 years ago
custom-function.php
4 years ago
login-widget.php
3 years ago
login.php
5 years ago
share-widget.php
3 years ago
share.php
3 years ago
login.php
125 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Inc; |
| 4 | |
| 5 | /** |
| 6 | * Login functionality for social logins |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | defined('ABSPATH') || exit; |
| 11 | |
| 12 | class Login { |
| 13 | |
| 14 | /** |
| 15 | * =================== |
| 16 | * Singleton |
| 17 | * =================== |
| 18 | */ |
| 19 | |
| 20 | private static $instance; |
| 21 | |
| 22 | |
| 23 | public static function instance() { |
| 24 | |
| 25 | if(!self::$instance) { |
| 26 | self::$instance = new self(); |
| 27 | } |
| 28 | |
| 29 | return self::$instance; |
| 30 | |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * ========================= |
| 36 | * Execution point |
| 37 | * ========================= |
| 38 | */ |
| 39 | |
| 40 | public function init() { |
| 41 | |
| 42 | add_action('wp_login', [$this, 'after_login'], 10, 2); |
| 43 | |
| 44 | add_action('profile_update', [$this, 'after_password_rest']); |
| 45 | |
| 46 | add_action('init', [$this, 'rest_api']); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | |
| 51 | public function rest_api() { |
| 52 | |
| 53 | add_action('rest_api_init', function() { |
| 54 | register_rest_route('wp-social', 'user/meta', [ |
| 55 | 'methods' => 'GET', |
| 56 | 'callback' => [$this, 'check_meta'], |
| 57 | 'permission_callback' => '__return_true', |
| 58 | ]); |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | public function check_meta() { |
| 64 | $user_meta = get_user_meta(5, 'xs_password_changed'); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * ===================== |
| 70 | * After login |
| 71 | * ===================== |
| 72 | */ |
| 73 | |
| 74 | public function after_login($user_login, $user) { |
| 75 | |
| 76 | |
| 77 | $user_meta = get_user_meta($user->ID, 'xs_password_changed', true); |
| 78 | |
| 79 | /* |
| 80 | ------------------------------------- |
| 81 | Check if user is created by WP Social |
| 82 | ------------------------------------- |
| 83 | */ |
| 84 | |
| 85 | if($user_meta) { |
| 86 | |
| 87 | /** |
| 88 | * Check if user changed the password. |
| 89 | * If it says 'no' that means user did |
| 90 | * not change the password so we should |
| 91 | * loggout them |
| 92 | */ |
| 93 | |
| 94 | if($user_meta == 'no') { |
| 95 | |
| 96 | wp_logout(); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * ====================================== |
| 104 | * After password reset |
| 105 | *======================================= |
| 106 | */ |
| 107 | |
| 108 | public function after_password_rest() { |
| 109 | |
| 110 | $user_id = get_current_user_id(); |
| 111 | |
| 112 | /** If password does not change */ |
| 113 | |
| 114 | if(!isset($_POST['pass1']) || '' == $_POST['pass1']) { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | $user_meta = get_user_meta($user_id, 'xs_password_changed', true); |
| 119 | |
| 120 | if($user_meta) { |
| 121 | update_user_meta($user_id, 'xs_password_changed', 'yes'); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 |