protected function currentUserCan(array $notice): bool
    {
        $WP_User = wp_get_current_user();
        $notice  = $this->normalize($notice);

        if ($notice['for_user_id'] && (int) $WP_User->ID !== $notice['for_user_id']) {
            return false; // Not for current user.
        } // ↓ Everything else is related to CAP checks.

        if (!$notice['requires_cap']) {
            return true; // No CAP requirements.
        } elseif (!$WP_User->exists()) { // Not logged in?
            return false; // Not possible to satisfy anything.
        }
        if (mb_strpos($notice['requires_cap'], '&') !== false) {
            $all_required_caps = preg_split('/[&\s]+/u', $notice['requires_cap'], -1, PREG_SPLIT_NO_EMPTY);
            // e.g., `edit_posts & manage_options`. NOTE: Do not mix `&|` logic.
            // A double `&&` is also OK to use here; e.g., `edit_posts && manage_options`.

            foreach ($all_required_caps as $_cap) {
                if (!$WP_User->has_cap($_cap)) {
                    return false; // i.e., AND logic.
                }
            } // unset($_cap); // Just a little housekeeping.
            return true; // Able to satisfy all if we get here.
            //
        } else { // Default is OR logic; i.e., if any are true.
            $any_required_caps = preg_split('/[|\s]+/u', $notice['requires_cap'], -1, PREG_SPLIT_NO_EMPTY);
            // e.g., `edit_posts|manage_options`. NOTE: Do not mix `&|` logic.
            // A double `||` is also OK to use here; e.g., `edit_posts || manage_options`.

            foreach ($any_required_caps as $_cap) {
                if ($WP_User->has_cap($_cap)) {
                    return true; // i.e., OR logic.
                }
            } // unset($_cap); // Just a little housekeeping.
            return false; // Unable to satisfy any if we get here.
        }
    }
protected function currentUserCan(array $notice): bool
    {
        $WP_User = wp_get_current_user();
        $notice  = $this->normalize($notice);

        if ($notice['for_user_id'] && (int) $WP_User->ID !== $notice['for_user_id']) {
            return false; // Not for current user.
        } // ↓ Everything else is related to CAP checks.

        if (!$notice['requires_cap']) {
            return true; // No CAP requirements.
        } elseif (!$WP_User->exists()) { // Not logged in?
            return false; // Not possible to satisfy anything.
        }
        if (mb_strpos($notice['requires_cap'], '&') !== false) {
            $all_required_caps = preg_split('/[&\s]+/u', $notice['requires_cap'], -1, PREG_SPLIT_NO_EMPTY);
            // e.g., `edit_posts & manage_options`. NOTE: Do not mix `&|` logic.
            // A double `&&` is also OK to use here; e.g., `edit_posts && manage_options`.

            foreach ($all_required_caps as $_cap) {
                if (!$WP_User->has_cap($_cap)) {
                    return false; // i.e., AND logic.
                }
            } // unset($_cap); // Just a little housekeeping.
            return true; // Able to satisfy all if we get here.
            //
        } else { // Default is OR logic; i.e., if any are true.
            $any_required_caps = preg_split('/[|\s]+/u', $notice['requires_cap'], -1, PREG_SPLIT_NO_EMPTY);
            // e.g., `edit_posts|manage_options`. NOTE: Do not mix `&|` logic.
            // A double `||` is also OK to use here; e.g., `edit_posts || manage_options`.

            foreach ($any_required_caps as $_cap) {
                if ($WP_User->has_cap($_cap)) {
                    return true; // i.e., OR logic.
                }
            } // unset($_cap); // Just a little housekeeping.
            return false; // Unable to satisfy any if we get here.
        }
    }
protected function currentUserCan ( array $ notice ) : bool { $ WP_User = wp_get_current_user ( ) ; $ notice = $ this -> normalize ( $ notice ) ; if ( $ notice [ 'for_user_id' ] && ( int ) $ WP_User -> ID !== $ notice [ 'for_user_id' ] ) { return false ; // Not for current user. } // ↓ Everything else is related to CAP checks. if ( ! $ notice [ 'requires_cap' ] ) { return true ; // No CAP requirements. } elseif ( ! $ WP_User -> exists ( ) ) { // Not logged in? return false ; // Not possible to satisfy anything. } if ( mb_strpos ( $ notice [ 'requires_cap' ] , '&' ) !== false ) { $ all_required_caps = preg_split ( '/[&\s]+/u' , $ notice [ 'requires_cap' ] , - 1 , PREG_SPLIT_NO_EMPTY ) ; // e.g., `edit_posts & manage_options`. NOTE: Do not mix `&|` logic. // A double `&&` is also OK to use here; e.g., `edit_posts && manage_options`. foreach ( $ all_required_caps as $ _cap ) { if ( ! $ WP_User -> has_cap ( $ _cap ) ) { return false ; // i.e., AND logic. } } // unset($_cap); // Just a little housekeeping. return true ; // Able to satisfy all if we get here. // } else { // Default is OR logic; i.e., if any are true. $ any_required_caps = preg_split ( '/[|\s]+/u' , $ notice [ 'requires_cap' ] , - 1 , PREG_SPLIT_NO_EMPTY ) ; // e.g., `edit_posts|manage_options`. NOTE: Do not mix `&|` logic. // A double `||` is also OK to use here; e.g., `edit_posts || manage_options`. foreach ( $ any_required_caps as $ _cap ) { if ( $ WP_User -> has_cap ( $ _cap ) ) { return true ; // i.e., OR logic. } } // unset($_cap); // Just a little housekeeping. return false ; // Unable to satisfy any if we get here. } }
Current user can?

@since 160524 First documented version.

@param array $notice Input notice.

@return bool True if current user can.
Current user can?