Skip to content

Instantly share code, notes, and snippets.

@2ndkauboy
Last active March 13, 2021 23:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 2ndkauboy/2427afd4368dcbb2a06c1e7afcd34134 to your computer and use it in GitHub Desktop.
Show comments from private posts in the comments widget
<?php
/**
* Comments of private posts
*
* @package copp
* @author Bernhard Kau
* @license GPLv3
*
* @wordpress-plugin
* Plugin Name: Comments of private posts
* Plugin URI: https://gist.github.com/2ndkauboy/2427afd4368dcbb2a06c1e7afcd34134
* Description: Show comments from private posts in the comments widget
* Version: 1.0.0
* Author: Bernhard Kau
* Author URI: https://kau-boys.de
* Text Domain: comments-of-private-posts
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*/
/**
* Show comments from private posts in the comments widget
*
* @param array $args The comments widget query args.
*
* @return array
*/
function comments_of_private_posts( $args ) {
if ( current_user_can( 'read_private_posts' ) ) {
if ( ! is_array( $args['post_status'] ) ) {
$args['post_status'] = array( $args['post_status'] );
}
$args['post_status'][] = 'private';
}
return $args;
}
add_filter( 'widget_comments_args', 'comments_of_private_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment