WPS Hide Login - Version 1.3.4

Version Description

  • Add : Review message
  • Fix : Redirect url wp-admin/options.php
Download this release

Release Info

Developer NicolasKulka
Plugin Icon 128x128 WPS Hide Login
Version 1.3.4
Comparing to
See all releases

Code changes from version 1.3.3 to 1.3.4

classes/lib/wp-dismissible-notices-handler/assets/js/main.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ $( '.notice.is-dismissible' ).on('click', '.notice-dismiss', function ( event ) {
3
+ event.preventDefault();
4
+ var $this = $(this);
5
+ if( 'undefined' == $this.parent().attr('id') ){
6
+ return;
7
+ }
8
+ $.post( ajaxurl, {
9
+ action: 'dnh_dismiss_notice',
10
+ url: ajaxurl,
11
+ id: $this.parent().attr('id')
12
+ });
13
+
14
+ });
15
+ });
classes/lib/wp-dismissible-notices-handler/composer.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "julien731/wp-dismissible-notices-handler",
3
+ "description": "A simple library to handle Ajax-dismissible admin notices for WordPress",
4
+ "homepage": "https://github.com/julien731/WP-Dismissible-Notices-Handler",
5
+ "license": "GNU GPL",
6
+ "authors": [
7
+ {
8
+ "name": "Julien Liabeuf",
9
+ "email": "julien@liabeuf.fr",
10
+ "homepage": "https://julienliabeuf.com",
11
+ "role": "Lead Developer"
12
+ }
13
+ ],
14
+ "require": {
15
+ "php": ">=5.5.0"
16
+ },
17
+ "autoload": {
18
+ "files": ["handler.php"]
19
+ }
20
+ }
classes/lib/wp-dismissible-notices-handler/handler.php ADDED
@@ -0,0 +1,639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dismissible Notices Handler.
4
+ *
5
+ * This library is designed to handle dismissible admin notices.
6
+ *
7
+ * LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU
8
+ * General Public License as published by the Free Software Foundation; either version 3 of the License, or (at
9
+ * your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ * General Public License for more details. You should have received a copy of the GNU General Public License along
12
+ * with this program. If not, see <http://opensource.org/licenses/gpl-license.php>
13
+ *
14
+ * @package Dismissible Notices Handler
15
+ * @author Julien Liabeuf <julien@liabeuf.fr>
16
+ * @version 1.1
17
+ * @license GPL-2.0+
18
+ * @link https://julienliabeuf.com
19
+ * @copyright 2018 Julien Liabeuf
20
+ */
21
+
22
+ // If this file is called directly, abort.
23
+ if ( ! defined( 'WPINC' ) ) {
24
+ die;
25
+ }
26
+
27
+ if ( ! class_exists( 'Dismissible_Notices_Handler' ) ) {
28
+
29
+ final class Dismissible_Notices_Handler {
30
+
31
+ /**
32
+ * @var Dismissible_Notices_Handler Holds the unique instance of the handler
33
+ * @since 1.0
34
+ */
35
+ private static $instance;
36
+
37
+ /**
38
+ * Library version
39
+ *
40
+ * @since 1.0
41
+ * @var string
42
+ */
43
+ public $version = '1.1';
44
+
45
+ /**
46
+ * Required version of PHP.
47
+ *
48
+ * @since 1.0
49
+ * @var string
50
+ */
51
+ public $php_version_required = '5.5';
52
+
53
+ /**
54
+ * Minimum version of WordPress required to use the library
55
+ *
56
+ * @since 1.0
57
+ * @var string
58
+ */
59
+ public $wordpress_version_required = '4.2';
60
+
61
+ /**
62
+ * @var array Holds all our registered notices
63
+ * @since 1.0
64
+ */
65
+ private $notices;
66
+
67
+ /**
68
+ * Instantiate and return the unique Dismissible_Notices_Handler object
69
+ *
70
+ * @since 1.0
71
+ * @return object Dismissible_Notices_Handler Unique instance of the handler
72
+ */
73
+ public static function instance() {
74
+
75
+ if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Dismissible_Notices_Handler ) ) {
76
+ self::$instance = new Dismissible_Notices_Handler;
77
+ self::$instance->init();
78
+ }
79
+
80
+ return self::$instance;
81
+
82
+ }
83
+
84
+ /**
85
+ * Initialize the library
86
+ *
87
+ * @since 1.0
88
+ * @return void
89
+ */
90
+ private function init() {
91
+
92
+ // Make sure WordPress is compatible
93
+ if ( ! self::$instance->is_wp_compatible() ) {
94
+ self::$instance->spit_error(
95
+ sprintf(
96
+ /* translators: %s: required wordpress version */
97
+ esc_html__( 'The library can not be used because your version of WordPress is too old. You need version %s at least.', 'wp-dismissible-notices-handler' ),
98
+ self::$instance->wordpress_version_required
99
+ )
100
+ );
101
+
102
+ return;
103
+ }
104
+
105
+ // Make sure PHP is compatible
106
+ if ( ! self::$instance->is_php_compatible() ) {
107
+ self::$instance->spit_error(
108
+ sprintf(
109
+ /* translators: %s: required php version */
110
+ esc_html__( 'The library can not be used because your version of PHP is too old. You need version %s at least.', 'wp-dismissible-notices-handler' ),
111
+ self::$instance->php_version_required
112
+ )
113
+ );
114
+
115
+ return;
116
+ }
117
+
118
+ self::$instance->includes();
119
+
120
+ add_action( 'admin_notices', array( self::$instance, 'display' ) );
121
+ add_action( 'admin_print_scripts', array( self::$instance, 'load_script' ) );
122
+ add_action( 'wp_ajax_dnh_dismiss_notice', array( self::$instance, 'dismiss_notice_ajax' ) );
123
+
124
+ }
125
+
126
+ /**
127
+ * Check if the current WordPress version fits the requirements
128
+ *
129
+ * @since 1.0
130
+ * @return boolean
131
+ */
132
+ private function is_wp_compatible() {
133
+
134
+ if ( version_compare( get_bloginfo( 'version' ), self::$instance->wordpress_version_required, '<' ) ) {
135
+ return false;
136
+ }
137
+
138
+ return true;
139
+
140
+ }
141
+
142
+ /**
143
+ * Check if the version of PHP is compatible with this library
144
+ *
145
+ * @since 1.0
146
+ * @return boolean
147
+ */
148
+ private function is_php_compatible() {
149
+
150
+ if ( version_compare( phpversion(), self::$instance->php_version_required, '<' ) ) {
151
+ return false;
152
+ }
153
+
154
+ return true;
155
+
156
+ }
157
+
158
+ /**
159
+ * Include all our files
160
+ *
161
+ * @since 1.0
162
+ * @return void
163
+ */
164
+ private function includes() {
165
+ require( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'includes/helper-functions.php' );
166
+ }
167
+
168
+ /**
169
+ * Load the script
170
+ *
171
+ * @since 1.0
172
+ * @return void
173
+ */
174
+ public function load_script() {
175
+ wp_register_script( 'dnh', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/js/main.js', array( 'jquery' ), self::$instance->version, true );
176
+ wp_enqueue_script( 'dnh' );
177
+ }
178
+
179
+ /**
180
+ * Display all the registered notices
181
+ *
182
+ * @since 1.0
183
+ * @return void
184
+ */
185
+ public function display() {
186
+
187
+ if ( is_null( self::$instance->notices ) || empty( self::$instance->notices ) ) {
188
+ return;
189
+ }
190
+
191
+ foreach ( self::$instance->notices as $id => $notice ) {
192
+
193
+ $id = self::$instance->get_id( $id );
194
+
195
+ // Check if the notice was dismissed
196
+ if ( self::$instance->is_dismissed( $id ) ) {
197
+ continue;
198
+ }
199
+
200
+ // Check if the current user has required capability
201
+ if ( ! empty( $notice['cap'] ) && ! current_user_can( $notice['cap'] ) ) {
202
+ continue;
203
+ }
204
+
205
+ $class = array(
206
+ 'notice',
207
+ $notice['type'],
208
+ 'is-dismissible',
209
+ $notice['class'],
210
+ );
211
+
212
+ printf( '<div id="%3$s" class="%1$s"><p>%2$s</p></div>', trim( implode( ' ', $class ) ), $notice['content'], "dnh-$id" );
213
+
214
+ }
215
+
216
+ }
217
+
218
+ /**
219
+ * Spits an error message at the top of the admin screen
220
+ *
221
+ * @since 1.0
222
+ *
223
+ * @param string $error Error message to spit
224
+ *
225
+ * @return void
226
+ */
227
+ protected function spit_error( $error ) {
228
+ printf(
229
+ '<div style="margin: 20px; text-align: center;"><strong>%1$s</strong> %2$s</pre></div>',
230
+ esc_html__( 'Dismissible Notices Handler Error:', 'wp-dismissible-notices-handler' ),
231
+ wp_kses_post( $error )
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Sanitize a notice ID and return it
237
+ *
238
+ * @since 1.0
239
+ *
240
+ * @param string $id
241
+ *
242
+ * @return string
243
+ */
244
+ public function get_id( $id ) {
245
+ return sanitize_key( $id );
246
+ }
247
+
248
+ /**
249
+ * Get available notice types
250
+ *
251
+ * @since 1.0
252
+ * @return array
253
+ */
254
+ public function get_types() {
255
+
256
+ $types = array(
257
+ 'error',
258
+ 'updated',
259
+ // New types of notification style.
260
+ 'notice-error',
261
+ 'notice-warning',
262
+ 'notice-success',
263
+ 'notice-info',
264
+ );
265
+
266
+ return apply_filters( 'dnh_notice_types', $types );
267
+
268
+ }
269
+
270
+ /**
271
+ * Get the default arguments for a notice
272
+ *
273
+ * @since 1.0
274
+ * @return array
275
+ */
276
+ private function default_args() {
277
+
278
+ $args = array(
279
+ 'screen' => '', // Coming soon
280
+ 'scope' => 'user', // Scope of the dismissal. Either user or global
281
+ 'cap' => '', // Required user capability
282
+ 'class' => '', // Additional class to add to the notice
283
+ );
284
+
285
+ return apply_filters( 'dnh_default_args', $args );
286
+
287
+ }
288
+
289
+ /**
290
+ * Register a new notice
291
+ *
292
+ * @since 1.0
293
+ *
294
+ * @param string $id Notice ID, used to identify it
295
+ * @param string $type Type of notice to display
296
+ * @param string $content Notice content
297
+ * @param array $args Additional parameters
298
+ *
299
+ * @return bool
300
+ */
301
+ public function register_notice( $id, $type, $content, $args = array() ) {
302
+
303
+ if ( is_null( self::$instance->notices ) ) {
304
+ self::$instance->notices = array();
305
+ }
306
+
307
+ $id = self::$instance->get_id( $id );
308
+ $type = in_array( $t = sanitize_text_field( $type ), self::$instance->get_types() ) ? $t : 'updated';
309
+ $content = wp_kses_post( $content );
310
+ $args = wp_parse_args( $args, self::$instance->default_args() );
311
+
312
+ if ( array_key_exists( $id, self::$instance->notices ) ) {
313
+
314
+ self::$instance->spit_error(
315
+ sprintf(
316
+ /* translators: %s: required php version */
317
+ esc_html__( 'A notice with the ID %s has already been registered.', 'wp-dismissible-notices-handler' ),
318
+ "<code>$id</code>"
319
+ )
320
+ );
321
+
322
+ return false;
323
+ }
324
+
325
+ $notice = array(
326
+ 'type' => $type,
327
+ 'content' => $content,
328
+ );
329
+
330
+ $notice = array_merge( $notice, $args );
331
+
332
+ self::$instance->notices[ $id ] = $notice;
333
+
334
+ return true;
335
+
336
+ }
337
+
338
+ /**
339
+ * Notice dismissal triggered by Ajax
340
+ *
341
+ * @since 1.0
342
+ * @return void
343
+ */
344
+ public function dismiss_notice_ajax() {
345
+
346
+ if ( ! isset( $_POST['id'] ) ) {
347
+ echo 0;
348
+ exit;
349
+ }
350
+
351
+ if ( empty( $_POST['id'] ) || false === strpos( $_POST['id'], 'dnh-' ) ) {
352
+ echo 0;
353
+ exit;
354
+ }
355
+
356
+ $id = self::$instance->get_id( str_replace( 'dnh-', '', $_POST['id'] ) );
357
+
358
+ echo self::$instance->dismiss_notice( $id );
359
+ exit;
360
+
361
+ }
362
+
363
+ /**
364
+ * Dismiss a notice
365
+ *
366
+ * @since 1.0
367
+ *
368
+ * @param string $id ID of the notice to dismiss
369
+ *
370
+ * @return bool
371
+ */
372
+ public function dismiss_notice( $id ) {
373
+
374
+ $notice = self::$instance->get_notice( self::$instance->get_id( $id ) );
375
+
376
+ if ( false === $notice ) {
377
+ return false;
378
+ }
379
+
380
+ if ( self::$instance->is_dismissed( $id ) ) {
381
+ return false;
382
+ }
383
+
384
+ return 'user' === $notice['scope'] ? self::$instance->dismiss_user( $id ) : self::$instance->dismiss_global( $id );
385
+
386
+ }
387
+
388
+ /**
389
+ * Dismiss notice for the current user
390
+ *
391
+ * @since 1.0
392
+ *
393
+ * @param string $id Notice ID
394
+ *
395
+ * @return int|bool
396
+ */
397
+ private function dismiss_user( $id ) {
398
+
399
+ $dismissed = self::$instance->dismissed_user();
400
+
401
+ if ( in_array( $id, $dismissed ) ) {
402
+ return false;
403
+ }
404
+
405
+ array_push( $dismissed, $id );
406
+
407
+ return update_user_meta( get_current_user_id(), 'dnh_dismissed_notices', $dismissed );
408
+
409
+ }
410
+
411
+ /**
412
+ * Dismiss notice globally on the site
413
+ *
414
+ * @since 1.0
415
+ *
416
+ * @param string $id Notice ID
417
+ *
418
+ * @return bool
419
+ */
420
+ private function dismiss_global( $id ) {
421
+
422
+ $dismissed = self::$instance->dismissed_global();
423
+
424
+ if ( in_array( $id, $dismissed ) ) {
425
+ return false;
426
+ }
427
+
428
+ array_push( $dismissed, $id );
429
+
430
+ return update_option( 'dnh_dismissed_notices', $dismissed );
431
+
432
+ }
433
+
434
+ /**
435
+ * Restore a dismissed notice
436
+ *
437
+ * @since 1.0
438
+ *
439
+ * @param string $id ID of the notice to restore
440
+ *
441
+ * @return bool
442
+ */
443
+ public function restore_notice( $id ) {
444
+
445
+ $id = self::$instance->get_id( $id );
446
+ $notice = self::$instance->get_notice( $id );
447
+
448
+ if ( false === $notice ) {
449
+ return false;
450
+ }
451
+
452
+ return 'user' === $notice['scope'] ? self::$instance->restore_user( $id ) : self::$instance->restore_global( $id );
453
+
454
+ }
455
+
456
+ /**
457
+ * Restore a notice dismissed by the current user
458
+ *
459
+ * @since 1.0
460
+ *
461
+ * @param string $id ID of the notice to restore
462
+ *
463
+ * @return bool
464
+ */
465
+ private function restore_user( $id ) {
466
+
467
+ $id = self::$instance->get_id( $id );
468
+ $notice = self::$instance->get_notice( $id );
469
+
470
+ if ( false === $notice ) {
471
+ return false;
472
+ }
473
+
474
+ $dismissed = self::$instance->dismissed_user();
475
+
476
+ if ( ! in_array( $id, $dismissed ) ) {
477
+ return false;
478
+ }
479
+
480
+ $flip = array_flip( $dismissed );
481
+ $key = $flip[ $id ];
482
+
483
+ unset( $dismissed[ $key ] );
484
+
485
+ return update_user_meta( get_current_user_id(), 'dnh_dismissed_notices', $dismissed );
486
+
487
+ }
488
+
489
+ /**
490
+ * Restore a notice dismissed globally
491
+ *
492
+ * @since 1.0
493
+ *
494
+ * @param string $id ID of the notice to restore
495
+ *
496
+ * @return bool
497
+ */
498
+ private function restore_global( $id ) {
499
+
500
+ $id = self::$instance->get_id( $id );
501
+ $notice = self::$instance->get_notice( $id );
502
+
503
+ if ( false === $notice ) {
504
+ return false;
505
+ }
506
+
507
+ $dismissed = self::$instance->dismissed_global();
508
+
509
+ if ( ! in_array( $id, $dismissed ) ) {
510
+ return false;
511
+ }
512
+
513
+ $flip = array_flip( $dismissed );
514
+ $key = $flip[ $id ];
515
+
516
+ unset( $dismissed[ $key ] );
517
+
518
+ return update_option( 'dnh_dismissed_notices', $dismissed );
519
+
520
+ }
521
+
522
+ /**
523
+ * Get all dismissed notices
524
+ *
525
+ * This includes notices dismissed globally or per user.
526
+ *
527
+ * @since 1.0
528
+ * @return array
529
+ */
530
+ public function dismissed_notices() {
531
+
532
+ $user = self::$instance->dismissed_user();
533
+ $global = self::$instance->dismissed_global();
534
+
535
+ return array_merge( $user, $global );
536
+
537
+ }
538
+
539
+ /**
540
+ * Get user dismissed notices
541
+ *
542
+ * @since 1.0
543
+ * @return array
544
+ */
545
+ private function dismissed_user() {
546
+
547
+ $dismissed = get_user_meta( get_current_user_id(), 'dnh_dismissed_notices', true );
548
+
549
+ if ( '' === $dismissed ) {
550
+ $dismissed = array();
551
+ }
552
+
553
+ return $dismissed;
554
+
555
+ }
556
+
557
+ /**
558
+ * Get globally dismissed notices
559
+ *
560
+ * @since 1.0
561
+ * @return array
562
+ */
563
+ private function dismissed_global() {
564
+ return get_option( 'dnh_dismissed_notices', array() );
565
+ }
566
+
567
+ /**
568
+ * Check if a notice has been dismissed
569
+ *
570
+ * @since 1.0
571
+ *
572
+ * @param string $id Notice ID
573
+ *
574
+ * @return bool
575
+ */
576
+ public function is_dismissed( $id ) {
577
+
578
+ $dismissed = self::$instance->dismissed_notices();
579
+
580
+ if ( ! in_array( self::$instance->get_id( $id ), $dismissed ) ) {
581
+ return false;
582
+ }
583
+
584
+ return true;
585
+
586
+ }
587
+
588
+ /**
589
+ * Get all the registered notices
590
+ *
591
+ * @since 1.0
592
+ * @return array|null
593
+ */
594
+ public function get_notices() {
595
+ return self::$instance->notices;
596
+ }
597
+
598
+ /**
599
+ * Return a specific notice
600
+ *
601
+ * @since 1.0
602
+ *
603
+ * @param string $id Notice ID
604
+ *
605
+ * @return array|false
606
+ */
607
+ public function get_notice( $id ) {
608
+
609
+ $id = self::$instance->get_id( $id );
610
+
611
+ if ( ! is_array( self::$instance->notices ) || ! array_key_exists( $id, self::$instance->notices ) ) {
612
+ return false;
613
+ }
614
+
615
+ return self::$instance->notices[ $id ];
616
+
617
+ }
618
+
619
+ }
620
+
621
+ /**
622
+ * The main function responsible for returning the unique Dismissible Notices Handler instance
623
+ *
624
+ * Use this function like you would a global variable, except without needing
625
+ * to declare the global.
626
+ *
627
+ * @since 1.0
628
+ * @return object Dismissible_Notices_Handler
629
+ */
630
+ function DNH() {
631
+ return Dismissible_Notices_Handler::instance();
632
+ }
633
+
634
+ /**
635
+ * Get the library running
636
+ */
637
+ DNH();
638
+
639
+ }
classes/lib/wp-dismissible-notices-handler/includes/helper-functions.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Dismissible Notices Handler.
4
+ *
5
+ * LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6
+ * General Public License as published by the Free Software Foundation; either version 3 of the License, or (at
7
+ * your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
8
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
+ * General Public License for more details. You should have received a copy of the GNU General Public License along
10
+ * with this program. If not, see <http://opensource.org/licenses/gpl-license.php>
11
+ *
12
+ * @package Dismissible Notices Handler/Helper Functions
13
+ * @author Julien Liabeuf <julien@liabeuf.fr>
14
+ * @version 1.0
15
+ * @license GPL-2.0+
16
+ * @link https://julienliabeuf.com
17
+ * @copyright 2016 Julien Liabeuf
18
+ */
19
+
20
+ // If this file is called directly, abort.
21
+ if ( ! defined( 'WPINC' ) ) {
22
+ die;
23
+ }
24
+
25
+ /**
26
+ * Register a new notice
27
+ *
28
+ * @since 1.0
29
+ *
30
+ * @param string $id Notice ID, used to identify it
31
+ * @param string $type Type of notice to display
32
+ * @param string $content Notice content
33
+ * @param array $args Additional parameters
34
+ *
35
+ * @return bool
36
+ */
37
+ function dnh_register_notice( $id, $type, $content, $args = array() ) {
38
+
39
+ if ( ! function_exists( 'DNH' ) ) {
40
+ return false;
41
+ }
42
+
43
+ return DNH()->register_notice( $id, $type, $content, $args );
44
+
45
+ }
46
+
47
+ /**
48
+ * Restore a previously dismissed notice
49
+ *
50
+ * @since 1.0
51
+ *
52
+ * @param string $id ID of the notice to restore
53
+ *
54
+ * @return bool
55
+ */
56
+ function dnh_restore_notice( $id ) {
57
+
58
+ if ( ! function_exists( 'DNH' ) ) {
59
+ return false;
60
+ }
61
+
62
+ return DNH()->restore_notice( $id );
63
+
64
+ }
65
+
66
+ /**
67
+ * Check if a notice has been dismissed
68
+ *
69
+ * @since 1.0
70
+ *
71
+ * @param string $id ID of the notice to check
72
+ *
73
+ * @return bool
74
+ */
75
+ function dnh_is_dismissed( $id ) {
76
+
77
+ if ( ! function_exists( 'DNH' ) ) {
78
+ return false;
79
+ }
80
+
81
+ return DNH()->is_dismissed( $id );
82
+
83
+ }
classes/plugin.php CHANGED
@@ -80,6 +80,7 @@ if ( ! class_exists( 'WPS_Hide_Login' ) ) {
80
  add_action( 'admin_init', array( $this, 'whl_template_redirect' ) );
81
 
82
  add_action( 'template_redirect', array( $this, 'wps_hide_login_redirect_page_email_notif_woocommerce' ) );
 
83
  }
84
 
85
  private function use_trailing_slashes() {
@@ -360,7 +361,7 @@ if ( ! class_exists( 'WPS_Hide_Login' ) ) {
360
 
361
  if ( ! is_multisite()
362
  && ( strpos( $_SERVER['REQUEST_URI'], 'wp-signup' ) !== false
363
- || strpos( $_SERVER['REQUEST_URI'], 'wp-activate' ) !== false ) && apply_filters( 'wps_hide_login_signup_enable' , false ) === false ) {
364
 
365
  wp_die( __( 'This feature is not enabled.', 'wpserveur-hide-login' ) );
366
 
@@ -584,5 +585,34 @@ if ( ! class_exists( 'WPS_Hide_Login' ) ) {
584
  }
585
  }
586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
  }
588
  }
80
  add_action( 'admin_init', array( $this, 'whl_template_redirect' ) );
81
 
82
  add_action( 'template_redirect', array( $this, 'wps_hide_login_redirect_page_email_notif_woocommerce' ) );
83
+ add_filter( 'login_url', array( __CLASS__, 'login_url' ), 10, 3 );
84
  }
85
 
86
  private function use_trailing_slashes() {
361
 
362
  if ( ! is_multisite()
363
  && ( strpos( $_SERVER['REQUEST_URI'], 'wp-signup' ) !== false
364
+ || strpos( $_SERVER['REQUEST_URI'], 'wp-activate' ) !== false ) && apply_filters( 'wps_hide_login_signup_enable', false ) === false ) {
365
 
366
  wp_die( __( 'This feature is not enabled.', 'wpserveur-hide-login' ) );
367
 
585
  }
586
  }
587
 
588
+ /**
589
+ *
590
+ * Update url redirect : wp-admin/options.php
591
+ *
592
+ * @param $login_url
593
+ * @param $redirect
594
+ * @param $force_reauth
595
+ *
596
+ * @return string
597
+ */
598
+ public function login_url( $login_url, $redirect, $force_reauth ) {
599
+
600
+ if ( $force_reauth === false ) {
601
+ return $login_url;
602
+ }
603
+
604
+ if ( empty( $redirect ) ) {
605
+ return $login_url;
606
+ }
607
+
608
+ $redirect = explode( '?', $redirect );
609
+
610
+ if ( $redirect[0] === admin_url( 'options.php' ) ) {
611
+ $login_url = admin_url();
612
+ }
613
+
614
+ return $login_url;
615
+ }
616
+
617
  }
618
  }
classes/review.php ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WP Review Me
4
+ *
5
+ * A lightweight library to help you get more reviews for your WordPress theme/plugin.
6
+ *
7
+ * LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU
8
+ * General Public License as published by the Free Software Foundation; either version 3 of the License, or (at
9
+ * your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ * General Public License for more details. You should have received a copy of the GNU General Public License along
12
+ * with this program. If not, see <http://opensource.org/licenses/gpl-license.php>
13
+ *
14
+ * @package WP Review Me
15
+ * @author Julien Liabeuf <julien@liabeuf.fr>
16
+ * @version 2.0.1
17
+ * @license GPL-2.0+
18
+ * @link https://julienliabeuf.com
19
+ * @copyright 2016 Julien Liabeuf
20
+ */
21
+ // If this file is called directly, abort.
22
+ if ( ! defined( 'WPINC' ) ) {
23
+ die;
24
+ }
25
+ if ( ! class_exists( 'WP_Review_Me' ) ) {
26
+ class WP_Review_Me {
27
+ /**
28
+ * Library version
29
+ *
30
+ * @since 1.0
31
+ * @var string
32
+ */
33
+ public $version = '2.0.1';
34
+ /**
35
+ * Required version of PHP.
36
+ *
37
+ * @since 1.0
38
+ * @var string
39
+ */
40
+ public $php_version_required = '5.5';
41
+ /**
42
+ * Minimum version of WordPress required to use the library
43
+ *
44
+ * @since 1.0
45
+ * @var string
46
+ */
47
+ public $wordpress_version_required = '4.2';
48
+ /**
49
+ * Holds the unique identifying key for this particular instance
50
+ *
51
+ * @since 1.0
52
+ * @var string
53
+ */
54
+ protected $key;
55
+ /**
56
+ * Link unique ID
57
+ *
58
+ * @since 1.0
59
+ * @var string
60
+ */
61
+ public $link_id;
62
+
63
+ /**
64
+ * WP_Review_Me constructor.
65
+ *
66
+ * @since 1.0
67
+ *
68
+ * @param array $args Object settings
69
+ */
70
+ public function __construct( $args ) {
71
+ $args = wp_parse_args( $args, $this->get_defaults() );
72
+ $this->days = $args['days_after'];
73
+ $this->type = $args['type'];
74
+ $this->slug = $args['slug'];
75
+ $this->rating = $args['rating'];
76
+ $this->message = $args['message'];
77
+ $this->link_label = $args['link_label'];
78
+ $this->cap = $args['cap'];
79
+ $this->scope = $args['scope'];
80
+ // Set the unique identifying key for this instance
81
+ $this->key = 'wrm_' . substr( md5( plugin_basename( __FILE__ ) . $args['slug'] ), 0, 20 );
82
+ $this->link_id = 'wrm-review-link-' . $this->key;
83
+ // Instantiate
84
+ $this->init();
85
+ }
86
+
87
+ /**
88
+ * Get default object settings
89
+ *
90
+ * @since 1.0
91
+ * @return array
92
+ */
93
+ protected function get_defaults() {
94
+ $defaults = array(
95
+ 'days_after' => 10,
96
+ 'type' => '',
97
+ 'slug' => '',
98
+ 'rating' => 5,
99
+ 'message' => sprintf( esc_html__( 'Hey! It&#039;s been a little while that you&#039;ve been using this product. You might not realize it, but user reviews are such a great help to us. We would be so grateful if you could take a minute to leave a review on WordPress.org. Many thanks in advance :)', 'wp-review-me' ) ),
100
+ 'link_label' => esc_html__( 'Click here to leave your review', 'wp-review-me' ),
101
+ // Parameters used in WP Dismissible Notices Handler
102
+ 'cap' => 'administrator',
103
+ 'scope' => 'global',
104
+ );
105
+
106
+ return $defaults;
107
+ }
108
+
109
+ /**
110
+ * Initialize the library
111
+ *
112
+ * @since 1.0
113
+ * @return void
114
+ */
115
+ private function init() {
116
+ // Make sure WordPress is compatible
117
+ if ( ! $this->is_wp_compatible() ) {
118
+ $this->spit_error(
119
+ sprintf(
120
+ esc_html__( 'The library can not be used because your version of WordPress is too old. You need version %s at least.', 'wp-review-me' ),
121
+ $this->wordpress_version_required
122
+ )
123
+ );
124
+
125
+ return;
126
+ }
127
+ // Make sure PHP is compatible
128
+ if ( ! $this->is_php_compatible() ) {
129
+ $this->spit_error(
130
+ sprintf(
131
+ esc_html__( 'The library can not be used because your version of PHP is too old. You need version %s at least.', 'wp-review-me' ),
132
+ $this->php_version_required
133
+ )
134
+ );
135
+
136
+ return;
137
+ }
138
+ // Make sure the dependencies are loaded
139
+ if ( ! function_exists( 'dnh_register_notice' ) ) {
140
+ $dnh_file = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'lib/wp-dismissible-notices-handler/handler.php';
141
+ if ( file_exists( $dnh_file ) ) {
142
+ require( $dnh_file );
143
+ }
144
+ }
145
+ add_action( 'admin_footer', array( $this, 'script' ) );
146
+ add_action( 'wp_ajax_wrm_clicked_review', array( $this, 'dismiss_notice' ) );
147
+ // And let's roll... maybe.
148
+ $this->maybe_prompt();
149
+ }
150
+
151
+ /**
152
+ * Check if the current WordPress version fits the requirements
153
+ *
154
+ * @since 1.0
155
+ * @return boolean
156
+ */
157
+ private function is_wp_compatible() {
158
+ if ( version_compare( get_bloginfo( 'version' ), $this->wordpress_version_required, '<' ) ) {
159
+ return false;
160
+ }
161
+
162
+ return true;
163
+ }
164
+
165
+ /**
166
+ * Check if the version of PHP is compatible with this library
167
+ *
168
+ * @since 1.0
169
+ * @return boolean
170
+ */
171
+ private function is_php_compatible() {
172
+ if ( version_compare( phpversion(), $this->php_version_required, '<' ) ) {
173
+ return false;
174
+ }
175
+
176
+ return true;
177
+ }
178
+
179
+ /**
180
+ * Spits an error message at the top of the admin screen
181
+ *
182
+ * @since 1.0
183
+ *
184
+ * @param string $error Error message to spit
185
+ *
186
+ * @return void
187
+ */
188
+ protected function spit_error( $error ) {
189
+ printf(
190
+ '<div style="margin: 20px; text-align: center;"><strong>%1$s</strong> %2$s</pre></div>',
191
+ esc_html__( 'WP Review Me Error:', 'wp-review-me' ),
192
+ wp_kses_post( $error )
193
+ );
194
+ }
195
+
196
+ /**
197
+ * Check if it is time to ask for a review
198
+ *
199
+ * @since 1.0
200
+ * @return bool
201
+ */
202
+ public function is_time() {
203
+ $installed = (int) get_option( $this->key, false );
204
+ if ( false == $installed ) {
205
+ $this->setup_date();
206
+ $installed = time();
207
+ }
208
+ if ( $installed + ( $this->days * 86400 ) > time() ) {
209
+ return false;
210
+ }
211
+
212
+ return true;
213
+ }
214
+
215
+ /**
216
+ * Save the current date as the installation date
217
+ *
218
+ * @since 1.0
219
+ * @return void
220
+ */
221
+ protected function setup_date() {
222
+ update_option( $this->key, time() );
223
+ }
224
+
225
+ /**
226
+ * Get the review link
227
+ *
228
+ * @since 1.0
229
+ * @return string
230
+ */
231
+ protected function get_review_link() {
232
+ $link = 'https://wordpress.org/support/';
233
+ switch ( $this->type ) {
234
+ case 'theme':
235
+ $link .= 'theme/';
236
+ break;
237
+ case 'plugin':
238
+ $link .= 'plugin/';
239
+ break;
240
+ }
241
+ $link .= $this->slug . '/reviews';
242
+ $link = add_query_arg( 'rate', $this->rating, $link );
243
+ $link = esc_url( $link . '#new-post' );
244
+
245
+ return $link;
246
+ }
247
+
248
+ /**
249
+ * Get the complete link tag
250
+ *
251
+ * @since 1.0
252
+ * @return string
253
+ */
254
+ protected function get_review_link_tag() {
255
+ $link = $this->get_review_link();
256
+
257
+ return "<a href='$link' target='_blank' id='$this->link_id'>$this->link_label</a>";
258
+ }
259
+
260
+ /**
261
+ * Trigger the notice if it is time to ask for a review
262
+ *
263
+ * @since 1.0
264
+ * @return void
265
+ */
266
+ protected function maybe_prompt() {
267
+ if ( ! $this->is_time() ) {
268
+ return;
269
+ }
270
+ dnh_register_notice( $this->key, 'updated', $this->get_message(), array(
271
+ 'scope' => $this->scope,
272
+ 'cap' => $this->cap
273
+ ) );
274
+ }
275
+
276
+ /**
277
+ * Echo the JS script in the admin footer
278
+ *
279
+ * @since 1.0
280
+ * @return void
281
+ */
282
+ public function script() { ?>
283
+
284
+ <script>
285
+ jQuery(document).ready(function ($) {
286
+ $('#<?php echo $this->link_id; ?>').on('click', wrmDismiss);
287
+
288
+ function wrmDismiss() {
289
+ var data = {
290
+ action: 'wrm_clicked_review',
291
+ id: '<?php echo $this->link_id; ?>'
292
+ };
293
+ jQuery.ajax({
294
+ type: 'POST',
295
+ url: ajaxurl,
296
+ data: data,
297
+ success: function (data) {
298
+ console.log(data);
299
+ }
300
+ });
301
+ }
302
+ });
303
+ </script>
304
+
305
+ <?php }
306
+
307
+ /**
308
+ * Dismiss the notice when the review link is clicked
309
+ *
310
+ * @since 1.0
311
+ * @return void
312
+ */
313
+ public function dismiss_notice() {
314
+ if ( empty( $_POST ) ) {
315
+ echo 'missing POST';
316
+ die();
317
+ }
318
+ if ( ! isset( $_POST['id'] ) ) {
319
+ echo 'missing ID';
320
+ die();
321
+ }
322
+ $id = sanitize_text_field( $_POST['id'] );
323
+ if ( $id !== $this->link_id ) {
324
+ echo "not this instance's job";
325
+ die();
326
+ }
327
+ // Get the DNH notice ID ready
328
+ $notice_id = DNH()->get_id( str_replace( 'wrm-review-link-', '', $id ) );
329
+ $dismissed = DNH()->dismiss_notice( $notice_id );
330
+
331
+ echo $dismissed;
332
+ /**
333
+ * Fires right after the notice has been dismissed. This allows for various integrations to perform additional tasks.
334
+ *
335
+ * @since 1.0
336
+ *
337
+ * @param string $id The notice ID
338
+ * @param string $notice_id The notice ID as defined by the DNH class
339
+ */
340
+ do_action( 'wrm_after_notice_dismissed', $id, $notice_id );
341
+ // Stop execution here
342
+ die();
343
+ }
344
+
345
+ /**
346
+ * Get the review prompt message
347
+ *
348
+ * @since 1.0
349
+ * @return string
350
+ */
351
+ protected function get_message() {
352
+ $message = $this->message;
353
+ $link = $this->get_review_link_tag();
354
+ $message = $message . ' ' . $link;
355
+
356
+ $reviews = '<br><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span>';
357
+
358
+ return wp_kses_post( $message ) . $reviews;
359
+ }
360
+ }
361
+ }
362
+
363
+ if( 'fr_FR' === get_locale() ) {
364
+ new WP_Review_Me(
365
+ array(
366
+ 'days_after' => 10,
367
+ 'type' => 'plugin',
368
+ 'slug' => 'wps-hide-login',
369
+ 'message' => 'Vous aimez l\'extension WPS Hide Login ?<br>Merci de prendre quelques secondes pour nous noter sur',
370
+ 'link_label' => 'WordPress.org'
371
+ )
372
+ );
373
+ } else {
374
+ new WP_Review_Me(
375
+ array(
376
+ 'days_after' => 10,
377
+ 'type' => 'plugin',
378
+ 'slug' => 'wps-hide-login',
379
+ 'message' => __( 'Do you like plugin WPS Hide Login? <br> Thank you for taking a few seconds to note us on', 'wps-hide-login' ),
380
+ 'link_label' => 'WordPress.org'
381
+ )
382
+ );
383
+ }
384
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: tabrisrp, WPServeur, nicolaskulka
4
  Tags: rename, login, wp-login, wp-login.php, custom login url
5
  Requires at least: 4.1
6
  Tested up to: 4.9
7
- Stable tag: 1.3.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -140,6 +140,10 @@ First step is to check your .htaccess file and compare it to a regular one, to s
140
 
141
  == Changelog ==
142
 
 
 
 
 
143
  = 1.3.3 =
144
  * Add : Filter hook for enable wp-signup (@sumobi)
145
 
4
  Tags: rename, login, wp-login, wp-login.php, custom login url
5
  Requires at least: 4.1
6
  Tested up to: 4.9
7
+ Stable tag: 1.3.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
140
 
141
  == Changelog ==
142
 
143
+ = 1.3.4 =
144
+ * Add : Review message
145
+ * Fix : Redirect url wp-admin/options.php
146
+
147
  = 1.3.3 =
148
  * Add : Filter hook for enable wp-signup (@sumobi)
149
 
wps-hide-login.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WPS Hide Login
4
  Description: Protect your website by changing the login URL and preventing access to wp-login.php page and wp-admin directory while not logged-in
5
  Author: WPServeur, NicolasKulka, tabrisrp
6
  Author URI: https://wpserveur.net
7
- Version: 1.3.3
8
  Requires at least: 4.1
9
  Tested up to: 4.9
10
  License: GPLv2 or later
@@ -17,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) {
17
  }
18
 
19
  // Plugin constants
20
- define( 'WPS_HIDE_LOGIN_VERSION', '1.3.3' );
21
  define( 'WPS_HIDE_LOGIN_FOLDER', 'wps-hide-login' );
22
 
23
  define( 'WPS_HIDE_LOGIN_URL', plugin_dir_url( __FILE__ ) );
@@ -36,6 +36,7 @@ function wps_hide_login_load_files( $dir, $files, $prefix = '' ) {
36
  // Plugin client classes
37
  wps_hide_login_load_files( WPS_HIDE_LOGIN_DIR . 'classes/', array(
38
  'plugin',
 
39
  ) );
40
 
41
  register_activation_hook( __FILE__, array( 'WPS_Hide_Login', 'activate' ) );
4
  Description: Protect your website by changing the login URL and preventing access to wp-login.php page and wp-admin directory while not logged-in
5
  Author: WPServeur, NicolasKulka, tabrisrp
6
  Author URI: https://wpserveur.net
7
+ Version: 1.3.4
8
  Requires at least: 4.1
9
  Tested up to: 4.9
10
  License: GPLv2 or later
17
  }
18
 
19
  // Plugin constants
20
+ define( 'WPS_HIDE_LOGIN_VERSION', '1.3.4' );
21
  define( 'WPS_HIDE_LOGIN_FOLDER', 'wps-hide-login' );
22
 
23
  define( 'WPS_HIDE_LOGIN_URL', plugin_dir_url( __FILE__ ) );
36
  // Plugin client classes
37
  wps_hide_login_load_files( WPS_HIDE_LOGIN_DIR . 'classes/', array(
38
  'plugin',
39
+ 'review',
40
  ) );
41
 
42
  register_activation_hook( __FILE__, array( 'WPS_Hide_Login', 'activate' ) );