Created
October 4, 2018 19:15
-
-
Save BurlesonBrad/1503f55b1c999621849e930ce862c73e to your computer and use it in GitHub Desktop.
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
function ap_user_can_read_comments( $_post = null, $user_id = false ) { | |
$_post = ap_get_post( $_post ); | |
// Get current user if no user_id supplied | |
if ( false === $user_id ) { | |
$user_id = get_current_user_id(); | |
} | |
// All support admins get the green light | |
if ( is_super_admin( $user_id ) ) { | |
return true; | |
} | |
/** | |
* Filter to hijack ap_user_can_read_comments. | |
* | |
* @param boolean|string $apply_filter Apply current filter, empty string by default. | |
* @param object $_post Post ID or object. | |
* @param integer $user_id User ID. | |
* @since 4.1.0 | |
*/ | |
$filter = apply_filters( 'ap_user_can_read_comments', '', $_post, $user_id ); | |
if(is_bool($filter)){ | |
return $filter; | |
} | |
// If user cannot read post then return from here. | |
if ( ! ap_user_can_read_post( $_post, $user_id ) ) { | |
return false; | |
} | |
try { | |
switch (strtolower(trim(ap_opt('read_comment_per')))) { | |
case 'have_cap': | |
if ($user = get_user_by('ID', $user_id)) { | |
return $user->has_cap('ap_read_comment'); | |
} | |
break; | |
case 'logged_in': | |
return is_user_logged_in(); | |
break; | |
case 'anyone': | |
return true; | |
break; | |
} | |
}catch (Exception $ex){ | |
// Can do some logging here without throwing a 500 Error | |
} | |
// Let's default this | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment