Last active
March 13, 2021 23:50
-
-
Save 2ndkauboy/2427afd4368dcbb2a06c1e7afcd34134 to your computer and use it in GitHub Desktop.
Show comments from private posts in the comments widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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