PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.11.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.11.1
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / modules / funnels / class-wpfnl-funnels.php

class-wpfnl-funnels.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.11.1, at admin/modules/funnels/class-wpfnl-funnels.php

296 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module
4 *
5 * @package
6 */
7 namespace WPFunnels\Modules\Admin\Funnels;
8
9 use WPFunnels\Admin\Module\Wpfnl_Admin_Module;
10 use WPFunnels\Data_Store\Wpfnl_Funnel_Store_Data;
11 use WPFunnels\Traits\SingletonTrait;
12
13 class Module extends Wpfnl_Admin_Module
14 {
15 use SingletonTrait;
16
17
18 /**
19 * List of published funnels
20 *
21 * @var
22 * @since 1.0.0
23 */
24 protected $funnels;
25
26
27 /**
28 * Ff needs to show pagination
29 *
30 * @var bool
31 * @since 1.0.0
32 */
33 protected $pagination = false;
34
35
36 /**
37 * Total number of funnels
38 *
39 * @var
40 * @since 1.0.0
41 */
42 protected $total_funnels;
43
44
45 /**
46 * Total number of pages
47 *
48 * @var
49 * @since 1.0.0
50 */
51 protected $total_page = 1;
52
53
54 /**
55 * Current page number
56 *
57 * @var
58 * @since 1.0.0
59 */
60 protected $current_page = 1;
61
62
63 /**
64 * Offset
65 *
66 * @var int
67 * @since 1.0.0
68 */
69 protected $offset = 1;
70
71 protected $utm_settings;
72
73
74 protected $page_name;
75
76
77 protected $total_live_funnel = 0;
78
79 protected $total_trash_funnel = 0;
80
81
82 /**
83 * Get view of the funnel list
84 *
85 * @since 1.0.0
86 */
87 public function get_view()
88 {
89 $this->current_page = isset( $_GET[ 'pageno' ] ) ? sanitize_text_field( $_GET[ 'pageno' ] ) : 1;
90 $this->page_name = isset( $_GET[ 'page' ] ) ? sanitize_text_field( $_GET[ 'page' ] ) : 'wp_funnels';
91 $per_page = isset( $_GET[ 'per_page' ] ) ? sanitize_text_field( $_GET[ 'per_page' ] ) : WPFNL_FUNNEL_PER_PAGE;
92 $this->offset = ( $this->current_page - 1 ) * $per_page;
93
94 $this->init_all_funnels( $per_page, $this->offset );
95 require_once WPFNL_DIR . '/admin/modules/funnels/views/view.php';
96 }
97
98
99 /**
100 * Get arguments for funnel
101 * query
102 *
103 * @return array
104 * @since 1.0.0
105 */
106 public function get_args( $per_page = WPFNL_FUNNEL_PER_PAGE )
107 {
108 $args = [
109 'post_type' => WPFNL_FUNNELS_POST_TYPE,
110 'posts_per_page' => $per_page,
111 'offset' => $this->offset,
112 ];
113
114 if( $this->page_name == 'wp_funnels' ){
115 $args['post_status'] = array('publish', 'draft');
116 }else{
117 $args['post_status'] = array('trash');
118 }
119
120 if (isset($_GET['s'])) {
121 $args['s'] = sanitize_text_field($_GET['s']);
122
123 }
124 if( ! defined( 'REMOTE_FUNNEL_VERSION')) {
125 // Exclude Store Checkout funnels from regular funnel listing
126 $args['meta_query'] = [
127 'relation' => 'OR',
128 [
129 'key' => '_wpfnl_funnel_type',
130 'compare' => 'NOT EXISTS',
131 ],
132 [
133 'key' => '_wpfnl_funnel_type',
134 'value' => 'store_checkout',
135 'compare' => '!=',
136 ],
137 ];
138 }
139
140 return $args;
141 }
142
143
144 /**
145 * Get all funnel list
146 *
147 * @param int $limit
148 * @param int $offset
149 *
150 * @since 1.0.0
151 */
152 public function init_all_funnels($limit = 10, $offset = 0)
153 {
154 // Exclude store checkout funnels from live/trash counts
155 $exclude_sc_meta = [
156 'relation' => 'OR',
157 [
158 'key' => '_wpfnl_funnel_type',
159 'compare' => 'NOT EXISTS',
160 ],
161 [
162 'key' => '_wpfnl_funnel_type',
163 'value' => 'store_checkout',
164 'compare' => '!=',
165 ],
166 ];
167
168 $args = [
169 'post_type' => WPFNL_FUNNELS_POST_TYPE,
170 'posts_per_page' => -1,
171 'suppress_filters' => true,
172 'fields' => 'ids',
173 'post_status' => array('publish', 'draft'),
174 'meta_query' => $exclude_sc_meta,
175 ];
176
177 $total_live_funnel = get_posts($args);
178 $this->total_live_funnel = count($total_live_funnel);
179
180
181 $args = [
182 'post_type' => WPFNL_FUNNELS_POST_TYPE,
183 'posts_per_page' => -1,
184 'suppress_filters' => true,
185 'fields' => 'ids',
186 'post_status' => array('trash'),
187 'meta_query' => $exclude_sc_meta,
188 ];
189
190 $total_trash_funnel = get_posts($args);
191 $this->total_trash_funnel = count($total_trash_funnel);
192
193 $args = [
194 'post_type' => WPFNL_FUNNELS_POST_TYPE,
195 'posts_per_page' => -1,
196 'suppress_filters' => true,
197 'fields' => 'ids'
198 ];
199
200 if( $this->page_name == 'wp_funnels' ){
201 $args['post_status'] = array('publish', 'draft');
202 }else{
203 $args['post_status'] = array('trash');
204 }
205
206 if (isset($_GET['s'])) {
207 $args['s'] = sanitize_text_field($_GET['s']);
208 }
209
210 if( ! defined( 'REMOTE_FUNNEL_VERSION')) {
211 // Exclude Store Checkout funnels
212 $args['meta_query'] = [
213 'relation' => 'OR',
214 [
215 'key' => '_wpfnl_funnel_type',
216 'compare' => 'NOT EXISTS',
217 ],
218 [
219 'key' => '_wpfnl_funnel_type',
220 'value' => 'store_checkout',
221 'compare' => '!=',
222 ],
223 ];
224 }
225
226 $all_funnels = get_posts($args);
227 $funnels = get_posts($this->get_args( $limit ));
228 $this->funnels = $this->get_formatted_funnel_array($funnels);
229
230 $this->total_funnels = count( $all_funnels );
231 $this->pagination = (bool)count( $this->funnels );
232 if (count($this->funnels)) {
233 $this->total_page = ceil($this->total_funnels / $limit);
234 }
235 $this->utm_settings = $this->get_utm_settings();
236 }
237
238
239 /**
240 * Get all funnel list
241 *
242 * @return array
243 * @since 1.0.0
244 */
245 public function get_formatted_funnel_array($funnels)
246 {
247 $_funnels = [];
248 if ($funnels) {
249 foreach ($funnels as $funnel) {
250 $_funnel = new Wpfnl_Funnel_Store_Data();
251 $_funnel->read($funnel->ID);
252 $_funnel->set_data($funnel);
253 $_funnels[] = $_funnel;
254 }
255 }
256 return $_funnels;
257 }
258
259
260 /**
261 * Get name
262 *
263 * @return String
264 * @since 2.0.4
265 */
266 public function get_name()
267 {
268 return __('funnels','wpfnl');
269 }
270
271
272 /**
273 * Get GTM Settings
274 *
275 * @return array
276 */
277 public function get_utm_settings() {
278 $default_settings = array(
279 'utm_enable' => 'off',
280 'utm_source' => '',
281 'utm_medium' => '',
282 'utm_campaign' => '',
283 'utm_content' => '',
284 );
285 $utm_settings = get_option('_wpfunnels_utm_params', $default_settings);
286 return wp_parse_args($utm_settings, $default_settings);
287 }
288
289 /**
290 * Init ajax
291 */
292 public function init_ajax(){
293
294 }
295 }
296