Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Permissions
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 rest_is_authorized_admin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 rest_is_authorized_shop_manager
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace NewfoldLabs\WP\Module\ECommerce;
4
5/**
6 * Permissions and Authorization constants and utilities.
7 */
8final class Permissions {
9
10    /**
11     * WordPress Admin capability string
12     */
13    const ADMIN = 'manage_options';
14
15    /**
16     * WooCommerce Shop Manager capability string
17     */
18    const SHOP_MANAGER = 'manage_woocommerce';
19
20    /**
21     * Confirm REST API caller has ADMIN user capabilities.
22     *
23     * @return boolean
24     */
25    public static function rest_is_authorized_admin() {
26        return \is_user_logged_in() && \current_user_can( self::ADMIN );
27    }
28
29    /**
30     * Confirm REST API caller has ADMIN user capabilities.
31     *
32     * @return boolean
33     */
34    public static function rest_is_authorized_shop_manager() {
35        return \is_user_logged_in() && \current_user_can( self::SHOP_MANAGER );
36    }
37}