Temporary Login Without Password - Version 1.4.1

Version Description

  • Added: Now, create a temporary login with custom expiry date.
Download this release

Release Info

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

Code changes from version 1.4 to 1.4.1

admin/class-wp-temporary-login-without-password-admin.php CHANGED
@@ -2,275 +2,385 @@
2
 
3
  class Wp_Temporary_Login_Without_Password_Admin {
4
 
5
- private $plugin_name;
6
- private $version;
7
 
8
- public function __construct($plugin_name, $version) {
9
 
10
- $this->plugin_name = $plugin_name;
11
- $this->version = $version;
12
- }
13
 
14
- public function enqueue_styles() {
15
- wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wp-temporary-login-without-password-admin.css', array(), $this->version, 'all');
16
- }
17
 
18
- public function enqueue_scripts() {
19
- wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wp-temporary-login-without-password-admin.js', array('jquery'), $this->version, false);
20
- wp_enqueue_script('clipboardjs', plugin_dir_url(__FILE__) . 'js/clipboard.min.js', array('jquery'), $this->version, false);
21
- }
 
 
22
 
23
- public function admin_menu() {
24
- $current_user_id = get_current_user_id();
25
- if (!Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($current_user_id)) {
26
- add_users_page(__('Temporary Logins', Wp_Temporary_Login_Without_Password_i18n::$text_domain), __('Temporary Logins', Wp_Temporary_Login_Without_Password_i18n::$text_domain), apply_filters('tempadmin_user_cap', 'manage_options'), Wp_Temporary_Login_Without_Password_i18n::$text_domain, array(__class__, 'admin_settings'));
27
  }
28
- }
29
 
30
- public static function admin_settings() {
31
- $_template_file = WTLWP_PLUGIN_DIR . '/templates/admin_settings.php';
32
- $wtlwp_generated_url = !empty($_REQUEST['wtlwp_generated_url']) ? $_REQUEST['wtlwp_generated_url'] : '';
33
- $user_email = !empty($_REQUEST['user_email']) ? $_REQUEST['user_email'] : '';
34
- include $_template_file;
35
- }
36
 
37
- public function create_user() {
 
 
38
 
39
- if (empty($_POST['wtlwp_data']) || empty($_POST['wtlwp-nonce'])) {
40
- return;
41
  }
42
 
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'])) {
68
- $result = array('status' => 'error', 'message' => 'user_creation_failed');
69
- } else {
70
- $result = array('status' => 'success', 'message' => 'user_created');
71
- $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link($result);
72
- $redirect_link = add_query_arg('wtlwp_generated_url', Wp_Temporary_Login_Without_Password_Common::get_login_url($user), $redirect_link);
73
- $redirect_link = add_query_arg('user_email', $email, $redirect_link);
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
- }
85
 
86
- public static function delete_user() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
- if ((false === Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) || empty($_REQUEST['wtlwp_action']) || ($_REQUEST['wtlwp_action'] != 'delete') || empty($_REQUEST['user_id']) || (absint($_REQUEST['user_id']) == 0)) {
89
- return;
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
- $user_id = absint($_REQUEST['user_id']);
93
- $nonce = $_REQUEST['manage-temporary-login'];
94
- $redirect_url = '';
95
- $error = false;
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
- }
103
 
104
- if (!$error) {
105
- $delete_user = wp_delete_user(absint($user_id), get_current_user_id());
106
- if (!is_wp_error($delete_user)) {
107
- $result = array('status' => 'success', 'message' => 'user_deleted');
108
- } else {
109
- $result = array('status' => 'error', 'message' => 'default_error_message');
110
- }
111
  }
112
 
113
- $redirect_url = Wp_Temporary_Login_Without_Password_Common::get_redirect_link($result);
114
- wp_redirect($redirect_url, 302);
115
- exit();
116
- }
117
 
118
- public static function manage_temporary_login() {
 
 
119
 
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) {
132
- $result = array('status' => 'error', 'message' => 'is_not_temporary_login');
133
- $error = true;
134
- } else if (!wp_verify_nonce($nonce, 'manage-temporary-login_' . $user_id)) {
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) {
143
- $result = array('status' => 'success', 'message' => 'login_disabled');
144
- } else {
145
- $result = array('status' => 'error', 'message' => 'default_error_message');
146
- $error = true;
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 {
154
- $result = array('status' => 'error', 'message' => 'default_error_message');
155
- $error = true;
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
- } else {
158
- $result = array('status' => 'error', 'message' => 'invalid_action');
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();
166
- }
167
 
168
- public function display_admin_notices() {
 
 
169
 
170
- if (empty($_REQUEST['page']) || (empty($_REQUEST['page']) && $_REQUEST['page'] !== 'wp-temporary-login-without-password') || !isset($_REQUEST['wtlwp_message']) || (!isset($_REQUEST['wtlwp_error']) && !isset($_REQUEST['wtlwp_success']))) {
171
- return;
172
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
- $class = $message = '';
175
- $error = !empty($_REQUEST['wtlwp_error']) ? true : false;
176
- $success = !empty($_REQUEST['wtlwp_success']) ? true : false;
177
- if ($error) {
178
- $message_type = !empty($_REQUEST['wtlwp_message']) ? $_REQUEST['wtlwp_message'] : 'default_error_message';
179
- switch ($message_type) {
180
- case 'user_creation_failed':
181
- $message = __('User creation failed', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
182
- break;
183
-
184
- case 'unathorised_access':
185
- $message = __('You do not have permission to create a temporary login', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
186
- break;
187
-
188
- case 'email_is_in_use':
189
- $message = __('Email already is in use', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
190
- break;
191
-
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;
199
-
200
- case 'is_not_temporary_login':
201
- $message = __('User you are trying to delete is not temporary', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
202
- break;
203
-
204
- case 'nonce_failed':
205
- $message = __('Nonce failed', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
206
- break;
207
-
208
- case 'invalid_action':
209
- $message = __('Invalid action', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
210
- break;
211
-
212
- case 'default_error_message':
213
- default:
214
- $message = __('Unknown error occured', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
215
- break;
216
- }
217
- $class = 'error';
218
- } else if ($success) {
219
- $message_type = !empty($_REQUEST['wtlwp_message']) ? $_REQUEST['wtlwp_message'] : 'default_success_message';
220
- switch ($message_type) {
221
- case 'user_created':
222
- $message = __('Login created successfully!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
223
- break;
224
-
225
- case 'user_deleted':
226
- $message = __('Login deleted successfully!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
227
- break;
228
-
229
- case 'login_disabled':
230
- $message = __('Login disabled successfully!', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
231
- break;
232
-
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;
240
- }
241
-
242
- $class = 'updated';
243
- }
244
 
 
245
 
246
- $class .= ' notice notice-succe is-dismissible';
 
 
 
 
 
 
 
 
 
 
 
247
 
248
- if (!empty($message)) {
249
- $notice = '';
250
- $notice .= '<div id="notice" class="' . $class . '">';
251
- $notice .= '<p>' . esc_attr($message) . '</p>';
252
- $notice .= '</div>';
253
 
254
- echo $notice;
255
  }
256
 
257
- return;
258
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
- /**
261
- *
262
- * Disable welcome notification for temporary user.
263
- */
264
- public function disable_welcome_notification($blog_id, $user_id, $password, $title, $meta) {
265
 
266
- if (!empty($user_id)) {
267
- $check_expiry = false;
268
- if (Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, $check_expiry)) {
269
- return false;
270
- }
271
  }
272
 
273
- return true;
274
- }
 
 
 
 
 
 
275
 
276
  }
2
 
3
  class Wp_Temporary_Login_Without_Password_Admin {
4
 
5
+ private $plugin_name;
 
6
 
7
+ private $version;
8
 
9
+ public function __construct( $plugin_name, $version ) {
 
 
10
 
11
+ $this->plugin_name = $plugin_name;
12
+ $this->version = $version;
 
13
 
14
+ }
15
+
16
+ public function enqueue_styles() {
17
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-temporary-login-without-password-admin.css', array(), $this->version, 'all' );
18
+
19
+ wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
20
 
 
 
 
 
21
  }
 
22
 
23
+ public function enqueue_scripts() {
24
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp-temporary-login-without-password-admin.js', array( 'jquery' ), $this->version, false );
25
+ wp_enqueue_script( 'clipboardjs', plugin_dir_url( __FILE__ ) . 'js/clipboard.min.js', array( 'jquery' ), $this->version, false );
 
 
 
26
 
27
+ wp_enqueue_script( 'jquery' );
28
+ wp_enqueue_script( 'jquery-ui-core' );
29
+ wp_enqueue_script( 'jquery-ui-datepicker' );
30
 
 
 
31
  }
32
 
33
+ public function admin_menu() {
34
+ $current_user_id = get_current_user_id();
35
+ if ( !Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login( $current_user_id ) ) {
36
+ add_users_page( __( 'Temporary Logins', 'wp-temporary-login-without-password' ), __( 'Temporary Logins', 'wp-temporary-login-without-password' ), apply_filters( 'tempadmin_user_cap', 'manage_options' ), 'wp-temporary-login-without-password', array( __class__, 'admin_settings' ) );
37
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41
+ public static function admin_settings() {
42
+ $_template_file = WTLWP_PLUGIN_DIR . '/templates/admin_settings.php';
43
+ $wtlwp_generated_url = !empty( $_REQUEST[ 'wtlwp_generated_url' ] ) ? $_REQUEST[ 'wtlwp_generated_url' ] : '';
44
+ $user_email = !empty( $_REQUEST[ 'user_email' ] ) ? $_REQUEST[ 'user_email' ] : '';
45
+ include $_template_file;
46
+
47
  }
48
 
49
+ public function create_user() {
50
 
51
+ if ( empty( $_POST[ 'wtlwp_data' ] ) || empty( $_POST[ 'wtlwp-nonce' ] ) ) {
52
+ return;
53
+ }
54
 
55
+ $data = $_POST[ 'wtlwp_data' ];
56
+ $email = $data[ 'user_email' ];
57
+ $error = false;
58
+
59
+ $redirect_link = '';
60
+ if ( false == Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp() ) {
61
+ $result = array(
62
+ 'status' => 'error',
63
+ 'message' => 'unathorised_access',
64
+ );
65
+ $error = true;
66
+ } elseif ( !wp_verify_nonce( $_POST[ 'wtlwp-nonce' ], 'wtlwp_generate_login_url' ) ) {
67
+ $result = array(
68
+ 'status' => 'error',
69
+ 'message' => 'nonce_failed',
70
+ );
71
+ $error = true;
72
+ } elseif ( empty( $data[ 'user_email' ] ) ) {
73
+ $result = array(
74
+ 'status' => 'error',
75
+ 'message' => 'empty_email',
76
+ );
77
+ $error = true;
78
+ } elseif ( !is_email( $email ) ) {
79
+ $result = array(
80
+ 'status' => 'error',
81
+ 'message' => 'not_valid_email',
82
+ );
83
+ $error = true;
84
+ } elseif ( !empty( $data[ 'user_email' ] ) && email_exists( $data[ 'user_email' ] ) ) {
85
+ $result = array(
86
+ 'status' => 'error',
87
+ 'message' => 'email_is_in_use',
88
+ );
89
+ $error = true;
90
+ }
91
 
92
+ if ( !$error ) {
93
+ $user = Wp_Temporary_Login_Without_Password_Common::create_new_user( $data );
94
+ if ( !empty( $user[ 'error' ] ) ) {
95
+ $result = array(
96
+ 'status' => 'error',
97
+ 'message' => 'user_creation_failed',
98
+ );
99
+ } else {
100
+ $result = array(
101
+ 'status' => 'success',
102
+ 'message' => 'user_created',
103
+ );
104
+ $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link( $result );
105
+ $redirect_link = add_query_arg( 'wtlwp_generated_url', Wp_Temporary_Login_Without_Password_Common::get_login_url( $user ), $redirect_link );
106
+ $redirect_link = add_query_arg( 'user_email', $email, $redirect_link );
107
+ }
108
+ }
109
 
110
+ if ( empty( $redirect_link ) ) {
111
+ $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link( $result );
112
+ }
113
+
114
+ wp_redirect( $redirect_link, 302 );
115
+ exit();
 
 
 
 
 
116
 
 
 
 
 
 
 
 
117
  }
118
 
119
+ public static function delete_user() {
 
 
 
120
 
121
+ if ( (false === Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) || empty( $_REQUEST[ 'wtlwp_action' ] ) || ($_REQUEST[ 'wtlwp_action' ] != 'delete') || empty( $_REQUEST[ 'user_id' ] ) || (absint( $_REQUEST[ 'user_id' ] ) == 0) ) {
122
+ return;
123
+ }
124
 
125
+ $user_id = absint( $_REQUEST[ 'user_id' ] );
126
+ $nonce = $_REQUEST[ 'manage-temporary-login' ];
127
+ $redirect_url = '';
128
+ $error = false;
129
+ if ( !wp_verify_nonce( $nonce, 'manage-temporary-login_' . $user_id ) ) {
130
+ $result = array(
131
+ 'status' => 'error',
132
+ 'message' => 'nonce_failed',
133
+ );
134
+ $error = true;
135
+ } elseif ( !Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login( $user_id, false ) ) {
136
+ $result = array(
137
+ 'status' => 'error',
138
+ 'message' => 'is_not_temporary_login',
139
+ );
140
+ $error = true;
141
+ }
142
 
143
+ if ( !$error ) {
144
+ $delete_user = wp_delete_user( absint( $user_id ), get_current_user_id() );
145
+ if ( !is_wp_error( $delete_user ) ) {
146
+ $result = array(
147
+ 'status' => 'success',
148
+ 'message' => 'user_deleted',
149
+ );
150
+ } else {
151
+ $result = array(
152
+ 'status' => 'error',
153
+ 'message' => 'default_error_message',
154
+ );
155
+ }
156
+ }
157
 
158
+ $redirect_url = Wp_Temporary_Login_Without_Password_Common::get_redirect_link( $result );
159
+ wp_redirect( $redirect_url, 302 );
160
+ exit();
161
 
 
 
 
 
 
 
162
  }
163
 
164
+ public static function manage_temporary_login() {
165
+
166
+ 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) ) {
167
+ return;
 
 
 
 
168
  }
169
+
170
+ $error = false;
171
+ $user_id = absint( $_REQUEST[ 'user_id' ] );
172
+ $action = $_REQUEST[ 'wtlwp_action' ];
173
+ $nonce = $_REQUEST[ 'manage-temporary-login' ];
174
+
175
+ $is_valid_temporary_user = Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login( $user_id, false );
176
+
177
+ if ( !$is_valid_temporary_user ) {
178
+ $result = array(
179
+ 'status' => 'error',
180
+ 'message' => 'is_not_temporary_login',
181
+ );
182
+ $error = true;
183
+ } elseif ( !wp_verify_nonce( $nonce, 'manage-temporary-login_' . $user_id ) ) {
184
+ $result = array(
185
+ 'status' => 'error',
186
+ 'message' => 'nonce_failed',
187
+ );
188
+ $error = true;
189
  }
190
+
191
+ if ( !$error ) {
192
+ if ( $action == 'disable' ) {
193
+ $disable_login = Wp_Temporary_Login_Without_Password_Common::manage_login( absint( $user_id ), 'disable' );
194
+ if ( $disable_login ) {
195
+ $result = array(
196
+ 'status' => 'success',
197
+ 'message' => 'login_disabled',
198
+ );
199
+ } else {
200
+ $result = array(
201
+ 'status' => 'error',
202
+ 'message' => 'default_error_message',
203
+ );
204
+ $error = true;
205
+ }
206
+ } elseif ( $action == 'enable' ) {
207
+ $enable_login = Wp_Temporary_Login_Without_Password_Common::manage_login( absint( $user_id ), 'enable' );
208
+
209
+ if ( $enable_login ) {
210
+ $result = array(
211
+ 'status' => 'success',
212
+ 'message' => 'login_enabled',
213
+ );
214
+ } else {
215
+ $result = array(
216
+ 'status' => 'error',
217
+ 'message' => 'default_error_message',
218
+ );
219
+ $error = true;
220
+ }
221
+ } else {
222
+ $result = array(
223
+ 'status' => 'error',
224
+ 'message' => 'invalid_action',
225
+ );
226
+ $error = true;
227
+ }// End if().
228
+ }// End if().
229
+
230
+ $redirect_link = Wp_Temporary_Login_Without_Password_Common::get_redirect_link( $result );
231
+ wp_redirect( $redirect_link, 302 );
232
+ exit();
233
+
234
  }
235
 
236
+ public function display_admin_notices() {
 
 
 
237
 
238
+ if ( empty( $_REQUEST[ 'page' ] ) || (empty( $_REQUEST[ 'page' ] ) && $_REQUEST[ 'page' ] !== 'wp-temporary-login-without-password') || !isset( $_REQUEST[ 'wtlwp_message' ] ) || (!isset( $_REQUEST[ 'wtlwp_error' ] ) && !isset( $_REQUEST[ 'wtlwp_success' ] )) ) {
239
+ return;
240
+ }
241
 
242
+ $class = $message = '';
243
+ $error = !empty( $_REQUEST[ 'wtlwp_error' ] ) ? true : false;
244
+ $success = !empty( $_REQUEST[ 'wtlwp_success' ] ) ? true : false;
245
+ if ( $error ) {
246
+ $message_type = !empty( $_REQUEST[ 'wtlwp_message' ] ) ? $_REQUEST[ 'wtlwp_message' ] : 'default_error_message';
247
+ switch ( $message_type ) {
248
+ case 'user_creation_failed':
249
+ $message = __( 'User creation failed', 'wp-temporary-login-without-password' );
250
+ break;
251
+
252
+ case 'unathorised_access':
253
+ $message = __( 'You do not have permission to create a temporary login', 'wp-temporary-login-without-password' );
254
+ break;
255
+
256
+ case 'email_is_in_use':
257
+ $message = __( 'Email already is in use', 'wp-temporary-login-without-password' );
258
+ break;
259
+
260
+ case 'empty_email':
261
+ $message = __( 'Please enter valid email address. Email field should not be empty', 'wp-temporary-login-without-password' );
262
+ break;
263
+
264
+ case 'not_valid_email':
265
+ $message = __( 'Please enter valid email address', 'wp-temporary-login-without-password' );
266
+ break;
267
+
268
+ case 'is_not_temporary_login':
269
+ $message = __( 'User you are trying to delete is not temporary', 'wp-temporary-login-without-password' );
270
+ break;
271
+
272
+ case 'nonce_failed':
273
+ $message = __( 'Nonce failed', 'wp-temporary-login-without-password' );
274
+ break;
275
+
276
+ case 'invalid_action':
277
+ $message = __( 'Invalid action', 'wp-temporary-login-without-password' );
278
+ break;
279
+
280
+ case 'default_error_message':
281
+ default:
282
+ $message = __( 'Unknown error occured', 'wp-temporary-login-without-password' );
283
+ break;
284
+ }// End switch().
285
+ $class = 'error';
286
+ } elseif ( $success ) {
287
+ $message_type = !empty( $_REQUEST[ 'wtlwp_message' ] ) ? $_REQUEST[ 'wtlwp_message' ] : 'default_success_message';
288
+ switch ( $message_type ) {
289
+ case 'user_created':
290
+ $message = __( 'Login created successfully!', 'wp-temporary-login-without-password' );
291
+ break;
292
+
293
+ case 'user_deleted':
294
+ $message = __( 'Login deleted successfully!', 'wp-temporary-login-without-password' );
295
+ break;
296
+
297
+ case 'login_disabled':
298
+ $message = __( 'Login disabled successfully!', 'wp-temporary-login-without-password' );
299
+ break;
300
+
301
+ case 'login_enabled':
302
+ $message = __( 'Login enabled successfully!', 'wp-temporary-login-without-password' );
303
+ break;
304
+
305
+ default:
306
+ $message = __( 'Success!', 'wp-temporary-login-without-password' );
307
+ break;
308
+ }
309
+
310
+ $class = 'updated';
311
+ }// End if().
312
+
313
+ $class .= ' notice notice-succe is-dismissible';
314
+
315
+ if ( !empty( $message ) ) {
316
+ $notice = '';
317
+ $notice .= '<div id="notice" class="' . $class . '">';
318
+ $notice .= '<p>' . esc_attr( $message ) . '</p>';
319
+ $notice .= '</div>';
320
+
321
+ echo $notice;
322
+ }
323
 
324
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
 
326
+ }
327
 
328
+ /**
329
+ *
330
+ * Disable welcome notification for temporary user.
331
+ */
332
+ public function disable_welcome_notification( $blog_id, $user_id, $password, $title, $meta ) {
333
+
334
+ if ( !empty( $user_id ) ) {
335
+ $check_expiry = false;
336
+ if ( Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login( $user_id, $check_expiry ) ) {
337
+ return false;
338
+ }
339
+ }
340
 
341
+ return true;
 
 
 
 
342
 
 
343
  }
344
 
345
+ /**
346
+ * Change the admin footer text on temporary login admin pages.
347
+ *
348
+ * @since 1.5
349
+ * @param string $footer_text
350
+ * @return string
351
+ */
352
+ public function admin_footer_text( $footer_text ) {
353
+
354
+ $current_screen = get_current_screen();
355
+
356
+ if ( isset( $current_screen->id ) && $current_screen->id == 'users_page_wp-temporary-login-without-password' ) {
357
+
358
+ // Change the footer text
359
+ if ( !get_option( 'tlwp_admin_footer_text_rated' ) ) {
360
+ /* translators: %s: five stars */
361
+ $footer_text = sprintf( __( 'If you like <strong>Temporary Login Without Password</strong> please leave us a %s rating. A huge thanks in advance!', 'wp-temporary-login-without-password' ), '<a href="https://wordpress.org/support/plugin/temporary-login-without-password/reviews?rate=5#new-post" target="_blank" class="tlwp-rating-link" data-rated="' . esc_attr__( 'Thank You :)', 'wp-temporary-login-without-password' ) . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>' );
362
+ wc_enqueue_js( "
363
+ jQuery( 'a.tlwp-rating-link' ).click( function() {
364
+ jQuery.post( '" . admin_url( 'admin-ajax.php', 'relative' ) . "', { action: 'tlwp_rated' } );
365
+ jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
366
+ });
367
+ " );
368
+ } else {
369
+ $footer_text = sprintf(__( 'Thank you for using %s.', 'wp-temporary-login-without-password' ), '<a href="https://wordpress.org/plugins/temporary-login-without-password/" target="_blank">Temporary Login Without Password</a>');
370
+ }
371
+ }
372
 
373
+ return $footer_text;
 
 
 
 
374
 
 
 
 
 
 
375
  }
376
 
377
+ /**
378
+ * Triggered when clicking the rating footer.
379
+ */
380
+ public static function tlwp_rated() {
381
+ update_option( 'tlwp_admin_footer_text_rated', 1 );
382
+ wp_die();
383
+
384
+ }
385
 
386
  }
admin/css/wp-temporary-login-without-password-admin.css CHANGED
@@ -1,81 +1,81 @@
1
  .new-wtlwp-form {
2
- border: 1px solid;
3
- padding: 10px;
4
- background-color: white;
5
- display: none;
6
  }
7
 
8
  .wtlwp-form-input {
9
- width: 300px !important;
10
  }
11
  .widefat .wtlwp-status {
12
- width: 40px;
13
  }
14
 
15
  .wtlwp-status-active {
16
- color: #008000 !important;
17
  }
18
 
19
  .wtlwp-status-expired {
20
- color: #FF0000 !important;
21
  }
22
 
23
  .wtlwp-status:after {
24
- border-radius: 32px;
25
- color: #fff;
26
- display: block;
27
- font-size: 11px;
28
- font-weight: bold;
29
- height: 16px;
30
- line-height: 17px;
31
- margin-left: 8px;
32
- text-align: center;
33
- width: 16px;
34
- }
35
 
36
  .wtlwp-status-active:after {
37
- background: #008000 none repeat scroll 0 0;
38
- content: "";
39
  }
40
 
41
  .wtlwp-status-expired:after {
42
- background: #FF0000 none repeat scroll 0 0;
43
- content: "";
44
  }
45
 
46
  .cancel-new-login-form {
47
- cursor: pointer;
48
  }
49
 
50
  .wtlwp-wide-input {
51
- width: 60%;
52
  }
53
 
54
  .generated-wtlwp-login-link {
55
- border: 1px solid;
56
- padding: 10px 10px 10px 10px;
57
  }
58
 
59
  .wtlwp-form-row {
60
- padding-left: 20px !important;
61
  }
62
 
63
  .wtlwp-form-submit-button {
64
- width: 115px;
65
  }
66
 
67
  .wtlwp-user-login {
68
- font-size: 12px;
69
  }
70
 
71
  .wtlwp-copy-to-clipboard, .wtlwp-click-to-copy-btn {
72
- cursor: pointer;
73
  }
74
 
75
  .wtlwp-copy-to-clipboard:hover {
76
- color: #0073aa;
77
  }
78
 
79
  .copied-text-message {
80
- padding: 20px;
81
- }
1
  .new-wtlwp-form {
2
+ border: 1px solid;
3
+ padding: 10px;
4
+ background-color: white;
5
+ display: none;
6
  }
7
 
8
  .wtlwp-form-input {
9
+ width: 300px !important;
10
  }
11
  .widefat .wtlwp-status {
12
+ width: 40px;
13
  }
14
 
15
  .wtlwp-status-active {
16
+ color: #008000 !important;
17
  }
18
 
19
  .wtlwp-status-expired {
20
+ color: #FF0000 !important;
21
  }
22
 
23
  .wtlwp-status:after {
24
+ border-radius: 32px;
25
+ color: #fff;
26
+ display: block;
27
+ font-size: 11px;
28
+ font-weight: bold;
29
+ height: 16px;
30
+ line-height: 17px;
31
+ margin-left: 8px;
32
+ text-align: center;
33
+ width: 16px;
34
+ }
35
 
36
  .wtlwp-status-active:after {
37
+ background: #008000 none repeat scroll 0 0;
38
+ content: "";
39
  }
40
 
41
  .wtlwp-status-expired:after {
42
+ background: #FF0000 none repeat scroll 0 0;
43
+ content: "";
44
  }
45
 
46
  .cancel-new-login-form {
47
+ cursor: pointer;
48
  }
49
 
50
  .wtlwp-wide-input {
51
+ width: 60%;
52
  }
53
 
54
  .generated-wtlwp-login-link {
55
+ border: 1px solid;
56
+ padding: 10px 10px 10px 10px;
57
  }
58
 
59
  .wtlwp-form-row {
60
+ padding-left: 20px !important;
61
  }
62
 
63
  .wtlwp-form-submit-button {
64
+ width: 115px;
65
  }
66
 
67
  .wtlwp-user-login {
68
+ font-size: 12px;
69
  }
70
 
71
  .wtlwp-copy-to-clipboard, .wtlwp-click-to-copy-btn {
72
+ cursor: pointer;
73
  }
74
 
75
  .wtlwp-copy-to-clipboard:hover {
76
+ color: #0073aa;
77
  }
78
 
79
  .copied-text-message {
80
+ padding: 20px;
81
+ }
admin/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
admin/js/clipboard.js CHANGED
@@ -4,739 +4,746 @@
4
  *
5
  * Licensed MIT © Zeno Rocha
6
  */
7
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
8
- var matches = require('matches-selector')
9
-
10
- module.exports = function (element, selector, checkYoSelf) {
11
- var parent = checkYoSelf ? element : element.parentNode
12
-
13
- while (parent && parent !== document) {
14
- if (matches(parent, selector)) return parent;
15
- parent = parent.parentNode
16
- }
17
- }
 
 
 
 
18
 
19
  },{"matches-selector":5}],2:[function(require,module,exports){
20
- var closest = require('closest');
21
-
22
- /**
23
- * Delegates event to a selector.
24
- *
25
- * @param {Element} element
26
- * @param {String} selector
27
- * @param {String} type
28
- * @param {Function} callback
29
- * @param {Boolean} useCapture
30
- * @return {Object}
31
- */
32
- function delegate(element, selector, type, callback, useCapture) {
33
- var listenerFn = listener.apply(this, arguments);
34
-
35
- element.addEventListener(type, listenerFn, useCapture);
36
-
37
- return {
38
- destroy: function() {
39
- element.removeEventListener(type, listenerFn, useCapture);
40
- }
41
- }
42
- }
43
-
44
- /**
45
- * Finds closest match and invokes callback.
46
- *
47
- * @param {Element} element
48
- * @param {String} selector
49
- * @param {String} type
50
- * @param {Function} callback
51
- * @return {Function}
52
- */
53
- function listener(element, selector, type, callback) {
54
- return function(e) {
55
- e.delegateTarget = closest(e.target, selector, true);
56
-
57
- if (e.delegateTarget) {
58
- callback.call(element, e);
59
- }
60
- }
61
- }
62
-
63
- module.exports = delegate;
64
 
65
  },{"closest":1}],3:[function(require,module,exports){
66
- /**
67
  * Check if argument is a HTML element.
68
  *
69
  * @param {Object} value
70
  * @return {Boolean}
71
  */
72
- exports.node = function(value) {
73
- return value !== undefined
74
- && value instanceof HTMLElement
75
- && value.nodeType === 1;
76
- };
77
 
78
- /**
79
  * Check if argument is a list of HTML elements.
80
  *
81
  * @param {Object} value
82
  * @return {Boolean}
83
  */
84
- exports.nodeList = function(value) {
85
- var type = Object.prototype.toString.call(value);
86
 
87
- return value !== undefined
88
- && (type === '[object NodeList]' || type === '[object HTMLCollection]')
89
- && ('length' in value)
90
- && (value.length === 0 || exports.node(value[0]));
91
- };
92
 
93
- /**
94
  * Check if argument is a string.
95
  *
96
  * @param {Object} value
97
  * @return {Boolean}
98
  */
99
- exports.string = function(value) {
100
- return typeof value === 'string'
101
- || value instanceof String;
102
- };
103
 
104
- /**
105
  * Check if argument is a function.
106
  *
107
  * @param {Object} value
108
  * @return {Boolean}
109
  */
110
- exports.fn = function(value) {
111
- var type = Object.prototype.toString.call(value);
112
 
113
- return type === '[object Function]';
114
- };
115
 
116
  },{}],4:[function(require,module,exports){
117
- var is = require('./is');
118
- var delegate = require('delegate');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
- /**
121
- * Validates all params and calls the right
122
- * listener function based on its target type.
123
- *
124
- * @param {String|HTMLElement|HTMLCollection|NodeList} target
125
- * @param {String} type
126
- * @param {Function} callback
127
- * @return {Object}
128
- */
129
- function listen(target, type, callback) {
130
- if (!target && !type && !callback) {
131
- throw new Error('Missing required arguments');
132
- }
133
-
134
- if (!is.string(type)) {
135
- throw new TypeError('Second argument must be a String');
136
- }
137
-
138
- if (!is.fn(callback)) {
139
- throw new TypeError('Third argument must be a Function');
140
- }
141
-
142
- if (is.node(target)) {
143
- return listenNode(target, type, callback);
144
- }
145
- else if (is.nodeList(target)) {
146
- return listenNodeList(target, type, callback);
147
- }
148
- else if (is.string(target)) {
149
- return listenSelector(target, type, callback);
150
- }
151
- else {
152
- throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
153
- }
154
- }
155
-
156
- /**
157
- * Adds an event listener to a HTML element
158
- * and returns a remove listener function.
159
- *
160
- * @param {HTMLElement} node
161
- * @param {String} type
162
- * @param {Function} callback
163
- * @return {Object}
164
- */
165
- function listenNode(node, type, callback) {
166
- node.addEventListener(type, callback);
167
-
168
- return {
169
- destroy: function() {
170
- node.removeEventListener(type, callback);
171
- }
172
- }
173
- }
174
-
175
- /**
176
- * Add an event listener to a list of HTML elements
177
- * and returns a remove listener function.
178
- *
179
- * @param {NodeList|HTMLCollection} nodeList
180
- * @param {String} type
181
- * @param {Function} callback
182
- * @return {Object}
183
- */
184
- function listenNodeList(nodeList, type, callback) {
185
- Array.prototype.forEach.call(nodeList, function(node) {
186
- node.addEventListener(type, callback);
187
- });
188
-
189
- return {
190
- destroy: function() {
191
- Array.prototype.forEach.call(nodeList, function(node) {
192
- node.removeEventListener(type, callback);
193
- });
194
- }
195
- }
196
- }
197
-
198
- /**
199
- * Add an event listener to a selector
200
- * and returns a remove listener function.
201
- *
202
- * @param {String} selector
203
- * @param {String} type
204
- * @param {Function} callback
205
- * @return {Object}
206
- */
207
- function listenSelector(selector, type, callback) {
208
- return delegate(document.body, selector, type, callback);
209
- }
210
 
211
- module.exports = listen;
 
 
212
 
213
- },{"./is":3,"delegate":2}],5:[function(require,module,exports){
214
-
215
- /**
216
- * Element prototype.
217
- */
218
-
219
- var proto = Element.prototype;
220
-
221
- /**
222
- * Vendor function.
223
- */
224
-
225
- var vendor = proto.matchesSelector
226
- || proto.webkitMatchesSelector
227
- || proto.mozMatchesSelector
228
- || proto.msMatchesSelector
229
- || proto.oMatchesSelector;
230
-
231
- /**
232
- * Expose `match()`.
233
- */
234
-
235
- module.exports = match;
236
-
237
- /**
238
- * Match `el` to `selector`.
239
- *
240
- * @param {Element} el
241
- * @param {String} selector
242
- * @return {Boolean}
243
- * @api public
244
- */
245
-
246
- function match(el, selector) {
247
- if (vendor) return vendor.call(el, selector);
248
- var nodes = el.parentNode.querySelectorAll(selector);
249
- for (var i = 0; i < nodes.length; ++i) {
250
- if (nodes[i] == el) return true;
251
- }
252
- return false;
253
- }
254
  },{}],6:[function(require,module,exports){
255
- function select(element) {
256
- var selectedText;
257
 
258
- if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
259
- element.focus();
260
- element.setSelectionRange(0, element.value.length);
261
 
262
- selectedText = element.value;
263
- }
264
- else {
265
- if (element.hasAttribute('contenteditable')) {
266
- element.focus();
267
- }
268
 
269
- var selection = window.getSelection();
270
- var range = document.createRange();
271
 
272
- range.selectNodeContents(element);
273
- selection.removeAllRanges();
274
- selection.addRange(range);
275
 
276
- selectedText = selection.toString();
277
- }
278
 
279
- return selectedText;
280
- }
281
 
282
- module.exports = select;
283
 
284
  },{}],7:[function(require,module,exports){
285
- function E () {
286
- // Keep this empty so it's easier to inherit from
287
- // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
288
- }
289
-
290
- E.prototype = {
291
- on: function (name, callback, ctx) {
292
- var e = this.e || (this.e = {});
293
-
294
- (e[name] || (e[name] = [])).push({
295
- fn: callback,
296
- ctx: ctx
297
- });
298
-
299
- return this;
300
- },
301
-
302
- once: function (name, callback, ctx) {
303
- var self = this;
304
- function listener () {
305
- self.off(name, listener);
306
- callback.apply(ctx, arguments);
307
- };
308
-
309
- listener._ = callback
310
- return this.on(name, listener, ctx);
311
- },
312
-
313
- emit: function (name) {
314
- var data = [].slice.call(arguments, 1);
315
- var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
316
- var i = 0;
317
- var len = evtArr.length;
318
-
319
- for (i; i < len; i++) {
320
- evtArr[i].fn.apply(evtArr[i].ctx, data);
321
- }
322
-
323
- return this;
324
- },
325
-
326
- off: function (name, callback) {
327
- var e = this.e || (this.e = {});
328
- var evts = e[name];
329
- var liveEvents = [];
330
-
331
- if (evts && callback) {
332
- for (var i = 0, len = evts.length; i < len; i++) {
333
- if (evts[i].fn !== callback && evts[i].fn._ !== callback)
334
- liveEvents.push(evts[i]);
335
- }
336
- }
337
-
338
- // Remove event from queue to prevent memory leak
339
- // Suggested by https://github.com/lazd
340
- // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
341
-
342
- (liveEvents.length)
343
- ? e[name] = liveEvents
344
- : delete e[name];
345
-
346
- return this;
347
- }
348
- };
349
-
350
- module.exports = E;
351
 
352
  },{}],8:[function(require,module,exports){
353
- (function (global, factory) {
354
- if (typeof define === "function" && define.amd) {
355
- define(['module', 'select'], factory);
356
- } else if (typeof exports !== "undefined") {
357
- factory(module, require('select'));
358
- } else {
359
- var mod = {
360
- exports: {}
361
- };
362
- factory(mod, global.select);
363
- global.clipboardAction = mod.exports;
364
- }
365
- })(this, function (module, _select) {
366
- 'use strict';
367
-
368
- var _select2 = _interopRequireDefault(_select);
369
-
370
- function _interopRequireDefault(obj) {
371
- return obj && obj.__esModule ? obj : {
372
- default: obj
373
- };
374
- }
375
-
376
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
377
- return typeof obj;
378
- } : function (obj) {
379
- return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
380
- };
381
-
382
- function _classCallCheck(instance, Constructor) {
383
- if (!(instance instanceof Constructor)) {
384
- throw new TypeError("Cannot call a class as a function");
385
- }
386
- }
387
-
388
- var _createClass = function () {
389
- function defineProperties(target, props) {
390
- for (var i = 0; i < props.length; i++) {
391
- var descriptor = props[i];
392
- descriptor.enumerable = descriptor.enumerable || false;
393
- descriptor.configurable = true;
394
- if ("value" in descriptor) descriptor.writable = true;
395
- Object.defineProperty(target, descriptor.key, descriptor);
396
- }
397
- }
398
-
399
- return function (Constructor, protoProps, staticProps) {
400
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
401
- if (staticProps) defineProperties(Constructor, staticProps);
402
- return Constructor;
403
- };
404
- }();
405
-
406
- var ClipboardAction = function () {
407
- /**
408
- * @param {Object} options
409
- */
410
-
411
- function ClipboardAction(options) {
412
- _classCallCheck(this, ClipboardAction);
413
-
414
- this.resolveOptions(options);
415
- this.initSelection();
416
- }
417
-
418
- /**
419
- * Defines base properties passed from constructor.
420
- * @param {Object} options
421
- */
422
-
423
-
424
- ClipboardAction.prototype.resolveOptions = function resolveOptions() {
425
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
426
-
427
- this.action = options.action;
428
- this.emitter = options.emitter;
429
- this.target = options.target;
430
- this.text = options.text;
431
- this.trigger = options.trigger;
432
-
433
- this.selectedText = '';
434
- };
435
-
436
- ClipboardAction.prototype.initSelection = function initSelection() {
437
- if (this.text) {
438
- this.selectFake();
439
- } else if (this.target) {
440
- this.selectTarget();
441
- }
442
- };
443
-
444
- ClipboardAction.prototype.selectFake = function selectFake() {
445
- var _this = this;
446
-
447
- var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
448
-
449
- this.removeFake();
450
-
451
- this.fakeHandlerCallback = function () {
452
- return _this.removeFake();
453
- };
454
- this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true;
455
-
456
- this.fakeElem = document.createElement('textarea');
457
- // Prevent zooming on iOS
458
- this.fakeElem.style.fontSize = '12pt';
459
- // Reset box model
460
- this.fakeElem.style.border = '0';
461
- this.fakeElem.style.padding = '0';
462
- this.fakeElem.style.margin = '0';
463
- // Move element out of screen horizontally
464
- this.fakeElem.style.position = 'absolute';
465
- this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
466
- // Move element to the same position vertically
467
- this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
468
- this.fakeElem.setAttribute('readonly', '');
469
- this.fakeElem.value = this.text;
470
-
471
- document.body.appendChild(this.fakeElem);
472
-
473
- this.selectedText = (0, _select2.default)(this.fakeElem);
474
- this.copyText();
475
- };
476
-
477
- ClipboardAction.prototype.removeFake = function removeFake() {
478
- if (this.fakeHandler) {
479
- document.body.removeEventListener('click', this.fakeHandlerCallback);
480
- this.fakeHandler = null;
481
- this.fakeHandlerCallback = null;
482
- }
483
-
484
- if (this.fakeElem) {
485
- document.body.removeChild(this.fakeElem);
486
- this.fakeElem = null;
487
- }
488
- };
489
-
490
- ClipboardAction.prototype.selectTarget = function selectTarget() {
491
- this.selectedText = (0, _select2.default)(this.target);
492
- this.copyText();
493
- };
494
-
495
- ClipboardAction.prototype.copyText = function copyText() {
496
- var succeeded = undefined;
497
-
498
- try {
499
- succeeded = document.execCommand(this.action);
500
- } catch (err) {
501
- succeeded = false;
502
- }
503
-
504
- this.handleResult(succeeded);
505
- };
506
-
507
- ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
508
- if (succeeded) {
509
- this.emitter.emit('success', {
510
- action: this.action,
511
- text: this.selectedText,
512
- trigger: this.trigger,
513
- clearSelection: this.clearSelection.bind(this)
514
- });
515
- } else {
516
- this.emitter.emit('error', {
517
- action: this.action,
518
- trigger: this.trigger,
519
- clearSelection: this.clearSelection.bind(this)
520
- });
521
- }
522
- };
523
-
524
- ClipboardAction.prototype.clearSelection = function clearSelection() {
525
- if (this.target) {
526
- this.target.blur();
527
- }
528
-
529
- window.getSelection().removeAllRanges();
530
- };
531
-
532
- ClipboardAction.prototype.destroy = function destroy() {
533
- this.removeFake();
534
- };
535
-
536
- _createClass(ClipboardAction, [{
537
- key: 'action',
538
- set: function set() {
539
- var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
540
-
541
- this._action = action;
542
-
543
- if (this._action !== 'copy' && this._action !== 'cut') {
544
- throw new Error('Invalid "action" value, use either "copy" or "cut"');
545
- }
546
- },
547
- get: function get() {
548
- return this._action;
549
- }
550
- }, {
551
- key: 'target',
552
- set: function set(target) {
553
- if (target !== undefined) {
554
- if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
555
- if (this.action === 'copy' && target.hasAttribute('disabled')) {
556
- throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
557
- }
558
-
559
- if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
560
- throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
561
- }
562
-
563
- this._target = target;
564
- } else {
565
- throw new Error('Invalid "target" value, use a valid Element');
566
- }
567
- }
568
- },
569
- get: function get() {
570
- return this._target;
571
- }
572
- }]);
573
-
574
- return ClipboardAction;
575
- }();
576
-
577
- module.exports = ClipboardAction;
578
- });
 
 
 
579
 
580
  },{"select":6}],9:[function(require,module,exports){
581
- (function (global, factory) {
582
- if (typeof define === "function" && define.amd) {
583
- define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
584
- } else if (typeof exports !== "undefined") {
585
- factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
586
- } else {
587
- var mod = {
588
- exports: {}
589
- };
590
- factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
591
- global.clipboard = mod.exports;
592
- }
593
- })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
594
- 'use strict';
595
-
596
- var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
597
-
598
- var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
599
-
600
- var _goodListener2 = _interopRequireDefault(_goodListener);
601
-
602
- function _interopRequireDefault(obj) {
603
- return obj && obj.__esModule ? obj : {
604
- default: obj
605
- };
606
- }
607
-
608
- function _classCallCheck(instance, Constructor) {
609
- if (!(instance instanceof Constructor)) {
610
- throw new TypeError("Cannot call a class as a function");
611
- }
612
- }
613
-
614
- function _possibleConstructorReturn(self, call) {
615
- if (!self) {
616
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
617
- }
618
-
619
- return call && (typeof call === "object" || typeof call === "function") ? call : self;
620
- }
621
-
622
- function _inherits(subClass, superClass) {
623
- if (typeof superClass !== "function" && superClass !== null) {
624
- throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
625
- }
626
-
627
- subClass.prototype = Object.create(superClass && superClass.prototype, {
628
- constructor: {
629
- value: subClass,
630
- enumerable: false,
631
- writable: true,
632
- configurable: true
633
- }
634
- });
635
- if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
636
- }
637
-
638
- var Clipboard = function (_Emitter) {
639
- _inherits(Clipboard, _Emitter);
640
-
641
- /**
642
- * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
643
- * @param {Object} options
644
- */
645
-
646
- function Clipboard(trigger, options) {
647
- _classCallCheck(this, Clipboard);
648
-
649
- var _this = _possibleConstructorReturn(this, _Emitter.call(this));
650
-
651
- _this.resolveOptions(options);
652
- _this.listenClick(trigger);
653
- return _this;
654
- }
655
-
656
- /**
657
- * Defines if attributes would be resolved using internal setter functions
658
- * or custom functions that were passed in the constructor.
659
- * @param {Object} options
660
- */
661
-
662
-
663
- Clipboard.prototype.resolveOptions = function resolveOptions() {
664
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
665
-
666
- this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
667
- this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
668
- this.text = typeof options.text === 'function' ? options.text : this.defaultText;
669
- };
670
-
671
- Clipboard.prototype.listenClick = function listenClick(trigger) {
672
- var _this2 = this;
673
-
674
- this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
675
- return _this2.onClick(e);
676
- });
677
- };
678
-
679
- Clipboard.prototype.onClick = function onClick(e) {
680
- var trigger = e.delegateTarget || e.currentTarget;
681
-
682
- if (this.clipboardAction) {
683
- this.clipboardAction = null;
684
- }
685
-
686
- this.clipboardAction = new _clipboardAction2.default({
687
- action: this.action(trigger),
688
- target: this.target(trigger),
689
- text: this.text(trigger),
690
- trigger: trigger,
691
- emitter: this
692
- });
693
- };
694
-
695
- Clipboard.prototype.defaultAction = function defaultAction(trigger) {
696
- return getAttributeValue('action', trigger);
697
- };
698
-
699
- Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
700
- var selector = getAttributeValue('target', trigger);
701
-
702
- if (selector) {
703
- return document.querySelector(selector);
704
- }
705
- };
706
-
707
- Clipboard.prototype.defaultText = function defaultText(trigger) {
708
- return getAttributeValue('text', trigger);
709
- };
710
-
711
- Clipboard.prototype.destroy = function destroy() {
712
- this.listener.destroy();
713
-
714
- if (this.clipboardAction) {
715
- this.clipboardAction.destroy();
716
- this.clipboardAction = null;
717
- }
718
- };
719
-
720
- return Clipboard;
721
- }(_tinyEmitter2.default);
722
-
723
- /**
724
- * Helper function to retrieve attribute value.
725
- * @param {String} suffix
726
- * @param {Element} element
727
- */
728
- function getAttributeValue(suffix, element) {
729
- var attribute = 'data-clipboard-' + suffix;
730
-
731
- if (!element.hasAttribute(attribute)) {
732
- return;
733
- }
734
-
735
- return element.getAttribute(attribute);
736
- }
737
-
738
- module.exports = Clipboard;
739
- });
 
 
740
 
741
  },{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9)
742
- });
4
  *
5
  * Licensed MIT © Zeno Rocha
6
  */
7
+ (function(f){if (typeof exports === "object"&&typeof module !== "undefined") {module.exports = f()} else if (typeof define === "function"&&define.amd) {define( [],f )} else {var g;if (typeof window !== "undefined") {g = window} else if (typeof global !== "undefined") {g = global} else if (typeof self !== "undefined") {g = self} else {g = this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if ( ! n[o]) {if ( ! t[o]) {var a = typeof require == "function"&&require;if ( ! u&&a) { return a( o, ! 0 );
8
+ }if (i) { return i( o, ! 0 );
9
+ }var f = new Error( "Cannot find module '" + o + "'" );throw f.code = "MODULE_NOT_FOUND",f}var l = n[o] = {exports:{}};t[o][0].call( l.exports,function(e){var n = t[o][1][e];return s( n?n:e )},l,l.exports,e,t,n,r )}return n[o].exports}var i = typeof require == "function"&&require;for (var o = 0;o < r.length;o++) { s( r[o] );
10
+ }return s})({1:[function(require,module,exports){
11
+ var matches = require( 'matches-selector' )
12
+
13
+ module.exports = function (element, selector, checkYoSelf) {
14
+ var parent = checkYoSelf ? element : element.parentNode
15
+
16
+ while (parent && parent !== document) {
17
+ if (matches( parent, selector )) { return parent;
18
+ }
19
+ parent = parent.parentNode
20
+ }
21
+ }
22
 
23
  },{"matches-selector":5}],2:[function(require,module,exports){
24
+ var closest = require( 'closest' );
25
+
26
+ /**
27
+ * Delegates event to a selector.
28
+ *
29
+ * @param {Element} element
30
+ * @param {String} selector
31
+ * @param {String} type
32
+ * @param {Function} callback
33
+ * @param {Boolean} useCapture
34
+ * @return {Object}
35
+ */
36
+ function delegate(element, selector, type, callback, useCapture) {
37
+ var listenerFn = listener.apply( this, arguments );
38
+
39
+ element.addEventListener( type, listenerFn, useCapture );
40
+
41
+ return {
42
+ destroy: function() {
43
+ element.removeEventListener( type, listenerFn, useCapture );
44
+ }
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Finds closest match and invokes callback.
50
+ *
51
+ * @param {Element} element
52
+ * @param {String} selector
53
+ * @param {String} type
54
+ * @param {Function} callback
55
+ * @return {Function}
56
+ */
57
+ function listener(element, selector, type, callback) {
58
+ return function(e) {
59
+ e.delegateTarget = closest( e.target, selector, true );
60
+
61
+ if (e.delegateTarget) {
62
+ callback.call( element, e );
63
+ }
64
+ }
65
+ }
66
+
67
+ module.exports = delegate;
68
 
69
  },{"closest":1}],3:[function(require,module,exports){
70
+ /**
71
  * Check if argument is a HTML element.
72
  *
73
  * @param {Object} value
74
  * @return {Boolean}
75
  */
76
+ exports.node = function(value) {
77
+ return value !== undefined
78
+ && value instanceof HTMLElement
79
+ && value.nodeType === 1;
80
+ };
81
 
82
+ /**
83
  * Check if argument is a list of HTML elements.
84
  *
85
  * @param {Object} value
86
  * @return {Boolean}
87
  */
88
+ exports.nodeList = function(value) {
89
+ var type = Object.prototype.toString.call( value );
90
 
91
+ return value !== undefined
92
+ && (type === '[object NodeList]' || type === '[object HTMLCollection]')
93
+ && ('length' in value)
94
+ && (value.length === 0 || exports.node( value[0] ));
95
+ };
96
 
97
+ /**
98
  * Check if argument is a string.
99
  *
100
  * @param {Object} value
101
  * @return {Boolean}
102
  */
103
+ exports.string = function(value) {
104
+ return typeof value === 'string'
105
+ || value instanceof String;
106
+ };
107
 
108
+ /**
109
  * Check if argument is a function.
110
  *
111
  * @param {Object} value
112
  * @return {Boolean}
113
  */
114
+ exports.fn = function(value) {
115
+ var type = Object.prototype.toString.call( value );
116
 
117
+ return type === '[object Function]';
118
+ };
119
 
120
  },{}],4:[function(require,module,exports){
121
+ var is = require( './is' );
122
+ var delegate = require( 'delegate' );
123
+
124
+ /**
125
+ * Validates all params and calls the right
126
+ * listener function based on its target type.
127
+ *
128
+ * @param {String|HTMLElement|HTMLCollection|NodeList} target
129
+ * @param {String} type
130
+ * @param {Function} callback
131
+ * @return {Object}
132
+ */
133
+ function listen(target, type, callback) {
134
+ if ( ! target && ! type && ! callback) {
135
+ throw new Error( 'Missing required arguments' );
136
+ }
137
+
138
+ if ( ! is.string( type )) {
139
+ throw new TypeError( 'Second argument must be a String' );
140
+ }
141
+
142
+ if ( ! is.fn( callback )) {
143
+ throw new TypeError( 'Third argument must be a Function' );
144
+ }
145
+
146
+ if (is.node( target )) {
147
+ return listenNode( target, type, callback );
148
+ } else if (is.nodeList( target )) {
149
+ return listenNodeList( target, type, callback );
150
+ } else if (is.string( target )) {
151
+ return listenSelector( target, type, callback );
152
+ } else {
153
+ throw new TypeError( 'First argument must be a String, HTMLElement, HTMLCollection, or NodeList' );
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Adds an event listener to a HTML element
159
+ * and returns a remove listener function.
160
+ *
161
+ * @param {HTMLElement} node
162
+ * @param {String} type
163
+ * @param {Function} callback
164
+ * @return {Object}
165
+ */
166
+ function listenNode(node, type, callback) {
167
+ node.addEventListener( type, callback );
168
+
169
+ return {
170
+ destroy: function() {
171
+ node.removeEventListener( type, callback );
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Add an event listener to a list of HTML elements
178
+ * and returns a remove listener function.
179
+ *
180
+ * @param {NodeList|HTMLCollection} nodeList
181
+ * @param {String} type
182
+ * @param {Function} callback
183
+ * @return {Object}
184
+ */
185
+ function listenNodeList(nodeList, type, callback) {
186
+ Array.prototype.forEach.call(nodeList, function(node) {
187
+ node.addEventListener( type, callback );
188
+ });
189
+
190
+ return {
191
+ destroy: function() {
192
+ Array.prototype.forEach.call(nodeList, function(node) {
193
+ node.removeEventListener( type, callback );
194
+ });
195
+ }
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Add an event listener to a selector
201
+ * and returns a remove listener function.
202
+ *
203
+ * @param {String} selector
204
+ * @param {String} type
205
+ * @param {Function} callback
206
+ * @return {Object}
207
+ */
208
+ function listenSelector(selector, type, callback) {
209
+ return delegate( document.body, selector, type, callback );
210
+ }
211
+
212
+ module.exports = listen;
213
 
214
+ },{"./is":3,"delegate":2}],5:[function(require,module,exports){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
+ /**
217
+ * Element prototype.
218
+ */
219
 
220
+ var proto = Element.prototype;
221
+
222
+ /**
223
+ * Vendor function.
224
+ */
225
+
226
+ var vendor = proto.matchesSelector
227
+ || proto.webkitMatchesSelector
228
+ || proto.mozMatchesSelector
229
+ || proto.msMatchesSelector
230
+ || proto.oMatchesSelector;
231
+
232
+ /**
233
+ * Expose `match()`.
234
+ */
235
+
236
+ module.exports = match;
237
+
238
+ /**
239
+ * Match `el` to `selector`.
240
+ *
241
+ * @param {Element} el
242
+ * @param {String} selector
243
+ * @return {Boolean}
244
+ * @api public
245
+ */
246
+
247
+ function match(el, selector) {
248
+ if (vendor) { return vendor.call( el, selector );
249
+ }
250
+ var nodes = el.parentNode.querySelectorAll( selector );
251
+ for (var i = 0; i < nodes.length; ++i) {
252
+ if (nodes[i] == el) { return true;
253
+ }
254
+ }
255
+ return false;
256
+ }
 
 
 
 
257
  },{}],6:[function(require,module,exports){
258
+ function select(element) {
259
+ var selectedText;
260
 
261
+ if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
262
+ element.focus();
263
+ element.setSelectionRange( 0, element.value.length );
264
 
265
+ selectedText = element.value;
266
+ } else {
267
+ if (element.hasAttribute( 'contenteditable' )) {
268
+ element.focus();
269
+ }
 
270
 
271
+ var selection = window.getSelection();
272
+ var range = document.createRange();
273
 
274
+ range.selectNodeContents( element );
275
+ selection.removeAllRanges();
276
+ selection.addRange( range );
277
 
278
+ selectedText = selection.toString();
279
+ }
280
 
281
+ return selectedText;
282
+ }
283
 
284
+ module.exports = select;
285
 
286
  },{}],7:[function(require,module,exports){
287
+ function E () {
288
+ // Keep this empty so it's easier to inherit from
289
+ // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
290
+ }
291
+
292
+ E.prototype = {
293
+ on: function (name, callback, ctx) {
294
+ var e = this.e || (this.e = {});
295
+
296
+ (e[name] || (e[name] = [])).push({
297
+ fn: callback,
298
+ ctx: ctx
299
+ });
300
+
301
+ return this;
302
+ },
303
+
304
+ once: function (name, callback, ctx) {
305
+ var self = this;
306
+ function listener () {
307
+ self.off( name, listener );
308
+ callback.apply( ctx, arguments );
309
+ };
310
+
311
+ listener._ = callback
312
+ return this.on( name, listener, ctx );
313
+ },
314
+
315
+ emit: function (name) {
316
+ var data = [].slice.call( arguments, 1 );
317
+ var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
318
+ var i = 0;
319
+ var len = evtArr.length;
320
+
321
+ for (i; i < len; i++) {
322
+ evtArr[i].fn.apply( evtArr[i].ctx, data );
323
+ }
324
+
325
+ return this;
326
+ },
327
+
328
+ off: function (name, callback) {
329
+ var e = this.e || (this.e = {});
330
+ var evts = e[name];
331
+ var liveEvents = [];
332
+
333
+ if (evts && callback) {
334
+ for (var i = 0, len = evts.length; i < len; i++) {
335
+ if (evts[i].fn !== callback && evts[i].fn._ !== callback) {
336
+ liveEvents.push( evts[i] );
337
+ }
338
+ }
339
+ }
340
+
341
+ // Remove event from queue to prevent memory leak
342
+ // Suggested by https://github.com/lazd
343
+ // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
344
+ (liveEvents.length)
345
+ ? e[name] = liveEvents
346
+ : delete e[name];
347
+
348
+ return this;
349
+ }
350
+ };
351
+
352
+ module.exports = E;
353
 
354
  },{}],8:[function(require,module,exports){
355
+ (function (global, factory) {
356
+ if (typeof define === "function" && define.amd) {
357
+ define( ['module', 'select'], factory );
358
+ } else if (typeof exports !== "undefined") {
359
+ factory( module, require( 'select' ) );
360
+ } else {
361
+ var mod = {
362
+ exports: {}
363
+ };
364
+ factory( mod, global.select );
365
+ global.clipboardAction = mod.exports;
366
+ }
367
+ })(this, function (module, _select) {
368
+ 'use strict';
369
+
370
+ var _select2 = _interopRequireDefault( _select );
371
+
372
+ function _interopRequireDefault(obj) {
373
+ return obj && obj.__esModule ? obj : {
374
+ default: obj
375
+ };
376
+ }
377
+
378
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
379
+ return typeof obj;
380
+ } : function (obj) {
381
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
382
+ };
383
+
384
+ function _classCallCheck(instance, Constructor) {
385
+ if ( ! (instance instanceof Constructor)) {
386
+ throw new TypeError( "Cannot call a class as a function" );
387
+ }
388
+ }
389
+
390
+ var _createClass = function () {
391
+ function defineProperties(target, props) {
392
+ for (var i = 0; i < props.length; i++) {
393
+ var descriptor = props[i];
394
+ descriptor.enumerable = descriptor.enumerable || false;
395
+ descriptor.configurable = true;
396
+ if ("value" in descriptor) { descriptor.writable = true;
397
+ }
398
+ Object.defineProperty( target, descriptor.key, descriptor );
399
+ }
400
+ }
401
+
402
+ return function (Constructor, protoProps, staticProps) {
403
+ if (protoProps) { defineProperties( Constructor.prototype, protoProps );
404
+ }
405
+ if (staticProps) { defineProperties( Constructor, staticProps );
406
+ }
407
+ return Constructor;
408
+ };
409
+ }();
410
+
411
+ var ClipboardAction = function () {
412
+ /**
413
+ * @param {Object} options
414
+ */
415
+
416
+ function ClipboardAction(options) {
417
+ _classCallCheck( this, ClipboardAction );
418
+
419
+ this.resolveOptions( options );
420
+ this.initSelection();
421
+ }
422
+
423
+ /**
424
+ * Defines base properties passed from constructor.
425
+ *
426
+ * @param {Object} options
427
+ */
428
+
429
+ ClipboardAction.prototype.resolveOptions = function resolveOptions() {
430
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
431
+
432
+ this.action = options.action;
433
+ this.emitter = options.emitter;
434
+ this.target = options.target;
435
+ this.text = options.text;
436
+ this.trigger = options.trigger;
437
+
438
+ this.selectedText = '';
439
+ };
440
+
441
+ ClipboardAction.prototype.initSelection = function initSelection() {
442
+ if (this.text) {
443
+ this.selectFake();
444
+ } else if (this.target) {
445
+ this.selectTarget();
446
+ }
447
+ };
448
+
449
+ ClipboardAction.prototype.selectFake = function selectFake() {
450
+ var _this = this;
451
+
452
+ var isRTL = document.documentElement.getAttribute( 'dir' ) == 'rtl';
453
+
454
+ this.removeFake();
455
+
456
+ this.fakeHandlerCallback = function () {
457
+ return _this.removeFake();
458
+ };
459
+ this.fakeHandler = document.body.addEventListener( 'click', this.fakeHandlerCallback ) || true;
460
+
461
+ this.fakeElem = document.createElement( 'textarea' );
462
+ // Prevent zooming on iOS
463
+ this.fakeElem.style.fontSize = '12pt';
464
+ // Reset box model
465
+ this.fakeElem.style.border = '0';
466
+ this.fakeElem.style.padding = '0';
467
+ this.fakeElem.style.margin = '0';
468
+ // Move element out of screen horizontally
469
+ this.fakeElem.style.position = 'absolute';
470
+ this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
471
+ // Move element to the same position vertically
472
+ this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
473
+ this.fakeElem.setAttribute( 'readonly', '' );
474
+ this.fakeElem.value = this.text;
475
+
476
+ document.body.appendChild( this.fakeElem );
477
+
478
+ this.selectedText = (0, _select2.default)(this.fakeElem);
479
+ this.copyText();
480
+ };
481
+
482
+ ClipboardAction.prototype.removeFake = function removeFake() {
483
+ if (this.fakeHandler) {
484
+ document.body.removeEventListener( 'click', this.fakeHandlerCallback );
485
+ this.fakeHandler = null;
486
+ this.fakeHandlerCallback = null;
487
+ }
488
+
489
+ if (this.fakeElem) {
490
+ document.body.removeChild( this.fakeElem );
491
+ this.fakeElem = null;
492
+ }
493
+ };
494
+
495
+ ClipboardAction.prototype.selectTarget = function selectTarget() {
496
+ this.selectedText = (0, _select2.default)(this.target);
497
+ this.copyText();
498
+ };
499
+
500
+ ClipboardAction.prototype.copyText = function copyText() {
501
+ var succeeded = undefined;
502
+
503
+ try {
504
+ succeeded = document.execCommand( this.action );
505
+ } catch (err) {
506
+ succeeded = false;
507
+ }
508
+
509
+ this.handleResult( succeeded );
510
+ };
511
+
512
+ ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
513
+ if (succeeded) {
514
+ this.emitter.emit('success', {
515
+ action: this.action,
516
+ text: this.selectedText,
517
+ trigger: this.trigger,
518
+ clearSelection: this.clearSelection.bind( this )
519
+ });
520
+ } else {
521
+ this.emitter.emit('error', {
522
+ action: this.action,
523
+ trigger: this.trigger,
524
+ clearSelection: this.clearSelection.bind( this )
525
+ });
526
+ }
527
+ };
528
+
529
+ ClipboardAction.prototype.clearSelection = function clearSelection() {
530
+ if (this.target) {
531
+ this.target.blur();
532
+ }
533
+
534
+ window.getSelection().removeAllRanges();
535
+ };
536
+
537
+ ClipboardAction.prototype.destroy = function destroy() {
538
+ this.removeFake();
539
+ };
540
+
541
+ _createClass(ClipboardAction, [{
542
+ key: 'action',
543
+ set: function set() {
544
+ var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
545
+
546
+ this._action = action;
547
+
548
+ if (this._action !== 'copy' && this._action !== 'cut') {
549
+ throw new Error( 'Invalid "action" value, use either "copy" or "cut"' );
550
+ }
551
+ },
552
+ get: function get() {
553
+ return this._action;
554
+ }
555
+ }, {
556
+ key: 'target',
557
+ set: function set(target) {
558
+ if (target !== undefined) {
559
+ if (target && (typeof target === 'undefined' ? 'undefined' : _typeof( target )) === 'object' && target.nodeType === 1) {
560
+ if (this.action === 'copy' && target.hasAttribute( 'disabled' )) {
561
+ throw new Error( 'Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute' );
562
+ }
563
+
564
+ if (this.action === 'cut' && (target.hasAttribute( 'readonly' ) || target.hasAttribute( 'disabled' ))) {
565
+ throw new Error( 'Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes' );
566
+ }
567
+
568
+ this._target = target;
569
+ } else {
570
+ throw new Error( 'Invalid "target" value, use a valid Element' );
571
+ }
572
+ }
573
+ },
574
+ get: function get() {
575
+ return this._target;
576
+ }
577
+ }]);
578
+
579
+ return ClipboardAction;
580
+ }();
581
+
582
+ module.exports = ClipboardAction;
583
+ });
584
 
585
  },{"select":6}],9:[function(require,module,exports){
586
+ (function (global, factory) {
587
+ if (typeof define === "function" && define.amd) {
588
+ define( ['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory );
589
+ } else if (typeof exports !== "undefined") {
590
+ factory( module, require( './clipboard-action' ), require( 'tiny-emitter' ), require( 'good-listener' ) );
591
+ } else {
592
+ var mod = {
593
+ exports: {}
594
+ };
595
+ factory( mod, global.clipboardAction, global.tinyEmitter, global.goodListener );
596
+ global.clipboard = mod.exports;
597
+ }
598
+ })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
599
+ 'use strict';
600
+
601
+ var _clipboardAction2 = _interopRequireDefault( _clipboardAction );
602
+
603
+ var _tinyEmitter2 = _interopRequireDefault( _tinyEmitter );
604
+
605
+ var _goodListener2 = _interopRequireDefault( _goodListener );
606
+
607
+ function _interopRequireDefault(obj) {
608
+ return obj && obj.__esModule ? obj : {
609
+ default: obj
610
+ };
611
+ }
612
+
613
+ function _classCallCheck(instance, Constructor) {
614
+ if ( ! (instance instanceof Constructor)) {
615
+ throw new TypeError( "Cannot call a class as a function" );
616
+ }
617
+ }
618
+
619
+ function _possibleConstructorReturn(self, call) {
620
+ if ( ! self) {
621
+ throw new ReferenceError( "this hasn't been initialised - super() hasn't been called" );
622
+ }
623
+
624
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
625
+ }
626
+
627
+ function _inherits(subClass, superClass) {
628
+ if (typeof superClass !== "function" && superClass !== null) {
629
+ throw new TypeError( "Super expression must either be null or a function, not " + typeof superClass );
630
+ }
631
+
632
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
633
+ constructor: {
634
+ value: subClass,
635
+ enumerable: false,
636
+ writable: true,
637
+ configurable: true
638
+ }
639
+ });
640
+ if (superClass) { Object.setPrototypeOf ? Object.setPrototypeOf( subClass, superClass ) : subClass.__proto__ = superClass;
641
+ }
642
+ }
643
+
644
+ var Clipboard = function (_Emitter) {
645
+ _inherits( Clipboard, _Emitter );
646
+
647
+ /**
648
+ * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
649
+ * @param {Object} options
650
+ */
651
+
652
+ function Clipboard(trigger, options) {
653
+ _classCallCheck( this, Clipboard );
654
+
655
+ var _this = _possibleConstructorReturn( this, _Emitter.call( this ) );
656
+
657
+ _this.resolveOptions( options );
658
+ _this.listenClick( trigger );
659
+ return _this;
660
+ }
661
+
662
+ /**
663
+ * Defines if attributes would be resolved using internal setter functions
664
+ * or custom functions that were passed in the constructor.
665
+ *
666
+ * @param {Object} options
667
+ */
668
+
669
+ Clipboard.prototype.resolveOptions = function resolveOptions() {
670
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
671
+
672
+ this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
673
+ this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
674
+ this.text = typeof options.text === 'function' ? options.text : this.defaultText;
675
+ };
676
+
677
+ Clipboard.prototype.listenClick = function listenClick(trigger) {
678
+ var _this2 = this;
679
+
680
+ this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
681
+ return _this2.onClick( e );
682
+ });
683
+ };
684
+
685
+ Clipboard.prototype.onClick = function onClick(e) {
686
+ var trigger = e.delegateTarget || e.currentTarget;
687
+
688
+ if (this.clipboardAction) {
689
+ this.clipboardAction = null;
690
+ }
691
+
692
+ this.clipboardAction = new _clipboardAction2.default({
693
+ action: this.action( trigger ),
694
+ target: this.target( trigger ),
695
+ text: this.text( trigger ),
696
+ trigger: trigger,
697
+ emitter: this
698
+ });
699
+ };
700
+
701
+ Clipboard.prototype.defaultAction = function defaultAction(trigger) {
702
+ return getAttributeValue( 'action', trigger );
703
+ };
704
+
705
+ Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
706
+ var selector = getAttributeValue( 'target', trigger );
707
+
708
+ if (selector) {
709
+ return document.querySelector( selector );
710
+ }
711
+ };
712
+
713
+ Clipboard.prototype.defaultText = function defaultText(trigger) {
714
+ return getAttributeValue( 'text', trigger );
715
+ };
716
+
717
+ Clipboard.prototype.destroy = function destroy() {
718
+ this.listener.destroy();
719
+
720
+ if (this.clipboardAction) {
721
+ this.clipboardAction.destroy();
722
+ this.clipboardAction = null;
723
+ }
724
+ };
725
+
726
+ return Clipboard;
727
+ }(_tinyEmitter2.default);
728
+
729
+ /**
730
+ * Helper function to retrieve attribute value.
731
+ *
732
+ * @param {String} suffix
733
+ * @param {Element} element
734
+ */
735
+ function getAttributeValue(suffix, element) {
736
+ var attribute = 'data-clipboard-' + suffix;
737
+
738
+ if ( ! element.hasAttribute( attribute )) {
739
+ return;
740
+ }
741
+
742
+ return element.getAttribute( attribute );
743
+ }
744
+
745
+ module.exports = Clipboard;
746
+ });
747
 
748
  },{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9)
749
+ });
admin/js/wp-temporary-login-without-password-admin.js CHANGED
@@ -1,38 +1,58 @@
1
  (function ($) {
2
- 'use strict';
3
-
4
- jQuery(document).ready(function () {
5
- //jQuery('#new-wtlwp-form').hide();
6
-
7
- jQuery('#add-new-wtlwp-form-button').click(function () {
8
- jQuery('#new-wtlwp-form').show();
9
- });
10
-
11
- jQuery('#cancel-new-login-form').click(function () {
12
- jQuery('#new-wtlwp-form').hide();
13
- });
14
-
15
- if (jQuery('.wtlwp-click-to-copy-btn').get(0)) {
16
-
17
- var clipboard = new Clipboard('.wtlwp-click-to-copy-btn');
18
-
19
- clipboard.on('success', function (e) {
20
- var elem = e.trigger;
21
- var className = elem.getAttribute('class');
22
- jQuery('#copied-text-message-' + className).text('Copied').fadeIn();
23
- jQuery('#copied-text-message-' + className).fadeOut('slow');
24
- });
25
- }
26
-
27
- if (jQuery('.wtlwp-copy-to-clipboard').get(0)) {
28
- var clipboard_link = new Clipboard('.wtlwp-copy-to-clipboard');
29
-
30
- clipboard_link.on('success', function (e) {
31
- var elem = e.trigger;
32
- var id = elem.getAttribute('id');
33
- jQuery('#copied-' + id).text('Copied').fadeIn();
34
- jQuery('#copied-' + id).fadeOut('slow');
35
- });
36
- }
37
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  })(jQuery);
1
  (function ($) {
2
+ 'use strict';
3
+
4
+ jQuery( document ).ready(function () {
5
+
6
+
7
+
8
+
9
+ // jQuery('#new-wtlwp-form').hide();
10
+ jQuery( '#add-new-wtlwp-form-button' ).click(function () {
11
+ jQuery( '#new-wtlwp-form' ).show();
12
+ });
13
+
14
+ jQuery( '#cancel-new-login-form' ).click(function () {
15
+ jQuery( '#new-wtlwp-form' ).hide();
16
+ });
17
+
18
+ if (jQuery( '.wtlwp-click-to-copy-btn' ).get( 0 )) {
19
+
20
+ var clipboard = new Clipboard( '.wtlwp-click-to-copy-btn' );
21
+
22
+ clipboard.on('success', function (e) {
23
+ var elem = e.trigger;
24
+ var className = elem.getAttribute( 'class' );
25
+ jQuery( '#copied-text-message-' + className ).text( 'Copied' ).fadeIn();
26
+ jQuery( '#copied-text-message-' + className ).fadeOut( 'slow' );
27
+ });
28
+ }
29
+
30
+ if (jQuery( '.wtlwp-copy-to-clipboard' ).get( 0 )) {
31
+ var clipboard_link = new Clipboard( '.wtlwp-copy-to-clipboard' );
32
+
33
+ clipboard_link.on('success', function (e) {
34
+ var elem = e.trigger;
35
+ var id = elem.getAttribute( 'id' );
36
+ jQuery( '#copied-' + id ).text( 'Copied' ).fadeIn();
37
+ jQuery( '#copied-' + id ).fadeOut( 'slow' );
38
+ });
39
+ }
40
+
41
+ jQuery('#user-expiry-time').change(function(){
42
+
43
+ var value = jQuery(this).val();
44
+ if(value === 'custom_date') {
45
+ var tomorrowDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
46
+ jQuery('.example-datepicker').datepicker({
47
+ dateFormat: 'yy-mm-dd',
48
+ minDate: tomorrowDate
49
+ });
50
+ jQuery('#custom-date-picker').show();
51
+ } else {
52
+ jQuery('#custom-date-picker').hide();
53
+ }
54
+
55
+
56
+ });
57
+ });
58
  })(jQuery);
includes/class-wp-temporary-login-without-password-activator.php CHANGED
@@ -2,20 +2,23 @@
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
  }
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(
12
+ 'ID' => $user_id,
13
+ 'role' => $user_role,
14
+ ) );
15
+ }
16
+ }
17
 
18
+ $add = 'yes';
19
 
20
+ // Empty set
21
+ update_option( 'temporary_logins_data', array(), $add );
22
+ }
23
 
24
  }
includes/class-wp-temporary-login-without-password-common.php CHANGED
@@ -2,457 +2,505 @@
2
 
3
  class Wp_Temporary_Login_Without_Password_Common {
4
 
5
- public static function create_username($data) {
6
-
7
- $first_name = isset($data['user_first_name']) ? $data['user_first_name'] : '';
8
- $last_name = isset($data['user_last_name']) ? $data['user_last_name'] : '';
9
- $email = isset($data['user_email']) ? $data['user_email'] : '';
10
-
11
- $name = '';
12
- if (!empty($first_name) || !empty($last_name)) {
13
- $name = str_replace(array('.', '+'), '', trim($first_name . $last_name));
14
- } else {
15
- if (!empty($email)) {
16
- $explode = explode('@', $email);
17
- $name = str_replace(array('.', '+'), '', $explode[0]);
18
- }
 
 
 
 
 
 
 
 
19
  }
20
 
21
- if (username_exists($name)) {
22
- $name = $name . substr(uniqid('', true), -6);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
- return sanitize_user($name, true);
26
- }
 
 
 
 
 
27
 
28
- public static function create_new_user($data) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- if (false === Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp()) {
31
- return;
32
  }
33
 
34
- $time = !empty($data['expiry']) ? $data['expiry'] : 'day';
35
-
36
- $password = Wp_Temporary_Login_Without_Password_Common::generate_password();
37
- $username = Wp_Temporary_Login_Without_Password_Common::create_username($data);
38
- $first_name = isset($data['user_first_name']) ? sanitize_text_field($data['user_first_name']) : '';
39
- $last_name = isset($data['user_last_name']) ? sanitize_text_field($data['user_last_name']) : '';
40
- $email = isset($data['user_email']) ? sanitize_email($data['user_email']) : '';
41
- $user_args = array(
42
- 'first_name' => $first_name,
43
- 'last_name' => $last_name,
44
- 'user_login' => $username,
45
- 'user_pass' => $password,
46
- 'user_email' => sanitize_email($email, true),
47
- 'role' => $data['role'],
48
- );
49
-
50
- $user_id = wp_insert_user($user_args);
51
-
52
- if (is_wp_error($user_id)) {
53
- $code = $user_id->get_error_code();
54
- return array(
55
- 'error' => true,
56
- 'errcode' => $code,
57
- 'message' => $user_id->get_error_message($code)
58
- );
59
  }
60
 
61
- update_user_meta($user_id, '_wtlwp_user', true);
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;
69
- }
70
-
71
- /**
72
- * get the expiry duration
73
- *
74
- * @param type $key
75
- * @return boolean|array
76
- */
77
- public static function get_expiry_duration($key = '') {
78
-
79
- $expiry_duration = array(
80
- '3_days' => array(
81
- 'value' => DAY_IN_SECONDS * 3,
82
- 'label' => __('Three Days', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
83
- ),
84
- 'day' => array(
85
- 'value' => DAY_IN_SECONDS,
86
- 'label' => __('One Day', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
87
- ),
88
- '3_hours' => array(
89
- 'value' => HOUR_IN_SECONDS * 3,
90
- 'label' => __('Three Hours', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
91
- ),
92
- 'hour' => array(
93
- 'value' => HOUR_IN_SECONDS,
94
- 'label' => __('One Hour', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
95
- ),
96
- 'week' => array(
97
- 'value' => WEEK_IN_SECONDS,
98
- 'label' => __('One Week', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
99
- ),
100
- 'month' => array(
101
- 'value' => DAY_IN_SECONDS * 30,
102
- 'label' => __('One Month', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
103
- ),
104
- );
105
-
106
-
107
- if (empty($key)) {
108
- return $expiry_duration;
109
- } elseif (isset($expiry_duration[$key])) {
110
- return $expiry_duration[$key];
111
- } else {
112
- return;
113
  }
114
- }
115
 
116
- static function get_expiry_duration_html($selected = '') {
117
 
118
- $p = '';
119
- $r = '';
120
 
121
- $expiry_duration = self::get_expiry_duration();
 
 
 
122
 
123
- foreach ($expiry_duration as $key => $duration) {
124
- $label = $duration['label'];
125
- if ($selected == $key)
126
- $p = "\n\t<option selected='selected' value='" . esc_attr($key) . "'>$label</option>";
127
- else
128
- $r .= "\n\t<option value='" . esc_attr($key) . "'>$label</option>";
129
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- echo $p . $r;
132
- }
133
-
134
- public static function generate_password() {
135
- return wp_generate_password(absint(15), true, false);
136
- }
137
-
138
- public static function get_user_expire_time($time = '') {
139
- $data = self::get_expiry_duration($time);
140
- $range = !empty($data['value']) ? $data['value'] : DAY_IN_SECONDS;
141
-
142
- return self::get_current_gmt_timestamp() + floatval($range);
143
- }
144
-
145
- public static function get_current_gmt_timestamp() {
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',
153
- 'meta_key' => '_wtlwp_expire',
154
- 'order' => 'DESC',
155
- 'orderby' => 'meta_value',
156
- 'meta_query' => array(
157
- 0 => array(
158
- 'key' => '_wtlwp_user',
159
- 'value' => 1
160
- )
161
- )
162
- );
163
-
164
- if (!empty($role)) {
165
- $args['role'] = $role;
166
  }
167
 
168
- $users = new WP_User_Query($args);
 
169
 
170
- if (!($users->results)) {
171
- return false;
172
  }
173
 
174
- return $users->results;
175
- }
176
 
177
- public static function format_date_display($stamp = 0, $type = 'date_format') {
 
 
 
 
 
 
 
 
 
 
 
178
 
179
- $type_format = 'date_format';
180
- if ($type == 'date_format') {
181
- $type_format = get_option('date_format');
182
- } else if ($type == 'time_format') {
183
- $type_format = get_option('time_format');
184
- }
185
 
 
 
 
186
 
187
- $timezone = get_option('timezone_string');
188
 
189
- if (empty($timezone)) {
190
- return date($type_format, $stamp);
191
  }
192
 
193
- $date = new DateTime('@' . $stamp);
194
 
195
- $date->setTimezone(new DateTimeZone($timezone));
 
 
 
 
 
196
 
197
- return $date->format($type_format);
198
- }
199
 
200
- public static function get_redirect_link($result = array()) {
 
 
201
 
202
- if (empty($result)) {
203
- return false;
204
- }
205
 
206
- $base_url = menu_page_url('wp-temporary-login-without-password', false);
207
 
208
- if (empty($base_url)) {
209
- return false;
210
- }
211
 
212
- $query_string = '';
213
- if (!empty($result['status'])) {
214
- if ($result['status'] == 'success') {
215
- $query_string .= '&wtlwp_success=1';
216
- } elseif ($result['status'] == 'error') {
217
- $query_string .= '&wtlwp_error=1';
218
- }
219
  }
220
 
221
- if (!empty($result['message'])) {
222
- $query_string .= '&wtlwp_message=' . $result['message'];
223
- }
224
 
225
- $redirect_link = $base_url . $query_string;
 
 
226
 
227
- return $redirect_link;
228
- }
229
 
230
- public static function can_manage_wtlwp($user_id = 0) {
 
 
231
 
232
- if (empty($user_id)) {
233
- $user_id = get_current_user_id();
234
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
- if (empty($user_id)) {
237
- return false;
238
  }
239
 
240
- $check = get_user_meta($user_id, '_wtlwp_user', true);
 
 
 
 
241
 
242
- return !empty($check) ? false : true;
243
- }
 
244
 
245
- public static function is_login_expired($user_id = 0) {
246
 
247
- if (empty($user_id)) {
248
- $user_id = get_current_user_id();
249
- }
250
 
251
- if (empty($user_id)) {
252
- return false;
253
  }
254
 
255
- $expire = get_user_meta($user_id, '_wtlwp_expire', true);
256
 
257
- return !empty($expire) && self::get_current_gmt_timestamp() >= floatval($expire) ? true : false;
258
- }
 
259
 
260
- public static function generate_wtlwp_token($user_id) {
261
- $str = $user_id . time() . uniqid('', true);
262
- return md5($str);
263
- }
264
 
265
- public static function get_valid_user_based_on_wtlwp_token($token = '', $user_id = 0, $fields = 'all') {
266
- $users_data = array();
267
- if (empty($token)) {
268
- return false;
269
- }
270
 
271
- $args = array(
272
- 'fields' => $fields,
273
- 'meta_key' => '_wtlwp_expire',
274
- 'order' => 'DESC',
275
- 'orderby' => 'meta_value',
276
- 'meta_query' => array(
277
- 0 => array(
278
- 'key' => '_wtlwp_token',
279
- 'value' => sanitize_text_field($token),
280
- 'compare' => '='
281
- )
282
- )
283
- );
284
-
285
- $users = new WP_User_Query($args);
286
-
287
- if (empty($users->results)) {
288
- return false;
289
  }
290
 
291
- $users_data = $users->results;
292
- foreach ($users_data as $key => $user) {
293
- $expire = get_user_meta($user->ID, '_wtlwp_expire', true);
294
- if ($expire <= self::get_current_gmt_timestamp()) {
295
- unset($users_data[$key]);
296
- }
297
  }
298
 
299
- return $users_data;
300
- }
 
 
 
301
 
302
- public static function is_valid_temporary_login($user_id = 0, $check_expiry = true) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
 
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
 
314
- return !empty($check) ? true : false;
315
- }
316
 
317
- public static function get_manage_login_url($user_id, $action = '') {
 
 
318
 
319
- if (empty($user_id) || empty($action)) {
320
- return;
321
- }
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
 
355
- $is_valid_temporary_login = self::is_valid_temporary_login($user_id, false);
356
- if (!$is_valid_temporary_login) {
357
- return;
358
- }
 
 
 
359
 
360
- $wtlwp_token = get_user_meta($user_id, '_wtlwp_token', true);
361
- if (empty($wtlwp_token)) {
362
- return;
363
  }
364
 
365
- $login_url = add_query_arg('wtlwp_token', $wtlwp_token, trailingslashit(admin_url()));
 
 
 
 
 
 
 
 
 
366
 
367
- return $login_url;
368
- }
 
 
369
 
370
- public static function manage_login($user_id = 0, $action = '') {
371
 
372
- if (empty($user_id) || empty($action)) {
373
- return;
374
- }
375
 
376
- $is_valid_temporary_login = self::is_valid_temporary_login($user_id, false);
377
- if (!$is_valid_temporary_login) {
378
- return;
379
  }
380
 
381
- $manage_login = false;
382
- if ($action == 'disable') {
383
- $manage_login = update_user_meta($user_id, '_wtlwp_expire', self::get_current_gmt_timestamp());
384
- } elseif ($action == 'enable') {
385
- $manage_login = update_user_meta($user_id, '_wtlwp_expire', self::get_user_expire_time());
386
- }
387
 
388
- if ($manage_login) {
389
- return true;
390
- }
391
 
392
- return false;
393
- }
 
 
394
 
395
- public static function time_elapsed_string($time, $ago = false) {
 
 
 
 
 
396
 
397
- if ($ago) {
398
- $etime = self::get_current_gmt_timestamp() - $time;
399
- } else {
400
- $etime = $time - self::get_current_gmt_timestamp();
401
- }
402
 
403
- if ($etime < 1) {
404
- return __('Expired', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
405
  }
406
 
407
- $a = array(365 * 24 * 60 * 60 => 'year',
408
- 30 * 24 * 60 * 60 => 'month',
409
- 24 * 60 * 60 => 'day',
410
- 60 * 60 => 'hour',
411
- 60 => 'minute',
412
- 1 => 'second'
413
- );
414
-
415
- $a_plural = array('year' => 'years',
416
- 'month' => 'months',
417
- 'day' => 'days',
418
- 'hour' => 'hours',
419
- 'minute' => 'minutes',
420
- 'second' => 'seconds'
421
- );
422
-
423
- foreach ($a as $secs => $str) {
424
- $d = $etime / $secs;
425
- if ($d >= 1) {
426
- $r = round($d);
427
- if ($ago) {
428
- return __(sprintf('%d %s ago', $r, ($r > 1 ? $a_plural[$str] : $str)), Wp_Temporary_Login_Without_Password_i18n::$text_domain);
429
  } else {
430
- return __(sprintf('%d %s remaining', $r, ($r > 1 ? $a_plural[$str] : $str)), Wp_Temporary_Login_Without_Password_i18n::$text_domain);
431
  }
432
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
433
  }
434
- }
435
-
436
- public static function get_blocked_pages() {
437
- $blocked_pages = array('wp-temporary-login-without-password', 'user-new.php', 'user-edit.php', 'profile.php');
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
  }
2
 
3
  class Wp_Temporary_Login_Without_Password_Common {
4
 
5
+ public static function create_username( $data ) {
6
+
7
+ $first_name = isset( $data[ 'user_first_name' ] ) ? $data[ 'user_first_name' ] : '';
8
+ $last_name = isset( $data[ 'user_last_name' ] ) ? $data[ 'user_last_name' ] : '';
9
+ $email = isset( $data[ 'user_email' ] ) ? $data[ 'user_email' ] : '';
10
+
11
+ $name = '';
12
+ if ( !empty( $first_name ) || !empty( $last_name ) ) {
13
+ $name = str_replace( array( '.', '+' ), '', trim( $first_name . $last_name ) );
14
+ } else {
15
+ if ( !empty( $email ) ) {
16
+ $explode = explode( '@', $email );
17
+ $name = str_replace( array( '.', '+' ), '', $explode[ 0 ] );
18
+ }
19
+ }
20
+
21
+ if ( username_exists( $name ) ) {
22
+ $name = $name . substr( uniqid( '', true ), -6 );
23
+ }
24
+
25
+ return sanitize_user( $name, true );
26
+
27
  }
28
 
29
+ public static function create_new_user( $data ) {
30
+
31
+ if ( false === Wp_Temporary_Login_Without_Password_Common::can_manage_wtlwp() ) {
32
+ return;
33
+ }
34
+
35
+ $expiry_option = !empty( $data[ 'expiry' ] ) ? $data[ 'expiry' ] : 'day';
36
+ $date = !empty($data['custom_date']) ? $data['custom_date'] : '';
37
+
38
+ $password = Wp_Temporary_Login_Without_Password_Common::generate_password();
39
+ $username = Wp_Temporary_Login_Without_Password_Common::create_username( $data );
40
+ $first_name = isset( $data[ 'user_first_name' ] ) ? sanitize_text_field( $data[ 'user_first_name' ] ) : '';
41
+ $last_name = isset( $data[ 'user_last_name' ] ) ? sanitize_text_field( $data[ 'user_last_name' ] ) : '';
42
+ $email = isset( $data[ 'user_email' ] ) ? sanitize_email( $data[ 'user_email' ] ) : '';
43
+ $user_args = array(
44
+ 'first_name' => $first_name,
45
+ 'last_name' => $last_name,
46
+ 'user_login' => $username,
47
+ 'user_pass' => $password,
48
+ 'user_email' => sanitize_email( $email, true ),
49
+ 'role' => $data[ 'role' ],
50
+ );
51
+
52
+ $user_id = wp_insert_user( $user_args );
53
+
54
+ if ( is_wp_error( $user_id ) ) {
55
+ $code = $user_id->get_error_code();
56
+ return array(
57
+ 'error' => true,
58
+ 'errcode' => $code,
59
+ 'message' => $user_id->get_error_message( $code ),
60
+ );
61
+ }
62
+
63
+ update_user_meta( $user_id, '_wtlwp_user', true );
64
+ update_user_meta( $user_id, '_wtlwp_created', Wp_Temporary_Login_Without_Password_Common::get_current_gmt_timestamp() );
65
+ update_user_meta( $user_id, '_wtlwp_expire', Wp_Temporary_Login_Without_Password_Common::get_user_expire_time( $expiry_option, $date ) );
66
+ update_user_meta( $user_id, '_wtlwp_token', Wp_Temporary_Login_Without_Password_Common::generate_wtlwp_token( $user_id ) );
67
+
68
+ update_user_meta( $user_id, 'show_welcome_panel', 0 );
69
+
70
+ return $user_id;
71
+
72
  }
73
 
74
+ /**
75
+ * get the expiry duration
76
+ *
77
+ * @param type $key
78
+ * @return boolean|array
79
+ */
80
+ public static function get_expiry_options( $key = '' ) {
81
 
82
+ $expiry_duration = array(
83
+ '3_days' => __( 'Three Days', 'wp-temporary-login-without-password' ),
84
+ 'day' => __( 'One Day', 'wp-temporary-login-without-password' ),
85
+ '3_hours' => __( 'Three Hours', 'wp-temporary-login-without-password' ),
86
+ 'hour' => __( 'One Hour', 'wp-temporary-login-without-password' ),
87
+ 'week' => __( 'One Week', 'wp-temporary-login-without-password' ),
88
+ 'month' => __( 'One Month', 'wp-temporary-login-without-password' ),
89
+ 'custom_date' => __( 'Custom Date', 'wp-temporary-login-without-password' )
90
+ );
91
+
92
+ if ( empty( $key ) ) {
93
+ return $expiry_duration;
94
+ } elseif ( isset( $expiry_duration[ $key ] ) ) {
95
+ return $expiry_duration[ $key ];
96
+ } else {
97
+ return;
98
+ }
99
 
 
 
100
  }
101
 
102
+ static function get_expiry_duration_html( $selected = '' ) {
103
+
104
+ $p = '';
105
+ $r = '';
106
+
107
+ $expiry_duration = self::get_expiry_options();
108
+
109
+ foreach ( $expiry_duration as $key => $label ) {
110
+ if ( $selected == $key ) {
111
+ $p = "\n\t<option selected='selected' value='" . esc_attr( $key ) . "'>$label</option>";
112
+ } else {
113
+ $r .= "\n\t<option value='" . esc_attr( $key ) . "'>$label</option>";
114
+ }
115
+ }
116
+
117
+ echo $p . $r;
118
+
 
 
 
 
 
 
 
 
119
  }
120
 
121
+ public static function generate_password() {
122
+ return wp_generate_password( absint( 15 ), true, false );
123
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
 
125
 
126
+ public static function get_user_expire_time( $expiry_option = 'day', $date = '' ) {
127
 
128
+ $current_timestamp = self::get_current_gmt_timestamp();
 
129
 
130
+ switch ( $expiry_option ) {
131
+ case '3_days' :
132
+ $timestamp = DAY_IN_SECONDS * 3;
133
+ break;
134
 
135
+ case 'day':
136
+ $timestamp = DAY_IN_SECONDS;
137
+ break;
138
+
139
+ case '3_hours':
140
+ $timestamp = HOUR_IN_SECONDS * 3;
141
+ break;
142
+
143
+ case 'hour':
144
+ $timestamp = HOUR_IN_SECONDS;
145
+ break;
146
+
147
+ case 'week':
148
+ $timestamp = WEEK_IN_SECONDS;
149
+ break;
150
+
151
+ case 'month':
152
+ $timestamp = MONTH_IN_SECONDS;
153
+ break;
154
+
155
+ case 'custom_date':
156
+ $timestamp = strtotime( $date );
157
+ $current_timestamp = 0;
158
+ break;
159
+
160
+ default:
161
+ $timestamp = DAY_IN_SECONDS;
162
+ break;
163
+ }
164
+
165
+ return $current_timestamp + floatval( $timestamp );
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
 
169
+ public static function get_current_gmt_timestamp() {
170
+ return strtotime( gmdate( 'Y-m-d H:i:s', time() ) );
171
 
 
 
172
  }
173
 
174
+ public static function get_temporary_logins( $role = '' ) {
 
175
 
176
+ $args = array(
177
+ 'fields' => 'all',
178
+ 'meta_key' => '_wtlwp_expire',
179
+ 'order' => 'DESC',
180
+ 'orderby' => 'meta_value',
181
+ 'meta_query' => array(
182
+ 0 => array(
183
+ 'key' => '_wtlwp_user',
184
+ 'value' => 1,
185
+ ),
186
+ ),
187
+ );
188
 
189
+ if ( !empty( $role ) ) {
190
+ $args[ 'role' ] = $role;
191
+ }
192
+
193
+ $users = new WP_User_Query( $args );
 
194
 
195
+ if ( !($users->results) ) {
196
+ return false;
197
+ }
198
 
199
+ return $users->results;
200
 
 
 
201
  }
202
 
203
+ public static function format_date_display( $stamp = 0, $type = 'date_format' ) {
204
 
205
+ $type_format = 'date_format';
206
+ if ( $type == 'date_format' ) {
207
+ $type_format = get_option( 'date_format' );
208
+ } elseif ( $type == 'time_format' ) {
209
+ $type_format = get_option( 'time_format' );
210
+ }
211
 
212
+ $timezone = get_option( 'timezone_string' );
 
213
 
214
+ if ( empty( $timezone ) ) {
215
+ return date( $type_format, $stamp );
216
+ }
217
 
218
+ $date = new DateTime( '@' . $stamp );
 
 
219
 
220
+ $date->setTimezone( new DateTimeZone( $timezone ) );
221
 
222
+ return $date->format( $type_format );
 
 
223
 
 
 
 
 
 
 
 
224
  }
225
 
226
+ public static function get_redirect_link( $result = array() ) {
 
 
227
 
228
+ if ( empty( $result ) ) {
229
+ return false;
230
+ }
231
 
232
+ $base_url = menu_page_url( 'wp-temporary-login-without-password', false );
 
233
 
234
+ if ( empty( $base_url ) ) {
235
+ return false;
236
+ }
237
 
238
+ $query_string = '';
239
+ if ( !empty( $result[ 'status' ] ) ) {
240
+ if ( $result[ 'status' ] == 'success' ) {
241
+ $query_string .= '&wtlwp_success=1';
242
+ } elseif ( $result[ 'status' ] == 'error' ) {
243
+ $query_string .= '&wtlwp_error=1';
244
+ }
245
+ }
246
+
247
+ if ( !empty( $result[ 'message' ] ) ) {
248
+ $query_string .= '&wtlwp_message=' . $result[ 'message' ];
249
+ }
250
+
251
+ $redirect_link = $base_url . $query_string;
252
+
253
+ return $redirect_link;
254
 
 
 
255
  }
256
 
257
+ public static function can_manage_wtlwp( $user_id = 0 ) {
258
+
259
+ if ( empty( $user_id ) ) {
260
+ $user_id = get_current_user_id();
261
+ }
262
 
263
+ if ( empty( $user_id ) ) {
264
+ return false;
265
+ }
266
 
267
+ $check = get_user_meta( $user_id, '_wtlwp_user', true );
268
 
269
+ return !empty( $check ) ? false : true;
 
 
270
 
 
 
271
  }
272
 
273
+ public static function is_login_expired( $user_id = 0 ) {
274
 
275
+ if ( empty( $user_id ) ) {
276
+ $user_id = get_current_user_id();
277
+ }
278
 
279
+ if ( empty( $user_id ) ) {
280
+ return false;
281
+ }
 
282
 
283
+ $expire = get_user_meta( $user_id, '_wtlwp_expire', true );
284
+
285
+ return !empty( $expire ) && self::get_current_gmt_timestamp() >= floatval( $expire ) ? true : false;
 
 
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  }
288
 
289
+ public static function generate_wtlwp_token( $user_id ) {
290
+ $str = $user_id . time() . uniqid( '', true );
291
+ return md5( $str );
292
+
 
 
293
  }
294
 
295
+ public static function get_valid_user_based_on_wtlwp_token( $token = '', $user_id = 0, $fields = 'all' ) {
296
+ $users_data = array();
297
+ if ( empty( $token ) ) {
298
+ return false;
299
+ }
300
 
301
+ $args = array(
302
+ 'fields' => $fields,
303
+ 'meta_key' => '_wtlwp_expire',
304
+ 'order' => 'DESC',
305
+ 'orderby' => 'meta_value',
306
+ 'meta_query' => array(
307
+ 0 => array(
308
+ 'key' => '_wtlwp_token',
309
+ 'value' => sanitize_text_field( $token ),
310
+ 'compare' => '=',
311
+ ),
312
+ ),
313
+ );
314
+
315
+ $users = new WP_User_Query( $args );
316
+
317
+ if ( empty( $users->results ) ) {
318
+ return false;
319
+ }
320
 
321
+ $users_data = $users->results;
322
+ foreach ( $users_data as $key => $user ) {
323
+ $expire = get_user_meta( $user->ID, '_wtlwp_expire', true );
324
+ if ( $expire <= self::get_current_gmt_timestamp() ) {
325
+ unset( $users_data[ $key ] );
326
+ }
327
+ }
328
 
329
+ return $users_data;
330
 
 
 
331
  }
332
 
333
+ public static function is_valid_temporary_login( $user_id = 0, $check_expiry = true ) {
 
334
 
335
+ if ( empty( $user_id ) ) {
336
+ return false;
337
+ }
338
 
339
+ $check = get_user_meta( $user_id, '_wtlwp_user', true );
 
 
340
 
341
+ if ( !empty( $check ) && $check_expiry ) {
342
+ $check = !(self::is_login_expired( $user_id ));
343
+ }
344
+
345
+ return !empty( $check ) ? true : false;
 
 
 
 
 
 
 
 
 
 
 
346
 
 
 
 
 
347
  }
348
 
349
+ public static function get_manage_login_url( $user_id, $action = '' ) {
 
350
 
351
+ if ( empty( $user_id ) || empty( $action ) ) {
352
+ return;
353
+ }
354
 
355
+ $base_url = menu_page_url( 'wp-temporary-login-without-password', false );
356
+ $args = array();
357
+
358
+ switch ( $action ) {
359
+ case 'disable';
360
+ $args = array(
361
+ 'wtlwp_action' => 'disable',
362
+ 'user_id' => $user_id,
363
+ );
364
+ break;
365
+ case 'enable';
366
+ $args = array(
367
+ 'wtlwp_action' => 'enable',
368
+ 'user_id' => $user_id,
369
+ );
370
+ break;
371
+ case 'delete';
372
+ $args = array(
373
+ 'wtlwp_action' => 'delete',
374
+ 'user_id' => $user_id,
375
+ );
376
+ break;
377
+ default:
378
+ break;
379
+ }
380
 
381
+ $manage_login_url = '';
382
+ if ( !empty( $args ) ) {
383
+ $base_url = add_query_arg( $args, trailingslashit( $base_url ) );
384
+ $manage_login_url = wp_nonce_url( $base_url, 'manage-temporary-login_' . $user_id, 'manage-temporary-login' );
385
+ }
386
+
387
+ return $manage_login_url;
388
 
 
 
 
389
  }
390
 
391
+ public static function get_login_url( $user_id ) {
392
+
393
+ if ( empty( $user_id ) ) {
394
+ return;
395
+ }
396
+
397
+ $is_valid_temporary_login = self::is_valid_temporary_login( $user_id, false );
398
+ if ( !$is_valid_temporary_login ) {
399
+ return;
400
+ }
401
 
402
+ $wtlwp_token = get_user_meta( $user_id, '_wtlwp_token', true );
403
+ if ( empty( $wtlwp_token ) ) {
404
+ return;
405
+ }
406
 
407
+ $login_url = add_query_arg( 'wtlwp_token', $wtlwp_token, trailingslashit( admin_url() ) );
408
 
409
+ return $login_url;
 
 
410
 
 
 
 
411
  }
412
 
413
+ public static function manage_login( $user_id = 0, $action = '' ) {
 
 
 
 
 
414
 
415
+ if ( empty( $user_id ) || empty( $action ) ) {
416
+ return;
417
+ }
418
 
419
+ $is_valid_temporary_login = self::is_valid_temporary_login( $user_id, false );
420
+ if ( !$is_valid_temporary_login ) {
421
+ return;
422
+ }
423
 
424
+ $manage_login = false;
425
+ if ( $action == 'disable' ) {
426
+ $manage_login = update_user_meta( $user_id, '_wtlwp_expire', self::get_current_gmt_timestamp() );
427
+ } elseif ( $action == 'enable' ) {
428
+ $manage_login = update_user_meta( $user_id, '_wtlwp_expire', self::get_user_expire_time() );
429
+ }
430
 
431
+ if ( $manage_login ) {
432
+ return true;
433
+ }
434
+
435
+ return false;
436
 
 
 
437
  }
438
 
439
+ public static function time_elapsed_string( $time, $ago = false ) {
440
+
441
+ if ( $ago ) {
442
+ $etime = self::get_current_gmt_timestamp() - $time;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  } else {
444
+ $etime = $time - self::get_current_gmt_timestamp();
445
  }
446
+
447
+ if ( $etime < 1 ) {
448
+ return __( 'Expired', 'wp-temporary-login-without-password' );
449
+ }
450
+
451
+ $a = array(
452
+ //365 * 24 * 60 * 60 => 'year',
453
+ //30 * 24 * 60 * 60 => 'month',
454
+ 24 * 60 * 60 => 'day',
455
+ 60 * 60 => 'hour',
456
+ 60 => 'minute',
457
+ 1 => 'second',
458
+ );
459
+
460
+ $a_plural = array(
461
+ 'year' => 'years',
462
+ 'month' => 'months',
463
+ 'day' => 'days',
464
+ 'hour' => 'hours',
465
+ 'minute' => 'minutes',
466
+ 'second' => 'seconds',
467
+ );
468
+
469
+ foreach ( $a as $secs => $str ) {
470
+ $d = $etime / $secs;
471
+
472
+ if ( $d >= 1 ) {
473
+ $r = round( $d );
474
+
475
+ if ( $ago ) {
476
+ return __( sprintf( '%d %s ago', $r, ($r > 1 ? $a_plural[ $str ] : $str ) ), 'wp-temporary-login-without-password' );
477
+ } else {
478
+ return __( sprintf( '%d %s remaining', $r, ($r > 1 ? $a_plural[ $str ] : $str ) ), 'wp-temporary-login-without-password' );
479
+ }
480
+ }
481
+ }
482
+
483
+ }
484
+
485
+ public static function get_blocked_pages() {
486
+ $blocked_pages = array( 'wp-temporary-login-without-password', 'user-new.php', 'user-edit.php', 'profile.php' );
487
+ $blocked_pages = apply_filters( 'wtlwp_restricted_pages_for_temporary_users', $blocked_pages );
488
+ return $blocked_pages;
489
+
490
  }
491
+
492
+ public static function delete_temporary_logins() {
493
+
494
+ $temporary_logins = Wp_Temporary_Login_Without_Password_Common::get_temporary_logins();
495
+
496
+ if ( count( $temporary_logins ) > 0 ) {
497
+ foreach ( $temporary_logins as $user ) {
498
+ if ( $user instanceof WP_User ) {
499
+ $user = wp_delete_user( $user->ID ); // Delete User
500
+ }
501
+ }
502
+ }
503
+
 
 
 
 
 
504
  }
 
 
 
 
505
 
506
  }
includes/class-wp-temporary-login-without-password-deactivator.php CHANGED
@@ -2,22 +2,25 @@
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
  }
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(
15
+ 'ID' => $user->ID,
16
+ 'role' => '',
17
+ ) ); // Downgrade role to none. So, user won't be able to login
18
+ }
19
+ }
20
+ }
21
 
22
+ $add = 'yes';
23
+ update_option( 'temporary_logins_data', $temporary_logins_data, $add );
24
+ }
25
 
26
  }
includes/class-wp-temporary-login-without-password-i18n.php CHANGED
@@ -5,13 +5,13 @@
5
  */
6
  class Wp_Temporary_Login_Without_Password_i18n {
7
 
8
- static $text_domain = 'wp-temporary-login-without-password';
9
 
10
- public function load_plugin_textdomain() {
 
 
 
 
 
11
 
12
- load_plugin_textdomain(
13
- self::$text_domain, false, dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
14
- );
15
- }
16
-
17
  }
5
  */
6
  class Wp_Temporary_Login_Without_Password_i18n {
7
 
8
+ static $text_domain = 'wp-temporary-login-without-password';
9
 
10
+ public function load_plugin_textdomain() {
11
+
12
+ load_plugin_textdomain(
13
+ self::$text_domain, false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
14
+ );
15
+ }
16
 
 
 
 
 
 
17
  }
includes/class-wp-temporary-login-without-password-layout.php CHANGED
@@ -2,120 +2,119 @@
2
 
3
  class Wp_Temporary_Login_Without_Password_Layout {
4
 
5
- public static function prepare_header_footer_row() {
6
 
7
- $row = '';
8
 
9
- $row .= '<th class="manage-column column-details" colspan="2">' . __('Users', Wp_Temporary_Login_Without_Password_i18n::$text_domain) . '</th>';
10
- $row .= '<th class="manage-column column-email">' . __('Role', Wp_Temporary_Login_Without_Password_i18n::$text_domain) . '</th>';
11
- $row .= '<th class="manage-column column-expired">' . __('Last Logged In', Wp_Temporary_Login_Without_Password_i18n::$text_domain) . '</th>';
12
- $row .= '<th class="manage-column column-expired">' . __('Expiry', Wp_Temporary_Login_Without_Password_i18n::$text_domain) . '</th>';
13
- $row .= '<th class="manage-column column-expired">' . __('Actions', Wp_Temporary_Login_Without_Password_i18n::$text_domain) . '</th>';
14
 
15
- return $row;
16
- }
17
 
18
- public static function prepare_empty_user_row() {
19
 
20
- $row = '';
21
 
22
- $row .= '<tr class="tempadmin-single-user-row tempadmin-empty-users-row standard">';
23
- $row .= '<td colspan="6">';
24
- $row .= '<span class="description">' . __('You have not created any temporary logins yet.', Wp_Temporary_Login_Without_Password_i18n::$text_domain) . '</span>';
25
- $row .= '</td>';
26
- $row .= '</tr>';
27
 
28
- return $row;
29
- }
30
 
31
- public static function prepare_single_user_row($user = OBJECT, $class = 'standard') {
32
- global $wpdb;
33
- if (is_numeric($user) && !is_object($user)) {
34
- $user = get_user_by('id', $user);
35
- }
36
 
37
- $create = get_user_meta($user->ID, '_wtlwp_created', true);
38
- $expire = get_user_meta($user->ID, '_wtlwp_expire', true);
39
- $token = get_user_meta($user->ID, '_wtlwp_token', true);
40
- $last_login_time = get_user_meta($user->ID, '_wtlwp_last_login', true);
41
 
42
- $last_login_str = __('Not yet logged in', Wp_Temporary_Login_Without_Password_i18n::$text_domain);
43
- if (!empty($last_login_time)) {
44
- $last_login_str = Wp_Temporary_Login_Without_Password_Common::time_elapsed_string($last_login_time, true);
45
- }
46
 
47
- $wtlwp_status = "Active";
48
- if (Wp_Temporary_Login_Without_Password_Common::is_login_expired($user->ID)) {
49
- $wtlwp_status = "Expired";
50
- }
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;
58
- }
59
- }
60
 
 
 
 
 
61
 
62
- $user_details = "<div><span>";
63
- if ((esc_attr($user->first_name))) {
64
- $user_details .= "<span>" . esc_attr($user->first_name) . "</span>";
65
- }
66
 
67
- if ((esc_attr($user->last_name))) {
68
- $user_details .= "<span> " . esc_attr($user->last_name) . "</span>";
69
- }
70
 
71
- $user_details .= " (<span class='wtlwp-user-login'>" . esc_attr($user->user_login) . ")</span><br />";
 
 
72
 
73
- if ((esc_attr($user->user_email))) {
74
- $user_details .= "<span><b>" . esc_attr($user->user_email) . "</b></span> <br />";
75
- }
76
 
77
- $user_details .= "</span></div>";
78
 
79
- $row = '';
 
 
 
80
 
81
- $row .= '<tr id="single-user-' . absint($user->ID) . '" class="tempadmin-single-user-row">';
82
- $row .= '<td class="email column-details" colspan="2">' . $user_details . '</td>';
83
- $row .= '<td class="wtlwp-token column-role">' . esc_attr($user_role) . '</td>';
84
- $row .= '<td class="wtlwp-token column-last-login">' . esc_attr($last_login_str) . '</td>';
 
 
 
85
 
86
- $row .= '<td class="expired column-expired wtlwp-status-' . strtolower($wtlwp_status) . '">';
87
- if (!empty($expire)) {
88
- $row .= Wp_Temporary_Login_Without_Password_Common::time_elapsed_string($expire);
89
- }
90
- $row .= '</td>';
91
- $row .= '<td class="wtlwp-token column-email">' . self::prepare_row_actions($user, $wtlwp_status) . '</td>';
92
- $row .= '</tr>';
93
 
94
- return $row;
95
- }
96
 
97
- public static function prepare_row_actions($user, $wtlwp_status) {
98
 
99
- $action_row = '<div class="actions">';
100
 
101
- $user_id = $user->ID;
 
 
102
 
103
- $delete_login_url = Wp_Temporary_Login_Without_Password_Common::get_manage_login_url($user_id, 'delete');
104
- $disable_login_url = Wp_Temporary_Login_Without_Password_Common::get_manage_login_url($user_id, 'disable');
105
- $enable_login_url = Wp_Temporary_Login_Without_Password_Common::get_manage_login_url($user_id, 'enable');
 
 
 
 
 
 
 
106
 
107
- if (strtolower($wtlwp_status) == 'expired') {
108
- $action_row .= '<span class="enable"><a title="'. __('Reactivate for one day', Wp_Temporary_Login_Without_Password_i18n::$text_domain) .'" href="' . $enable_login_url . '"><span class="dashicons dashicons-lock"></a></span></span>';
109
- } elseif (strtolower($wtlwp_status) == 'active') {
110
- $action_row .= '<span class="disable"><a title="'. __('Disable', Wp_Temporary_Login_Without_Password_i18n::$text_domain) .'" href="' . $disable_login_url . '"><span class="dashicons dashicons-unlock"></span></a></span>';
111
- }
112
-
113
- $action_row .= '<span class="edit"><a title="'. __('Delete', Wp_Temporary_Login_Without_Password_i18n::$text_domain) .'" href="' . $delete_login_url . '"><span class="dashicons dashicons-no"></span></a></span>';
114
- $action_row .= '<span class="edit"><span id="text-' . $user->ID . '" class="dashicons dashicons-admin-links wtlwp-copy-to-clipboard" title="'. __('Copy login link', Wp_Temporary_Login_Without_Password_i18n::$text_domain) .'" data-clipboard-text="' . Wp_Temporary_Login_Without_Password_Common::get_login_url($user->ID) . '"></span></span>';
115
- $action_row .= '<span id="copied-text-' . $user->ID . '" class="copied-text-message"></span>';
116
- $action_row .= '</div>';
117
-
118
- return $action_row;
119
- }
120
 
121
  }
2
 
3
  class Wp_Temporary_Login_Without_Password_Layout {
4
 
5
+ public static function prepare_header_footer_row() {
6
 
7
+ $row = '';
8
 
9
+ $row .= '<th class="manage-column column-details" colspan="2">' . __( 'Users', 'wp-temporary-login-without-password' ) . '</th>';
10
+ $row .= '<th class="manage-column column-email">' . __( 'Role', 'wp-temporary-login-without-password' ) . '</th>';
11
+ $row .= '<th class="manage-column column-expired">' . __( 'Last Logged In', 'wp-temporary-login-without-password' ) . '</th>';
12
+ $row .= '<th class="manage-column column-expired">' . __( 'Expiry', 'wp-temporary-login-without-password' ) . '</th>';
13
+ $row .= '<th class="manage-column column-expired">' . __( 'Actions', 'wp-temporary-login-without-password' ) . '</th>';
14
 
15
+ return $row;
16
+ }
17
 
18
+ public static function prepare_empty_user_row() {
19
 
20
+ $row = '';
21
 
22
+ $row .= '<tr class="tempadmin-single-user-row tempadmin-empty-users-row standard">';
23
+ $row .= '<td colspan="6">';
24
+ $row .= '<span class="description">' . __( 'You have not created any temporary logins yet.', 'wp-temporary-login-without-password' ) . '</span>';
25
+ $row .= '</td>';
26
+ $row .= '</tr>';
27
 
28
+ return $row;
29
+ }
30
 
31
+ public static function prepare_single_user_row( $user = OBJECT, $class = 'standard' ) {
32
+ global $wpdb;
33
+ if ( is_numeric( $user ) && ! is_object( $user ) ) {
34
+ $user = get_user_by( 'id', $user );
35
+ }
36
 
37
+ $create = get_user_meta( $user->ID, '_wtlwp_created', true );
38
+ $expire = get_user_meta( $user->ID, '_wtlwp_expire', true );
39
+ $token = get_user_meta( $user->ID, '_wtlwp_token', true );
40
+ $last_login_time = get_user_meta( $user->ID, '_wtlwp_last_login', true );
41
 
42
+ $last_login_str = __( 'Not yet logged in', 'wp-temporary-login-without-password' );
43
+ if ( ! empty( $last_login_time ) ) {
44
+ $last_login_str = Wp_Temporary_Login_Without_Password_Common::time_elapsed_string( $last_login_time, true );
45
+ }
46
 
47
+ $wtlwp_status = 'Active';
48
+ if ( Wp_Temporary_Login_Without_Password_Common::is_login_expired( $user->ID ) ) {
49
+ $wtlwp_status = 'Expired';
50
+ }
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;
58
+ }
59
+ }
60
 
61
+ $user_details = '<div><span>';
62
+ if ( (esc_attr( $user->first_name )) ) {
63
+ $user_details .= '<span>' . esc_attr( $user->first_name ) . '</span>';
64
+ }
65
 
66
+ if ( (esc_attr( $user->last_name )) ) {
67
+ $user_details .= '<span> ' . esc_attr( $user->last_name ) . '</span>';
68
+ }
 
69
 
70
+ $user_details .= " (<span class='wtlwp-user-login'>" . esc_attr( $user->user_login ) . ')</span><br />';
 
 
71
 
72
+ if ( (esc_attr( $user->user_email )) ) {
73
+ $user_details .= '<span><b>' . esc_attr( $user->user_email ) . '</b></span> <br />';
74
+ }
75
 
76
+ $user_details .= '</span></div>';
 
 
77
 
78
+ $row = '';
79
 
80
+ $row .= '<tr id="single-user-' . absint( $user->ID ) . '" class="tempadmin-single-user-row">';
81
+ $row .= '<td class="email column-details" colspan="2">' . $user_details . '</td>';
82
+ $row .= '<td class="wtlwp-token column-role">' . esc_attr( $user_role ) . '</td>';
83
+ $row .= '<td class="wtlwp-token column-last-login">' . esc_attr( $last_login_str ) . '</td>';
84
 
85
+ $row .= '<td class="expired column-expired wtlwp-status-' . strtolower( $wtlwp_status ) . '">';
86
+ if ( ! empty( $expire ) ) {
87
+ $row .= Wp_Temporary_Login_Without_Password_Common::time_elapsed_string( $expire );
88
+ }
89
+ $row .= '</td>';
90
+ $row .= '<td class="wtlwp-token column-email">' . self::prepare_row_actions( $user, $wtlwp_status ) . '</td>';
91
+ $row .= '</tr>';
92
 
93
+ return $row;
94
+ }
 
 
 
 
 
95
 
96
+ public static function prepare_row_actions( $user, $wtlwp_status ) {
 
97
 
98
+ $action_row = '<div class="actions">';
99
 
100
+ $user_id = $user->ID;
101
 
102
+ $delete_login_url = Wp_Temporary_Login_Without_Password_Common::get_manage_login_url( $user_id, 'delete' );
103
+ $disable_login_url = Wp_Temporary_Login_Without_Password_Common::get_manage_login_url( $user_id, 'disable' );
104
+ $enable_login_url = Wp_Temporary_Login_Without_Password_Common::get_manage_login_url( $user_id, 'enable' );
105
 
106
+ if ( strtolower( $wtlwp_status ) == 'expired' ) {
107
+ $action_row .= '<span class="enable"><a title="' . __( 'Reactivate for one day', 'wp-temporary-login-without-password' ) . '" href="' . $enable_login_url . '"><span class="dashicons dashicons-lock"></a></span></span>';
108
+ } elseif ( strtolower( $wtlwp_status ) == 'active' ) {
109
+ $action_row .= '<span class="disable"><a title="' . __( 'Disable', 'wp-temporary-login-without-password' ) . '" href="' . $disable_login_url . '"><span class="dashicons dashicons-unlock"></span></a></span>';
110
+ }
111
+
112
+ $action_row .= '<span class="edit"><a title="' . __( 'Delete', 'wp-temporary-login-without-password' ) . '" href="' . $delete_login_url . '"><span class="dashicons dashicons-no"></span></a></span>';
113
+ $action_row .= '<span class="edit"><span id="text-' . $user->ID . '" class="dashicons dashicons-admin-links wtlwp-copy-to-clipboard" title="' . __( 'Copy login link', 'wp-temporary-login-without-password' ) . '" data-clipboard-text="' . Wp_Temporary_Login_Without_Password_Common::get_login_url( $user->ID ) . '"></span></span>';
114
+ $action_row .= '<span id="copied-text-' . $user->ID . '" class="copied-text-message"></span>';
115
+ $action_row .= '</div>';
116
 
117
+ return $action_row;
118
+ }
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  }
includes/class-wp-temporary-login-without-password-loader.php CHANGED
@@ -5,44 +5,44 @@
5
  */
6
  class Wp_Temporary_Login_Without_Password_Loader {
7
 
8
- protected $actions;
9
- protected $filters;
10
 
11
- public function __construct() {
12
- $this->actions = array();
13
- $this->filters = array();
14
- }
15
 
16
- public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) {
17
- $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
18
- }
19
 
20
- public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) {
21
- $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args);
22
- }
23
 
24
- private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) {
25
 
26
- $hooks[] = array(
27
- 'hook' => $hook,
28
- 'component' => $component,
29
- 'callback' => $callback,
30
- 'priority' => $priority,
31
- 'accepted_args' => $accepted_args
32
- );
33
 
34
- return $hooks;
35
- }
36
 
37
- public function run() {
38
 
39
- foreach ($this->filters as $hook) {
40
- add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
41
- }
42
 
43
- foreach ($this->actions as $hook) {
44
- add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
45
- }
46
- }
47
 
48
  }
5
  */
6
  class Wp_Temporary_Login_Without_Password_Loader {
7
 
8
+ protected $actions;
9
+ protected $filters;
10
 
11
+ public function __construct() {
12
+ $this->actions = array();
13
+ $this->filters = array();
14
+ }
15
 
16
+ public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
17
+ $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
18
+ }
19
 
20
+ public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
21
+ $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
22
+ }
23
 
24
+ private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
25
 
26
+ $hooks[] = array(
27
+ 'hook' => $hook,
28
+ 'component' => $component,
29
+ 'callback' => $callback,
30
+ 'priority' => $priority,
31
+ 'accepted_args' => $accepted_args,
32
+ );
33
 
34
+ return $hooks;
35
+ }
36
 
37
+ public function run() {
38
 
39
+ foreach ( $this->filters as $hook ) {
40
+ add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
41
+ }
42
 
43
+ foreach ( $this->actions as $hook ) {
44
+ add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
45
+ }
46
+ }
47
 
48
  }
includes/class-wp-temporary-login-without-password.php CHANGED
@@ -2,86 +2,89 @@
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();
16
- $this->define_admin_hooks();
17
- $this->define_public_hooks();
18
- }
19
 
20
- public function define_constant($name, $value) {
21
- if (!defined($name)) {
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';
29
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wp-temporary-login-without-password-i18n.php';
30
- require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wp-temporary-login-without-password-admin.php';
31
- require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-wp-temporary-login-without-password-public.php';
32
 
33
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wp-temporary-login-without-password-common.php';
34
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wp-temporary-login-without-password-layout.php';
35
 
36
- $this->loader = new Wp_Temporary_Login_Without_Password_Loader();
37
- }
38
 
39
- private function set_locale() {
40
 
41
- $plugin_i18n = new Wp_Temporary_Login_Without_Password_i18n();
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());
49
 
50
- $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
51
- $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
52
 
53
- $this->loader->add_action('admin_menu', $plugin_admin, 'admin_menu');
54
- $this->loader->add_action('admin_init', $plugin_admin, 'create_user');
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() {
72
- $this->loader->run();
73
- }
 
74
 
75
- public function get_plugin_name() {
76
- return $this->plugin_name;
77
- }
78
 
79
- public function get_loader() {
80
- return $this->loader;
81
- }
82
 
83
- public function get_version() {
84
- return $this->version;
85
- }
 
 
 
 
86
 
87
  }
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.1';
13
 
14
+ $this->load_dependencies();
15
+ $this->set_locale();
16
+ $this->define_admin_hooks();
17
+ $this->define_public_hooks();
18
+ }
19
 
20
+ public function define_constant( $name, $value ) {
21
+ if ( ! defined( $name ) ) {
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';
29
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-temporary-login-without-password-i18n.php';
30
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-temporary-login-without-password-admin.php';
31
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-temporary-login-without-password-public.php';
32
 
33
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-temporary-login-without-password-common.php';
34
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-temporary-login-without-password-layout.php';
35
 
36
+ $this->loader = new Wp_Temporary_Login_Without_Password_Loader();
37
+ }
38
 
39
+ private function set_locale() {
40
 
41
+ $plugin_i18n = new Wp_Temporary_Login_Without_Password_i18n();
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() );
49
 
50
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
51
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
52
 
53
+ $this->loader->add_action( 'admin_menu', $plugin_admin, 'admin_menu' );
54
+ $this->loader->add_action( 'admin_init', $plugin_admin, 'create_user' );
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_action( 'wp_ajax_tlwp_rated', $plugin_admin, 'tlwp_rated' );
 
60
 
61
+ $this->loader->add_filter( 'wpmu_welcome_notification', $plugin_admin, 'disable_welcome_notification', 10, 5 );
62
+ $this->loader->add_filter( 'admin_footer_text', $plugin_admin, 'admin_footer_text', 1 );
63
+ }
64
 
65
+ private function define_public_hooks() {
66
 
67
+ $plugin_public = new Wp_Temporary_Login_Without_Password_Public( $this->get_plugin_name(), $this->get_version() );
 
 
 
68
 
69
+ $this->loader->add_action( 'init', $plugin_public, 'init_wtlwp' );
70
+ $this->loader->add_filter( 'wp_authenticate_user', $plugin_public, 'disable_temporary_user_login', 10, 2 );
71
+ $this->loader->add_filter( 'allow_password_reset', $plugin_public, 'disable_password_reset', 10, 2 );
72
+ }
73
 
74
+ public function run() {
75
+ $this->loader->run();
76
+ }
77
 
78
+ public function get_plugin_name() {
79
+ return $this->plugin_name;
80
+ }
81
 
82
+ public function get_loader() {
83
+ return $this->loader;
84
+ }
85
+
86
+ public function get_version() {
87
+ return $this->version;
88
+ }
89
 
90
  }
includes/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
languages/wp-temporary-login-without-password.pot CHANGED
@@ -1,246 +1,262 @@
1
- # Loco Gettext template
2
- #, fuzzy
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: WP Temporary Login Without Password\n"
6
- "Report-Msgid-Bugs-To: \n"
7
- "POT-Creation-Date: Tue Jul 26 2016 14:37:55 GMT+0530 (IST)\n"
8
- "POT-Revision-Date: Wed Aug 03 2016 14:53:20 GMT+0530 (IST)\n"
9
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
10
- "Last-Translator: \n"
11
- "Language-Team: \n"
12
- "Language: \n"
13
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION\n"
14
- "MIME-Version: 1.0\n"
15
- "Content-Type: text/plain; charset=UTF-8\n"
16
- "Content-Transfer-Encoding: 8bit\n"
17
- "X-Poedit-SourceCharset: UTF-8\n"
18
- "X-Poedit-Basepath: .\n"
19
- "X-Poedit-SearchPath-0: ..\n"
20
- "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
21
- "__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
22
- "_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
23
- "esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
24
- "esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
25
- "X-Generator: Loco - https://localise.biz/"
26
-
27
- #. Name of the plugin
28
- msgid "Temporary Login Without Password"
29
- msgstr ""
30
-
31
- #. URI of the plugin
32
- msgid "http://storeapps.org"
33
- msgstr ""
34
-
35
- #. Description of the plugin
36
- msgid ""
37
- "Create a temporary login link for your developer with any role using which "
38
- "they can access to your sytem without login and password for limited period "
39
- "of time."
40
- msgstr ""
41
-
42
- #. Author of the plugin
43
- msgid "StoreApps"
44
- msgstr ""
45
-
46
- #: ../admin/class-wp-temporary-login-without-password-admin.php:26 ../admin/class-
47
- #: wp-temporary-login-without-password-admin.php:26 ../templates/admin_settings.
48
- #: php:3
49
- msgid "Temporary Logins"
50
- msgstr ""
51
-
52
- #: ../admin/class-wp-temporary-login-without-password-admin.php:181
53
- msgid "User creation failed"
54
- msgstr ""
55
-
56
- #: ../admin/class-wp-temporary-login-without-password-admin.php:185
57
- msgid "You do not have permission to create a temporary login"
58
- msgstr ""
59
-
60
- #: ../admin/class-wp-temporary-login-without-password-admin.php:189
61
- msgid "Email already is in use"
62
- msgstr ""
63
-
64
- #: ../admin/class-wp-temporary-login-without-password-admin.php:193
65
- msgid "Please enter valid email address. Email field should not be empty"
66
- msgstr ""
67
-
68
- #: ../admin/class-wp-temporary-login-without-password-admin.php:197
69
- msgid "Please enter valid email address"
70
- msgstr ""
71
-
72
- #: ../admin/class-wp-temporary-login-without-password-admin.php:201
73
- msgid "User you are trying to delete is not temporary"
74
- msgstr ""
75
-
76
- #: ../admin/class-wp-temporary-login-without-password-admin.php:205
77
- msgid "Nonce failed"
78
- msgstr ""
79
-
80
- #: ../admin/class-wp-temporary-login-without-password-admin.php:209
81
- msgid "Invalid action"
82
- msgstr ""
83
-
84
- #: ../admin/class-wp-temporary-login-without-password-admin.php:214
85
- msgid "Unknown error occured"
86
- msgstr ""
87
-
88
- #: ../admin/class-wp-temporary-login-without-password-admin.php:222
89
- msgid "Login created successfully!"
90
- msgstr ""
91
-
92
- #: ../admin/class-wp-temporary-login-without-password-admin.php:226
93
- msgid "Login deleted successfully!"
94
- msgstr ""
95
-
96
- #: ../admin/class-wp-temporary-login-without-password-admin.php:230
97
- msgid "Login disabled successfully!"
98
- msgstr ""
99
-
100
- #: ../admin/class-wp-temporary-login-without-password-admin.php:234
101
- msgid "Login enabled successfully!"
102
- msgstr ""
103
-
104
- #: ../admin/class-wp-temporary-login-without-password-admin.php:238
105
- msgid "Success!"
106
- msgstr ""
107
-
108
- #: ../includes/class-wp-temporary-login-without-password-common.php:82
109
- msgid "Three Days"
110
- msgstr ""
111
-
112
- #: ../includes/class-wp-temporary-login-without-password-common.php:86
113
- msgid "One Day"
114
- msgstr ""
115
-
116
- #: ../includes/class-wp-temporary-login-without-password-common.php:90
117
- msgid "Three Hours"
118
- msgstr ""
119
-
120
- #: ../includes/class-wp-temporary-login-without-password-common.php:94
121
- msgid "One Hour"
122
- msgstr ""
123
-
124
- #: ../includes/class-wp-temporary-login-without-password-common.php:98
125
- msgid "One Week"
126
- msgstr ""
127
-
128
- #: ../includes/class-wp-temporary-login-without-password-common.php:102
129
- msgid "One Month"
130
- msgstr ""
131
-
132
- #: ../includes/class-wp-temporary-login-without-password-common.php:404
133
- msgid "Expired"
134
- msgstr ""
135
-
136
- #: ../includes/class-wp-temporary-login-without-password-layout.php:9
137
- msgid "Users"
138
- msgstr ""
139
-
140
- #: ../includes/class-wp-temporary-login-without-password-layout.php:10 ..
141
- #: /templates/new_login.php:19
142
- msgid "Role"
143
- msgstr ""
144
-
145
- #: ../includes/class-wp-temporary-login-without-password-layout.php:11
146
- msgid "Last Logged In"
147
- msgstr ""
148
-
149
- #: ../includes/class-wp-temporary-login-without-password-layout.php:12 ..
150
- #: /templates/new_login.php:27
151
- msgid "Expiry"
152
- msgstr ""
153
-
154
- #: ../includes/class-wp-temporary-login-without-password-layout.php:13
155
- msgid "Actions"
156
- msgstr ""
157
-
158
- #: ../includes/class-wp-temporary-login-without-password-layout.php:24
159
- msgid "You have not created any temporary logins yet."
160
- msgstr ""
161
-
162
- #: ../includes/class-wp-temporary-login-without-password-layout.php:42
163
- msgid "Not yet logged in"
164
- msgstr ""
165
-
166
- #: ../includes/class-wp-temporary-login-without-password-layout.php:107
167
- msgid "Reactivate for one day"
168
- msgstr ""
169
-
170
- #: ../includes/class-wp-temporary-login-without-password-layout.php:109
171
- msgid "Disable"
172
- msgstr ""
173
-
174
- #: ../includes/class-wp-temporary-login-without-password-layout.php:112
175
- msgid "Delete"
176
- msgstr ""
177
-
178
- #: ../includes/class-wp-temporary-login-without-password-layout.php:113
179
- msgid "Copy login link"
180
- msgstr ""
181
-
182
- #: ../public/class-wp-temporary-login-without-password-public.php:16
183
- msgid "Token empty"
184
- msgstr ""
185
-
186
- #: ../public/class-wp-temporary-login-without-password-public.php:17
187
- msgid "Authentication failed"
188
- msgstr ""
189
-
190
- #: ../public/class-wp-temporary-login-without-password-public.php:63
191
- msgid "You don't have permission to access this page"
192
- msgstr ""
193
-
194
- #: ../public/class-wp-temporary-login-without-password-public.php:75
195
- msgid "ERROR: Invalid username."
196
- msgstr ""
197
-
198
- #: ../public/class-wp-temporary-login-without-password-public.php:84
199
- msgid "ERROR: User can't find."
200
- msgstr ""
201
-
202
- #: ../templates/admin_settings.php:3
203
- msgid "Create New"
204
- msgstr ""
205
-
206
- #: ../templates/admin_settings.php:13
207
- msgid "Here's a temporary login link"
208
- msgstr ""
209
-
210
- #: ../templates/admin_settings.php:15
211
- msgid "Click To Copy"
212
- msgstr ""
213
-
214
- #: ../templates/admin_settings.php:17
215
- msgid ""
216
- "User can directly login to wordpress admin panel without username and "
217
- "password by opening this link."
218
- msgstr ""
219
-
220
- #: ../templates/new_login.php:1
221
- msgid "Create a new Temporary Login"
222
- msgstr ""
223
-
224
- #: ../templates/new_login.php:5
225
- msgid "Email*"
226
- msgstr ""
227
-
228
- #: ../templates/new_login.php:10
229
- msgid "First Name"
230
- msgstr ""
231
-
232
- #: ../templates/new_login.php:15
233
- msgid "Last Name"
234
- msgstr ""
235
-
236
- #: ../templates/new_login.php:36
237
- msgid "Submit"
238
- msgstr ""
239
-
240
- #: ../templates/new_login.php:36
241
- msgid "or"
242
- msgstr ""
243
-
244
- #: ../templates/new_login.php:36
245
- msgid "Cancel"
246
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #, fuzzy
2
+ msgid ""
3
+ msgstr ""
4
+ "Project-Id-Version: WP Temporary Login Without Password\n"
5
+ "Report-Msgid-Bugs-To: \n"
6
+ "POT-Creation-Date: 2017-06-23 03:40+0000\n"
7
+ "POT-Revision-Date: Wed Aug 03 2016 14:53:20 GMT+0530 (IST)\n"
8
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
9
+ "Last-Translator: \n"
10
+ "Language-Team: \n"
11
+ "Language: \n"
12
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=UTF-8\n"
15
+ "Content-Transfer-Encoding: 8bit\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-Basepath: .\n"
18
+ "X-Poedit-SearchPath-0: ..\n"
19
+ "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
20
+ "__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
21
+ "_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
22
+ "esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
23
+ "esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
24
+ "X-Generator: Loco - https://localise.biz/"
25
+
26
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:36
27
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:36
28
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/admin_settings.php:3
29
+ msgid "Temporary Logins"
30
+ msgstr ""
31
+
32
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:249
33
+ msgid "User creation failed"
34
+ msgstr ""
35
+
36
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:253
37
+ msgid "You do not have permission to create a temporary login"
38
+ msgstr ""
39
+
40
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:257
41
+ msgid "Email already is in use"
42
+ msgstr ""
43
+
44
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:261
45
+ msgid "Please enter valid email address. Email field should not be empty"
46
+ msgstr ""
47
+
48
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:265
49
+ msgid "Please enter valid email address"
50
+ msgstr ""
51
+
52
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:269
53
+ msgid "User you are trying to delete is not temporary"
54
+ msgstr ""
55
+
56
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:273
57
+ msgid "Nonce failed"
58
+ msgstr ""
59
+
60
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:277
61
+ msgid "Invalid action"
62
+ msgstr ""
63
+
64
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:282
65
+ msgid "Unknown error occured"
66
+ msgstr ""
67
+
68
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:290
69
+ msgid "Login created successfully!"
70
+ msgstr ""
71
+
72
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:294
73
+ msgid "Login deleted successfully!"
74
+ msgstr ""
75
+
76
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:298
77
+ msgid "Login disabled successfully!"
78
+ msgstr ""
79
+
80
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:302
81
+ msgid "Login enabled successfully!"
82
+ msgstr ""
83
+
84
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:306
85
+ msgid "Success!"
86
+ msgstr ""
87
+
88
+ #. %s: five stars
89
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:361
90
+ #, php-format
91
+ msgid ""
92
+ "If you like <strong>Temporary Login Without Password</strong> please leave "
93
+ "us a %s rating. A huge thanks in advance!"
94
+ msgstr ""
95
+
96
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:361
97
+ msgid "Thank You :)"
98
+ msgstr ""
99
+
100
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/admin/class-wp-temporary-login-without-password-admin.php:369
101
+ #, php-format
102
+ msgid "Thank you for using %s."
103
+ msgstr ""
104
+
105
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:83
106
+ msgid "Three Days"
107
+ msgstr ""
108
+
109
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:84
110
+ msgid "One Day"
111
+ msgstr ""
112
+
113
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:85
114
+ msgid "Three Hours"
115
+ msgstr ""
116
+
117
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:86
118
+ msgid "One Hour"
119
+ msgstr ""
120
+
121
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:87
122
+ msgid "One Week"
123
+ msgstr ""
124
+
125
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:88
126
+ msgid "One Month"
127
+ msgstr ""
128
+
129
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:89
130
+ msgid "Custom Date"
131
+ msgstr ""
132
+
133
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-common.php:448
134
+ msgid "Expired"
135
+ msgstr ""
136
+
137
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:9
138
+ msgid "Users"
139
+ msgstr ""
140
+
141
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:10
142
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:19
143
+ msgid "Role"
144
+ msgstr ""
145
+
146
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:11
147
+ msgid "Last Logged In"
148
+ msgstr ""
149
+
150
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:12
151
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:27
152
+ msgid "Expiry"
153
+ msgstr ""
154
+
155
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:13
156
+ msgid "Actions"
157
+ msgstr ""
158
+
159
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:24
160
+ msgid "You have not created any temporary logins yet."
161
+ msgstr ""
162
+
163
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:42
164
+ msgid "Not yet logged in"
165
+ msgstr ""
166
+
167
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:107
168
+ msgid "Reactivate for one day"
169
+ msgstr ""
170
+
171
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:109
172
+ msgid "Disable"
173
+ msgstr ""
174
+
175
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:112
176
+ msgid "Delete"
177
+ msgstr ""
178
+
179
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/includes/class-wp-temporary-login-without-password-layout.php:113
180
+ msgid "Copy login link"
181
+ msgstr ""
182
+
183
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/public/class-wp-temporary-login-without-password-public.php:16
184
+ msgid "Token empty"
185
+ msgstr ""
186
+
187
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/public/class-wp-temporary-login-without-password-public.php:17
188
+ msgid "Authentication failed"
189
+ msgstr ""
190
+
191
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/public/class-wp-temporary-login-without-password-public.php:74
192
+ msgid "You don't have permission to access this page"
193
+ msgstr ""
194
+
195
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/admin_settings.php:3
196
+ msgid "Create New"
197
+ msgstr ""
198
+
199
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/admin_settings.php:13
200
+ msgid "Here's a temporary login link"
201
+ msgstr ""
202
+
203
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/admin_settings.php:15
204
+ msgid "Click To Copy"
205
+ msgstr ""
206
+
207
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/admin_settings.php:17
208
+ msgid ""
209
+ "User can directly login to wordpress admin panel without username and "
210
+ "password by opening this link."
211
+ msgstr ""
212
+
213
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:1
214
+ msgid "Create a new Temporary Login"
215
+ msgstr ""
216
+
217
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:5
218
+ msgid "Email*"
219
+ msgstr ""
220
+
221
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:10
222
+ msgid "First Name"
223
+ msgstr ""
224
+
225
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:15
226
+ msgid "Last Name"
227
+ msgstr ""
228
+
229
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:44
230
+ msgid "Submit"
231
+ msgstr ""
232
+
233
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:44
234
+ msgid "or"
235
+ msgstr ""
236
+
237
+ #: ../../../../../repositories/GitLab/store-apps/temporary-login-without-password/templates/new_login.php:44
238
+ msgid "Cancel"
239
+ msgstr ""
240
+
241
+ #. Name of the plugin
242
+ msgid "Temporary Login Without Password"
243
+ msgstr ""
244
+
245
+ #. Description of the plugin
246
+ msgid ""
247
+ "Create a temporary login link with any role using which one can access to "
248
+ "your sytem without username and password for limited period of time."
249
+ msgstr ""
250
+
251
+ #. URI of the plugin
252
+ msgid ""
253
+ "http://www.storeapps.org/create-secure-login-without-password-for-wordpress/"
254
+ msgstr ""
255
+
256
+ #. Author of the plugin
257
+ msgid "StoreApps"
258
+ msgstr ""
259
+
260
+ #. URI of the plugin
261
+ msgid "http://storeapps.org"
262
+ msgstr ""
public/class-wp-temporary-login-without-password-public.php CHANGED
@@ -2,120 +2,120 @@
2
 
3
  class Wp_Temporary_Login_Without_Password_Public {
4
 
5
- private $plugin_name;
6
- private $version;
7
-
8
- public function __construct($plugin_name, $version) {
9
- $this->plugin_name = $plugin_name;
10
- $this->version = $version;
11
- }
12
-
13
- public static function get_error_messages($error_code) {
14
-
15
- $error_messages = array(
16
- 'token' => __('Token empty', Wp_Temporary_Login_Without_Password_i18n::$text_domain),
17
- 'unauth' => __('Authentication failed', Wp_Temporary_Login_Without_Password_i18n::$text_domain)
18
- );
19
-
20
- if (!empty($error_code)) {
21
- return (isset($error_messages[$error_code]) ? $error_messages[$error_code] : '');
22
- }
23
-
24
- return $error_messages;
25
- }
26
-
27
- public function init_wtlwp() {
28
-
29
- if (!is_user_logged_in() && !empty($_GET['wtlwp_token'])) {
30
-
31
- $error_messages = array();
32
-
33
- $wtlwp_token = $_GET['wtlwp_token'];
34
- $users = Wp_Temporary_Login_Without_Password_Common::get_valid_user_based_on_wtlwp_token($wtlwp_token);
35
-
36
- if (empty($users)) {
37
- wp_safe_redirect(home_url());
38
- } else {
39
- $user = $users[0];
40
-
41
- $user_id = $user->ID;
42
- $user_login = $user->login;
43
- update_user_meta($user_id, '_wtlwp_last_login', Wp_Temporary_Login_Without_Password_Common::get_current_gmt_timestamp());
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
- }
61
-
62
- if (is_user_logged_in()) {
63
- $user_id = get_current_user_id();
64
- if (!empty($user_id) && Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login($user_id, false)) {
65
- if (Wp_Temporary_Login_Without_Password_Common::is_login_expired($user_id)) {
66
- wp_logout();
67
- wp_safe_redirect(home_url());
68
- exit();
69
- } else {
70
- global $pagenow;
71
- $bloked_pages = Wp_Temporary_Login_Without_Password_Common::get_blocked_pages();
72
- $page = !empty($_GET['page']) ? $_GET['page'] : '';
73
- if ((!empty($page) && in_array($page, $bloked_pages)) || (!empty($pagenow) && in_array($pagenow, $bloked_pages))) {
74
- wp_die(__("You don't have permission to access this page", Wp_Temporary_Login_Without_Password_i18n::$text_domain));
75
- }
76
- }
77
- }
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
  }
2
 
3
  class Wp_Temporary_Login_Without_Password_Public {
4
 
5
+ private $plugin_name;
6
+ private $version;
7
+
8
+ public function __construct( $plugin_name, $version ) {
9
+ $this->plugin_name = $plugin_name;
10
+ $this->version = $version;
11
+ }
12
+
13
+ public static function get_error_messages( $error_code ) {
14
+
15
+ $error_messages = array(
16
+ 'token' => __( 'Token empty', 'wp-temporary-login-without-password' ),
17
+ 'unauth' => __( 'Authentication failed', 'wp-temporary-login-without-password' ),
18
+ );
19
+
20
+ if ( ! empty( $error_code ) ) {
21
+ return (isset( $error_messages[ $error_code ] ) ? $error_messages[ $error_code ] : '');
22
+ }
23
+
24
+ return $error_messages;
25
+ }
26
+
27
+ public function init_wtlwp() {
28
+
29
+ if ( ! is_user_logged_in() && ! empty( $_GET['wtlwp_token'] ) ) {
30
+
31
+ $error_messages = array();
32
+
33
+ $wtlwp_token = $_GET['wtlwp_token'];
34
+ $users = Wp_Temporary_Login_Without_Password_Common::get_valid_user_based_on_wtlwp_token( $wtlwp_token );
35
+
36
+ if ( empty( $users ) ) {
37
+ wp_safe_redirect( home_url() );
38
+ } else {
39
+ $user = $users[0];
40
+
41
+ $user_id = $user->ID;
42
+ $user_login = $user->login;
43
+ update_user_meta( $user_id, '_wtlwp_last_login', Wp_Temporary_Login_Without_Password_Common::get_current_gmt_timestamp() );
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
+ }
61
+
62
+ if ( is_user_logged_in() ) {
63
+ $user_id = get_current_user_id();
64
+ if ( ! empty( $user_id ) && Wp_Temporary_Login_Without_Password_Common::is_valid_temporary_login( $user_id, false ) ) {
65
+ if ( Wp_Temporary_Login_Without_Password_Common::is_login_expired( $user_id ) ) {
66
+ wp_logout();
67
+ wp_safe_redirect( home_url() );
68
+ exit();
69
+ } else {
70
+ global $pagenow;
71
+ $bloked_pages = Wp_Temporary_Login_Without_Password_Common::get_blocked_pages();
72
+ $page = ! empty( $_GET['page'] ) ? $_GET['page'] : '';
73
+ if ( ( ! empty( $page ) && in_array( $page, $bloked_pages )) || ( ! empty( $pagenow ) && in_array( $pagenow, $bloked_pages )) ) {
74
+ wp_die( __( "You don't have permission to access this page", 'wp-temporary-login-without-password' ) );
75
+ }
76
+ }
77
+ }
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
  }
public/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
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: 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,6 +40,10 @@ If you like Temporary Login Without Password, please leave a five star review on
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.
@@ -48,7 +52,7 @@ If you like Temporary Login Without Password, please leave a five star review on
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
 
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 login, custom login, customer access, customer login, secure login, access, admin, log in, login, login security, protection, 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.8
7
+ Stable tag: 1.4.1
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.1 =
44
+
45
+ - Added: Now, create a temporary login with custom expiry date.
46
+
47
  = 1.4 =
48
 
49
  - Added: Support for "Theme My Login" plugin. Now, temporary user will be redirected to page which is defined in Theme My Login plugin.
52
 
53
  - 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
54
  - Bug Fixed: Temporary user was able to reset password. Now onwards, they won't be able to reset password.
55
+ - Added: Now, role of temporary user is downgrade to "none" on deactivation of plugin and change to default on re activation of plugin
56
 
57
  = 1.2 =
58
 
templates/admin_settings.php CHANGED
@@ -1,34 +1,34 @@
1
  <?php ?>
2
  <div class="wrap wtlwp-settings-wrap">
3
- <h2> <?php echo __('Temporary Logins', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?> <span class="page-title-action" id="add-new-wtlwp-form-button"><?php _e('Create New', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></span> </h2>
4
- <div class="wtlwp-settings">
5
- <!-- Add New Form Start -->
6
- <div class="wrap new-wtlwp-form" id="new-wtlwp-form">
7
- <?php load_template(WTLWP_PLUGIN_DIR . '/templates/new_login.php'); ?>
8
- </div>
9
-
10
- <?php if(!empty($wtlwp_generated_url)) { ?>
11
-
12
- <div class="wrap generated-wtlwp-login-link" id="generated-wtlwp-login-link">
13
- <p><?php _e("Here's a temporary login link", Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></p>
14
- <input id="wtlwp-click-to-copy-btn" type="text" class="wtlwp-wide-input" value="<?php echo $wtlwp_generated_url; ?>">
15
- <button class="wtlwp-click-to-copy-btn" data-clipboard-action="copy" data-clipboard-target="#wtlwp-click-to-copy-btn"><?php echo __('Click To Copy', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></button>
16
- <span id="copied-text-message-wtlwp-click-to-copy-btn"></span>
17
- <p><?php _e("User can directly login to wordpress admin panel without username and password by opening this link.", Wp_Temporary_Login_Without_Password_i18n::$text_domain);
18
- if(!empty($user_email)) {
19
- echo __(sprintf(" <a href='mailto:%s'>Email</a> copied login link to user.", $user_email ), Wp_Temporary_Login_Without_Password_i18n::$text_domain);
20
- }
21
- ?>
22
- </p>
23
-
24
- </div>
25
- <?php } ?>
26
- <!-- Add New Form End -->
27
 
28
- <!-- List All Generated Logins Start -->
29
- <div class="wrap list-wtlwp-logins" id="list-wtlwp-logins">
30
- <?php load_template(WTLWP_PLUGIN_DIR . '/templates/list_temporary_logins.php'); ?>
31
- </div>
32
- <!-- List All Generated Logins End -->
33
- </div>
34
- </div>
1
  <?php ?>
2
  <div class="wrap wtlwp-settings-wrap">
3
+ <h2> <?php echo __( 'Temporary Logins', 'wp-temporary-login-without-password' ); ?> <span class="page-title-action" id="add-new-wtlwp-form-button"><?php _e( 'Create New', 'wp-temporary-login-without-password' ); ?></span> </h2>
4
+ <div class="wtlwp-settings">
5
+ <!-- Add New Form Start -->
6
+ <div class="wrap new-wtlwp-form" id="new-wtlwp-form">
7
+ <?php load_template( WTLWP_PLUGIN_DIR . '/templates/new_login.php' ); ?>
8
+ </div>
9
+
10
+ <?php if ( ! empty( $wtlwp_generated_url ) ) { ?>
11
+
12
+ <div class="wrap generated-wtlwp-login-link" id="generated-wtlwp-login-link">
13
+ <p><?php _e( "Here's a temporary login link", 'wp-temporary-login-without-password' ); ?></p>
14
+ <input id="wtlwp-click-to-copy-btn" type="text" class="wtlwp-wide-input" value="<?php echo $wtlwp_generated_url; ?>">
15
+ <button class="wtlwp-click-to-copy-btn" data-clipboard-action="copy" data-clipboard-target="#wtlwp-click-to-copy-btn"><?php echo __( 'Click To Copy', 'wp-temporary-login-without-password' ); ?></button>
16
+ <span id="copied-text-message-wtlwp-click-to-copy-btn"></span>
17
+ <p><?php _e( 'User can directly login to wordpress admin panel without username and password by opening this link.', 'wp-temporary-login-without-password' );
18
+ if ( ! empty( $user_email ) ) {
19
+ echo __( sprintf( " <a href='mailto:%s'>Email</a> copied login link to user.", $user_email ), 'wp-temporary-login-without-password' );
20
+ }
21
+ ?>
22
+ </p>
23
+
24
+ </div>
25
+ <?php } ?>
26
+ <!-- Add New Form End -->
27
 
28
+ <!-- List All Generated Logins Start -->
29
+ <div class="wrap list-wtlwp-logins" id="list-wtlwp-logins">
30
+ <?php load_template( WTLWP_PLUGIN_DIR . '/templates/list_temporary_logins.php' ); ?>
31
+ </div>
32
+ <!-- List All Generated Logins End -->
33
+ </div>
34
+ </div>
templates/list_temporary_logins.php CHANGED
@@ -1,26 +1,26 @@
1
  <table class="wp-list-table widefat fixed striped users">
2
  <thead>
3
  <?php echo Wp_Temporary_Login_Without_Password_Layout::prepare_header_footer_row(); ?>
4
- </thead>
5
 
6
- <tbody>
7
- <?php
8
- $users = Wp_Temporary_Login_Without_Password_Common::get_temporary_logins();
9
-
10
- if (is_array($users) && count($users) > 0) {
11
-
12
- foreach ($users as $user) {
13
- echo Wp_Temporary_Login_Without_Password_Layout::prepare_single_user_row($user);
14
- }
15
- } else {
16
- echo Wp_Temporary_Login_Without_Password_Layout::prepare_empty_user_row();
17
- }
18
-
19
- ?>
20
 
21
- </tbody>
22
 
23
- <tfoot>
24
- <?php echo Wp_Temporary_Login_Without_Password_Layout::prepare_header_footer_row(); ?>
25
- </tfoot>
26
- </table>
 
 
 
 
 
 
 
 
 
 
 
1
  <table class="wp-list-table widefat fixed striped users">
2
  <thead>
3
  <?php echo Wp_Temporary_Login_Without_Password_Layout::prepare_header_footer_row(); ?>
4
+ </thead>
5
 
6
+ <tbody>
7
+ <?php
8
+ $users = Wp_Temporary_Login_Without_Password_Common::get_temporary_logins();
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ if ( is_array( $users ) && count( $users ) > 0 ) {
11
 
12
+ foreach ( $users as $user ) {
13
+ echo Wp_Temporary_Login_Without_Password_Layout::prepare_single_user_row( $user );
14
+ }
15
+ } else {
16
+ echo Wp_Temporary_Login_Without_Password_Layout::prepare_empty_user_row();
17
+ }
18
+
19
+ ?>
20
+
21
+ </tbody>
22
+
23
+ <tfoot>
24
+ <?php echo Wp_Temporary_Login_Without_Password_Layout::prepare_header_footer_row(); ?>
25
+ </tfoot>
26
+ </table>
templates/new_login.php CHANGED
@@ -1,41 +1,49 @@
1
- <h2> <?php echo __('Create a new Temporary Login', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></h2>
2
  <form method="post">
3
- <table class="form-table wtlwp-form">
4
- <tr class="form-field form-required">
5
- <th scope="row" class="wtlwp-form-row"> <label for="user_email"><?php echo __('Email*', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?> </label></th>
6
- <td><input name="wtlwp_data[user_email]" type="text" id="user_email" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" class="wtlwp-form-input"/></td>
7
- </tr>
8
 
9
- <tr class="form-field form-required">
10
- <th scope="row" class="wtlwp-form-row"> <label for="user_first_name"><?php echo __('First Name', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?> </label></th>
11
- <td><input name="wtlwp_data[user_first_name]" type="text" id="user_first_name" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" class="wtlwp-form-input"/></td>
12
- </tr>
13
 
14
- <tr class="form-field form-required">
15
- <th scope="row" class="wtlwp-form-row"> <label for="user_last_name"><?php echo __('Last Name', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?> </label></th>
16
- <td><input name="wtlwp_data[user_last_name]" type="text" id="user_last_name" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" class="wtlwp-form-input"/></td>
17
- </tr>
18
- <tr class="form-field">
19
- <th scope="row" class="wtlwp-form-row"><label for="adduser-role"><?php echo __('Role', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></label></th>
20
- <td><select name="wtlwp_data[role]" id="user-role">
21
- <?php wp_dropdown_roles('administrator'); ?>
22
- </select>
23
- </td>
24
- </tr>
25
 
26
- <tr class="form-field">
27
- <th scope="row" class="wtlwp-form-row"><label for="adduser-role"><?php echo __('Expiry', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></label></th>
28
- <td><select name="wtlwp_data[expiry]" id="user-expiry-time">
29
- <?php Wp_Temporary_Login_Without_Password_Common::get_expiry_duration_html(); ?>
30
- </select>
31
- </td>
32
- </tr>
33
-
34
- <tr class="form-field">
35
- <th scope="row" class="wtlwp-form-row"><label for="adduser-role"></label></th>
36
- <td><p class="submit"><input type="submit" class="button button-primary wtlwp-form-submit-button" value="<?php _e('Submit', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?>" class="button button-primary" id="generatetemporarylogin" name="generate_temporary_login"> <?php _e('or', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?> <span class="cancel-new-login-form" id="cancel-new-login-form"><?php _e('Cancel', Wp_Temporary_Login_Without_Password_i18n::$text_domain); ?></span></p>
37
- </td>
38
- </tr>
39
- <?php wp_nonce_field('wtlwp_generate_login_url', 'wtlwp-nonce', true, true); ?>
40
- </table>
 
 
 
 
 
 
 
 
41
  </form>
1
+ <h2> <?php echo __( 'Create a new Temporary Login', 'wp-temporary-login-without-password' ); ?></h2>
2
  <form method="post">
3
+ <table class="form-table wtlwp-form">
4
+ <tr class="form-field form-required">
5
+ <th scope="row" class="wtlwp-form-row"> <label for="user_email"><?php echo __( 'Email*', 'wp-temporary-login-without-password' ); ?> </label></th>
6
+ <td><input name="wtlwp_data[user_email]" type="text" id="user_email" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" class="wtlwp-form-input"/></td>
7
+ </tr>
8
 
9
+ <tr class="form-field form-required">
10
+ <th scope="row" class="wtlwp-form-row"> <label for="user_first_name"><?php echo __( 'First Name', 'wp-temporary-login-without-password' ); ?> </label></th>
11
+ <td><input name="wtlwp_data[user_first_name]" type="text" id="user_first_name" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" class="wtlwp-form-input"/></td>
12
+ </tr>
13
 
14
+ <tr class="form-field form-required">
15
+ <th scope="row" class="wtlwp-form-row"> <label for="user_last_name"><?php echo __( 'Last Name', 'wp-temporary-login-without-password' ); ?> </label></th>
16
+ <td><input name="wtlwp_data[user_last_name]" type="text" id="user_last_name" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60" class="wtlwp-form-input"/></td>
17
+ </tr>
18
+ <tr class="form-field">
19
+ <th scope="row" class="wtlwp-form-row"><label for="adduser-role"><?php echo __( 'Role', 'wp-temporary-login-without-password' ); ?></label></th>
20
+ <td><select name="wtlwp_data[role]" id="user-role">
21
+ <?php wp_dropdown_roles( 'administrator' ); ?>
22
+ </select>
23
+ </td>
24
+ </tr>
25
 
26
+ <tr class="form-field">
27
+ <th scope="row" class="wtlwp-form-row"><label for="adduser-role"><?php echo __( 'Expiry', 'wp-temporary-login-without-password' ); ?></label></th>
28
+ <td>
29
+ <span id="expiry-date-selection">
30
+ <select name="wtlwp_data[expiry]" id="user-expiry-time">
31
+ <?php Wp_Temporary_Login_Without_Password_Common::get_expiry_duration_html(); ?>
32
+ </select>
33
+ </span>
34
+
35
+ <span style="display:none;" id="custom-date-picker">
36
+ <input type="date" id="datepicker" name="wtlwp_data[custom_date]" value="" class="example-datepicker" />
37
+ </span>
38
+
39
+ </td>
40
+ </tr>
41
+
42
+ <tr class="form-field">
43
+ <th scope="row" class="wtlwp-form-row"><label for="adduser-role"></label></th>
44
+ <td><p class="submit"><input type="submit" class="button button-primary wtlwp-form-submit-button" value="<?php _e( 'Submit', 'wp-temporary-login-without-password' ); ?>" class="button button-primary" id="generatetemporarylogin" name="generate_temporary_login"> <?php _e( 'or', 'wp-temporary-login-without-password' ); ?> <span class="cancel-new-login-form" id="cancel-new-login-form"><?php _e( 'Cancel', 'wp-temporary-login-without-password' ); ?></span></p>
45
+ </td>
46
+ </tr>
47
+ <?php wp_nonce_field( 'wtlwp_generate_login_url', 'wtlwp-nonce', true, true ); ?>
48
+ </table>
49
  </form>
temporary-login-without-password.php CHANGED
@@ -2,27 +2,30 @@
2
 
3
  /**
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+
11
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
  * Text Domain: wp-temporary-login-without-password
13
  * Domain Path: /languages
 
14
  */
15
  // If this file is called directly, abort.
16
- if (!defined('WPINC')) {
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
  }
@@ -32,12 +35,12 @@ register_activation_hook( __FILE__, 'wp_activate_temporary_login_without_passwor
32
 
33
 
34
  // Include main class file
35
- require plugin_dir_path(__FILE__) . 'includes/class-wp-temporary-login-without-password.php';
36
 
37
  function run_wp_temporary_login_without_password() {
38
- $plugin = new Wp_Temporary_Login_Without_Password();
39
- $plugin->define_constant('WTLWP_PLUGIN_DIR', dirname(__FILE__));
40
- $plugin->run();
41
  }
42
 
43
  run_wp_temporary_login_without_password();
2
 
3
  /**
4
  * Plugin Name: Temporary Login Without Password
5
+ * Plugin URI: http://www.storeapps.org/create-secure-login-without-password-for-wordpress/
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.1
8
  * Author: StoreApps
9
  * Author URI: http://storeapps.org
10
+ * Requires at least: 3.3
11
+ * Tested up to: 4.8
12
  * License: GPL-2.0+
13
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
14
  * Text Domain: wp-temporary-login-without-password
15
  * Domain Path: /languages
16
+ * Copyright (c) 2016, 2017 StoreApps, All right reserved
17
  */
18
  // If this file is called directly, abort.
19
+ if ( ! defined( 'WPINC' ) ) {
20
+ die;
21
  }
22
 
23
+ function wp_deactivate_temporary_login_without_password() {
24
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-temporary-login-without-password-deactivator.php';
25
  Wp_Temporary_Login_Without_Password_Deactivator::deactivate();
26
  }
27
 
28
+ function wp_activate_temporary_login_without_password() {
29
  require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-temporary-login-without-password-activator.php';
30
  Wp_Temporary_Login_Without_Password_Activator::activate();
31
  }
35
 
36
 
37
  // Include main class file
38
+ require plugin_dir_path( __FILE__ ) . 'includes/class-wp-temporary-login-without-password.php';
39
 
40
  function run_wp_temporary_login_without_password() {
41
+ $plugin = new Wp_Temporary_Login_Without_Password();
42
+ $plugin->define_constant( 'WTLWP_PLUGIN_DIR', dirname( __FILE__ ) );
43
+ $plugin->run();
44
  }
45
 
46
  run_wp_temporary_login_without_password();