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 / WordPress / StaticPage.php

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

112 lines 2.2 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\WordPress;
4
5 use Averta\Core\Utility\Arr;
6 use Depicter\Rules\Condition\Base as ConditionBase;
7
8 class StaticPage extends ConditionBase
9 {
10 /**
11 * @inheritdoc
12 */
13 public $slug = 'WordPress_StaticPage';
14
15 /**
16 * @inheritdoc
17 */
18 public $control = 'multiSelect';
19
20 /**
21 * @inheritdoc
22 */
23 protected $belongsTo = 'WordPress';
24
25 /**
26 * Tier of this condition
27 *
28 * @var string
29 */
30 protected $tier = 'free-user';
31
32 /**
33 * @inheritdoc
34 */
35 public function getLabel(): ?string{
36 return __('WP Static Pages', 'depicter' );
37 }
38
39 /**
40 * @inheritDoc
41 */
42 public function getControlOptions(){
43 $options = parent::getControlOptions();
44
45 return Arr::merge( $options, [ 'options' => [
46 [
47 'label' => __( 'Home Page', 'depicter' ),
48 'value' => 'is_home'
49 ],
50 [
51 'label' => __( '404 Page', 'depicter' ),
52 'value' => 'is_404'
53 ],
54 [
55 'label' => __( 'Search Page', 'depicter' ),
56 'value' => 'is_search'
57 ],
58 [
59 'label' => __( 'Blog Page', 'depicter' ),
60 'value' => 'is_blog'
61 ],
62 [
63 'label' => __( 'Privacy Policy page', 'depicter' ),
64 'value' => 'is_privacy_policy'
65 ]
66 ]]);
67 }
68
69 /**
70 * @inheritdoc
71 */
72 public function check( $value = null ): bool{
73 $isIncluded = false;
74
75 $value = $value ?? $this->value ?? $this->defaultValue;
76
77 if( !empty( $value ) && is_array( $value ) ){
78 foreach( $value as $page ){
79 if( $page == 'all' ){
80 $isIncluded = is_home() || is_404() || is_search() || $this->is_blog() || is_privacy_policy();
81 } elseif( $page == 'is_home' ) {
82 $isIncluded = is_front_page();
83 } elseif( $page == 'is_404' ) {
84 $isIncluded = is_404();
85 } elseif( $page == 'is_search' ) {
86 $isIncluded = is_search();
87 } elseif( $page == 'is_blog' ) {
88 $isIncluded = $this->is_blog();
89 } elseif( $page == 'is_privacy_policy' ) {
90 $isIncluded = is_privacy_policy();
91 }
92
93 if( $isIncluded ){
94 break;
95 }
96 }
97
98 }
99
100 return $this->selectionMode === 'include' ? $isIncluded : ! $isIncluded;
101 }
102
103 /**
104 * Check if page is blog or not
105 *
106 * @return bool
107 */
108 public function is_blog(): bool{
109 return ( is_archive() || is_author() || is_category() || is_tag() || is_home() ) && 'post' == get_post_type();
110 }
111 }
112