Skip to content

Commit

Permalink
Restructure using guard conditionals for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Daniel Deepak committed Sep 12, 2017
1 parent eb02c84 commit f4fb219
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions include/Util/helper.php
Expand Up @@ -82,24 +82,24 @@ function get_log_columns_to_export() {
* @return bool
*/
function can_current_user_view_email_log() {
$return_value = false;
$option = get_option( 'el_email_log_core' );

if ( current_user_can( 'administrator' ) ) {
$return_value = true;
} elseif ( ! is_admin() && ! current_user_can( 'administrator' ) ) {
if ( $option && is_array( $option ) && array_key_exists( 'allowed_user_roles', $option ) ) {
$user = wp_get_current_user();
$allowed_user_roles = $option['allowed_user_roles'];
$allowed_user_roles = array_map( 'strtolower', $allowed_user_roles );
$matched_role = array_intersect( (array) $user->roles, $allowed_user_roles );
if ( is_array( $matched_role ) && ! empty( $matched_role ) ) {
$return_value = true;
}
}
return true;
}

$user = wp_get_current_user();
$allowed_user_roles = $option['allowed_user_roles'];
$allowed_user_roles = array_map( 'strtolower', $allowed_user_roles );
$matched_role = array_intersect( (array) $user->roles, $allowed_user_roles );

if ( is_array( $option ) &&
array_key_exists( 'allowed_user_roles', $option ) &&
is_array( $matched_role ) && ! empty( $matched_role ) ) {
return true;
}

return $return_value;
return false;
}

/**
Expand Down

0 comments on commit f4fb219

Please sign in to comment.