From 9b7cac4f507a4cdc29faffdccdfbd82a47cd912c Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Mon, 5 Feb 2018 11:25:47 +0200 Subject: [PATCH] - fixed content restriction for some themes, which make the_content filter; --- includes/core/class-access.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 8f2701b0..278c8af2 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -28,6 +28,12 @@ if ( ! class_exists( 'Access' ) ) { private $allow_access; + /** + * @var \WP_Post + */ + private $current_single_post; + + /** * Access constructor. */ @@ -35,7 +41,6 @@ if ( ! class_exists( 'Access' ) ) { $this->singular_page = false; - $this->redirect_handler = false; $this->allow_access = false; @@ -592,13 +597,19 @@ if ( ! class_exists( 'Access' ) ) { if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) { $post->post_content = stripslashes( $restricted_global_message ); + $this->current_single_post = $post; + add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 ); + if ( 'attachment' == $post->post_type ) { remove_filter( 'the_content', 'prepend_attachment' ); } } elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) { $post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : ''; - if ( 'attachment' == $post->post_type ) { + $this->current_single_post = $post; + add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 ); + + if ( 'attachment' == $post->post_type ) { remove_filter( 'the_content', 'prepend_attachment' ); } } @@ -694,6 +705,18 @@ if ( ! class_exists( 'Access' ) ) { } + /** + * @param $content + * + * @return string + */ + function replace_post_content( $content ) { + $content = $this->current_single_post->post_content; + + return $content; + } + + /** * Protect Post Types in menu query * Restrict content new logic