PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.6
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.6
1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 1.3.45 1.3.44 All 176 releases
disco / engine / Context.php

Context.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.6, at engine/Context.php

100 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Disco
5 *
6 * @package Disco
7 * @author Ohidul Islam <wahid0003@gmail.com>
8 * @copyright 2022 WebAppick
9 * @license GPL 2.0+
10 * @link http://domain.tld
11 */
12
13 namespace Disco\Engine;
14
15 use Inpsyde\WpContext;
16
17 /**
18 * Disco Is Methods
19 */
20 class Context {
21
22 /**
23 * WpContext Class
24 *
25 * @var object
26 */
27 public $context = null;
28
29 /**
30 * What type of request is this?
31 *
32 * @since 1.0.0
33 * @param string $type admin, ajax, cron, cli, amp or frontend.
34 * @return bool
35 * @SuppressWarnings("StaticAccess")
36 */
37 public function request( string $type ) {
38 $this->context = WpContext::determine();
39
40 switch ( $type ) {
41 case 'backend':
42 return $this->context->isBackoffice();
43
44 case 'ajax':
45 return $this->context->isAjax();
46
47 case 'installing_wp':
48 return $this->context->isInstalling();
49
50 case 'rest':
51 return $this->context->isRest();
52
53 // case 'cron':
54 // return $this->context->isCron();
55
56 case 'frontend':
57 return $this->context->isFrontoffice();
58
59 // case 'cli':
60 // return $this->context->isWpCli();
61
62 case 'amp':
63 return $this->is_amp();
64
65 default:
66 \_doing_it_wrong( __METHOD__, \esc_html( \sprintf( 'Unknown request type: %s', $type ) ), '1.0.0' );
67
68 return false;
69 }//end switch
70 }
71
72 /**
73 * Is AMP
74 *
75 * @return bool
76 */
77 public function is_amp() {
78 return \function_exists( 'is_amp_endpoint' ) && \is_amp_endpoint();
79 }
80
81 /**
82 * Whether given user is an administrator.
83 *
84 * @param \WP_User|null $user The given user.
85 * @return bool
86 */
87 public static function is_user_admin( \WP_User $user = null ) { // phpcs:ignore
88 if ( \is_null( $user ) ) {
89 $user = \wp_get_current_user();
90 }
91
92 if ( ! $user instanceof \WP_User ) {
93 \_doing_it_wrong( __METHOD__, 'To check if the user is admin is required a WP_User object.', '1.0.0' );
94 }
95
96 return \is_multisite() ? \user_can( $user, 'manage_network' ) : \user_can( $user, 'manage_options' ); // phpcs:ignore
97 }
98
99 }
100