PluginProbe
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools / 1.2.2
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools v1.2.2
1.5.5 1.5.4 trunk 1.0.0 1.0.1 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 All 47 releases
pixelavo / includes / base.php

base.php in Pixelavo – Server Side Tracking & Pixel + AI Ads Tools 1.2.2, at includes/base.php

305 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Pixelavo;
4
5 /**
6 * TODO: remove data from other events in the future update (in wp_localize_script)
7 */
8
9 /**
10 * Exit if accessed directly
11 * */
12 if (!defined('ABSPATH')) {
13 exit;
14 }
15
16 /**
17 * Base
18 */
19 final class Base {
20
21 private static $_instance = null;
22
23 /**
24 * Instance
25 *
26 * Initializes a singleton instance
27 *
28 * @return self class
29 */
30 static function instance() {
31 if (is_null( self::$_instance )) {
32 self::$_instance = new self();
33 }
34 return self::$_instance;
35 }
36
37 /**
38 * Base class constructor
39 * @return void
40 */
41 private function __construct() {
42 if (!function_exists('is_plugin_active')) {
43 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
44 }
45 add_action('init', [$this, 'i18n']);
46 add_action('plugins_loaded', [$this, 'init']);
47 add_action('in_admin_header', [$this, 'remove_admin_notice'], 1000);
48 add_action('wp_enqueue_scripts', [$this, 'scripts']);
49 add_action('admin_init', [$this, 'show_diagnostic_notice']);
50 add_action('admin_init', [$this, 'show_rating_notice']);
51 add_action('admin_init', [$this, 'show_promo_notice']);
52 /**
53 * Register Plugin Active Hook
54 */
55 register_activation_hook( PIXELAVO_PL_ROOT, [ $this, 'plugin_activate_hook' ] );
56 }
57
58 /**
59 * i18n
60 *
61 * Load text domain
62 * @return void
63 */
64 function i18n() {
65 load_plugin_textdomain('pixelavo', false, dirname(plugin_basename(PIXELAVO_PL_ROOT)) . '/languages');
66 }
67
68 /**
69 * Remove all Notices on admin pages.
70 * @return void
71 */
72 function remove_admin_notice(){
73 $current_screen = get_current_screen();
74 $hide_screen = ['toplevel_page_pixelavo', 'update'];
75 if( in_array( $current_screen->id, $hide_screen) ){
76 remove_all_actions('admin_notices');
77 remove_all_actions('all_admin_notices');
78 }
79 }
80
81 /**
82 * init
83 *
84 * Plugins loaded init hook
85 * @return void
86 */
87 function init() {
88
89 /**
90 * Include required files.
91 */
92 $this->include_files();
93
94 /**
95 * Redirect to option page after plugin activate
96 */
97 $this->plugin_redirect_option_page();
98
99 /**
100 * Add plugin setting link to the plugin.
101 */
102 add_filter('plugin_action_links_' . PIXELAVO_PLUGIN_BASE, [$this, 'plugins_setting_links']);
103
104 }
105
106 /**
107 * Include Require Files
108 */
109 function include_files() {
110 require_once (PIXELAVO_PL_PATH . 'includes/helper-functions.php');
111 require_once (PIXELAVO_PL_PATH . 'admin/admin-setting.php');
112 require_once (PIXELAVO_PL_PATH . 'includes/add-pixel.php');
113 if(pixelavo_is_woocommerce_active()) {
114 require_once (PIXELAVO_PL_PATH . 'includes/pixel-events-data.php');
115 if(pixelavo_get_option('product_feed', 'pixelavo_settings') == 'on') {
116 require_once (PIXELAVO_PL_PATH . 'includes/pixel-feed.php');
117 }
118 }
119 if(pixelavo_is_edd_active()) {
120 require_once (PIXELAVO_PL_PATH . 'includes/pixel-edd-events-data.php');
121 if(pixelavo_get_option('edd_product_feed', 'pixelavo_settings') == 'on') {
122 require_once (PIXELAVO_PL_PATH . 'includes/pixel-edd-feed.php');
123 }
124 }
125 if(!empty(pixelavo_get_custom_events())) {
126 require_once (PIXELAVO_PL_PATH . 'includes/pixel-custom-events-data.php');
127 }
128 require_once PIXELAVO_PL_PATH . 'includes/pixel-ajax-events-data.php';
129
130 if( is_admin() ){
131 require_once (PIXELAVO_PL_PATH . 'admin/class-notice-manager.php');
132 require_once (PIXELAVO_PL_PATH . 'admin/class-diagnostic-data.php');
133 require_once (PIXELAVO_PL_PATH . 'admin/class-notices.php');
134 require_once (PIXELAVO_PL_PATH . 'admin/class-trial.php');
135 }
136 add_action('wp_footer', [$this, 'localizedEventsData'], 11);
137 }
138
139 function localizedEventsData() {
140 global $pixelavoEventsLocalizedData;
141 if(count($pixelavoEventsLocalizedData) > 0) {
142 wp_localize_script('pixelavo', 'pixelavo_event', $pixelavoEventsLocalizedData);
143 }
144 }
145
146 /**
147 * Scripts
148 *
149 * Enqueue style and scripts for frontend part
150 * @return void
151 */
152 function scripts() {
153 if(pixelavo_pixel_status()) {
154 wp_enqueue_script('pixelavo', PIXELAVO_DIR_URL . 'assets/public/js/main.js', ['jquery'], PIXELAVO_VERSION, true);
155 wp_localize_script('pixelavo', 'pixelavo', [
156 'ajax_url' => admin_url('admin-ajax.php'),
157 'nonce' => wp_create_nonce('pixelavo_ajax_event_nonce'),
158 'other_events' => wp_json_encode(array_merge(pixelavo_get_other_events(), ['data' => pixelavo_get_event_common_data()])),
159 'custom_events' => wp_json_encode(pixelavo_get_custom_events()),
160 'additional_user_info' => apply_filters('pixelavo_additional_user_info', [], [] ),
161 'common_params' => pixelavo_get_event_common_data(),
162 ]);
163 wp_localize_script('pixelavo', 'pixelavo_event', []);
164 }
165 }
166
167 /**
168 * Plugins setting links
169
170 * @param array plugin default action links
171 * @return array plugin action link
172 */
173 function plugins_setting_links($links) {
174 $link = sprintf(
175 '<a href="%1$s">%2$s</a>',
176 admin_url('admin.php?page=pixelavo#/pixels'),
177 __( 'Settings', 'pixelavo' )
178 );
179 array_unshift($links, $link);
180 return $links;
181 }
182
183 /**
184 * Plugin Active Hook
185 * Run when plugin is activated
186 */
187 public function plugin_activate_hook() {
188 $events = get_option('pixelavo_events', [
189 'search' => 'on',
190 'view_content' => 'on',
191 'view_category' => 'on',
192 ]);
193 $edd_events = get_option('pixelavo_edd_events', [
194 'edd_search' => 'on',
195 'edd_view_content' => 'on',
196 'edd_view_category' => 'on',
197 ]);
198 update_option('pixelavo_events', $events);
199 update_option('pixelavo_edd_events', $edd_events);
200 add_option('pixelavo_do_activation_redirect', true);
201 flush_rewrite_rules();
202
203 if ( ! get_option( 'pixelavo_installed' ) ) {
204 update_option( 'pixelavo_installed', time() );
205 }
206 }
207
208 /**
209 * After Active the plugin then redirect to option page
210 * @return void
211 */
212 public function plugin_redirect_option_page() {
213 if ( get_option( 'pixelavo_do_activation_redirect', false ) ) {
214 delete_option('pixelavo_do_activation_redirect');
215 if( !isset( $_GET['activate-multi'] ) ){
216 wp_redirect( admin_url("admin.php?page=pixelavo#/pixels") );
217 }
218 }
219 }
220
221
222 function show_diagnostic_notice() {
223 $notice_instance = \Pixelavo_Diagnostic_Data::get_instance();
224 ob_start();
225 $notice_instance->show_notices();
226 $message = ob_get_clean();
227 if (! empty( $message ) ) {
228 \Pixelavo_Notice::set_notice(
229 [
230 'id' => 'diagnostic-data',
231 'type' => 'success',
232 'dismissible' => false,
233 'message_type' => 'html',
234 'message' => $message,
235 'display_after' => ( 7 * DAY_IN_SECONDS ),
236 'expire_time' => ( 0 * DAY_IN_SECONDS ),
237 'close_by' => 'transient'
238 ]
239 );
240 }
241 }
242
243 function show_rating_notice() {
244 $message = '<div class="pixelavo-review-notice-wrap">
245 <div class="pixelavo-rating-notice-logo">
246 <img src="' . esc_url(PIXELAVO_PL_URL . 'assets/images/logo.png') . '" alt="Pixelavo" style="max-width:110px"/>
247 </div>
248 <div class="pixelavo-review-notice-content">
249 <h3>'.esc_html__('Thank you for choosing Pixelavo to manage you plugins!','pixelavo').'</h3>
250 <p>'.esc_html__('Would you mind doing us a huge favor by providing your feedback on WordPress? Your support helps us spread the word and greatly boosts our motivation.','pixelavo').'</p>
251 <div class="pixelavo-review-notice-action">
252 <a href="https://wordpress.org/support/plugin/pixelavo/reviews/?filter=5#new-post" class="pixelavo-review-notice button-primary" target="_blank">'.esc_html__('Ok, you deserve it!','pixelavo').'</a>
253 <a href="#" class="pixelavo-notice-close pixelavo-review-notice"><span class="dashicons dashicons-calendar"></span>'.esc_html__('Maybe Later','pixelavo').'</a>
254 <a href="#" data-already-did="yes" class="pixelavo-notice-close pixelavo-review-notice"><span class="dashicons dashicons-smiley"></span>'.esc_html__('I already did','pixelavo').'</a>
255 </div>
256 </div>
257 </div>';
258 if (! empty( $message ) ) {
259 \Pixelavo_Notice::set_notice(
260 [
261 'id' => 'ratting',
262 'type' => 'info',
263 'dismissible' => true,
264 'message_type' => 'html',
265 'message' => $message,
266 'display_after' => ( 14 * DAY_IN_SECONDS ),
267 'close_by' => 'transient'
268 ]
269 );
270 }
271 }
272
273
274
275 function show_promo_notice() {
276
277 // remove on next update
278 if(!get_option('force_update_pixelavo_notice_info')) {
279 delete_transient('pixelavo_notice_info');
280 update_option('force_update_pixelavo_notice_info', true);
281 }
282
283 $noticeManager = \Pixelavo_Notice_Manager::instance();
284 $notices = $noticeManager->get_notices_info();
285 if(!empty($notices)) {
286 $notices = array_map(function($notice) {
287 $notice["display_after"] = false;
288 $notice["expire_time"] = 0;
289 return $notice;
290 }, $notices);
291 foreach ($notices as $notice) {
292 if(empty($notice['disable'])) {
293 \Pixelavo_Notice::set_notice($notice);
294 }
295 }
296 }
297 }
298
299 }
300
301 /**
302 * Initialize Base Class
303 */
304 Base::instance();
305