2
2
3
3
namespace Poppy \Controllers \Client ;
4
4
5
+ use Poppy \Utils \Helpers ;
6
+
5
7
class Enqueue
6
8
{
7
9
private static $ class = null ;
@@ -19,7 +21,7 @@ public static function enqueue_scripts()
19
21
20
22
wp_register_script (
21
23
'poppy ' ,
22
- \ Poppy \ URI . $ path ,
24
+ Helpers:: env_check ( $ path) ,
23
25
null ,
24
26
false ,
25
27
true
@@ -38,77 +40,118 @@ public static function enqueue_scripts()
38
40
39
41
public static function enqueue_styles ()
40
42
{
43
+ if (is_admin ()) {
44
+ return false ;
45
+ }
46
+
41
47
$ path = 'dist/styles/poppy.css ' ;
42
48
43
49
wp_enqueue_style (
44
50
'poppy ' ,
45
- \ Poppy \ URI . $ path
51
+ Helpers:: env_check ( $ path)
46
52
);
47
53
}
48
54
49
- private function get_popup_data ($ popup ) {
50
- $ meta = get_post_meta ( $ popup -> ID );
51
- // var_dump($meta );
55
+ private function get_popup_data ($ popup )
56
+ {
57
+ $ fields = get_fields ( $ popup -> ID );
52
58
53
59
return [
54
60
'title ' => $ popup ->post_title ,
55
61
'slug ' => $ popup ->post_name ,
56
62
57
63
// Appearance
58
- 'alignment ' => array_key_exists ('alignment ' , $ meta ) ? $ meta ['alignment ' ] : 'center ' ,
59
- 'position ' => array_key_exists ('position ' , $ meta ) ? $ meta ['position ' ] : 'center ' ,
60
- 'size ' => array_key_exists ('size ' , $ meta ) ? $ meta ['size ' ] : 'narrow ' ,
61
- 'docked ' => array_key_exists ('alignment ' , $ meta ) ? $ meta ['docked ' ] : false ,
62
- 'peek ' => array_key_exists ('peek ' , $ meta ) ? $ meta ['peek ' ] : true ,
63
- 'peek_message ' => array_key_exists ('peek_message ' , $ meta ) ? $ meta ['peek_message ' ] : 'Hola ' ,
64
+ 'alignment ' => array_key_exists ('alignment ' , $ fields ) ? $ fields ['alignment ' ] : 'center ' ,
65
+ 'position ' => array_key_exists ('position ' , $ fields ) ? $ fields ['position ' ] : 'center ' ,
66
+ 'size ' => array_key_exists ('size ' , $ fields ) ? $ fields ['size ' ] : 'narrow ' ,
67
+ 'docked ' => array_key_exists ('alignment ' , $ fields ) ? $ fields ['docked ' ] : false ,
68
+ 'peek ' => array_key_exists ('peek ' , $ fields ) ? $ fields ['peek ' ] : true ,
69
+ 'peek_message ' => array_key_exists ('peek_message ' , $ fields ) ? $ fields ['peek_message ' ] : '' ,
64
70
65
71
// Actions
66
- 'actions ' => [
67
- [
68
- 'label ' => 'More ' ,
69
- 'action ' => 'more ' ,
70
- 'url ' => 'https://www.google.com ' ,
71
- 'target ' => '_blank ' ,
72
- ],
73
- [
74
- 'label ' => 'Decline ' ,
75
- 'action ' => 'decline '
76
- ],
77
- [
78
- 'label ' => 'Accept ' ,
79
- 'action ' => 'accept '
80
- ]
81
- ],
72
+ 'actions ' => self ::get_actions ($ fields ),
82
73
83
74
// Trigger
84
- 'trigger ' => [
85
- 'type ' => 'load ' ,
86
- ],
87
-
88
- // Rewrite using slug
89
- 'cookie ' => [
90
- 'name ' => 'testing-cookie ' ,
91
- 'expires ' => '' ,
92
- ],
75
+ 'trigger ' => self ::get_trigger ($ fields ),
93
76
94
77
// content
95
78
'content ' => apply_filters ('the_content ' , $ popup ->post_content )
96
79
];
97
80
}
98
81
99
- private function get_popups () {
82
+ private function get_popups ()
83
+ {
84
+ global $ post ;
85
+
100
86
$ popups_query_args = [
101
87
'post_type ' => 'poppy ' ,
102
88
'post_status ' => 'publish ' ,
89
+ 'meta_query ' => [
90
+ 'relation ' => 'OR ' ,
91
+ [
92
+ 'key ' => 'pages ' ,
93
+ 'value ' => '" ' . $ post ->ID . '" ' ,
94
+ 'compare ' => 'LIKE '
95
+ ],
96
+ [
97
+ 'key ' => 'all_pages ' ,
98
+ 'value ' => '1 ' ,
99
+ ]
100
+ ]
103
101
];
104
102
$ popups_query = new \WP_Query ($ popups_query_args );
105
- $ _popups = array_map (
103
+ $ popups = array_map (
106
104
[self ::$ class , 'get_popup_data ' ],
107
105
$ popups_query ->posts
108
106
);
109
107
110
108
return [
111
- 'popups ' => $ _popups ,
109
+ 'popups ' => $ popups ,
110
+ ];
111
+ }
112
+
113
+ private function get_actions ($ fields )
114
+ {
115
+ $ actions = [
116
+ [
117
+ 'label ' => array_key_exists ('more_link ' , $ fields ) && $ fields ['more_link ' ] !== '' ? $ fields ['more_link ' ]['title ' ] : 'More ' ,
118
+ 'action ' => 'more ' ,
119
+ 'url ' => array_key_exists ('url ' , $ fields ) && $ fields ['more_link ' ] !== '' ? $ fields ['more_link ' ]['url ' ] : '# ' ,
120
+ 'target ' => array_key_exists ('target ' , $ fields ) && $ fields ['more_link ' ] !== '' ? $ fields ['more_link ' ]['target ' ] : '_blank ' ,
121
+ ],
122
+ [
123
+ 'label ' => array_key_exists ('decline_label ' , $ fields ) && $ fields ['decline_label ' ] !== '' ? $ fields ['decline_label ' ] : 'Decline ' ,
124
+ 'action ' => 'decline '
125
+ ],
126
+ [
127
+ 'label ' => array_key_exists ('accept_label ' , $ fields ) && $ fields ['accept_label ' ]!== '' ? $ fields ['accept_label ' ] : 'Accept ' ,
128
+ 'action ' => 'accept '
129
+ ]
112
130
];
131
+
132
+ return array_values (array_filter (
133
+ $ actions ,
134
+ function ($ action ) use ($ fields ) {
135
+ return array_key_exists ($ action ['action ' ], $ fields ) && $ fields [$ action ['action ' ]];
136
+ }
137
+ ));
138
+ }
139
+
140
+ private function get_trigger ($ fields ) {
141
+ $ trigger = [
142
+ 'type ' => array_key_exists ('trigger_type ' , $ fields ) ? $ fields ['trigger_type ' ] : 'load ' ,
143
+ ];
144
+
145
+ if (array_key_exists ("trigger_scroll " , $ fields )) {
146
+ $ trigger = array_merge (
147
+ $ trigger ,
148
+ [
149
+ 'measurement ' => $ fields ['trigger_scroll ' ]['measurement ' ],
150
+ 'value ' => $ fields ['trigger_scroll ' ]['value_ ' . $ fields ['trigger_scroll ' ]['measurement ' ]],
151
+ ]
152
+ );
153
+ }
154
+
155
+ return $ trigger ;
113
156
}
114
157
}
0 commit comments