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-public.php +33 -11 4.3.54.3.16 View file →
@@ -28,9 +28,9 @@
28 28 add_filter( 'the_content', array($this, 'filter_the_content') );
29 29 add_filter( 'acf_the_content', array($this, 'filter_the_content') );
30 30 add_filter( 'get_the_excerpt', array($this, 'filter_the_content') );
31 31 add_action( 'template_redirect', array($this, 'check_global_proctection') );
32 - add_action( 'wp_enqueue_scripts', array($this, 'add_public_scripts') );
32 + add_action( 'wp_enqueue_scripts', array($this, 'add_public_scripts'), 9999 );
33 33 }
34 34
35 35 /**
36 36 * Returns instance of PS_Public.
@@ -44,8 +44,22 @@
44 44 return self::$instance;
45 45 }
46 46
47 47 /**
48 + * Avoids re-entering the_content recursively.
49 + *
50 + * @param string $content the unlocked content.
51 + *
52 + * @return string
53 + */
54 + private function render_unlocked_content( string $content ) : string {
55 + if ( doing_filter( 'the_content' ) ) {
56 + return wpautop( do_shortcode( $content ) );
57 + }
58 + return apply_filters( 'the_content', $content );
59 + }
60 +
61 + /**
48 62 * Render the Passster shortcode.
49 63 *
50 64 * @param array $atts array of attributes.
51 65 * @param string|null $content the current content.
@@ -70,9 +84,9 @@
70 84 }
71 85 if ( !$in_schedule ) {
72 86 $area = get_post( $area_id );
73 87 if ( $area && ('publish' === $area->post_status || current_user_can( 'edit_post', $area_id )) ) {
74 - return apply_filters( 'the_content', str_replace( '{post-id}', get_the_id(), $area->post_content ) );
88 + return $this->render_unlocked_content( str_replace( '{post-id}', get_the_id(), $area->post_content ) );
75 89 }
76 90 return $content ?? '';
77 91 }
78 92 }
@@ -86,12 +100,12 @@
86 100 $area = get_post( $area_id );
87 101 if ( 'publish' === $area->post_status || current_user_can( 'edit_post', $area_id ) ) {
88 102 $content = $area->post_content;
89 103 do_action( 'passster_content_unlocked' );
90 - return apply_filters( 'the_content', str_replace( '{post-id}', get_the_id(), $content ) );
104 + return $this->render_unlocked_content( str_replace( '{post-id}', get_the_id(), $content ) );
91 105 }
92 106 } else {
93 - $content = apply_filters( 'the_content', $content );
107 + $content = $this->render_unlocked_content( $content );
94 108 do_action( 'passster_content_unlocked' );
95 109 return apply_filters( 'passster_content', $content );
96 110 }
97 111 }
@@ -178,8 +192,11 @@
178 192 $form = str_replace( '[PASSSTER_POST_ID]', absint( get_the_ID() ), $form );
179 193 // term id (for category archive protection — passed to REST API so it can validate against term meta).
180 194 $term_id_val = ( !empty( $atts['term_id'] ) ? absint( $atts['term_id'] ) : 0 );
181 195 $form = str_replace( '[PASSSTER_TERM_ID]', $term_id_val, $form );
196 + // post type (for post type archive protection — passed to REST API so it can validate against post type config).
197 + $post_type_val = ( !empty( $atts['post_type'] ) ? sanitize_key( $atts['post_type'] ) : '' );
198 + $form = str_replace( '[PASSSTER_POST_TYPE]', esc_attr( $post_type_val ), $form );
182 199 // hide or not.
183 200 if ( !empty( $atts['hide'] ) ) {
184 201 $form = str_replace( '[PASSSTER_HIDE]', ' passster-hide', $form );
185 202 } else {
@@ -228,12 +245,13 @@
228 245 $user_restriction = get_post_meta( $post_id, 'passster_user_restriction', true );
229 246 // Redirection.
230 247 $redirection = get_post_meta( $post_id, 'passster_redirect_url', true );
231 248 // texts.
232 - $headline = get_post_meta( $post_id, 'passster_headline', true );
233 - $instruction = get_post_meta( $post_id, 'passster_instruction', true );
234 - $placeholder = get_post_meta( $post_id, 'passster_placeholder', true );
235 - $button = get_post_meta( $post_id, 'passster_button', true );
249 + $overwrite_defaults = get_post_meta( $post_id, 'passster_activate_overwrite_defaults', true );
250 + $headline = ( $overwrite_defaults ? get_post_meta( $post_id, 'passster_headline', true ) : '' );
251 + $instruction = ( $overwrite_defaults ? get_post_meta( $post_id, 'passster_instruction', true ) : '' );
252 + $placeholder = ( $overwrite_defaults ? get_post_meta( $post_id, 'passster_placeholder', true ) : '' );
253 + $button = ( $overwrite_defaults ? get_post_meta( $post_id, 'passster_button', true ) : '' );
236 254 $id = get_post_meta( $post_id, 'passster_id', true );
237 255 if ( !$activate_protection ) {
238 256 return $content;
239 257 }
@@ -309,9 +327,9 @@
309 327 $post_id = esc_html( $options['global_protection_id'] );
310 328 $is_active = esc_html( $options['activate_global_protection'] );
311 329 $atts = array();
312 330 $password = get_post_meta( $post_id, 'passster_password', true );
313 - $atts['password'] = esc_html( $password );
331 + $atts['password'] = $password;
314 332 if ( !empty( $post_id ) ) {
315 333 if ( $is_active ) {
316 334 if ( is_page( $post_id ) || is_single( $post_id ) ) {
317 335 return;
@@ -379,8 +397,12 @@
379 397 $shortcodes[$shortcode] = do_shortcode( str_replace( '{post-id}', get_the_id(), $shortcode ) );
380 398 }
381 399 }
382 400 }
401 + // Archive/taxonomy pages have no singular post, so get_permalink() can't be used
402 + // to build the "reload after unlock" URL for links generated by area/CPT-level protection.
403 + $current_post_id = get_the_id();
404 + $reload_url = ( $current_post_id ? get_permalink( $current_post_id ) : esc_url_raw( remove_query_arg( 'pass' ) ) );
383 405 $args = array(
384 406 'ajax_url' => admin_url() . 'admin-ajax.php',
385 407 'rest_url' => get_rest_url(),
386 408 'nonce' => wp_create_nonce( 'ps-password-nonce' ),
@@ -385,11 +407,11 @@
385 407 'rest_url' => get_rest_url(),
386 408 'nonce' => wp_create_nonce( 'ps-password-nonce' ),
387 409 'hash_nonce' => wp_create_nonce( 'ps-hash-nonce' ),
388 410 'logout_nonce' => wp_create_nonce( 'ps-logout-nonce' ),
389 - 'post_id' => get_the_id(),
411 + 'post_id' => $current_post_id,
390 412 'shortcodes' => $shortcodes,
391 - 'permalink' => get_permalink( get_the_id() ),
413 + 'permalink' => $reload_url,
392 414 );
393 415 if ( isset( $options['cookie_duration_unit'] ) ) {
394 416 $args['cookie_duration_unit'] = esc_html( $options['cookie_duration_unit'] );
395 417 } else {