PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Rules / Condition / Audience / Device.php

Device.php in Depicter — Popup & Slider Builder trunk, at app/src/Rules/Condition/Audience/Device.php

76 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Rules\Condition\Audience;
4
5 use Averta\Core\Utility\Arr;
6 use Depicter\Rules\Condition\Base as ConditionBase;
7
8 class Device extends ConditionBase
9 {
10 /**
11 * @inheritdoc
12 */
13 public $slug = 'Audience_Device';
14
15 /**
16 * @inheritdoc
17 */
18 public $control = 'multiSelect';
19
20 /**
21 * @inheritdoc
22 */
23 protected $belongsTo = 'Audience';
24
25 /**
26 * @inheritdoc
27 */
28 public function getLabel(): ?string{
29 return __('Visitor Device', 'depicter' );
30 }
31
32 /**
33 * @inheritDoc
34 */
35 public function getControlOptions(){
36 $options = parent::getControlOptions();
37
38 return Arr::merge( $options, [ 'options' => [
39 [
40 'label' => __( 'Desktop', 'depicter' ),
41 'value' => 'desktop'
42 ],
43 [
44 'label' => __( 'Mobile', 'depicter' ),
45 'value' => 'mobile'
46 ],
47 ]]);
48 }
49
50 /**
51 * @inheritdoc
52 */
53 public function check( $value = null ): bool{
54
55 $value = $value ?? $this->value;
56 $isIncluded = empty( $value );
57 if ( ! $isIncluded ) {
58 foreach( $value as $device ) {
59 if ( $device == 'mobile' ) {
60 $isIncluded = wp_is_mobile();
61 }
62
63 if ( $device == 'desktop' ) {
64 $isIncluded = ! wp_is_mobile();
65 }
66
67 if ( $isIncluded ) {
68 break;
69 }
70 }
71 }
72
73 return $this->selectionMode === 'include' ? $isIncluded : ! $isIncluded;
74 }
75 }
76