PluginProbe
Passster – Password Protect Pages and Content / 4.3.16
Passster – Password Protect Pages and Content v4.3.16
4.3.16 4.3.15 4.3.14 4.3.12 4.3.13 4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 trunk 3.5.4 3.5.5.2 3.5.5.8 3.5.5.9 4.0 4.1.4 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.15 All 48 releases
← All changes | inc/class-ps-helper.php +48 -4 4.3.104.3.16 View file →
@@ -3,8 +3,43 @@
3 3 namespace passster;
4 4
5 5 use Exception;
6 6 class PS_Helper {
7 + public static function remember_unlock( string $proof ) {
8 + $options = get_option( 'passster', array() );
9 + if ( !empty( $options['disable_cookie'] ) ) {
10 + return;
11 + }
12 + $existing = array();
13 + if ( !empty( $_COOKIE['passster'] ) ) {
14 + $existing = array_filter( explode( '|', esc_html( wp_unslash( $_COOKIE['passster'] ) ) ) );
15 + }
16 + if ( in_array( $proof, $existing, true ) ) {
17 + return;
18 + }
19 + $existing[] = $proof;
20 + $unit = $options['cookie_duration_unit'] ?? 'days';
21 + $duration = (int) ($options['cookie_duration'] ?? 1);
22 + switch ( $unit ) {
23 + case 'hours':
24 + $expires = time() + $duration * HOUR_IN_SECONDS;
25 + break;
26 + case 'minutes':
27 + $expires = time() + $duration * MINUTE_IN_SECONDS;
28 + break;
29 + default:
30 + $expires = time() + $duration * DAY_IN_SECONDS;
31 + break;
32 + }
33 + setcookie( 'passster', implode( '|', $existing ), array(
34 + 'expires' => $expires,
35 + 'path' => '/',
36 + 'secure' => is_ssl(),
37 + 'httponly' => false,
38 + 'samesite' => 'Strict',
39 + ) );
40 + }
41 +
7 42 /**
8 43 * Get string between two strings.
9 44 *
10 45 * @param string $string string to find.
@@ -30,14 +65,23 @@
30 65 * @param string $content given content.
31 66 *
32 67 * @return string
33 68 */
34 - public static function get_shortcode_content( string $content, $password ) {
69 + public static function get_shortcode_content( string $content, $password, string $mode = 'password' ) {
70 + $string = '';
71 + if ( 'captcha' === $mode ) {
72 + return $string;
73 + $recaptcha_re = '/\\[passster[^\\]]*recaptcha="true"[^\\]]*\\]/';
74 + $turnstile_re = '/\\[passster[^\\]]*turnstile="true"[^\\]]*\\]/';
75 + if ( preg_match( $recaptcha_re, $content, $m ) ) {
76 + $string = self::get_string_between( $content, $m[0], '[/passster]' );
77 + } elseif ( preg_match( $turnstile_re, $content, $m ) ) {
78 + $string = self::get_string_between( $content, $m[0], '[/passster]' );
79 + }
80 + return $string;
81 + }
35 82 $password = preg_quote( (string) $password, '/' );
36 83 $pass_re = '/\\[passster[^\\]]*password="' . $password . '"[^\\]]*\\]/';
37 - $recaptcha_re = '/\\[passster[^\\]]*recaptcha="true"[^\\]]*\\]/';
38 - $turnstile_re = '/\\[passster[^\\]]*turnstile="true"[^\\]]*\\]/';
39 - $string = '';
40 84 if ( preg_match( $pass_re, $content, $m ) ) {
41 85 $string = self::get_string_between( $content, $m[0], '[/passster]' );
42 86 }
43 87 return $string;