Skip to content

Instantly share code, notes, and snippets.

@christianwach
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianwach/c9d69b8b783e21e8bba6 to your computer and use it in GitHub Desktop.
Save christianwach/c9d69b8b783e21e8bba6 to your computer and use it in GitHub Desktop.
Hide CommentPress Comments
<?php
/*
Plugin Name: Hide CommentPress Comments
Description: Hides comments and comment form from users who are not logged in
Author: Christian Wach
Version: 1.0
*/
add_filter( 'commentpress_reply_to_para_link_text', 'my_override_reply_to_text', 10, 2 );
function my_override_reply_to_text( $link_text, $paragraph_text ) {
if ( ! is_user_logged_in() ) {
$link_text = 'Create an account to view and leave comments';
}
return $link_text;
}
add_filter( 'commentpress_reply_to_para_link_href', 'my_override_reply_to_href', 10, 1 );
function my_override_reply_to_href( $href ) {
if ( ! is_user_logged_in() ) {
$href = '/your-login-page-url';
}
return $href;
}
add_filter( 'commentpress_reply_to_para_link_onclick', 'my_override_reply_to_onclick', 10, 1 );
function my_override_reply_to_onclick( $onclick ) {
if ( ! is_user_logged_in() ) {
$onclick = '';
}
return $onclick;
}
add_filter( 'wp_list_comments_args', 'my_wp_list_comments_args', 10, 1 );
function my_wp_list_comments_args( $r ) {
if ( ! is_user_logged_in() ) {
$r['echo'] = false;
}
return $r;
}
add_filter( 'commentpress_show_comment_form', 'my_show_comment_form', 10, 1 );
function my_show_comment_form( $show ) {
if ( ! is_user_logged_in() ) {
$show = false;
}
return $show;
}
add_filter( 'cp_override_tinymce', 'my_disable_tinymce', 10, 1 );
function my_disable_tinymce( $tinymce ) {
if ( ! is_user_logged_in() ) {
$tinymce = 0;
}
return $tinymce;
}
add_action( 'pre_get_comments', 'my_filter_comments', 10, 1 );
function my_filter_comments( $comments ) {
if ( ! is_user_logged_in() ) {
// filter comments by an impossible user ID
$comments->query_vars['user_id'] = -1;
}
return $comments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment