Temporary Login Without Password - Version 1.4

Version Description

  • Added: Support for "Theme My Login" plugin. Now, temporary user will be redirected to page which is defined in Theme My Login plugin.
Download this release

Release Info

Developer storeapps
Plugin Icon 128x128 Temporary Login Without Password
Version 1.4
Comparing to
See all releases

Code changes from version 1.2 to 1.4

admin/class-wp-temporary-login-without-password-admin.php CHANGED
@@ -43,25 +43,25 @@ class Wp_Temporary_Login_Without_Password_Admin {
43
  $data = $_POST['wtlwp_data'];
44
  $email = $data['user_email'];
45
  $error = false;
46
-
47
  $redirect_link = '';
48
  if (false == Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) {
49
  $result = array('status' => 'error', 'message' => 'unathorised_access');
50
  $error = true;
51
- }else if (!wp_verify_nonce($_POST['wtlwp-nonce'], 'wtlwp_generate_login_url')) {
52
  $result = array('status' => 'error', 'message' => 'nonce_failed');
53
  $error = true;
54
- }else if (empty($data['user_email'])) {
55
  $result = array('status' => 'error', 'message' => 'empty_email');
56
  $error = true;
57
- }else if (!is_email($email)) {
58
  $result = array('status' => 'error', 'message' => 'not_valid_email');
59
  $error = true;
60
- }else if (!empty($data['user_email']) && email_exists($data['user_email'])) {
61
  $result = array('status' => 'error', 'message' => 'email_is_in_use');
62
  $error = true;
63
  }
64
-
65
  if (!$error) {
66
  $user = Wp_Temporary_Login_Without_Password_Common::create_new_user($data);
67
  if (!empty($user['error'])) {
@@ -74,11 +74,11 @@ class Wp_Temporary_Login_Without_Password_Admin {
74
  }
75
  }
76
 
77
- if(empty($redirect_link)) {
78
  $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link($result);
79
  }
80
-
81
-
82
  wp_redirect($redirect_link, 302);
83
  exit();
84
  }
@@ -96,7 +96,7 @@ class Wp_Temporary_Login_Without_Password_Admin {
96
  if (!wp_verify_nonce($nonce, 'manage-temporary-login_' . $user_id)) {
97
  $result = array('status' => 'error', 'message' => 'nonce_failed');
98
  $error = true;
99
- } else if(!Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, false)) {
100
  $result = array('status' => 'error', 'message' => 'is_not_temporary_login');
101
  $error = true;
102
  }
@@ -120,12 +120,12 @@ class Wp_Temporary_Login_Without_Password_Admin {
120
  if ((false === Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) || empty($_REQUEST['wtlwp_action']) || ($_REQUEST['wtlwp_action'] != 'disable' && $_REQUEST['wtlwp_action'] != 'enable') || empty($_REQUEST['user_id']) || (absint($_REQUEST['user_id']) == 0)) {
121
  return;
122
  }
123
-
124
  $error = false;
125
  $user_id = absint($_REQUEST['user_id']);
126
  $action = $_REQUEST['wtlwp_action'];
127
  $nonce = $_REQUEST['manage-temporary-login'];
128
-
129
  $is_valid_temporary_user = Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, false);
130
 
131
  if (!$is_valid_temporary_user) {
@@ -135,8 +135,8 @@ class Wp_Temporary_Login_Without_Password_Admin {
135
  $result = array('status' => 'error', 'message' => 'nonce_failed');
136
  $error = true;
137
  }
138
-
139
- if(!$error) {
140
  if ($action == 'disable') {
141
  $disable_login = Wp_Temporary_Login_Without_Password_Common::manage_login(absint($user_id), 'disable');
142
  if ($disable_login) {
@@ -147,7 +147,7 @@ class Wp_Temporary_Login_Without_Password_Admin {
147
  }
148
  } else if ($action == 'enable') {
149
  $enable_login = Wp_Temporary_Login_Without_Password_Common::manage_login(absint($user_id), 'enable');
150
-
151
  if ($enable_login) {
152
  $result = array('status' => 'success', 'message' => 'login_enabled');
153
  } else {
@@ -159,7 +159,7 @@ class Wp_Temporary_Login_Without_Password_Admin {
159
  $error = true;
160
  }
161
  }
162
-
163
  $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link($result);
164
  wp_redirect($redirect_link, 302);
165
  exit();
@@ -192,7 +192,7 @@ class Wp_Temporary_Login_Without_Password_Admin {
192
  case 'empty_email':
193
  $message = __('Please enter valid email address. Email field should not be empty', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
194
  break;
195
-
196
  case 'not_valid_email':
197
  $message = __('Please enter valid email address', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
198
  break;
@@ -233,7 +233,7 @@ class Wp_Temporary_Login_Without_Password_Admin {
233
  case 'login_enabled':
234
  $message = __('Login enabled successfully!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
235
  break;
236
-
237
  default:
238
  $message = __('Success!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
239
  break;
43
  $data = $_POST['wtlwp_data'];
44
  $email = $data['user_email'];
45
  $error = false;
46
+
47
  $redirect_link = '';
48
  if (false == Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) {
49
  $result = array('status' => 'error', 'message' => 'unathorised_access');
50
  $error = true;
51
+ } else if (!wp_verify_nonce($_POST['wtlwp-nonce'], 'wtlwp_generate_login_url')) {
52
  $result = array('status' => 'error', 'message' => 'nonce_failed');
53
  $error = true;
54
+ } else if (empty($data['user_email'])) {
55
  $result = array('status' => 'error', 'message' => 'empty_email');
56
  $error = true;
57
+ } else if (!is_email($email)) {
58
  $result = array('status' => 'error', 'message' => 'not_valid_email');
59
  $error = true;
60
+ } else if (!empty($data['user_email']) && email_exists($data['user_email'])) {
61
  $result = array('status' => 'error', 'message' => 'email_is_in_use');
62
  $error = true;
63
  }
64
+
65
  if (!$error) {
66
  $user = Wp_Temporary_Login_Without_Password_Common::create_new_user($data);
67
  if (!empty($user['error'])) {
74
  }
75
  }
76
 
77
+ if (empty($redirect_link)) {
78
  $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link($result);
79
  }
80
+
81
+
82
  wp_redirect($redirect_link, 302);
83
  exit();
84
  }
96
  if (!wp_verify_nonce($nonce, 'manage-temporary-login_' . $user_id)) {
97
  $result = array('status' => 'error', 'message' => 'nonce_failed');
98
  $error = true;
99
+ } else if (!Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, false)) {
100
  $result = array('status' => 'error', 'message' => 'is_not_temporary_login');
101
  $error = true;
102
  }
120
  if ((false === Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) || empty($_REQUEST['wtlwp_action']) || ($_REQUEST['wtlwp_action'] != 'disable' && $_REQUEST['wtlwp_action'] != 'enable') || empty($_REQUEST['user_id']) || (absint($_REQUEST['user_id']) == 0)) {
121
  return;
122
  }
123
+
124
  $error = false;
125
  $user_id = absint($_REQUEST['user_id']);
126
  $action = $_REQUEST['wtlwp_action'];
127
  $nonce = $_REQUEST['manage-temporary-login'];
128
+
129
  $is_valid_temporary_user = Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, false);
130
 
131
  if (!$is_valid_temporary_user) {
135
  $result = array('status' => 'error', 'message' => 'nonce_failed');
136
  $error = true;
137
  }
138
+
139
+ if (!$error) {
140
  if ($action == 'disable') {
141
  $disable_login = Wp_Temporary_Login_Without_Password_Common::manage_login(absint($user_id), 'disable');
142
  if ($disable_login) {
147
  }
148
  } else if ($action == 'enable') {
149
  $enable_login = Wp_Temporary_Login_Without_Password_Common::manage_login(absint($user_id), 'enable');
150
+
151
  if ($enable_login) {
152
  $result = array('status' => 'success', 'message' => 'login_enabled');
153
  } else {
159
  $error = true;
160
  }
161
  }
162
+
163
  $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link($result);
164
  wp_redirect($redirect_link, 302);
165
  exit();
192
  case 'empty_email':
193
  $message = __('Please enter valid email address. Email field should not be empty', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
194
  break;
195
+
196
  case 'not_valid_email':
197
  $message = __('Please enter valid email address', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
198
  break;
233
  case 'login_enabled':
234
  $message = __('Login enabled successfully!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
235
  break;
236
+
237
  default:
238
  $message = __('Success!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
239
  break;
includes/class-wp-temporary-login-without-password-activator.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wp_Temporary_Login_Without_Password_Activator {
4
+
5
+ public static function activate() {
6
+
7
+ $temporary_logins_data = get_option('temporary_logins_data', array());
8
+
9
+ if (count($temporary_logins_data) > 0) {
10
+ foreach ($temporary_logins_data as $user_id => $user_role) {
11
+ wp_update_user(array('ID' => $user_id, 'role' => $user_role));
12
+ }
13
+ }
14
+
15
+ $add = 'yes';
16
+
17
+ // Empty set
18
+ update_option('temporary_logins_data', array(), $add);
19
+ }
20
+
21
+ }
includes/class-wp-temporary-login-without-password-common.php CHANGED
@@ -62,7 +62,7 @@ class Wp_Temporary_Login_Without_Password_Common {
62
  update_user_meta($user_id, '_wtlwp_created', Wp_Temporary_Login_Without_Password_Common::get_current_gmt_timestamp());
63
  update_user_meta($user_id, '_wtlwp_expire', Wp_Temporary_Login_Without_Password_Common::get_user_expire_time($time));
64
  update_user_meta($user_id, '_wtlwp_token', Wp_Temporary_Login_Without_Password_Common::generate_wtlwp_token($user_id));
65
-
66
  update_user_meta($user_id, 'show_welcome_panel', 0);
67
 
68
  return $user_id;
@@ -146,7 +146,7 @@ class Wp_Temporary_Login_Without_Password_Common {
146
  return strtotime(gmdate('Y-m-d H:i:s', time()));
147
  }
148
 
149
- public static function get_temporary_logins() {
150
 
151
  $args = array(
152
  'fields' => 'all',
@@ -267,7 +267,7 @@ class Wp_Temporary_Login_Without_Password_Common {
267
  if (empty($token)) {
268
  return false;
269
  }
270
-
271
  $args = array(
272
  'fields' => $fields,
273
  'meta_key' => '_wtlwp_expire',
@@ -304,10 +304,10 @@ class Wp_Temporary_Login_Without_Password_Common {
304
  if (empty($user_id)) {
305
  return false;
306
  }
307
-
308
  $check = get_user_meta($user_id, '_wtlwp_user', true);
309
-
310
- if(!empty($check) && $check_expiry) {
311
  $check = !(self::is_login_expired($user_id));
312
  }
313
 
@@ -322,33 +322,33 @@ class Wp_Temporary_Login_Without_Password_Common {
322
 
323
  $base_url = menu_page_url('wp-temporary-login-without-password', false);
324
  $args = array();
325
-
326
- switch($action) {
327
  case 'disable';
328
- $args = array('wtlwp_action' => 'disable','user_id' => $user_id);
329
  break;
330
  case 'enable';
331
- $args = array('wtlwp_action' => 'enable','user_id' => $user_id);
332
  break;
333
  case 'delete';
334
- $args = array('wtlwp_action' => 'delete','user_id' => $user_id);
335
  break;
336
  default:
337
  break;
338
  }
339
-
340
  $manage_login_url = '';
341
  if (!empty($args)) {
342
  $base_url = add_query_arg($args, trailingslashit($base_url));
343
  $manage_login_url = wp_nonce_url($base_url, 'manage-temporary-login_' . $user_id, 'manage-temporary-login');
344
- }
345
 
346
  return $manage_login_url;
347
  }
348
 
349
  public static function get_login_url($user_id) {
350
 
351
- if (empty($user_id) ) {
352
  return;
353
  }
354
 
@@ -411,7 +411,7 @@ class Wp_Temporary_Login_Without_Password_Common {
411
  60 => 'minute',
412
  1 => 'second'
413
  );
414
-
415
  $a_plural = array('year' => 'years',
416
  'month' => 'months',
417
  'day' => 'days',
@@ -438,5 +438,21 @@ class Wp_Temporary_Login_Without_Password_Common {
438
  $blocked_pages = apply_filters('wtlwp_restricted_pages_for_temporary_users', $blocked_pages);
439
  return $blocked_pages;
440
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
 
442
  }
62
  update_user_meta($user_id, '_wtlwp_created', Wp_Temporary_Login_Without_Password_Common::get_current_gmt_timestamp());
63
  update_user_meta($user_id, '_wtlwp_expire', Wp_Temporary_Login_Without_Password_Common::get_user_expire_time($time));
64
  update_user_meta($user_id, '_wtlwp_token', Wp_Temporary_Login_Without_Password_Common::generate_wtlwp_token($user_id));
65
+
66
  update_user_meta($user_id, 'show_welcome_panel', 0);
67
 
68
  return $user_id;
146
  return strtotime(gmdate('Y-m-d H:i:s', time()));
147
  }
148
 
149
+ public static function get_temporary_logins( $role = '') {
150
 
151
  $args = array(
152
  'fields' => 'all',
267
  if (empty($token)) {
268
  return false;
269
  }
270
+
271
  $args = array(
272
  'fields' => $fields,
273
  'meta_key' => '_wtlwp_expire',
304
  if (empty($user_id)) {
305
  return false;
306
  }
307
+
308
  $check = get_user_meta($user_id, '_wtlwp_user', true);
309
+
310
+ if (!empty($check) && $check_expiry) {
311
  $check = !(self::is_login_expired($user_id));
312
  }
313
 
322
 
323
  $base_url = menu_page_url('wp-temporary-login-without-password', false);
324
  $args = array();
325
+
326
+ switch ($action) {
327
  case 'disable';
328
+ $args = array('wtlwp_action' => 'disable', 'user_id' => $user_id);
329
  break;
330
  case 'enable';
331
+ $args = array('wtlwp_action' => 'enable', 'user_id' => $user_id);
332
  break;
333
  case 'delete';
334
+ $args = array('wtlwp_action' => 'delete', 'user_id' => $user_id);
335
  break;
336
  default:
337
  break;
338
  }
339
+
340
  $manage_login_url = '';
341
  if (!empty($args)) {
342
  $base_url = add_query_arg($args, trailingslashit($base_url));
343
  $manage_login_url = wp_nonce_url($base_url, 'manage-temporary-login_' . $user_id, 'manage-temporary-login');
344
+ }
345
 
346
  return $manage_login_url;
347
  }
348
 
349
  public static function get_login_url($user_id) {
350
 
351
+ if (empty($user_id)) {
352
  return;
353
  }
354
 
411
  60 => 'minute',
412
  1 => 'second'
413
  );
414
+
415
  $a_plural = array('year' => 'years',
416
  'month' => 'months',
417
  'day' => 'days',
438
  $blocked_pages = apply_filters('wtlwp_restricted_pages_for_temporary_users', $blocked_pages);
439
  return $blocked_pages;
440
  }
441
+
442
+ public static function delete_temporary_logins () {
443
+
444
+ $temporary_logins = Wp_Temporary_Login_Without_Password_Common::get_temporary_logins();
445
+
446
+ if (count($temporary_logins) > 0) {
447
+ foreach ($temporary_logins as $user) {
448
+ if ($user instanceof WP_User) {
449
+ $user = wp_delete_user($user->ID); // Delete User
450
+ }
451
+ }
452
+ }
453
+
454
+
455
+ }
456
+
457
 
458
  }
includes/class-wp-temporary-login-without-password-deactivator.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wp_Temporary_Login_Without_Password_Deactivator {
4
+
5
+ public static function deactivate() {
6
+
7
+ $temporary_logins = Wp_Temporary_Login_Without_Password_Common::get_temporary_logins();
8
+
9
+ $temporary_logins_data = array();
10
+ if (count($temporary_logins) > 0) {
11
+ foreach ($temporary_logins as $user) {
12
+ if ($user instanceof WP_User) {
13
+ $temporary_logins_data[$user->ID] = $user->roles[0];
14
+ $user = wp_update_user(array('ID' => $user->ID, 'role' => '')); // Downgrade role to none. So, user won't be able to login
15
+ }
16
+ }
17
+ }
18
+
19
+ $add = 'yes';
20
+ update_option('temporary_logins_data', $temporary_logins_data, $add);
21
+ }
22
+
23
+ }
includes/class-wp-temporary-login-without-password-layout.php CHANGED
@@ -51,6 +51,7 @@ class Wp_Temporary_Login_Without_Password_Layout {
51
 
52
  $capabilities = $user->{$wpdb->prefix . 'capabilities'};
53
  $wp_roles = new WP_Roles();
 
54
  foreach ($wp_roles->role_names as $role => $name) {
55
  if (array_key_exists($role, $capabilities)) {
56
  $user_role = $name;
51
 
52
  $capabilities = $user->{$wpdb->prefix . 'capabilities'};
53
  $wp_roles = new WP_Roles();
54
+ $user_role = '';
55
  foreach ($wp_roles->role_names as $role => $name) {
56
  if (array_key_exists($role, $capabilities)) {
57
  $user_role = $name;
includes/class-wp-temporary-login-without-password.php CHANGED
@@ -1,17 +1,15 @@
1
  <?php
2
 
3
  class Wp_Temporary_Login_Without_Password {
4
-
5
  protected $loader;
6
-
7
  protected $plugin_name;
8
-
9
  protected $version;
10
-
11
  public function __construct() {
12
 
13
  $this->plugin_name = 'wp-temporary-login-without-password';
14
- $this->version = '1.1';
15
 
16
  $this->load_dependencies();
17
  $this->set_locale();
@@ -24,7 +22,7 @@ class Wp_Temporary_Login_Without_Password {
24
  define($name, $value);
25
  }
26
  }
27
-
28
  private function load_dependencies() {
29
 
30
  require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wp-temporary-login-without-password-loader.php';
@@ -44,7 +42,7 @@ class Wp_Temporary_Login_Without_Password {
44
 
45
  $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
46
  }
47
-
48
  private function define_admin_hooks() {
49
 
50
  $plugin_admin = new Wp_Temporary_Login_Without_Password_Admin($this->get_plugin_name(), $this->get_version());
@@ -57,16 +55,17 @@ class Wp_Temporary_Login_Without_Password {
57
  $this->loader->add_action('admin_init', $plugin_admin, 'delete_user');
58
  $this->loader->add_action('admin_init', $plugin_admin, 'manage_temporary_login');
59
  $this->loader->add_action('admin_notices', $plugin_admin, 'display_admin_notices');
60
-
61
  $this->loader->add_filter('wpmu_welcome_notification', $plugin_admin, 'disable_welcome_notification', 10, 5);
62
  }
63
 
64
  private function define_public_hooks() {
65
 
66
  $plugin_public = new Wp_Temporary_Login_Without_Password_Public($this->get_plugin_name(), $this->get_version());
67
-
68
  $this->loader->add_action('init', $plugin_public, 'init_wtlwp');
69
- $this->loader->add_filter('authenticate', $plugin_public, 'wtlwp_authenticate', 10, 3);
 
70
  }
71
 
72
  public function run() {
@@ -76,7 +75,7 @@ class Wp_Temporary_Login_Without_Password {
76
  public function get_plugin_name() {
77
  return $this->plugin_name;
78
  }
79
-
80
  public function get_loader() {
81
  return $this->loader;
82
  }
1
  <?php
2
 
3
  class Wp_Temporary_Login_Without_Password {
4
+
5
  protected $loader;
 
6
  protected $plugin_name;
 
7
  protected $version;
8
+
9
  public function __construct() {
10
 
11
  $this->plugin_name = 'wp-temporary-login-without-password';
12
+ $this->version = '1.4';
13
 
14
  $this->load_dependencies();
15
  $this->set_locale();
22
  define($name, $value);
23
  }
24
  }
25
+
26
  private function load_dependencies() {
27
 
28
  require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wp-temporary-login-without-password-loader.php';
42
 
43
  $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
44
  }
45
+
46
  private function define_admin_hooks() {
47
 
48
  $plugin_admin = new Wp_Temporary_Login_Without_Password_Admin($this->get_plugin_name(), $this->get_version());
55
  $this->loader->add_action('admin_init', $plugin_admin, 'delete_user');
56
  $this->loader->add_action('admin_init', $plugin_admin, 'manage_temporary_login');
57
  $this->loader->add_action('admin_notices', $plugin_admin, 'display_admin_notices');
58
+
59
  $this->loader->add_filter('wpmu_welcome_notification', $plugin_admin, 'disable_welcome_notification', 10, 5);
60
  }
61
 
62
  private function define_public_hooks() {
63
 
64
  $plugin_public = new Wp_Temporary_Login_Without_Password_Public($this->get_plugin_name(), $this->get_version());
65
+
66
  $this->loader->add_action('init', $plugin_public, 'init_wtlwp');
67
+ $this->loader->add_filter('wp_authenticate_user', $plugin_public, 'disable_temporary_user_login', 10, 2);
68
+ $this->loader->add_filter('allow_password_reset', $plugin_public, 'disable_password_reset', 10, 2);
69
  }
70
 
71
  public function run() {
75
  public function get_plugin_name() {
76
  return $this->plugin_name;
77
  }
78
+
79
  public function get_loader() {
80
  return $this->loader;
81
  }
public/class-wp-temporary-login-without-password-public.php CHANGED
@@ -44,8 +44,17 @@ class Wp_Temporary_Login_Without_Password_Public {
44
  wp_set_current_user($user_id, $user_login);
45
  wp_set_auth_cookie($user_id);
46
 
 
 
 
47
  do_action('wp_login', $user_login, $user);
48
- wp_safe_redirect(admin_url()); // Redirect to admin dashboard after successfull login
 
 
 
 
 
 
49
  }
50
  exit();
51
  }
@@ -69,24 +78,44 @@ class Wp_Temporary_Login_Without_Password_Public {
69
  }
70
  }
71
 
72
- function wtlwp_authenticate($user, $username, $password) {
73
-
74
- $user_id = username_exists($username);
75
-
76
- if (!$user_id) {
77
- return new WP_Error('denied', __("ERROR: Invalid username."));
 
 
 
 
 
 
 
 
 
78
  }
79
 
80
- $check_expiry = false;
81
- $is_valid_temporary_login = Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, $check_expiry);
82
- if ($is_valid_temporary_login) {
83
- $is_login_expired = Wp_Temporary_Login_Without_Password_Common::is_login_expired($user_id);
84
- update_user_meta($user_id, '_wtlwp_last_login', Wp_Temporary_Login_Without_Password_Common::get_current_gmt_timestamp());
85
- $user = new WP_Error('denied', __("ERROR: User can't find."));
86
- remove_action('authenticate', 'wp_authenticate_username_password', 20);
87
- }
88
-
89
  return $user;
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  }
44
  wp_set_current_user($user_id, $user_login);
45
  wp_set_auth_cookie($user_id);
46
 
47
+ $redirect_to = admin_url();
48
+ $redirect_to_url = apply_filters( 'login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user );
49
+
50
  do_action('wp_login', $user_login, $user);
51
+
52
+ // If empty redirect user to admin page.
53
+ if(!empty($redirect_to_url)) {
54
+ $redirect_to = $redirect_to_url;
55
+ }
56
+
57
+ wp_safe_redirect($redirect_to); // Redirect to given url after successfull login
58
  }
59
  exit();
60
  }
78
  }
79
  }
80
 
81
+ /**
82
+ * Hooked to wp_authenticate_user filter to disable login for temporary user using username/email and password
83
+ *
84
+ * @param type $user
85
+ * @param type $password
86
+ * @return \WP_Error
87
+ */
88
+ function disable_temporary_user_login($user, $password) {
89
+
90
+ if ($user instanceof WP_User) {
91
+ $check_expiry = false;
92
+ $is_valid_temporary_login = Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user->ID, $check_expiry);
93
+ if ($is_valid_temporary_login) {
94
+ $user = new WP_Error('denied', __("ERROR: User can't find."));
95
+ }
96
  }
97
 
 
 
 
 
 
 
 
 
 
98
  return $user;
99
  }
100
+
101
+ /**
102
+ * Hooked to allow_password_reset filter to disable reset password for temporary user
103
+ *
104
+ * @param boolean $allow
105
+ * @param type $user_id
106
+ * @return boolean
107
+ */
108
+ function disable_password_reset($allow, $user_id) {
109
+
110
+ if (is_int($user_id)) {
111
+ $check_expiry = false;
112
+ $is_valid_temporary_login = Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, $check_expiry);
113
+ if ($is_valid_temporary_login) {
114
+ $allow = false;
115
+ }
116
+ }
117
+
118
+ return $allow;
119
+ }
120
 
121
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Temporary Login Without Password ===
2
  Contributors: storeapps, niravmehta, malayladu
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CPTHCDC382KVA
4
- Tags: admin, custom login, login, temporary login, wp admin, wordpress admin, access, expiration, user, login without password
5
  Requires at least: 3.0.1
6
- Tested up to: 4.5.3
7
- Stable tag: 1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -40,6 +40,16 @@ If you like Temporary Login Without Password, please leave a five star review on
40
 
41
  == Changelog ==
42
 
 
 
 
 
 
 
 
 
 
 
43
  = 1.2 =
44
 
45
  - Bug Fixed: Temporary user is able to login with username and password.
1
  === Temporary Login Without Password ===
2
  Contributors: storeapps, niravmehta, malayladu
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CPTHCDC382KVA
4
+ Tags: access, admin, admin login, custom login, customer access, customer login, log in, login, login security, protection, secure login, user login, user login, wordpress admin login, wordpress login, wp-admin, wp-login, expiration, login, Login Without Password, temporary login, user, WordPress Admin, wp-admin, developer account, developer login, developer account, passwordless login, password less login
5
  Requires at least: 3.0.1
6
+ Tested up to: 4.6
7
+ Stable tag: 1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
40
 
41
  == Changelog ==
42
 
43
+ = 1.4 =
44
+
45
+ - Added: Support for "Theme My Login" plugin. Now, temporary user will be redirected to page which is defined in Theme My Login plugin.
46
+
47
+ = 1.3 =
48
+
49
+ - Bug Fixed: Temporary user is able to login with email address. Now onwards, temporary user is not able to login using username/email and password
50
+ - Bug Fixed: Temporary user was able to reset password. Now onwards, they won't be able to reset password.
51
+ - Now, role of temporary user is downgrade to "none" on deactivation of plugin and change to default on re activation of plugin
52
+
53
  = 1.2 =
54
 
55
  - Bug Fixed: Temporary user is able to login with username and password.
temporary-login-without-password.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Temporary Login Without Password
5
  * Plugin URI: http://storeapps.org
6
  * Description: Create a temporary login link with any role using which one can access to your sytem without username and password for limited period of time.
7
- * Version: 1.2
8
  * Author: StoreApps
9
  * Author URI: http://storeapps.org
10
  * License: GPL-2.0+
@@ -17,6 +17,20 @@ if (!defined('WPINC')) {
17
  die;
18
  }
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  // Include main class file
21
  require plugin_dir_path(__FILE__) . 'includes/class-wp-temporary-login-without-password.php';
22
 
4
  * Plugin Name: Temporary Login Without Password
5
  * Plugin URI: http://storeapps.org
6
  * Description: Create a temporary login link with any role using which one can access to your sytem without username and password for limited period of time.
7
+ * Version: 1.4
8
  * Author: StoreApps
9
  * Author URI: http://storeapps.org
10
  * License: GPL-2.0+
17
  die;
18
  }
19
 
20
+ function wp_deactivate_temporary_login_without_password () {
21
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-temporary-login-without-password-deactivator.php';
22
+ Wp_Temporary_Login_Without_Password_Deactivator::deactivate();
23
+ }
24
+
25
+ function wp_activate_temporary_login_without_password () {
26
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-temporary-login-without-password-activator.php';
27
+ Wp_Temporary_Login_Without_Password_Activator::activate();
28
+ }
29
+
30
+ register_deactivation_hook( __FILE__, 'wp_deactivate_temporary_login_without_password' );
31
+ register_activation_hook( __FILE__, 'wp_activate_temporary_login_without_password' );
32
+
33
+
34
  // Include main class file
35
  require plugin_dir_path(__FILE__) . 'includes/class-wp-temporary-login-without-password.php';
36
 
uninstall.php CHANGED
@@ -2,30 +2,10 @@
2
 
3
  /**
4
  * Fired when the plugin is uninstalled.
5
- *
6
- * When populating this file, consider the following flow
7
- * of control:
8
- *
9
- * - This method should be static
10
- * - Check if the $_REQUEST content actually is the plugin name
11
- * - Run an admin referrer check to make sure it goes through authentication
12
- * - Verify the output of $_GET makes sense
13
- * - Repeat with other user roles. Best directly by using the links/query string parameters.
14
- * - Repeat things for multisite. Once for a single site in the network, once sitewide.
15
- *
16
- * This file may be updated more in future version of the Boilerplate; however, this is the
17
- * general skeleton and outline for how the file should work.
18
- *
19
- * For more information, see the following discussion:
20
- * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
21
- *
22
- * @link http://storeapps.org
23
- * @since 1.0
24
- *
25
- * @package Wp_Temporary_Login_Without_Password
26
  */
27
 
28
  // If uninstall not called from WordPress, then exit.
29
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
30
  exit;
31
  }
 
2
 
3
  /**
4
  * Fired when the plugin is uninstalled.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  */
6
 
7
  // If uninstall not called from WordPress, then exit.
8
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
9
  exit;
10
  }
11
+