Skip to content

Commit

Permalink
Ensure comments are disabled on CPT page also
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsanford committed Oct 29, 2018
1 parent c3f5692 commit 29d145f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Expand Up @@ -75,29 +75,16 @@ public function handle_request() {
add_filter( 'the_content', array( $this, 'cpt_page_content_filter' ) );
add_filter( 'template_include', array( $this, 'force_page_template' ) );

// Disable comments.
Sensei_Unsupported_Theme_Handler_Utils::disable_comments();

// Handle some type-specific items.
if ( 'sensei_message' === $this->post_type ) {
// Hide the message title until `the_content` is displayed.
$this->add_filter_hide_the_title();
}
}

/**
* Disable rendering of comments.
*/
public function disable_comments() {
add_filter( 'comments_open', '__return_false', 100 );
add_filter( 'get_comments_number', '__return_false', 100 );
}

/**
* If we have previously disabled comments, re-enable them.
*/
public function reenable_comments() {
remove_filter( 'comments_open', '__return_false', 100 );
remove_filter( 'get_comments_number', '__return_false', 100 );
}

/**
* Filter the content and insert Sensei CPT content.
*
Expand All @@ -119,13 +106,13 @@ public function cpt_page_content_filter( $content ) {
$this->remove_filter_hide_the_title();

// Temporarily re-enable comments.
$this->reenable_comments();
Sensei_Unsupported_Theme_Handler_Utils::reenable_comments();

$renderer = $this->get_renderer();
$content = $renderer->render();

// Disable comments again.
$this->disable_comments();
// Disable theme comments.
Sensei_Unsupported_Theme_Handler_Utils::disable_comments();

// Disable pagination.
Sensei_Unsupported_Theme_Handler_Utils::disable_theme_pagination();
Expand Down
Expand Up @@ -80,9 +80,7 @@ protected function output_content_as_page( $content, $object_to_copy = null, $po
$wp_query->is_archive = false;
$wp_query->max_num_pages = 0;

add_filter( 'comments_template_query_args', array( $this, 'filter_comment_args_load_none' ), 100 );
add_filter( 'comments_open', '__return_false', 100 );
add_filter( 'get_comments_number', '__return_false', 100 );
Sensei_Unsupported_Theme_Handler_Utils::disable_comments();

$this->prepare_wp_query( $wp_query, $object_to_copy, $post_params );

Expand Down
Expand Up @@ -22,4 +22,22 @@ public static function disable_theme_pagination() {
add_filter( 'next_post_link', '__return_false' );
}

/**
* Disable rendering of comments.
*/
public static function disable_comments() {
add_filter( 'comments_template_query_args', array( 'Sensei_Unsupported_Theme_Handler_Utils', 'filter_comment_args_load_none' ), 100 );
add_filter( 'comments_open', '__return_false', 100 );
add_filter( 'get_comments_number', '__return_false', 100 );
}

/**
* If we have previously disabled comments, re-enable them.
*/
public static function reenable_comments() {
remove_filter( 'comments_template_query_args', array( 'Sensei_Unsupported_Theme_Handler_Utils', 'filter_comment_args_load_none' ), 100 );
remove_filter( 'comments_open', '__return_false', 100 );
remove_filter( 'get_comments_number', '__return_false', 100 );
}

}

0 comments on commit 29d145f

Please sign in to comment.