Version Description
Download this release
Release Info
Developer | PixelYourSite |
Plugin | PixelYourSite – Facebook Pixel (Events, WooCommerce & Easy Digital Downloads) |
Version | 5.0.7 |
Comparing to | |
See all releases |
Code changes from version 5.0.6 to 5.0.7
- facebook-pixel-master.php +62 -62
- inc/common.php +1508 -1506
- inc/core.php +464 -464
- inc/integrations/facebook-for-woocommerce.php +221 -221
- readme.txt +6 -1
facebook-pixel-master.php
CHANGED
@@ -1,63 +1,63 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: PixelYourSite
|
4 |
-
Description: Add the Facebook Pixel code into your Wordpress site and set up standard events with just a few clicks. Fully compatible with Woocommerce, purchase event included.
|
5 |
-
Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
|
6 |
-
Author: PixelYourSite
|
7 |
-
Author URI: http://www.pixelyoursite.com
|
8 |
-
Version: 5.0.
|
9 |
-
License: GPLv3
|
10 |
-
*/
|
11 |
-
|
12 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
13 |
-
exit; // Exit if accessed directly.
|
14 |
-
}
|
15 |
-
|
16 |
-
define( 'PYS_FREE_VERSION', '5.0.
|
17 |
-
|
18 |
-
if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Check whatever PixelYourSite PRO version activated.
|
22 |
-
*
|
23 |
-
* @return bool
|
24 |
-
*/
|
25 |
-
function pys_is_pixelyoursite_pro_active() {
|
26 |
-
|
27 |
-
if ( ! function_exists( 'is_plugin_active' ) ) {
|
28 |
-
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
29 |
-
}
|
30 |
-
|
31 |
-
return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
|
32 |
-
|
33 |
-
}
|
34 |
-
|
35 |
-
}
|
36 |
-
|
37 |
-
if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
|
38 |
-
|
39 |
-
register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
|
40 |
-
function pys_free_plugin_activated() {
|
41 |
-
|
42 |
-
if ( pys_is_pixelyoursite_pro_active() ) {
|
43 |
-
wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
|
44 |
-
'back_link' => true,
|
45 |
-
) );
|
46 |
-
}
|
47 |
-
|
48 |
-
$options = get_option( 'pixel_your_site' );
|
49 |
-
|
50 |
-
if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
|
51 |
-
|
52 |
-
require_once 'inc/general.php';
|
53 |
-
pys_initialize_settings();
|
54 |
-
|
55 |
-
}
|
56 |
-
|
57 |
-
}
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
if ( ! pys_is_pixelyoursite_pro_active() ) {
|
62 |
-
require_once 'inc/general.php';
|
63 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: PixelYourSite
|
4 |
+
Description: Add the Facebook Pixel code into your Wordpress site and set up standard events with just a few clicks. Fully compatible with Woocommerce, purchase event included.
|
5 |
+
Plugin URI: http://www.pixelyoursite.com/facebook-pixel-plugin-help
|
6 |
+
Author: PixelYourSite
|
7 |
+
Author URI: http://www.pixelyoursite.com
|
8 |
+
Version: 5.0.7
|
9 |
+
License: GPLv3
|
10 |
+
*/
|
11 |
+
|
12 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
13 |
+
exit; // Exit if accessed directly.
|
14 |
+
}
|
15 |
+
|
16 |
+
define( 'PYS_FREE_VERSION', '5.0.7' );
|
17 |
+
|
18 |
+
if ( ! function_exists( 'pys_is_pixelyoursite_pro_active' ) ) {
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Check whatever PixelYourSite PRO version activated.
|
22 |
+
*
|
23 |
+
* @return bool
|
24 |
+
*/
|
25 |
+
function pys_is_pixelyoursite_pro_active() {
|
26 |
+
|
27 |
+
if ( ! function_exists( 'is_plugin_active' ) ) {
|
28 |
+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
29 |
+
}
|
30 |
+
|
31 |
+
return is_plugin_active( 'pixelyoursite-pro/pixelyoursite-pro.php' );
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( ! function_exists( 'pys_free_plugin_activated' ) ) {
|
38 |
+
|
39 |
+
register_activation_hook( __FILE__, 'pys_free_plugin_activated' );
|
40 |
+
function pys_free_plugin_activated() {
|
41 |
+
|
42 |
+
if ( pys_is_pixelyoursite_pro_active() ) {
|
43 |
+
wp_die( 'Please deactivate PixelYourSite PRO version first.', 'Plugin Activation', array(
|
44 |
+
'back_link' => true,
|
45 |
+
) );
|
46 |
+
}
|
47 |
+
|
48 |
+
$options = get_option( 'pixel_your_site' );
|
49 |
+
|
50 |
+
if ( ! $options || ! isset( $options['general']['pixel_id'] ) || empty( $options['general']['pixel_id'] ) ) {
|
51 |
+
|
52 |
+
require_once 'inc/general.php';
|
53 |
+
pys_initialize_settings();
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
if ( ! pys_is_pixelyoursite_pro_active() ) {
|
62 |
+
require_once 'inc/general.php';
|
63 |
}
|
inc/common.php
CHANGED
@@ -1,1507 +1,1509 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Common functions for both versions.
|
4 |
-
*/
|
5 |
-
|
6 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
7 |
-
exit; // Exit if accessed directly.
|
8 |
-
}
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Check if WooCommerce plugin is installed and activated.
|
12 |
-
*/
|
13 |
-
if( !function_exists( 'pys_is_woocommerce_active' ) ) {
|
14 |
-
|
15 |
-
function pys_is_woocommerce_active() {
|
16 |
-
return class_exists( 'WooCommerce' ) == true ? true : false;
|
17 |
-
}
|
18 |
-
|
19 |
-
}
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Check if Easy Digital Downloads plugin is installed and activated.
|
23 |
-
*/
|
24 |
-
if( !function_exists( 'pys_is_edd_active' ) ) {
|
25 |
-
|
26 |
-
function pys_is_edd_active() {
|
27 |
-
return class_exists( 'Easy_Digital_Downloads' ) == true ? true : false;
|
28 |
-
}
|
29 |
-
|
30 |
-
}
|
31 |
-
|
32 |
-
if ( ! function_exists( 'pys_is_pcf_pro_active' ) ) {
|
33 |
-
|
34 |
-
function pys_is_pcf_pro_active() {
|
35 |
-
return class_exists( 'wpwoof_product_catalog' ) == true ? true : false;
|
36 |
-
}
|
37 |
-
|
38 |
-
}
|
39 |
-
|
40 |
-
if( !function_exists( 'pys_get_option' ) ) {
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Return option value.
|
44 |
-
*
|
45 |
-
* @param string $section Options section, eg. 'general', 'woo', etc.
|
46 |
-
* @param string $option Option name
|
47 |
-
* @param mixed|string $default Default option value
|
48 |
-
*
|
49 |
-
* @return mixed Option or default option value
|
50 |
-
*/
|
51 |
-
function pys_get_option( $section, $option, $default = '' ) {
|
52 |
-
|
53 |
-
$options = get_option( 'pixel_your_site' );
|
54 |
-
|
55 |
-
return isset( $options[ $section ][ $option ] ) ? $options[ $section ][ $option ] : $default;
|
56 |
-
|
57 |
-
}
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
if( !function_exists( 'pys_checkbox_state' ) ) {
|
62 |
-
|
63 |
-
/**
|
64 |
-
* @param string $section Option section name
|
65 |
-
* @param string $option Option name
|
66 |
-
* @param bool $echo Echo or return value
|
67 |
-
* @param int $checked Value to state compare
|
68 |
-
*
|
69 |
-
* @return string
|
70 |
-
*/
|
71 |
-
function pys_checkbox_state( $section, $option, $echo = true, $checked = 1 ) {
|
72 |
-
|
73 |
-
$options = get_option( 'pixel_your_site' );
|
74 |
-
|
75 |
-
if ( isset( $options[ $section ][ $option ] ) ) {
|
76 |
-
$value = $options[ $section ][ $option ] == $checked ? 'checked' : '';
|
77 |
-
} else {
|
78 |
-
$value = '';
|
79 |
-
}
|
80 |
-
|
81 |
-
if( $echo ) {
|
82 |
-
echo $value;
|
83 |
-
}
|
84 |
-
|
85 |
-
return $value;
|
86 |
-
|
87 |
-
}
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
if ( ! function_exists( 'pys_checkbox' ) ) {
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Echos checkbox input.
|
95 |
-
*
|
96 |
-
* @param string $section Input section name
|
97 |
-
* @param string $option Input option name
|
98 |
-
* @param string $classes Class names (optional)
|
99 |
-
* @param int $value Input value (optional)
|
100 |
-
*/
|
101 |
-
function pys_checkbox( $section, $option, $classes = '', $value = 1 ) {
|
102 |
-
|
103 |
-
$state = pys_checkbox_state( $section, $option, false, $value );
|
104 |
-
$value = esc_attr( $value );
|
105 |
-
|
106 |
-
echo "<input type='checkbox' value='$value' name='pys[$section][$option]' class='$classes' $state>";
|
107 |
-
|
108 |
-
}
|
109 |
-
|
110 |
-
}
|
111 |
-
|
112 |
-
if ( ! function_exists( 'pys_text_field' ) ) {
|
113 |
-
|
114 |
-
/**
|
115 |
-
* Echos text input.
|
116 |
-
*
|
117 |
-
* @param string $section Input section name
|
118 |
-
* @param string $option Input option name
|
119 |
-
*/
|
120 |
-
function pys_text_field( $section, $option ) {
|
121 |
-
|
122 |
-
$value = pys_get_option( $section, $option );
|
123 |
-
$value = esc_attr( $value );
|
124 |
-
|
125 |
-
echo "<input type='text' value='$value' name='pys[$section][$option]'>";
|
126 |
-
|
127 |
-
}
|
128 |
-
|
129 |
-
}
|
130 |
-
|
131 |
-
if ( ! function_exists( 'pys_radio_box' ) ) {
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Echos radio box input.
|
135 |
-
*
|
136 |
-
* @param string $section Input section name
|
137 |
-
* @param string $option Input option name
|
138 |
-
* @param string $value Option value
|
139 |
-
*/
|
140 |
-
function pys_radio_box( $section, $option, $value ) {
|
141 |
-
|
142 |
-
$state = pys_radio_state( $section, $option, $value );
|
143 |
-
echo "<input type='radio' value='$value' name='pys[$section][$option]' $state>";
|
144 |
-
|
145 |
-
}
|
146 |
-
|
147 |
-
}
|
148 |
-
|
149 |
-
/**
|
150 |
-
* Return radio box state.
|
151 |
-
*/
|
152 |
-
if( !function_exists( 'pys_radio_state' ) ) {
|
153 |
-
|
154 |
-
function pys_radio_state( $section, $option, $value ) {
|
155 |
-
|
156 |
-
$options = get_option( 'pixel_your_site' );
|
157 |
-
|
158 |
-
if ( isset( $options[ $section ][ $option ] ) ) {
|
159 |
-
|
160 |
-
return $options[ $section ][ $option ] == $value ? 'checked' : '';
|
161 |
-
|
162 |
-
} else {
|
163 |
-
|
164 |
-
$defaults = pys_get_default_options();
|
165 |
-
return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
|
166 |
-
|
167 |
-
}
|
168 |
-
|
169 |
-
}
|
170 |
-
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Facebook Pixel Event types options html.
|
175 |
-
*/
|
176 |
-
if( !function_exists( 'pys_event_types_select_options' ) ) {
|
177 |
-
|
178 |
-
function pys_event_types_select_options( $current = null, $full = true ) {
|
179 |
-
?>
|
180 |
-
|
181 |
-
<option <?php selected( null, $current ); ?> disabled>Select Type</option>
|
182 |
-
<option <?php selected( 'ViewContent', $current ); ?> value="ViewContent">ViewContent</option>
|
183 |
-
|
184 |
-
<?php if ( $full ) : ?>
|
185 |
-
|
186 |
-
<option <?php selected( 'Search', $current ); ?> value="Search">Search</option>
|
187 |
-
|
188 |
-
<?php endif; ?>
|
189 |
-
|
190 |
-
<option <?php selected( 'AddToCart', $current ); ?> value="AddToCart">AddToCart</option>
|
191 |
-
<option <?php selected( 'AddToWishlist', $current ); ?> value="AddToWishlist">AddToWishlist</option>
|
192 |
-
<option <?php selected( 'InitiateCheckout', $current ); ?> value="InitiateCheckout">InitiateCheckout</option>
|
193 |
-
<option <?php selected( 'AddPaymentInfo', $current ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
|
194 |
-
<option <?php selected( 'Purchase', $current ); ?> value="Purchase">Purchase</option>
|
195 |
-
<option <?php selected( 'Lead', $current ); ?> value="Lead">Lead</option>
|
196 |
-
<option <?php selected( 'CompleteRegistration', $current ); ?> value="CompleteRegistration">CompleteRegistration</option>
|
197 |
-
|
198 |
-
<?php if ( $full ) : ?>
|
199 |
-
|
200 |
-
<option disabled></option>
|
201 |
-
<option <?php selected( 'CustomEvent', $current ); ?> value="CustomEvent">Custom event</option>
|
202 |
-
<option <?php selected( 'CustomCode', $current); ?> value="CustomCode">Custom event code</option>
|
203 |
-
|
204 |
-
<?php endif; ?>
|
205 |
-
|
206 |
-
<?php
|
207 |
-
}
|
208 |
-
|
209 |
-
}
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Current Page Full URL without trailing slash
|
213 |
-
*/
|
214 |
-
if( !function_exists( 'pys_get_current_url' ) ) {
|
215 |
-
|
216 |
-
function pys_get_current_url() {
|
217 |
-
|
218 |
-
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
219 |
-
$current_url = rtrim( $current_url, '/' );
|
220 |
-
|
221 |
-
return $current_url;
|
222 |
-
|
223 |
-
}
|
224 |
-
|
225 |
-
}
|
226 |
-
|
227 |
-
/**
|
228 |
-
* Returns relative path without protocol, host, slashes.
|
229 |
-
*/
|
230 |
-
if( !function_exists( 'pys_get_relative_path' ) ) {
|
231 |
-
|
232 |
-
function pys_get_relative_path( $url ) {
|
233 |
-
|
234 |
-
$host = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', home_url() );
|
235 |
-
|
236 |
-
$url = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', $url );
|
237 |
-
$url = str_replace( $host, '', $url );
|
238 |
-
|
239 |
-
$url = trim( $url );
|
240 |
-
$url = ltrim( $url, '/' );
|
241 |
-
$url = rtrim( $url, '/' );
|
242 |
-
|
243 |
-
return $url;
|
244 |
-
|
245 |
-
}
|
246 |
-
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* Check if needle URL (full or relative) matches with current.
|
251 |
-
*/
|
252 |
-
if( !function_exists( 'pys_match_url' ) ) {
|
253 |
-
|
254 |
-
function pys_match_url( $match_url, $current_url = '' ) {
|
255 |
-
|
256 |
-
// use current url by default
|
257 |
-
if ( ! isset( $current_url ) || empty( $current_url ) ) {
|
258 |
-
$current_url = pys_get_current_url();
|
259 |
-
}
|
260 |
-
|
261 |
-
$current_url = pys_get_relative_path( $current_url );
|
262 |
-
$match_url = pys_get_relative_path( $match_url );
|
263 |
-
|
264 |
-
if ( substr( $match_url, - 1 ) == '*' ) {
|
265 |
-
// if match_url ends with wildcard
|
266 |
-
|
267 |
-
$match_url = rtrim( $match_url, '*' );
|
268 |
-
|
269 |
-
if ( pys_startsWith( $current_url, $match_url ) ) {
|
270 |
-
return true;
|
271 |
-
}
|
272 |
-
|
273 |
-
} else {
|
274 |
-
// exact url
|
275 |
-
|
276 |
-
if ( $current_url == $match_url ) {
|
277 |
-
return true;
|
278 |
-
}
|
279 |
-
|
280 |
-
}
|
281 |
-
|
282 |
-
return false;
|
283 |
-
|
284 |
-
}
|
285 |
-
|
286 |
-
}
|
287 |
-
|
288 |
-
if( !function_exists( 'pys_startsWith' ) ) {
|
289 |
-
|
290 |
-
function pys_startsWith( $haystack, $needle ) {
|
291 |
-
// search backwards starting from haystack length characters from the end
|
292 |
-
return $needle === "" || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
|
293 |
-
}
|
294 |
-
|
295 |
-
}
|
296 |
-
|
297 |
-
if( !function_exists( 'pys_endsWith' ) ) {
|
298 |
-
|
299 |
-
function pys_endsWith( $haystack, $needle ) {
|
300 |
-
// search forward starting from end minus needle length characters
|
301 |
-
return $needle === "" || ( ( $temp = strlen( $haystack ) - strlen( $needle ) ) >= 0 && strpos( $haystack, $needle, $temp ) !== false );
|
302 |
-
}
|
303 |
-
|
304 |
-
}
|
305 |
-
|
306 |
-
if( !function_exists( 'pys_currency_options' ) ) {
|
307 |
-
|
308 |
-
function pys_currency_options( $current = 'USD' ) {
|
309 |
-
|
310 |
-
$currencies = apply_filters( 'pys_currencies_list', array(
|
311 |
-
'AUD' => 'Australian Dollar',
|
312 |
-
'BRL' => 'Brazilian Real',
|
313 |
-
'CAD' => 'Canadian Dollar',
|
314 |
-
'CZK' => 'Czech Koruna',
|
315 |
-
'DKK' => 'Danish Krone',
|
316 |
-
'EUR' => 'Euro',
|
317 |
-
'HKD' => 'Hong Kong Dollar',
|
318 |
-
'HUF' => 'Hungarian Forint',
|
319 |
-
'IDR' => 'Indonesian Rupiah',
|
320 |
-
'ILS' => 'Israeli New Sheqel',
|
321 |
-
'JPY' => 'Japanese Yen',
|
322 |
-
'KRW' => 'Korean Won',
|
323 |
-
'MYR' => 'Malaysian Ringgit',
|
324 |
-
'MXN' => 'Mexican Peso',
|
325 |
-
'NOK' => 'Norwegian Krone',
|
326 |
-
'NZD' => 'New Zealand Dollar',
|
327 |
-
'PHP' => 'Philippine Peso',
|
328 |
-
'PLN' => 'Polish Zloty',
|
329 |
-
'RON' => 'Romanian Leu',
|
330 |
-
'GBP' => 'Pound Sterling',
|
331 |
-
'SGD' => 'Singapore Dollar',
|
332 |
-
'SEK' => 'Swedish Krona',
|
333 |
-
'CHF' => 'Swiss Franc',
|
334 |
-
'TWD' => 'Taiwan New Dollar',
|
335 |
-
'THB' => 'Thai Baht',
|
336 |
-
'TRY' => 'Turkish Lira',
|
337 |
-
'USD' => 'U.S. Dollar',
|
338 |
-
'ZAR' => 'South African Rands'
|
339 |
-
) );
|
340 |
-
|
341 |
-
foreach( $currencies as $symbol => $name ) {
|
342 |
-
echo '<option ' . selected( $symbol, $current, false ) . ' value="' . esc_attr( $symbol ) . '">' . esc_html( $name ) . '</option>';
|
343 |
-
}
|
344 |
-
|
345 |
-
}
|
346 |
-
|
347 |
-
}
|
348 |
-
|
349 |
-
/**
|
350 |
-
* Extract Object taxonomies list.
|
351 |
-
*/
|
352 |
-
if( !function_exists( 'pys_get_content_taxonomies' ) ) {
|
353 |
-
|
354 |
-
function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
|
355 |
-
|
356 |
-
$post_id = isset( $post_id ) ? $post_id : get_the_ID();
|
357 |
-
$terms = get_the_terms( $post_id, $taxonomy );
|
358 |
-
|
359 |
-
if ( is_wp_error( $terms ) || empty ( $terms ) ) {
|
360 |
-
return false;
|
361 |
-
}
|
362 |
-
|
363 |
-
$list = array();
|
364 |
-
|
365 |
-
foreach( $terms as $term ) {
|
366 |
-
$list[ $term->term_id ] = html_entity_decode( $term->name );
|
367 |
-
}
|
368 |
-
|
369 |
-
return implode( ', ', $list );
|
370 |
-
|
371 |
-
}
|
372 |
-
|
373 |
-
}
|
374 |
-
|
375 |
-
if( !function_exists( 'pys_add_event' ) ) {
|
376 |
-
|
377 |
-
/**
|
378 |
-
* Add event with params to global events list.
|
379 |
-
*
|
380 |
-
* @param string $event Event name, eg. "PageView"
|
381 |
-
* @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
|
382 |
-
* @param int $delay Optional. If set, event will be fired with desired delay in seconds.
|
383 |
-
*/
|
384 |
-
function pys_add_event( $event, $params = array(), $delay = 0 ) {
|
385 |
-
global $pys_events;
|
386 |
-
|
387 |
-
$params = apply_filters( 'pys_event_params', $params, $event );
|
388 |
-
|
389 |
-
$sanitized = array();
|
390 |
-
|
391 |
-
// sanitize param names and its values
|
392 |
-
foreach ( $params as $name => $value ) {
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
$
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
'
|
406 |
-
'
|
407 |
-
'
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
*
|
462 |
-
*
|
463 |
-
* @param string $
|
464 |
-
* @param string $
|
465 |
-
* @param
|
466 |
-
* @param
|
467 |
-
*
|
468 |
-
*
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
*
|
486 |
-
*
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
*
|
499 |
-
*
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
$
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
$
|
639 |
-
$
|
640 |
-
$
|
641 |
-
|
642 |
-
|
643 |
-
$
|
644 |
-
$
|
645 |
-
$
|
646 |
-
$
|
647 |
-
$
|
648 |
-
$
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
$params['
|
655 |
-
$params['
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
$params['
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
$params['
|
697 |
-
$params['
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
$
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
$
|
715 |
-
|
716 |
-
|
717 |
-
$params['
|
718 |
-
$params['
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
$
|
724 |
-
|
725 |
-
|
726 |
-
$params['
|
727 |
-
$params['
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
$params['
|
735 |
-
$params['
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
$params['
|
755 |
-
$params['
|
756 |
-
|
757 |
-
|
758 |
-
$
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
if
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
$custom_code =
|
836 |
-
$custom_code =
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
$
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
'
|
864 |
-
'
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
$args['
|
890 |
-
$args['
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
//
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
unset( $params['
|
949 |
-
unset( $params['
|
950 |
-
unset( $params['
|
951 |
-
unset( $params['
|
952 |
-
unset( $params['
|
953 |
-
unset( $params['
|
954 |
-
unset( $params['
|
955 |
-
unset( $params['
|
956 |
-
unset( $params['
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
$params
|
972 |
-
|
973 |
-
|
974 |
-
$
|
975 |
-
$
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
$
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
$
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
$options['general']['
|
1023 |
-
$options['general']['
|
1024 |
-
$options['general']['
|
1025 |
-
$options['general']['
|
1026 |
-
|
1027 |
-
|
1028 |
-
$options['general']['
|
1029 |
-
$options['general']['
|
1030 |
-
$options['general']['
|
1031 |
-
$options['general']['
|
1032 |
-
$options['general']['
|
1033 |
-
$options['general']['
|
1034 |
-
$options['general']['
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
$options['dyn']['
|
1044 |
-
$options['dyn']['
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
$options['woo']['
|
1050 |
-
|
1051 |
-
|
1052 |
-
$options['woo']['
|
1053 |
-
$options['woo']['
|
1054 |
-
|
1055 |
-
|
1056 |
-
$options['woo']['
|
1057 |
-
$options['woo']['
|
1058 |
-
$options['woo']['
|
1059 |
-
$options['woo']['
|
1060 |
-
|
1061 |
-
|
1062 |
-
$options['woo']['
|
1063 |
-
$options['woo']['
|
1064 |
-
$options['woo']['
|
1065 |
-
$options['woo']['
|
1066 |
-
$options['woo']['
|
1067 |
-
|
1068 |
-
|
1069 |
-
$options['woo']['
|
1070 |
-
$options['woo']['
|
1071 |
-
$options['woo']['
|
1072 |
-
$options['woo']['
|
1073 |
-
|
1074 |
-
|
1075 |
-
$options['woo']['
|
1076 |
-
$options['woo']['
|
1077 |
-
$options['woo']['
|
1078 |
-
$options['woo']['
|
1079 |
-
$options['woo']['
|
1080 |
-
$options['woo']['
|
1081 |
-
|
1082 |
-
|
1083 |
-
$options['woo']['
|
1084 |
-
$options['woo']['
|
1085 |
-
$options['woo']['
|
1086 |
-
|
1087 |
-
|
1088 |
-
$options['woo']['
|
1089 |
-
$options['woo']['
|
1090 |
-
$options['woo']['
|
1091 |
-
$options['woo']['
|
1092 |
-
$options['woo']['
|
1093 |
-
|
1094 |
-
|
1095 |
-
$options['woo']['
|
1096 |
-
$options['woo']['
|
1097 |
-
$options['woo']['
|
1098 |
-
$options['woo']['
|
1099 |
-
$options['woo']['
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
$options['edd']['
|
1109 |
-
$options['edd']['
|
1110 |
-
$options['edd']['
|
1111 |
-
|
1112 |
-
|
1113 |
-
$options['edd']['
|
1114 |
-
$options['edd']['
|
1115 |
-
$options['edd']['
|
1116 |
-
$options['edd']['
|
1117 |
-
$options['edd']['
|
1118 |
-
|
1119 |
-
|
1120 |
-
$options['edd']['
|
1121 |
-
$options['edd']['
|
1122 |
-
$options['edd']['
|
1123 |
-
$options['edd']['
|
1124 |
-
|
1125 |
-
|
1126 |
-
$options['edd']['
|
1127 |
-
$options['edd']['
|
1128 |
-
$options['edd']['
|
1129 |
-
$options['edd']['
|
1130 |
-
|
1131 |
-
|
1132 |
-
$options['edd']['
|
1133 |
-
$options['edd']['
|
1134 |
-
$options['edd']['
|
1135 |
-
$options['edd']['
|
1136 |
-
$options['edd']['
|
1137 |
-
|
1138 |
-
|
1139 |
-
$options['edd']['
|
1140 |
-
$options['edd']['
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
'
|
1162 |
-
'
|
1163 |
-
'
|
1164 |
-
'
|
1165 |
-
'
|
1166 |
-
'
|
1167 |
-
'
|
1168 |
-
'
|
1169 |
-
'
|
1170 |
-
'
|
1171 |
-
'
|
1172 |
-
'
|
1173 |
-
'
|
1174 |
-
'
|
1175 |
-
'
|
1176 |
-
'
|
1177 |
-
'
|
1178 |
-
'
|
1179 |
-
'
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
'
|
1208 |
-
'
|
1209 |
-
'
|
1210 |
-
'
|
1211 |
-
'
|
1212 |
-
'
|
1213 |
-
'
|
1214 |
-
'
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
$params =
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
$
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
$
|
1313 |
-
|
1314 |
-
|
1315 |
-
'
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
/*
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
}
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
}
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
$version = "
|
1357 |
-
}
|
1358 |
-
$version =
|
1359 |
-
}
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
<?php
|
1366 |
-
|
1367 |
-
|
1368 |
-
}
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
$
|
1380 |
-
|
1381 |
-
$
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
}
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
}
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
$_post = $
|
1423 |
-
} elseif (
|
1424 |
-
$_post = $post;
|
1425 |
-
}
|
1426 |
-
|
1427 |
-
}
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
$
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
}
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
*
|
1446 |
-
* @
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
}
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
$option_name = '
|
1475 |
-
}
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
}
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
return version_compare(
|
1501 |
-
} else {
|
1502 |
-
return
|
1503 |
-
}
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
|
|
|
|
1507 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Common functions for both versions.
|
4 |
+
*/
|
5 |
+
|
6 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
7 |
+
exit; // Exit if accessed directly.
|
8 |
+
}
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Check if WooCommerce plugin is installed and activated.
|
12 |
+
*/
|
13 |
+
if( !function_exists( 'pys_is_woocommerce_active' ) ) {
|
14 |
+
|
15 |
+
function pys_is_woocommerce_active() {
|
16 |
+
return class_exists( 'WooCommerce' ) == true ? true : false;
|
17 |
+
}
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Check if Easy Digital Downloads plugin is installed and activated.
|
23 |
+
*/
|
24 |
+
if( !function_exists( 'pys_is_edd_active' ) ) {
|
25 |
+
|
26 |
+
function pys_is_edd_active() {
|
27 |
+
return class_exists( 'Easy_Digital_Downloads' ) == true ? true : false;
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
if ( ! function_exists( 'pys_is_pcf_pro_active' ) ) {
|
33 |
+
|
34 |
+
function pys_is_pcf_pro_active() {
|
35 |
+
return class_exists( 'wpwoof_product_catalog' ) == true ? true : false;
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
if( !function_exists( 'pys_get_option' ) ) {
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Return option value.
|
44 |
+
*
|
45 |
+
* @param string $section Options section, eg. 'general', 'woo', etc.
|
46 |
+
* @param string $option Option name
|
47 |
+
* @param mixed|string $default Default option value
|
48 |
+
*
|
49 |
+
* @return mixed Option or default option value
|
50 |
+
*/
|
51 |
+
function pys_get_option( $section, $option, $default = '' ) {
|
52 |
+
|
53 |
+
$options = get_option( 'pixel_your_site' );
|
54 |
+
|
55 |
+
return isset( $options[ $section ][ $option ] ) ? $options[ $section ][ $option ] : $default;
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
if( !function_exists( 'pys_checkbox_state' ) ) {
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @param string $section Option section name
|
65 |
+
* @param string $option Option name
|
66 |
+
* @param bool $echo Echo or return value
|
67 |
+
* @param int $checked Value to state compare
|
68 |
+
*
|
69 |
+
* @return string
|
70 |
+
*/
|
71 |
+
function pys_checkbox_state( $section, $option, $echo = true, $checked = 1 ) {
|
72 |
+
|
73 |
+
$options = get_option( 'pixel_your_site' );
|
74 |
+
|
75 |
+
if ( isset( $options[ $section ][ $option ] ) ) {
|
76 |
+
$value = $options[ $section ][ $option ] == $checked ? 'checked' : '';
|
77 |
+
} else {
|
78 |
+
$value = '';
|
79 |
+
}
|
80 |
+
|
81 |
+
if( $echo ) {
|
82 |
+
echo $value;
|
83 |
+
}
|
84 |
+
|
85 |
+
return $value;
|
86 |
+
|
87 |
+
}
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
if ( ! function_exists( 'pys_checkbox' ) ) {
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Echos checkbox input.
|
95 |
+
*
|
96 |
+
* @param string $section Input section name
|
97 |
+
* @param string $option Input option name
|
98 |
+
* @param string $classes Class names (optional)
|
99 |
+
* @param int $value Input value (optional)
|
100 |
+
*/
|
101 |
+
function pys_checkbox( $section, $option, $classes = '', $value = 1 ) {
|
102 |
+
|
103 |
+
$state = pys_checkbox_state( $section, $option, false, $value );
|
104 |
+
$value = esc_attr( $value );
|
105 |
+
|
106 |
+
echo "<input type='checkbox' value='$value' name='pys[$section][$option]' class='$classes' $state>";
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
if ( ! function_exists( 'pys_text_field' ) ) {
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Echos text input.
|
116 |
+
*
|
117 |
+
* @param string $section Input section name
|
118 |
+
* @param string $option Input option name
|
119 |
+
*/
|
120 |
+
function pys_text_field( $section, $option ) {
|
121 |
+
|
122 |
+
$value = pys_get_option( $section, $option );
|
123 |
+
$value = esc_attr( $value );
|
124 |
+
|
125 |
+
echo "<input type='text' value='$value' name='pys[$section][$option]'>";
|
126 |
+
|
127 |
+
}
|
128 |
+
|
129 |
+
}
|
130 |
+
|
131 |
+
if ( ! function_exists( 'pys_radio_box' ) ) {
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Echos radio box input.
|
135 |
+
*
|
136 |
+
* @param string $section Input section name
|
137 |
+
* @param string $option Input option name
|
138 |
+
* @param string $value Option value
|
139 |
+
*/
|
140 |
+
function pys_radio_box( $section, $option, $value ) {
|
141 |
+
|
142 |
+
$state = pys_radio_state( $section, $option, $value );
|
143 |
+
echo "<input type='radio' value='$value' name='pys[$section][$option]' $state>";
|
144 |
+
|
145 |
+
}
|
146 |
+
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Return radio box state.
|
151 |
+
*/
|
152 |
+
if( !function_exists( 'pys_radio_state' ) ) {
|
153 |
+
|
154 |
+
function pys_radio_state( $section, $option, $value ) {
|
155 |
+
|
156 |
+
$options = get_option( 'pixel_your_site' );
|
157 |
+
|
158 |
+
if ( isset( $options[ $section ][ $option ] ) ) {
|
159 |
+
|
160 |
+
return $options[ $section ][ $option ] == $value ? 'checked' : '';
|
161 |
+
|
162 |
+
} else {
|
163 |
+
|
164 |
+
$defaults = pys_get_default_options();
|
165 |
+
return $defaults[ $section ][ $option ] == $value ? 'checked' : '';
|
166 |
+
|
167 |
+
}
|
168 |
+
|
169 |
+
}
|
170 |
+
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Facebook Pixel Event types options html.
|
175 |
+
*/
|
176 |
+
if( !function_exists( 'pys_event_types_select_options' ) ) {
|
177 |
+
|
178 |
+
function pys_event_types_select_options( $current = null, $full = true ) {
|
179 |
+
?>
|
180 |
+
|
181 |
+
<option <?php selected( null, $current ); ?> disabled>Select Type</option>
|
182 |
+
<option <?php selected( 'ViewContent', $current ); ?> value="ViewContent">ViewContent</option>
|
183 |
+
|
184 |
+
<?php if ( $full ) : ?>
|
185 |
+
|
186 |
+
<option <?php selected( 'Search', $current ); ?> value="Search">Search</option>
|
187 |
+
|
188 |
+
<?php endif; ?>
|
189 |
+
|
190 |
+
<option <?php selected( 'AddToCart', $current ); ?> value="AddToCart">AddToCart</option>
|
191 |
+
<option <?php selected( 'AddToWishlist', $current ); ?> value="AddToWishlist">AddToWishlist</option>
|
192 |
+
<option <?php selected( 'InitiateCheckout', $current ); ?> value="InitiateCheckout">InitiateCheckout</option>
|
193 |
+
<option <?php selected( 'AddPaymentInfo', $current ); ?> value="AddPaymentInfo">AddPaymentInfo</option>
|
194 |
+
<option <?php selected( 'Purchase', $current ); ?> value="Purchase">Purchase</option>
|
195 |
+
<option <?php selected( 'Lead', $current ); ?> value="Lead">Lead</option>
|
196 |
+
<option <?php selected( 'CompleteRegistration', $current ); ?> value="CompleteRegistration">CompleteRegistration</option>
|
197 |
+
|
198 |
+
<?php if ( $full ) : ?>
|
199 |
+
|
200 |
+
<option disabled></option>
|
201 |
+
<option <?php selected( 'CustomEvent', $current ); ?> value="CustomEvent">Custom event</option>
|
202 |
+
<option <?php selected( 'CustomCode', $current); ?> value="CustomCode">Custom event code</option>
|
203 |
+
|
204 |
+
<?php endif; ?>
|
205 |
+
|
206 |
+
<?php
|
207 |
+
}
|
208 |
+
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Current Page Full URL without trailing slash
|
213 |
+
*/
|
214 |
+
if( !function_exists( 'pys_get_current_url' ) ) {
|
215 |
+
|
216 |
+
function pys_get_current_url() {
|
217 |
+
|
218 |
+
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
219 |
+
$current_url = rtrim( $current_url, '/' );
|
220 |
+
|
221 |
+
return $current_url;
|
222 |
+
|
223 |
+
}
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Returns relative path without protocol, host, slashes.
|
229 |
+
*/
|
230 |
+
if( !function_exists( 'pys_get_relative_path' ) ) {
|
231 |
+
|
232 |
+
function pys_get_relative_path( $url ) {
|
233 |
+
|
234 |
+
$host = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', home_url() );
|
235 |
+
|
236 |
+
$url = str_replace( array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' ), '', $url );
|
237 |
+
$url = str_replace( $host, '', $url );
|
238 |
+
|
239 |
+
$url = trim( $url );
|
240 |
+
$url = ltrim( $url, '/' );
|
241 |
+
$url = rtrim( $url, '/' );
|
242 |
+
|
243 |
+
return $url;
|
244 |
+
|
245 |
+
}
|
246 |
+
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Check if needle URL (full or relative) matches with current.
|
251 |
+
*/
|
252 |
+
if( !function_exists( 'pys_match_url' ) ) {
|
253 |
+
|
254 |
+
function pys_match_url( $match_url, $current_url = '' ) {
|
255 |
+
|
256 |
+
// use current url by default
|
257 |
+
if ( ! isset( $current_url ) || empty( $current_url ) ) {
|
258 |
+
$current_url = pys_get_current_url();
|
259 |
+
}
|
260 |
+
|
261 |
+
$current_url = pys_get_relative_path( $current_url );
|
262 |
+
$match_url = pys_get_relative_path( $match_url );
|
263 |
+
|
264 |
+
if ( substr( $match_url, - 1 ) == '*' ) {
|
265 |
+
// if match_url ends with wildcard
|
266 |
+
|
267 |
+
$match_url = rtrim( $match_url, '*' );
|
268 |
+
|
269 |
+
if ( pys_startsWith( $current_url, $match_url ) ) {
|
270 |
+
return true;
|
271 |
+
}
|
272 |
+
|
273 |
+
} else {
|
274 |
+
// exact url
|
275 |
+
|
276 |
+
if ( $current_url == $match_url ) {
|
277 |
+
return true;
|
278 |
+
}
|
279 |
+
|
280 |
+
}
|
281 |
+
|
282 |
+
return false;
|
283 |
+
|
284 |
+
}
|
285 |
+
|
286 |
+
}
|
287 |
+
|
288 |
+
if( !function_exists( 'pys_startsWith' ) ) {
|
289 |
+
|
290 |
+
function pys_startsWith( $haystack, $needle ) {
|
291 |
+
// search backwards starting from haystack length characters from the end
|
292 |
+
return $needle === "" || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
|
293 |
+
}
|
294 |
+
|
295 |
+
}
|
296 |
+
|
297 |
+
if( !function_exists( 'pys_endsWith' ) ) {
|
298 |
+
|
299 |
+
function pys_endsWith( $haystack, $needle ) {
|
300 |
+
// search forward starting from end minus needle length characters
|
301 |
+
return $needle === "" || ( ( $temp = strlen( $haystack ) - strlen( $needle ) ) >= 0 && strpos( $haystack, $needle, $temp ) !== false );
|
302 |
+
}
|
303 |
+
|
304 |
+
}
|
305 |
+
|
306 |
+
if( !function_exists( 'pys_currency_options' ) ) {
|
307 |
+
|
308 |
+
function pys_currency_options( $current = 'USD' ) {
|
309 |
+
|
310 |
+
$currencies = apply_filters( 'pys_currencies_list', array(
|
311 |
+
'AUD' => 'Australian Dollar',
|
312 |
+
'BRL' => 'Brazilian Real',
|
313 |
+
'CAD' => 'Canadian Dollar',
|
314 |
+
'CZK' => 'Czech Koruna',
|
315 |
+
'DKK' => 'Danish Krone',
|
316 |
+
'EUR' => 'Euro',
|
317 |
+
'HKD' => 'Hong Kong Dollar',
|
318 |
+
'HUF' => 'Hungarian Forint',
|
319 |
+
'IDR' => 'Indonesian Rupiah',
|
320 |
+
'ILS' => 'Israeli New Sheqel',
|
321 |
+
'JPY' => 'Japanese Yen',
|
322 |
+
'KRW' => 'Korean Won',
|
323 |
+
'MYR' => 'Malaysian Ringgit',
|
324 |
+
'MXN' => 'Mexican Peso',
|
325 |
+
'NOK' => 'Norwegian Krone',
|
326 |
+
'NZD' => 'New Zealand Dollar',
|
327 |
+
'PHP' => 'Philippine Peso',
|
328 |
+
'PLN' => 'Polish Zloty',
|
329 |
+
'RON' => 'Romanian Leu',
|
330 |
+
'GBP' => 'Pound Sterling',
|
331 |
+
'SGD' => 'Singapore Dollar',
|
332 |
+
'SEK' => 'Swedish Krona',
|
333 |
+
'CHF' => 'Swiss Franc',
|
334 |
+
'TWD' => 'Taiwan New Dollar',
|
335 |
+
'THB' => 'Thai Baht',
|
336 |
+
'TRY' => 'Turkish Lira',
|
337 |
+
'USD' => 'U.S. Dollar',
|
338 |
+
'ZAR' => 'South African Rands'
|
339 |
+
) );
|
340 |
+
|
341 |
+
foreach( $currencies as $symbol => $name ) {
|
342 |
+
echo '<option ' . selected( $symbol, $current, false ) . ' value="' . esc_attr( $symbol ) . '">' . esc_html( $name ) . '</option>';
|
343 |
+
}
|
344 |
+
|
345 |
+
}
|
346 |
+
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Extract Object taxonomies list.
|
351 |
+
*/
|
352 |
+
if( !function_exists( 'pys_get_content_taxonomies' ) ) {
|
353 |
+
|
354 |
+
function pys_get_content_taxonomies( $taxonomy = 'category', $post_id = null ) {
|
355 |
+
|
356 |
+
$post_id = isset( $post_id ) ? $post_id : get_the_ID();
|
357 |
+
$terms = get_the_terms( $post_id, $taxonomy );
|
358 |
+
|
359 |
+
if ( is_wp_error( $terms ) || empty ( $terms ) ) {
|
360 |
+
return false;
|
361 |
+
}
|
362 |
+
|
363 |
+
$list = array();
|
364 |
+
|
365 |
+
foreach( $terms as $term ) {
|
366 |
+
$list[ $term->term_id ] = html_entity_decode( $term->name );
|
367 |
+
}
|
368 |
+
|
369 |
+
return implode( ', ', $list );
|
370 |
+
|
371 |
+
}
|
372 |
+
|
373 |
+
}
|
374 |
+
|
375 |
+
if( !function_exists( 'pys_add_event' ) ) {
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Add event with params to global events list.
|
379 |
+
*
|
380 |
+
* @param string $event Event name, eg. "PageView"
|
381 |
+
* @param array $params Optional. Associated array of event parameters in 'param_name' => 'param_value' format.
|
382 |
+
* @param int $delay Optional. If set, event will be fired with desired delay in seconds.
|
383 |
+
*/
|
384 |
+
function pys_add_event( $event, $params = array(), $delay = 0 ) {
|
385 |
+
global $pys_events;
|
386 |
+
|
387 |
+
$params = apply_filters( 'pys_event_params', $params, $event );
|
388 |
+
|
389 |
+
$sanitized = array();
|
390 |
+
|
391 |
+
// sanitize param names and its values
|
392 |
+
foreach ( $params as $name => $value ) {
|
393 |
+
|
394 |
+
// skip empty but not zero values
|
395 |
+
if ( empty( $value ) && ! is_numeric( $value ) ) {
|
396 |
+
continue;
|
397 |
+
}
|
398 |
+
|
399 |
+
$key = esc_js( $name );
|
400 |
+
$sanitized[ $key ] = $value;
|
401 |
+
|
402 |
+
}
|
403 |
+
|
404 |
+
$pys_events[] = array(
|
405 |
+
'type' => pys_is_standard_event( $event ) ? 'track' : 'trackCustom',
|
406 |
+
'name' => $event,
|
407 |
+
'params' => $sanitized,
|
408 |
+
'delay' => $delay
|
409 |
+
);
|
410 |
+
|
411 |
+
}
|
412 |
+
|
413 |
+
}
|
414 |
+
|
415 |
+
if ( ! function_exists( 'pys_get_product_content_id' ) ) {
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Return product id or sku.
|
419 |
+
*/
|
420 |
+
function pys_get_product_content_id( $product_id ) {
|
421 |
+
|
422 |
+
$content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
|
423 |
+
|
424 |
+
if ( pys_get_option( 'woo', 'content_id' ) == 'sku' ) {
|
425 |
+
$content_id = get_post_meta( $product_id, '_sku', true );
|
426 |
+
} else {
|
427 |
+
$content_id = intval( $product_id );
|
428 |
+
}
|
429 |
+
|
430 |
+
return apply_filters( 'pys_fb_pixel_woo_product_content_id', array( $content_id ), $product_id,
|
431 |
+
$content_id_format );
|
432 |
+
|
433 |
+
}
|
434 |
+
|
435 |
+
}
|
436 |
+
|
437 |
+
if ( ! function_exists( 'pys_get_woo_cart_item_product_id' ) ) {
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Return main or variation product id.
|
441 |
+
*/
|
442 |
+
function pys_get_woo_cart_item_product_id( $cart_item ) {
|
443 |
+
|
444 |
+
$content_id_format = pys_get_option( 'woo', 'content_id_format', 'default' );
|
445 |
+
|
446 |
+
if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
|
447 |
+
$product_id = $cart_item['variation_id'];
|
448 |
+
} else {
|
449 |
+
$product_id = $cart_item['product_id'];
|
450 |
+
}
|
451 |
+
|
452 |
+
return apply_filters( 'pys_fb_pixel_woo_cart_item_product_id', $product_id, $cart_item, $content_id_format );
|
453 |
+
|
454 |
+
}
|
455 |
+
|
456 |
+
}
|
457 |
+
|
458 |
+
if ( ! function_exists( 'pys_insert_attribute' ) ) {
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Add attribute with value to a HTML tag.
|
462 |
+
*
|
463 |
+
* @param string $attr_name Attribute name, eg. "class"
|
464 |
+
* @param string $attr_value Attribute value
|
465 |
+
* @param string $content HTML content where attribute should be inserted
|
466 |
+
* @param bool $overwrite Override existing value of attribute or append it
|
467 |
+
* @param string $tag Selector name, eg. "button". Default "a"
|
468 |
+
*
|
469 |
+
* @return string Modified HTML content
|
470 |
+
*/
|
471 |
+
function pys_insert_attribute( $attr_name, $attr_value, $content, $overwrite = false, $tag = 'a' ) {
|
472 |
+
|
473 |
+
## do not modify js attributes
|
474 |
+
if( $attr_name == 'on' ) {
|
475 |
+
return $content;
|
476 |
+
}
|
477 |
+
|
478 |
+
$attr_value = trim( $attr_value );
|
479 |
+
|
480 |
+
try {
|
481 |
+
|
482 |
+
$doc = new DOMDocument();
|
483 |
+
|
484 |
+
/**
|
485 |
+
* Old libxml does not support options parameter.
|
486 |
+
*
|
487 |
+
* @since 3.2.0
|
488 |
+
*/
|
489 |
+
if ( defined( 'LIBXML_DOTTED_VERSION' ) && version_compare( LIBXML_DOTTED_VERSION, '2.6.0', '>=' ) &&
|
490 |
+
version_compare( phpversion(), '5.4.0', '>=' )
|
491 |
+
) {
|
492 |
+
@$doc->loadHTML( '<?xml encoding="UTF-8">' . $content, LIBXML_NOEMPTYTAG );
|
493 |
+
} else {
|
494 |
+
@$doc->loadHTML( '<?xml encoding="UTF-8">' . $content );
|
495 |
+
}
|
496 |
+
|
497 |
+
/**
|
498 |
+
* Select top-level tag if it is not specified in args.
|
499 |
+
*
|
500 |
+
* @since: 5.0.6
|
501 |
+
*/
|
502 |
+
if ( $tag == 'any' ) {
|
503 |
+
|
504 |
+
/** @var DOMNodeList $node */
|
505 |
+
$node = $doc->getElementsByTagName( 'body' );
|
506 |
+
|
507 |
+
if ( $node->length == 0 ) {
|
508 |
+
throw new Exception( 'Empty or wrong tag passed to filter.' );
|
509 |
+
}
|
510 |
+
|
511 |
+
$node = $node->item( 0 )->childNodes->item( 0 );
|
512 |
+
|
513 |
+
} else {
|
514 |
+
$node = $doc->getElementsByTagName( $tag )->item( 0 );
|
515 |
+
}
|
516 |
+
|
517 |
+
if ( is_null( $node ) ) {
|
518 |
+
return $content;
|
519 |
+
}
|
520 |
+
|
521 |
+
/** @noinspection PhpUndefinedMethodInspection */
|
522 |
+
$attribute = $node->getAttribute( $attr_name );
|
523 |
+
|
524 |
+
// add attribute or override old one
|
525 |
+
if ( empty( $attribute ) || $overwrite ) {
|
526 |
+
|
527 |
+
/** @noinspection PhpUndefinedMethodInspection */
|
528 |
+
$node->setAttribute( $attr_name, $attr_value );
|
529 |
+
|
530 |
+
return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
|
531 |
+
|
532 |
+
}
|
533 |
+
|
534 |
+
// append value to exist attribute
|
535 |
+
if ( $overwrite == false ) {
|
536 |
+
|
537 |
+
$value = $attribute . ' ' . $attr_value;
|
538 |
+
/** @noinspection PhpUndefinedMethodInspection */
|
539 |
+
$node->setAttribute( $attr_name, $value );
|
540 |
+
|
541 |
+
return str_replace( array( '<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>' ), null, $doc->saveHTML() );
|
542 |
+
|
543 |
+
}
|
544 |
+
|
545 |
+
} catch ( Exception $e ) {
|
546 |
+
|
547 |
+
error_log( $e );
|
548 |
+
|
549 |
+
}
|
550 |
+
|
551 |
+
return $content;
|
552 |
+
|
553 |
+
}
|
554 |
+
|
555 |
+
}
|
556 |
+
|
557 |
+
if ( ! function_exists( 'pys_is_disabled_for_role' ) ) {
|
558 |
+
|
559 |
+
function pys_is_disabled_for_role() {
|
560 |
+
|
561 |
+
$options = get_option( 'pixel_your_site' );
|
562 |
+
$disabled_roles = $options['general'];
|
563 |
+
|
564 |
+
$user = wp_get_current_user();
|
565 |
+
foreach ( (array) $user->roles as $role ) {
|
566 |
+
|
567 |
+
if ( array_key_exists( "disable_for_$role", $disabled_roles ) ) {
|
568 |
+
|
569 |
+
add_action( 'wp_head', 'pys_head_message', 1 );
|
570 |
+
return true;
|
571 |
+
|
572 |
+
}
|
573 |
+
|
574 |
+
}
|
575 |
+
|
576 |
+
if( empty( $user->roles ) && isset( $disabled_roles['disable_for_guest'] ) ) {
|
577 |
+
|
578 |
+
add_action( 'wp_head', 'pys_head_message', 1 );
|
579 |
+
return true;
|
580 |
+
|
581 |
+
}
|
582 |
+
|
583 |
+
return false;
|
584 |
+
|
585 |
+
}
|
586 |
+
|
587 |
+
}
|
588 |
+
|
589 |
+
if( ! function_exists( 'pys_head_message' ) ) {
|
590 |
+
|
591 |
+
/**
|
592 |
+
* Output "disabled for role" and version number message to document head.
|
593 |
+
*/
|
594 |
+
function pys_head_message() {
|
595 |
+
echo "<!-- Facebook Pixel Code disabled for current role ( " . pys_get_version() . " ) -->\r\n";
|
596 |
+
}
|
597 |
+
|
598 |
+
}
|
599 |
+
|
600 |
+
if( ! function_exists( 'pys_get_version' ) ) {
|
601 |
+
|
602 |
+
function pys_get_version() {
|
603 |
+
|
604 |
+
if( defined('PYS_PRO_VERSION') ) {
|
605 |
+
$version = "PixelYourSite PRO v".PYS_PRO_VERSION;
|
606 |
+
} elseif( defined('PYS_FREE_VERSION') ) {
|
607 |
+
$version = "PixelYourSite FREE v".PYS_FREE_VERSION;
|
608 |
+
} else {
|
609 |
+
$version = null;
|
610 |
+
}
|
611 |
+
|
612 |
+
return $version;
|
613 |
+
|
614 |
+
}
|
615 |
+
|
616 |
+
}
|
617 |
+
|
618 |
+
if( ! function_exists( 'pys_page_view_event' ) ) {
|
619 |
+
|
620 |
+
/*
|
621 |
+
* PageView event. Present on each page if pixel setup is enabled.
|
622 |
+
*/
|
623 |
+
function pys_page_view_event() {
|
624 |
+
pys_add_event( 'PageView' );
|
625 |
+
}
|
626 |
+
|
627 |
+
}
|
628 |
+
|
629 |
+
if( ! function_exists( 'pys_general_event' ) ) {
|
630 |
+
|
631 |
+
function pys_general_event() {
|
632 |
+
global $post;
|
633 |
+
|
634 |
+
if ( pys_get_option( 'general', 'general_event_enabled' ) == false ) {
|
635 |
+
return;
|
636 |
+
}
|
637 |
+
|
638 |
+
$params = array();
|
639 |
+
$event_name = pys_get_option( 'general', 'general_event_name' );
|
640 |
+
$post_type = get_post_type();
|
641 |
+
$delay = floatval( pys_get_option( 'general', 'general_event_delay', 0 ) );
|
642 |
+
|
643 |
+
$on_posts_enabled = pys_get_option( 'general', 'general_event_on_posts_enabled' );
|
644 |
+
$on_pages_enables = pys_get_option( 'general', 'general_event_on_pages_enabled' );
|
645 |
+
$on_taxonomies_enabled = pys_get_option( 'general', 'general_event_on_tax_enabled' );
|
646 |
+
$on_cpt_enabled = pys_get_option( 'general', 'general_event_on_' . $post_type . '_enabled' );
|
647 |
+
$on_woo_enabled = pys_get_option( 'general', 'general_event_on_woo_enabled' );
|
648 |
+
$on_edd_enabled = pys_get_option( 'general', 'general_event_on_edd_enabled' );
|
649 |
+
$track_tags_enabled = pys_get_option( 'general', 'general_event_add_tags', false );
|
650 |
+
|
651 |
+
// Posts
|
652 |
+
if ( $on_posts_enabled && is_singular( 'post' ) ) {
|
653 |
+
|
654 |
+
$params['post_type'] = 'post';
|
655 |
+
$params['content_name'] = $post->post_title;
|
656 |
+
$params['post_id'] = $post->ID;
|
657 |
+
|
658 |
+
if ( $terms = pys_get_content_taxonomies() ) {
|
659 |
+
$params['content_category'] = $terms;
|
660 |
+
}
|
661 |
+
|
662 |
+
if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
|
663 |
+
$params['tags'] = implode( ', ', $tags );
|
664 |
+
}
|
665 |
+
|
666 |
+
pys_add_event( $event_name, $params, $delay );
|
667 |
+
|
668 |
+
return;
|
669 |
+
|
670 |
+
}
|
671 |
+
|
672 |
+
// Pages or Front Page
|
673 |
+
if ( $on_pages_enables && ( is_singular( 'page' ) || is_home() ) ) {
|
674 |
+
|
675 |
+
// exclude WooCommerce Cart page
|
676 |
+
if ( pys_is_woocommerce_active() && is_cart() ) {
|
677 |
+
return;
|
678 |
+
}
|
679 |
+
|
680 |
+
$params['post_type'] = 'page';
|
681 |
+
$params['content_name'] = is_home() == true ? get_bloginfo( 'name' ) : $post->post_title;
|
682 |
+
|
683 |
+
is_home() != true ? $params['post_id'] = $post->ID : null;
|
684 |
+
|
685 |
+
pys_add_event( $event_name, $params, $delay );
|
686 |
+
|
687 |
+
return;
|
688 |
+
|
689 |
+
}
|
690 |
+
|
691 |
+
// WooCommerce Shop page
|
692 |
+
if ( $on_pages_enables && pys_is_woocommerce_active() && is_shop() ) {
|
693 |
+
|
694 |
+
$page_id = wc_get_page_id( 'shop' );
|
695 |
+
|
696 |
+
$params['post_type'] = 'page';
|
697 |
+
$params['post_id'] = $page_id;
|
698 |
+
$params['content_name'] = get_the_title( $page_id );;
|
699 |
+
|
700 |
+
pys_add_event( $event_name, $params, $delay );
|
701 |
+
|
702 |
+
return;
|
703 |
+
|
704 |
+
}
|
705 |
+
|
706 |
+
// Taxonomies (built-in and custom)
|
707 |
+
if ( $on_taxonomies_enabled && ( is_category() || is_tax() || is_tag() ) ) {
|
708 |
+
|
709 |
+
$term = null;
|
710 |
+
$type = null;
|
711 |
+
|
712 |
+
if ( is_category() ) {
|
713 |
+
|
714 |
+
$cat = get_query_var( 'cat' );
|
715 |
+
$term = get_category( $cat );
|
716 |
+
|
717 |
+
$params['post_type'] = 'category';
|
718 |
+
$params['content_name'] = $term->name;
|
719 |
+
$params['post_id'] = $cat;
|
720 |
+
|
721 |
+
} elseif ( is_tag() ) {
|
722 |
+
|
723 |
+
$slug = get_query_var( 'tag' );
|
724 |
+
$term = get_term_by( 'slug', $slug, 'post_tag' );
|
725 |
+
|
726 |
+
$params['post_type'] = 'tag';
|
727 |
+
$params['content_name'] = $term->name;
|
728 |
+
$params['post_id'] = $term->term_id;
|
729 |
+
|
730 |
+
} else {
|
731 |
+
|
732 |
+
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
|
733 |
+
|
734 |
+
$params['post_type'] = get_query_var( 'taxonomy' );
|
735 |
+
$params['content_name'] = $term->name;
|
736 |
+
$params['post_id'] = $term->term_id;
|
737 |
+
|
738 |
+
}
|
739 |
+
|
740 |
+
pys_add_event( $event_name, $params, $delay );
|
741 |
+
|
742 |
+
return;
|
743 |
+
|
744 |
+
}
|
745 |
+
|
746 |
+
// Custom Post Type
|
747 |
+
if ( $on_cpt_enabled && $post_type != 'post' && $post_type != 'page' ) {
|
748 |
+
|
749 |
+
// skip products and downloads is plugins are activated
|
750 |
+
if ( ( pys_is_woocommerce_active() && $post_type == 'product' ) || ( pys_is_edd_active() && $post_type == 'download' ) ) {
|
751 |
+
return;
|
752 |
+
}
|
753 |
+
|
754 |
+
$params['post_type'] = $post_type;
|
755 |
+
$params['content_name'] = $post->post_title;
|
756 |
+
$params['post_id'] = $post->ID;
|
757 |
+
|
758 |
+
$taxonomies = get_post_taxonomies( get_post() );
|
759 |
+
$terms = pys_get_content_taxonomies( $taxonomies[0] );
|
760 |
+
if ( $terms ) {
|
761 |
+
$params['content_category'] = $terms;
|
762 |
+
}
|
763 |
+
|
764 |
+
if ( $track_tags_enabled && $tags = pys_get_post_tags( $post->ID ) ) {
|
765 |
+
$params['tags'] = implode( ', ', $tags );
|
766 |
+
}
|
767 |
+
|
768 |
+
pys_add_event( $event_name, $params, $delay );
|
769 |
+
|
770 |
+
return;
|
771 |
+
|
772 |
+
}
|
773 |
+
|
774 |
+
## WooCommerce Products
|
775 |
+
if ( $on_woo_enabled && pys_is_woocommerce_active() && $post_type == 'product' ) {
|
776 |
+
|
777 |
+
pys_general_woo_event( $post, $track_tags_enabled, $delay, $event_name );
|
778 |
+
return;
|
779 |
+
|
780 |
+
}
|
781 |
+
|
782 |
+
## Easy Digital Downloads
|
783 |
+
if ( $on_edd_enabled && pys_is_edd_active() && $post_type == 'download' ) {
|
784 |
+
|
785 |
+
pys_general_edd_event( $post, $track_tags_enabled, $delay, $event_name );
|
786 |
+
return;
|
787 |
+
|
788 |
+
}
|
789 |
+
|
790 |
+
}
|
791 |
+
|
792 |
+
}
|
793 |
+
|
794 |
+
if( ! function_exists( 'pys_search_event' ) ) {
|
795 |
+
|
796 |
+
function pys_search_event() {
|
797 |
+
|
798 |
+
if ( pys_get_option( 'general', 'search_event_enabled' ) == false || is_search() == false || ! isset( $_REQUEST['s'] ) ) {
|
799 |
+
return;
|
800 |
+
}
|
801 |
+
|
802 |
+
pys_add_event( 'Search', array(
|
803 |
+
'search_string' => $_REQUEST['s']
|
804 |
+
) );
|
805 |
+
|
806 |
+
}
|
807 |
+
|
808 |
+
}
|
809 |
+
|
810 |
+
if( ! function_exists( 'pys_standard_events' ) ) {
|
811 |
+
|
812 |
+
function pys_standard_events() {
|
813 |
+
global $pys_custom_events;
|
814 |
+
|
815 |
+
$std_events = get_option( 'pixel_your_site_std_events', array() );
|
816 |
+
|
817 |
+
if ( pys_get_option( 'std', 'enabled' ) == false || empty( $std_events ) ) {
|
818 |
+
return;
|
819 |
+
}
|
820 |
+
|
821 |
+
foreach ( $std_events as $event ) {
|
822 |
+
|
823 |
+
// skip wrong events
|
824 |
+
if( ! isset( $event['pageurl'] ) || ! isset( $event['eventtype'] ) ) {
|
825 |
+
continue;
|
826 |
+
}
|
827 |
+
|
828 |
+
// skip if current page does not match URL filter
|
829 |
+
if ( pys_match_url( $event['pageurl'] ) == false ) {
|
830 |
+
continue;
|
831 |
+
}
|
832 |
+
|
833 |
+
if ( $event['eventtype'] == 'CustomCode' ) {
|
834 |
+
|
835 |
+
$custom_code = $event['code'];
|
836 |
+
$custom_code = stripcslashes( $custom_code );
|
837 |
+
$custom_code = trim( $custom_code );
|
838 |
+
|
839 |
+
// add custom code to global custom events array
|
840 |
+
$pys_custom_events[] = $custom_code;
|
841 |
+
|
842 |
+
} else {
|
843 |
+
|
844 |
+
$type = $event['eventtype'];
|
845 |
+
$params = pys_clean_system_event_params( $event );
|
846 |
+
|
847 |
+
pys_add_event( $type, $params );
|
848 |
+
|
849 |
+
}
|
850 |
+
|
851 |
+
}
|
852 |
+
|
853 |
+
}
|
854 |
+
|
855 |
+
}
|
856 |
+
|
857 |
+
if( !function_exists( 'pys_pixel_init_event' ) ) {
|
858 |
+
|
859 |
+
function pys_pixel_init_event() {
|
860 |
+
global $pys_events;
|
861 |
+
|
862 |
+
$pys_events[] = array(
|
863 |
+
'type' => 'init',
|
864 |
+
'name' => pys_get_option( 'general', 'pixel_id' ),
|
865 |
+
'params' => pys_pixel_init_params()
|
866 |
+
);
|
867 |
+
|
868 |
+
}
|
869 |
+
|
870 |
+
}
|
871 |
+
|
872 |
+
if( ! function_exists( 'pys_output_noscript_code' ) ) {
|
873 |
+
|
874 |
+
function pys_output_noscript_code() {
|
875 |
+
global $pys_events;
|
876 |
+
|
877 |
+
if( empty( $pys_events ) ) {
|
878 |
+
return;
|
879 |
+
}
|
880 |
+
|
881 |
+
foreach( $pys_events as $event ) {
|
882 |
+
|
883 |
+
$args = array();
|
884 |
+
|
885 |
+
if( $event['type'] == 'init' ) {
|
886 |
+
continue;
|
887 |
+
}
|
888 |
+
|
889 |
+
$args['id'] = pys_get_option( 'general', 'pixel_id' );
|
890 |
+
$args['ev'] = $event['name'];
|
891 |
+
$args['noscript'] = 1;
|
892 |
+
|
893 |
+
foreach ( $event['params'] as $param => $value ) {
|
894 |
+
@$args[ 'cd[' . $param . ']' ] = urlencode( $value );
|
895 |
+
}
|
896 |
+
|
897 |
+
$src_attr = add_query_arg( $args, 'https://www.facebook.com/tr' );
|
898 |
+
|
899 |
+
// note: ALT tag used to pass ADA compliance
|
900 |
+
// @see: issue #63 for details
|
901 |
+
|
902 |
+
echo "<noscript><img height='1' width='1' style='display: none;' src='{$src_attr}' alt='facebook_pixel'></noscript>";
|
903 |
+
|
904 |
+
}
|
905 |
+
|
906 |
+
}
|
907 |
+
|
908 |
+
}
|
909 |
+
|
910 |
+
if( ! function_exists( 'pys_output_js_events_code' ) ) {
|
911 |
+
|
912 |
+
function pys_output_js_events_code() {
|
913 |
+
global $pys_events;
|
914 |
+
|
915 |
+
// allow external plugins modify events
|
916 |
+
$pys_events = apply_filters( 'pys_prepared_events', $pys_events );
|
917 |
+
|
918 |
+
if( empty( $pys_events ) ) {
|
919 |
+
return;
|
920 |
+
}
|
921 |
+
|
922 |
+
wp_localize_script( 'pys-public', 'pys_events', $pys_events );
|
923 |
+
|
924 |
+
}
|
925 |
+
|
926 |
+
}
|
927 |
+
|
928 |
+
if( ! function_exists( 'pys_output_custom_events_code' ) ) {
|
929 |
+
|
930 |
+
function pys_output_custom_events_code() {
|
931 |
+
global $pys_custom_events;
|
932 |
+
|
933 |
+
if( empty( $pys_custom_events ) ) {
|
934 |
+
return;
|
935 |
+
}
|
936 |
+
|
937 |
+
wp_localize_script( 'pys-public', 'pys_customEvents', $pys_custom_events );
|
938 |
+
|
939 |
+
}
|
940 |
+
|
941 |
+
}
|
942 |
+
|
943 |
+
if( !function_exists( 'pys_clean_system_event_params' ) ) {
|
944 |
+
|
945 |
+
function pys_clean_system_event_params( $params ) {
|
946 |
+
|
947 |
+
// remove unused params
|
948 |
+
unset( $params['pageurl'] );
|
949 |
+
unset( $params['eventtype'] );
|
950 |
+
unset( $params['code'] );
|
951 |
+
unset( $params['trigger_type'] ); // pro
|
952 |
+
unset( $params['custom_currency'] ); // pro
|
953 |
+
unset( $params['url'] ); // pro
|
954 |
+
unset( $params['css'] ); // pro
|
955 |
+
unset( $params['custom_name'] ); // custom events
|
956 |
+
unset( $params['scroll_pos'] ); // pro
|
957 |
+
unset( $params['url_filter'] ); // pro - dynamic events
|
958 |
+
|
959 |
+
return $params;
|
960 |
+
|
961 |
+
}
|
962 |
+
|
963 |
+
}
|
964 |
+
|
965 |
+
if( !function_exists( 'pys_get_woo_checkout_params' ) ) {
|
966 |
+
|
967 |
+
function pys_get_woo_checkout_params( $additional_params_enabled ) {
|
968 |
+
global $woocommerce;
|
969 |
+
|
970 |
+
// set defaults params
|
971 |
+
$params = array();
|
972 |
+
$params['content_type'] = 'product';
|
973 |
+
|
974 |
+
$ids = array(); // cart items ids or sku
|
975 |
+
$names = ''; // cart items names
|
976 |
+
$categories = ''; // cart items categories
|
977 |
+
|
978 |
+
foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
|
979 |
+
|
980 |
+
$product_id = pys_get_woo_cart_item_product_id( $item );
|
981 |
+
$ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
|
982 |
+
|
983 |
+
// content_name, category_name for each cart item
|
984 |
+
if ( $additional_params_enabled ) {
|
985 |
+
|
986 |
+
$temp = array();
|
987 |
+
pys_get_additional_woo_params( $product_id, $temp );
|
988 |
+
|
989 |
+
$names .= isset( $temp['content_name'] ) ? $temp['content_name'] . ' ' : null;
|
990 |
+
$categories .= isset( $temp['category_name'] ) ? $temp['category_name'] . ' ' : null;
|
991 |
+
|
992 |
+
}
|
993 |
+
|
994 |
+
}
|
995 |
+
|
996 |
+
if ( $additional_params_enabled ) {
|
997 |
+
$params['num_items'] = $woocommerce->cart->get_cart_contents_count();
|
998 |
+
}
|
999 |
+
|
1000 |
+
$params['content_ids'] = json_encode( $ids );
|
1001 |
+
|
1002 |
+
if ( ! empty( $names ) ) {
|
1003 |
+
$params['content_name'] = $names;
|
1004 |
+
}
|
1005 |
+
|
1006 |
+
if ( ! empty( $categories ) ) {
|
1007 |
+
$params['category_name'] = $categories;
|
1008 |
+
}
|
1009 |
+
|
1010 |
+
return $params;
|
1011 |
+
|
1012 |
+
}
|
1013 |
+
|
1014 |
+
}
|
1015 |
+
|
1016 |
+
if( !function_exists( 'pys_get_default_options' ) ) {
|
1017 |
+
|
1018 |
+
function pys_get_default_options() {
|
1019 |
+
|
1020 |
+
$options = array();
|
1021 |
+
|
1022 |
+
$options['general']['pixel_id'] = '';
|
1023 |
+
$options['general']['enabled'] = 0;
|
1024 |
+
$options['general']['add_traffic_source'] = 1;
|
1025 |
+
$options['general']['enable_advance_matching'] = 1;
|
1026 |
+
$options['general']['in_footer'] = 0;
|
1027 |
+
|
1028 |
+
$options['general']['general_event_enabled'] = 1;
|
1029 |
+
$options['general']['general_event_name'] = 'GeneralEvent';
|
1030 |
+
$options['general']['general_event_on_posts_enabled'] = 1;
|
1031 |
+
$options['general']['general_event_on_pages_enabled'] = 1;
|
1032 |
+
$options['general']['general_event_on_tax_enabled'] = 1;
|
1033 |
+
$options['general']['general_event_on_woo_enabled'] = 0;
|
1034 |
+
$options['general']['general_event_on_edd_enabled'] = 0;
|
1035 |
+
$options['general']['general_event_add_tags'] = 0;
|
1036 |
+
|
1037 |
+
$options['general']['timeonpage_enabled'] = 1;
|
1038 |
+
|
1039 |
+
$options['general']['search_event_enabled'] = 1;
|
1040 |
+
|
1041 |
+
$options['std']['enabled'] = 0;
|
1042 |
+
|
1043 |
+
$options['dyn']['enabled'] = 0;
|
1044 |
+
$options['dyn']['enabled_on_content'] = 0;
|
1045 |
+
$options['dyn']['enabled_on_widget'] = 0;
|
1046 |
+
|
1047 |
+
$options['woo']['enabled'] = pys_is_woocommerce_active() ? 1 : 0;
|
1048 |
+
|
1049 |
+
$options['woo']['content_id'] = 'id';
|
1050 |
+
$options['woo']['variation_id'] = 'variation';
|
1051 |
+
|
1052 |
+
$options['woo']['enable_additional_params'] = 1;
|
1053 |
+
$options['woo']['enable_tags'] = 1;
|
1054 |
+
$options['woo']['tax'] = 'incl';
|
1055 |
+
|
1056 |
+
$options['woo']['on_view_content'] = 1;
|
1057 |
+
$options['woo']['enable_view_content_value'] = 1;
|
1058 |
+
$options['woo']['view_content_value_option'] = 'price';
|
1059 |
+
$options['woo']['view_content_percent_value'] = '';
|
1060 |
+
$options['woo']['view_content_global_value'] = '';
|
1061 |
+
|
1062 |
+
$options['woo']['on_add_to_cart_btn'] = 1;
|
1063 |
+
$options['woo']['on_cart_page'] = 1;
|
1064 |
+
$options['woo']['enable_add_to_cart_value'] = 1;
|
1065 |
+
$options['woo']['add_to_cart_value_option'] = 'price';
|
1066 |
+
$options['woo']['add_to_cart_percent_value'] = '';
|
1067 |
+
$options['woo']['add_to_cart_global_value'] = '';
|
1068 |
+
|
1069 |
+
$options['woo']['on_checkout_page'] = 1;
|
1070 |
+
$options['woo']['enable_checkout_value'] = 1;
|
1071 |
+
$options['woo']['checkout_value_option'] = 'price';
|
1072 |
+
$options['woo']['checkout_percent_value'] = '';
|
1073 |
+
$options['woo']['checkout_global_value'] = '';
|
1074 |
+
|
1075 |
+
$options['woo']['on_thank_you_page'] = 1;
|
1076 |
+
$options['woo']['enable_purchase_value'] = 1;
|
1077 |
+
$options['woo']['purchase_fire_once'] = 1;
|
1078 |
+
$options['woo']['purchase_transport'] = 'included';
|
1079 |
+
$options['woo']['purchase_value_option'] = 'total';
|
1080 |
+
$options['woo']['purchase_percent_value'] = '';
|
1081 |
+
$options['woo']['purchase_global_value'] = '';
|
1082 |
+
|
1083 |
+
$options['woo']['purchase_add_address'] = 1;
|
1084 |
+
$options['woo']['purchase_add_payment_method'] = 1;
|
1085 |
+
$options['woo']['purchase_add_shipping_method'] = 1;
|
1086 |
+
$options['woo']['purchase_add_coupons'] = 1;
|
1087 |
+
|
1088 |
+
$options['woo']['enable_aff_event'] = 0;
|
1089 |
+
$options['woo']['aff_event'] = 'predefined';
|
1090 |
+
$options['woo']['aff_predefined_value'] = 'Lead';
|
1091 |
+
$options['woo']['aff_custom_value'] = '';
|
1092 |
+
$options['woo']['aff_value_option'] = 'none';
|
1093 |
+
$options['woo']['aff_global_value'] = '';
|
1094 |
+
|
1095 |
+
$options['woo']['enable_paypal_event'] = 0;
|
1096 |
+
$options['woo']['pp_event'] = 'predefined';
|
1097 |
+
$options['woo']['pp_predefined_value'] = 'InitiatePayment';
|
1098 |
+
$options['woo']['pp_custom_value'] = '';
|
1099 |
+
$options['woo']['pp_value_option'] = 'none';
|
1100 |
+
$options['woo']['pp_global_value'] = '';
|
1101 |
+
|
1102 |
+
/**
|
1103 |
+
* Easy Digital Downloads
|
1104 |
+
*/
|
1105 |
+
|
1106 |
+
$options['edd']['enabled'] = pys_is_edd_active() ? 1 : 0;
|
1107 |
+
|
1108 |
+
$options['edd']['content_id'] = 'id';
|
1109 |
+
$options['edd']['enable_additional_params'] = 1;
|
1110 |
+
$options['edd']['enable_tags'] = 1;
|
1111 |
+
$options['edd']['tax'] = 'incl';
|
1112 |
+
|
1113 |
+
$options['edd']['on_view_content'] = 1;
|
1114 |
+
$options['edd']['on_view_content_delay'] = null;
|
1115 |
+
$options['edd']['enable_view_content_value'] = 1;
|
1116 |
+
$options['edd']['view_content_value_option'] = 'price';
|
1117 |
+
$options['edd']['view_content_percent_value'] = null;
|
1118 |
+
$options['edd']['view_content_global_value'] = null;
|
1119 |
+
|
1120 |
+
$options['edd']['on_add_to_cart_btn'] = 1;
|
1121 |
+
$options['edd']['enable_add_to_cart_value'] = 1;
|
1122 |
+
$options['edd']['add_to_cart_value_option'] = 'price';
|
1123 |
+
$options['edd']['add_to_cart_percent_value'] = null;
|
1124 |
+
$options['edd']['add_to_cart_global_value'] = null;
|
1125 |
+
|
1126 |
+
$options['edd']['on_checkout_page'] = 1;
|
1127 |
+
$options['edd']['enable_checkout_value'] = 1;
|
1128 |
+
$options['edd']['checkout_value_option'] = 'price';
|
1129 |
+
$options['edd']['checkout_percent_value'] = null;
|
1130 |
+
$options['edd']['checkout_global_value'] = null;
|
1131 |
+
|
1132 |
+
$options['edd']['on_success_page'] = 1;
|
1133 |
+
$options['edd']['enable_purchase_value'] = 1;
|
1134 |
+
$options['edd']['purchase_fire_once'] = 1;
|
1135 |
+
$options['edd']['purchase_value_option'] = 'total';
|
1136 |
+
$options['edd']['purchase_percent_value'] = null;
|
1137 |
+
$options['edd']['purchase_global_value'] = null;
|
1138 |
+
|
1139 |
+
$options['edd']['purchase_add_address'] = true;
|
1140 |
+
$options['edd']['purchase_add_payment_method'] = true;
|
1141 |
+
$options['edd']['purchase_add_coupons'] = true;
|
1142 |
+
|
1143 |
+
return apply_filters( 'pys_fb_pixel_setting_defaults', $options );
|
1144 |
+
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
if( ! function_exists( 'pys_get_custom_params' ) ) {
|
1150 |
+
|
1151 |
+
/**
|
1152 |
+
* Extract non-system params array
|
1153 |
+
*/
|
1154 |
+
function pys_get_custom_params( $event ) {
|
1155 |
+
|
1156 |
+
if( !is_array( $event ) || empty( $event ) ) {
|
1157 |
+
return array();
|
1158 |
+
}
|
1159 |
+
|
1160 |
+
$system_params = array(
|
1161 |
+
'trigger_type',
|
1162 |
+
'url_filter',
|
1163 |
+
'url',
|
1164 |
+
'css',
|
1165 |
+
'pageurl',
|
1166 |
+
'eventtype',
|
1167 |
+
'value',
|
1168 |
+
'currency',
|
1169 |
+
'custom_currency',
|
1170 |
+
'content_name',
|
1171 |
+
'content_ids',
|
1172 |
+
'content_type',
|
1173 |
+
'content_category',
|
1174 |
+
'num_items',
|
1175 |
+
'order_id',
|
1176 |
+
'search_string',
|
1177 |
+
'status',
|
1178 |
+
'code',
|
1179 |
+
'custom_name',
|
1180 |
+
'scroll_pos'
|
1181 |
+
);
|
1182 |
+
|
1183 |
+
$custom_params = array();
|
1184 |
+
foreach( $event as $param => $value ) {
|
1185 |
+
|
1186 |
+
// skip standard params
|
1187 |
+
if( in_array( $param, $system_params ) ) {
|
1188 |
+
continue;
|
1189 |
+
}
|
1190 |
+
|
1191 |
+
$custom_params[ $param ] = $value;
|
1192 |
+
|
1193 |
+
}
|
1194 |
+
|
1195 |
+
|
1196 |
+
return $custom_params;
|
1197 |
+
|
1198 |
+
}
|
1199 |
+
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
if( ! function_exists( 'pys_is_standard_event' ) ) {
|
1203 |
+
|
1204 |
+
function pys_is_standard_event( $eventtype ) {
|
1205 |
+
|
1206 |
+
$std_events = array(
|
1207 |
+
'PageView',
|
1208 |
+
'ViewContent',
|
1209 |
+
'Search',
|
1210 |
+
'AddToCart',
|
1211 |
+
'AddToWishlist',
|
1212 |
+
'InitiateCheckout',
|
1213 |
+
'AddPaymentInfo',
|
1214 |
+
'Purchase',
|
1215 |
+
'Lead'
|
1216 |
+
);
|
1217 |
+
|
1218 |
+
return in_array( $eventtype, $std_events );
|
1219 |
+
|
1220 |
+
}
|
1221 |
+
|
1222 |
+
}
|
1223 |
+
|
1224 |
+
if( ! function_exists( 'pys_pixel_init_params' ) ) {
|
1225 |
+
|
1226 |
+
/**
|
1227 |
+
* Add extra params to FB init call.
|
1228 |
+
*/
|
1229 |
+
function pys_pixel_init_params() {
|
1230 |
+
|
1231 |
+
$params = array();
|
1232 |
+
$params = apply_filters( 'pys_pixel_init_params', $params );
|
1233 |
+
|
1234 |
+
$sanitized = array();
|
1235 |
+
|
1236 |
+
// sanitize params
|
1237 |
+
foreach ( $params as $name => $value ) {
|
1238 |
+
|
1239 |
+
if ( empty( $value ) ) {
|
1240 |
+
continue;
|
1241 |
+
}
|
1242 |
+
|
1243 |
+
$key = esc_js( $name );
|
1244 |
+
$sanitized[ $key ] = $value;
|
1245 |
+
|
1246 |
+
}
|
1247 |
+
|
1248 |
+
return $sanitized;
|
1249 |
+
|
1250 |
+
}
|
1251 |
+
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
if( ! function_exists( 'pys_woocommerce_events' ) ) {
|
1255 |
+
|
1256 |
+
function pys_woocommerce_events() {
|
1257 |
+
|
1258 |
+
if ( pys_get_option( 'woo', 'enabled' ) == false || pys_is_woocommerce_active() == false ) {
|
1259 |
+
return;
|
1260 |
+
}
|
1261 |
+
|
1262 |
+
pys_get_woo_code();
|
1263 |
+
|
1264 |
+
// WooCommerce non-ajax AddToCart Event handler
|
1265 |
+
if ( isset( $_REQUEST['add-to-cart'] ) ) {
|
1266 |
+
|
1267 |
+
if ( pys_get_option( 'woo', 'variation_id' ) != 'main' && isset( $_REQUEST['variation_id'] ) ) {
|
1268 |
+
$product_id = $_REQUEST['variation_id'];
|
1269 |
+
} else {
|
1270 |
+
$product_id = isset( $_REQUEST['add-to-cart'] ) ? $_REQUEST['add-to-cart'] : null;
|
1271 |
+
}
|
1272 |
+
|
1273 |
+
$params = pys_get_woo_ajax_addtocart_params( $product_id );
|
1274 |
+
|
1275 |
+
pys_add_event( 'AddToCart', $params );
|
1276 |
+
|
1277 |
+
}
|
1278 |
+
|
1279 |
+
}
|
1280 |
+
|
1281 |
+
}
|
1282 |
+
|
1283 |
+
if( ! function_exists( 'pys_output_woo_ajax_events_code' ) ) {
|
1284 |
+
|
1285 |
+
function pys_output_woo_ajax_events_code() {
|
1286 |
+
global $pys_woo_ajax_events;
|
1287 |
+
|
1288 |
+
if( empty( $pys_woo_ajax_events ) ) {
|
1289 |
+
return;
|
1290 |
+
}
|
1291 |
+
|
1292 |
+
$events = array();
|
1293 |
+
|
1294 |
+
foreach ( $pys_woo_ajax_events as $id => $event ) {
|
1295 |
+
|
1296 |
+
$params = pys_clean_system_event_params( $event['params'] );
|
1297 |
+
|
1298 |
+
// sanitize params
|
1299 |
+
$sanitized = array();
|
1300 |
+
foreach ( $params as $name => $value ) {
|
1301 |
+
|
1302 |
+
// skip empty but not zero values
|
1303 |
+
if ( empty( $value ) && ! is_numeric( $value ) ) {
|
1304 |
+
continue;
|
1305 |
+
}
|
1306 |
+
|
1307 |
+
$key = esc_js( $name );
|
1308 |
+
$sanitized[ $key ] = $value;
|
1309 |
+
|
1310 |
+
}
|
1311 |
+
|
1312 |
+
$name = $event['name'];
|
1313 |
+
|
1314 |
+
$events[ $id ] = array(
|
1315 |
+
'type' => pys_is_standard_event( $name ) ? 'track' : 'trackCustom',
|
1316 |
+
'name' => $name,
|
1317 |
+
'params' => $sanitized
|
1318 |
+
);
|
1319 |
+
|
1320 |
+
}
|
1321 |
+
|
1322 |
+
?>
|
1323 |
+
|
1324 |
+
<script type="text/javascript">
|
1325 |
+
/* <![CDATA[ */
|
1326 |
+
var pys_woo_ajax_events = <?php echo json_encode( $events ); ?>;
|
1327 |
+
/* ]]> */
|
1328 |
+
</script>
|
1329 |
+
|
1330 |
+
<?php
|
1331 |
+
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
}
|
1335 |
+
|
1336 |
+
if( ! function_exists( 'pys_output_options' ) ) {
|
1337 |
+
|
1338 |
+
function pys_output_options() {
|
1339 |
+
|
1340 |
+
$options = array(
|
1341 |
+
'site_url' => get_site_url(),
|
1342 |
+
'traffic_source_enabled' => pys_get_option( 'general', 'add_traffic_source' )
|
1343 |
+
);
|
1344 |
+
|
1345 |
+
wp_localize_script( 'pys-public', 'pys_options', $options );
|
1346 |
+
|
1347 |
+
}
|
1348 |
+
|
1349 |
+
}
|
1350 |
+
|
1351 |
+
if( ! function_exists( 'pys_head_comments' ) ) {
|
1352 |
+
|
1353 |
+
function pys_head_comments() {
|
1354 |
+
|
1355 |
+
if( defined( 'PYS_PRO_VERSION' ) ) {
|
1356 |
+
$version = "PRO v" . PYS_PRO_VERSION;
|
1357 |
+
} elseif( defined( 'PYS_FREE_VERSION' ) ) {
|
1358 |
+
$version = "FREE v" . PYS_FREE_VERSION;
|
1359 |
+
} else {
|
1360 |
+
$version = null;
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
?>
|
1364 |
+
|
1365 |
+
<!-- Facebook Pixel code is added on this page by PixelYourSite <?php echo esc_attr( $version ); ?> plugin. You can test it with Pixel Helper Chrome Extension. -->
|
1366 |
+
|
1367 |
+
<?php
|
1368 |
+
}
|
1369 |
+
|
1370 |
+
}
|
1371 |
+
|
1372 |
+
if( ! function_exists( 'pys_render_event_code' ) ) {
|
1373 |
+
|
1374 |
+
/**
|
1375 |
+
* Return full event code as a string value. Used to display event code preview on standard and dynamic event lists.
|
1376 |
+
*/
|
1377 |
+
function pys_render_event_code( $event_name, $params ) {
|
1378 |
+
|
1379 |
+
$event_type = pys_is_standard_event( $event_name ) ? 'track' : 'trackCustom';
|
1380 |
+
|
1381 |
+
$params = pys_clean_system_event_params( $params );
|
1382 |
+
|
1383 |
+
$event_params = '';
|
1384 |
+
foreach( $params as $name => $value ) {
|
1385 |
+
|
1386 |
+
if( empty( $value ) && $value !== "0" ) {
|
1387 |
+
continue;
|
1388 |
+
}
|
1389 |
+
|
1390 |
+
$event_params .= " " . esc_js( $name ) . ": '" . $value . "',";
|
1391 |
+
|
1392 |
+
}
|
1393 |
+
|
1394 |
+
$event_params = ltrim( $event_params );
|
1395 |
+
$event_params = rtrim( $event_params, "," );
|
1396 |
+
|
1397 |
+
return "fbq('{$event_type}', '{$event_name}', { {$event_params} } );";
|
1398 |
+
|
1399 |
+
}
|
1400 |
+
|
1401 |
+
}
|
1402 |
+
|
1403 |
+
if( !function_exists( 'pys_add_domain_param' ) ) {
|
1404 |
+
|
1405 |
+
function pys_add_domain_param( $params, $event ) {
|
1406 |
+
|
1407 |
+
// get home URL without protocol
|
1408 |
+
$params['domain'] = substr( get_home_url( null, '', 'http' ), 7 );
|
1409 |
+
return $params;
|
1410 |
+
|
1411 |
+
}
|
1412 |
+
|
1413 |
+
}
|
1414 |
+
|
1415 |
+
if ( ! function_exists( 'pys_get_additional_post_params' ) ) {
|
1416 |
+
|
1417 |
+
function pys_get_additional_post_params( $post, &$params, $taxonomy ) {
|
1418 |
+
|
1419 |
+
// get WP_Post object
|
1420 |
+
if ( is_numeric( $post ) ) {
|
1421 |
+
$id = absint( $post );
|
1422 |
+
$_post = get_post( $id );
|
1423 |
+
} elseif ( $post instanceof WC_Product ) {
|
1424 |
+
$_post = $post->post;
|
1425 |
+
} elseif ( isset( $post->ID ) ) {
|
1426 |
+
$_post = $post;
|
1427 |
+
} else {
|
1428 |
+
return;
|
1429 |
+
}
|
1430 |
+
|
1431 |
+
$params['content_name'] = $_post->post_title;
|
1432 |
+
|
1433 |
+
$terms = pys_get_content_taxonomies( $taxonomy, $_post->ID );
|
1434 |
+
if ( $terms ) {
|
1435 |
+
$params['category_name'] = $terms;
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
}
|
1439 |
+
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
if ( ! function_exists( 'pys_get_object_tags' ) ) {
|
1443 |
+
|
1444 |
+
/**
|
1445 |
+
* @param int|WP_Post $post Post ID or object
|
1446 |
+
* @param string $taxonomy Taxonomy name
|
1447 |
+
*
|
1448 |
+
* @return array Array of terms titles on success or empty array
|
1449 |
+
*/
|
1450 |
+
function pys_get_object_tags( $post, $taxonomy ) {
|
1451 |
+
|
1452 |
+
$tags = array();
|
1453 |
+
$terms = get_the_terms( $post, $taxonomy );
|
1454 |
+
|
1455 |
+
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
|
1456 |
+
|
1457 |
+
foreach ( $terms as $term ) {
|
1458 |
+
$tags[] = html_entity_decode( $term->name );
|
1459 |
+
}
|
1460 |
+
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
return $tags;
|
1464 |
+
|
1465 |
+
}
|
1466 |
+
|
1467 |
+
}
|
1468 |
+
|
1469 |
+
if ( ! function_exists( 'pys_delete_events' ) ) {
|
1470 |
+
|
1471 |
+
function pys_delete_events( $events_ids, $events_type ) {
|
1472 |
+
|
1473 |
+
if ( $events_type == 'standard' ) {
|
1474 |
+
$option_name = 'pixel_your_site_std_events';
|
1475 |
+
} else {
|
1476 |
+
$option_name = 'pixel_your_site_dyn_events';
|
1477 |
+
}
|
1478 |
+
|
1479 |
+
$events = (array) get_option( $option_name );
|
1480 |
+
|
1481 |
+
if ( empty( $events ) ) {
|
1482 |
+
return;
|
1483 |
+
}
|
1484 |
+
|
1485 |
+
foreach ( $events_ids as $id ) {
|
1486 |
+
unset( $events[ $id ] );
|
1487 |
+
}
|
1488 |
+
|
1489 |
+
update_option( $option_name, $events );
|
1490 |
+
|
1491 |
+
}
|
1492 |
+
|
1493 |
+
}
|
1494 |
+
|
1495 |
+
if( ! function_exists( 'pys_is_wc_version_gte' ) ) {
|
1496 |
+
|
1497 |
+
function pys_is_wc_version_gte( $version ) {
|
1498 |
+
|
1499 |
+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
|
1500 |
+
return version_compare( WC_VERSION, $version, '>=' );
|
1501 |
+
} else if ( defined( 'WOOCOMMERCE_VERSION' ) && WOOCOMMERCE_VERSION ) {
|
1502 |
+
return version_compare( WOOCOMMERCE_VERSION, $version, '>=' );
|
1503 |
+
} else {
|
1504 |
+
return false;
|
1505 |
+
}
|
1506 |
+
|
1507 |
+
}
|
1508 |
+
|
1509 |
}
|
inc/core.php
CHANGED
@@ -1,465 +1,465 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
-
exit; // Exit if accessed directly.
|
5 |
-
}
|
6 |
-
|
7 |
-
if ( ! function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
|
8 |
-
|
9 |
-
function pys_get_woo_ajax_addtocart_params( $product_id ) {
|
10 |
-
|
11 |
-
$params = array();
|
12 |
-
$params['content_type'] = 'product';
|
13 |
-
$params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
|
14 |
-
|
15 |
-
// currency, value
|
16 |
-
if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
|
17 |
-
|
18 |
-
$option = pys_get_option( 'woo', 'add_to_cart_value_option' );
|
19 |
-
switch ( $option ) {
|
20 |
-
case 'global':
|
21 |
-
$value = pys_get_option( 'woo', 'add_to_cart_global_value' );
|
22 |
-
break;
|
23 |
-
|
24 |
-
case 'price':
|
25 |
-
$value = pys_get_product_price( $product_id );
|
26 |
-
break;
|
27 |
-
|
28 |
-
default:
|
29 |
-
$value = null;
|
30 |
-
}
|
31 |
-
|
32 |
-
$params['value'] = $value;
|
33 |
-
$params['currency'] = get_woocommerce_currency();
|
34 |
-
|
35 |
-
}
|
36 |
-
|
37 |
-
return $params;
|
38 |
-
|
39 |
-
}
|
40 |
-
|
41 |
-
}
|
42 |
-
|
43 |
-
if ( ! function_exists( 'pys_get_post_tags' ) ) {
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Return array of product tags.
|
47 |
-
* PRO only.
|
48 |
-
*/
|
49 |
-
function pys_get_post_tags( $post_id ) {
|
50 |
-
|
51 |
-
return array(); // PRO feature
|
52 |
-
|
53 |
-
}
|
54 |
-
|
55 |
-
}
|
56 |
-
|
57 |
-
if ( ! function_exists( 'pys_get_woo_code' ) ) {
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Build WooCommerce related events code.
|
61 |
-
* Function adds evaluated event params to global array.
|
62 |
-
*/
|
63 |
-
function pys_get_woo_code() {
|
64 |
-
global $post, $woocommerce;
|
65 |
-
|
66 |
-
// set defaults params
|
67 |
-
$params = array();
|
68 |
-
$params['content_type'] = 'product';
|
69 |
-
|
70 |
-
// ViewContent Event
|
71 |
-
if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
|
72 |
-
|
73 |
-
$product = wc_get_product( $post->ID );
|
74 |
-
|
75 |
-
$params['content_ids'] = json_encode( pys_get_product_content_id( $post->ID ) );
|
76 |
-
|
77 |
-
if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
|
78 |
-
$params['content_type'] = 'product_group';
|
79 |
-
} else {
|
80 |
-
$params['content_type'] = 'product';
|
81 |
-
}
|
82 |
-
|
83 |
-
// @since 5.0.6
|
84 |
-
$params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
|
85 |
-
$product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
|
86 |
-
|
87 |
-
// currency, value
|
88 |
-
if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
|
89 |
-
|
90 |
-
$option = pys_get_option( 'woo', 'view_content_value_option' );
|
91 |
-
switch ( $option ) {
|
92 |
-
case 'global':
|
93 |
-
$value = pys_get_option( 'woo', 'view_content_global_value' );
|
94 |
-
break;
|
95 |
-
|
96 |
-
case 'price':
|
97 |
-
$value = pys_get_product_price( $post );
|
98 |
-
break;
|
99 |
-
|
100 |
-
default:
|
101 |
-
$value = null;
|
102 |
-
}
|
103 |
-
|
104 |
-
$params['value'] = $value;
|
105 |
-
$params['currency'] = get_woocommerce_currency();
|
106 |
-
|
107 |
-
}
|
108 |
-
|
109 |
-
pys_add_event( 'ViewContent', $params );
|
110 |
-
|
111 |
-
return;
|
112 |
-
|
113 |
-
}
|
114 |
-
|
115 |
-
// AddToCart Cart Page Event
|
116 |
-
if ( pys_get_option( 'woo', 'on_cart_page' ) && is_cart() ) {
|
117 |
-
|
118 |
-
$ids = array(); // cart items ids or sku
|
119 |
-
|
120 |
-
foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
|
121 |
-
|
122 |
-
$product_id = pys_get_woo_cart_item_product_id( $item );
|
123 |
-
$ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
|
124 |
-
|
125 |
-
}
|
126 |
-
|
127 |
-
$params['content_ids'] = json_encode( $ids );
|
128 |
-
|
129 |
-
// currency, value
|
130 |
-
if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
|
131 |
-
|
132 |
-
$option = pys_get_option( 'woo', 'add_to_cart_value_option' );
|
133 |
-
switch ( $option ) {
|
134 |
-
case 'global':
|
135 |
-
$value = pys_get_option( 'woo', 'add_to_cart_global_value' );
|
136 |
-
break;
|
137 |
-
|
138 |
-
case 'price':
|
139 |
-
$value = pys_get_cart_total();
|
140 |
-
break;
|
141 |
-
|
142 |
-
default:
|
143 |
-
$value = null;
|
144 |
-
}
|
145 |
-
|
146 |
-
$params['value'] = $value;
|
147 |
-
$params['currency'] = get_woocommerce_currency();
|
148 |
-
|
149 |
-
}
|
150 |
-
|
151 |
-
pys_add_event( 'AddToCart', $params );
|
152 |
-
|
153 |
-
return;
|
154 |
-
|
155 |
-
}
|
156 |
-
|
157 |
-
// Checkout Page Event
|
158 |
-
if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
|
159 |
-
|
160 |
-
$params = pys_get_woo_checkout_params( false );
|
161 |
-
|
162 |
-
// currency, value
|
163 |
-
if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
|
164 |
-
|
165 |
-
$option = pys_get_option( 'woo', 'checkout_value_option' );
|
166 |
-
switch ( $option ) {
|
167 |
-
case 'global':
|
168 |
-
$value = pys_get_option( 'woo', 'checkout_global_value' );
|
169 |
-
break;
|
170 |
-
|
171 |
-
case 'price':
|
172 |
-
$value = pys_get_cart_total();
|
173 |
-
break;
|
174 |
-
|
175 |
-
default:
|
176 |
-
$value = null;
|
177 |
-
}
|
178 |
-
|
179 |
-
$params['value'] = $value;
|
180 |
-
$params['currency'] = get_woocommerce_currency();
|
181 |
-
|
182 |
-
}
|
183 |
-
|
184 |
-
pys_add_event( 'InitiateCheckout', $params );
|
185 |
-
|
186 |
-
return;
|
187 |
-
|
188 |
-
}
|
189 |
-
|
190 |
-
// Purchase Event
|
191 |
-
if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
|
192 |
-
|
193 |
-
$order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
|
194 |
-
$order = new WC_Order( $order_id );
|
195 |
-
$items = $order->get_items( 'line_item' );
|
196 |
-
|
197 |
-
$ids = array(); // order items ids or sku
|
198 |
-
|
199 |
-
foreach ( $items as $item ) {
|
200 |
-
|
201 |
-
$product_id = pys_get_woo_cart_item_product_id( $item );
|
202 |
-
$ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
|
203 |
-
|
204 |
-
}
|
205 |
-
|
206 |
-
$params['content_ids'] = json_encode( $ids );
|
207 |
-
|
208 |
-
// currency, value
|
209 |
-
if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
|
210 |
-
|
211 |
-
$option = pys_get_option( 'woo', 'purchase_value_option' );
|
212 |
-
switch ( $option ) {
|
213 |
-
case 'global':
|
214 |
-
$value = pys_get_option( 'woo', 'purchase_global_value' );
|
215 |
-
break;
|
216 |
-
|
217 |
-
case 'total':
|
218 |
-
$value = pys_get_order_total( $order );
|
219 |
-
break;
|
220 |
-
|
221 |
-
default:
|
222 |
-
$value = null;
|
223 |
-
}
|
224 |
-
|
225 |
-
$params['value'] = $value;
|
226 |
-
$params['currency'] = get_woocommerce_currency();
|
227 |
-
|
228 |
-
}
|
229 |
-
|
230 |
-
pys_add_event( 'Purchase', $params );
|
231 |
-
|
232 |
-
return;
|
233 |
-
|
234 |
-
}
|
235 |
-
|
236 |
-
}
|
237 |
-
|
238 |
-
}
|
239 |
-
|
240 |
-
if ( ! function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
|
244 |
-
*
|
245 |
-
* @param string $tag
|
246 |
-
* @param WC_Product $product
|
247 |
-
*
|
248 |
-
* @return string
|
249 |
-
*/
|
250 |
-
function pys_add_code_to_woo_cart_link( $tag, $product ) {
|
251 |
-
global $pys_woo_ajax_events;
|
252 |
-
|
253 |
-
// do not add code if AJAX is disabled. event will be processed by another function
|
254 |
-
if ( 'yes' !== get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
|
255 |
-
return $tag;
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* @since 5.0.1
|
260 |
-
*/
|
261 |
-
if ( pys_is_wc_version_gte( '2.7' ) ) {
|
262 |
-
$is_simple_product = $product->is_type( 'simple' );
|
263 |
-
} else {
|
264 |
-
$is_simple_product = $product->product_type == 'simple';
|
265 |
-
}
|
266 |
-
|
267 |
-
if ( false == $is_simple_product ) {
|
268 |
-
return $tag;
|
269 |
-
}
|
270 |
-
|
271 |
-
$event_id = uniqid();
|
272 |
-
|
273 |
-
/**
|
274 |
-
* @since 5.0.1
|
275 |
-
*/
|
276 |
-
if ( pys_is_wc_version_gte( '2.6' ) ) {
|
277 |
-
$product_id = $product->get_id();
|
278 |
-
} else {
|
279 |
-
$product_id = $product->post->ID;
|
280 |
-
}
|
281 |
-
|
282 |
-
// common params
|
283 |
-
$params = array();
|
284 |
-
$params['content_type'] = 'product';
|
285 |
-
$params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
|
286 |
-
|
287 |
-
// currency, value
|
288 |
-
if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
|
289 |
-
|
290 |
-
$option = pys_get_option( 'woo', 'view_content_value_option' );
|
291 |
-
switch ( $option ) {
|
292 |
-
case 'global':
|
293 |
-
$value = pys_get_option( 'woo', 'view_content_global_value' );
|
294 |
-
break;
|
295 |
-
|
296 |
-
case 'price':
|
297 |
-
$value = pys_get_product_price( $product_id );
|
298 |
-
break;
|
299 |
-
|
300 |
-
default:
|
301 |
-
$value = null;
|
302 |
-
|
303 |
-
}
|
304 |
-
|
305 |
-
$params['value'] = $value;
|
306 |
-
$params['currency'] = get_woocommerce_currency();
|
307 |
-
|
308 |
-
}
|
309 |
-
|
310 |
-
$tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true, 'any' );
|
311 |
-
|
312 |
-
$pys_woo_ajax_events[ $event_id ] = array(
|
313 |
-
'name' => 'AddToCart',
|
314 |
-
'params' => $params
|
315 |
-
);
|
316 |
-
|
317 |
-
return $tag;
|
318 |
-
|
319 |
-
}
|
320 |
-
|
321 |
-
}
|
322 |
-
|
323 |
-
if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
|
324 |
-
|
325 |
-
/**
|
326 |
-
* Adds extra params to pixel init code. On Free always returns empty string.
|
327 |
-
* PRO only.
|
328 |
-
*
|
329 |
-
* @see: https://www.facebook.com/help/ipad-app/606443329504150
|
330 |
-
* @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
|
331 |
-
* @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
|
332 |
-
*
|
333 |
-
* @return string
|
334 |
-
*/
|
335 |
-
function pys_get_additional_matching_code() {
|
336 |
-
|
337 |
-
return ''; // PRO feature
|
338 |
-
|
339 |
-
}
|
340 |
-
|
341 |
-
}
|
342 |
-
|
343 |
-
if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
|
344 |
-
|
345 |
-
/**
|
346 |
-
* Adds additional post parameters like `content_name` and `category_name`.
|
347 |
-
* PRO only.
|
348 |
-
*
|
349 |
-
* @param $post WP_Post|int
|
350 |
-
* @param $params array reference to $params array
|
351 |
-
*/
|
352 |
-
function pys_get_additional_woo_params( $post, &$params ) {
|
353 |
-
|
354 |
-
// PRO only
|
355 |
-
|
356 |
-
}
|
357 |
-
|
358 |
-
}
|
359 |
-
|
360 |
-
if ( ! function_exists( 'pys_general_woo_event' ) ) {
|
361 |
-
|
362 |
-
/**
|
363 |
-
* Add General event on Woo Product page. PRO only.
|
364 |
-
*
|
365 |
-
* @param $post WP_Post|int
|
366 |
-
* @param $track_tags bool
|
367 |
-
* @param $delay int
|
368 |
-
* @param $event_name string
|
369 |
-
*/
|
370 |
-
function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
|
371 |
-
// PRO feature
|
372 |
-
}
|
373 |
-
|
374 |
-
}
|
375 |
-
|
376 |
-
if ( ! function_exists( 'pys_general_edd_event' ) ) {
|
377 |
-
|
378 |
-
/**
|
379 |
-
* Add General event on EDD Download page. PRO only.
|
380 |
-
*
|
381 |
-
* @param $post WP_Post|int
|
382 |
-
* @param $track_tags bool
|
383 |
-
* @param $delay int
|
384 |
-
* @param $event_name string
|
385 |
-
*/
|
386 |
-
function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
|
387 |
-
// PRO feature
|
388 |
-
}
|
389 |
-
|
390 |
-
}
|
391 |
-
|
392 |
-
if ( ! function_exists( 'pys_get_product_price' ) ) {
|
393 |
-
|
394 |
-
/**
|
395 |
-
* Return product price depends on plugin, product and WooCommerce settings.
|
396 |
-
*
|
397 |
-
* @param $product_id
|
398 |
-
*
|
399 |
-
* @return null|int Product price
|
400 |
-
*/
|
401 |
-
function pys_get_product_price( $product_id ) {
|
402 |
-
|
403 |
-
$product = wc_get_product( $product_id );
|
404 |
-
|
405 |
-
/**
|
406 |
-
* @since 5.0.9
|
407 |
-
*/
|
408 |
-
if ( false == $product instanceof WC_Product ) {
|
409 |
-
return 0;
|
410 |
-
}
|
411 |
-
|
412 |
-
if ( $product->is_taxable() ) {
|
413 |
-
|
414 |
-
/**
|
415 |
-
* @since 5.0.8
|
416 |
-
*/
|
417 |
-
if ( pys_is_wc_version_gte( '2.7' ) ) {
|
418 |
-
$value = wc_get_price_including_tax( $product, $product->get_price() );
|
419 |
-
} else {
|
420 |
-
$value = $product->get_price_including_tax( 1, $product->get_price() );
|
421 |
-
}
|
422 |
-
|
423 |
-
} else {
|
424 |
-
|
425 |
-
/**
|
426 |
-
* @since 5.0.8
|
427 |
-
*/
|
428 |
-
if ( pys_is_wc_version_gte( '2.7' ) ) {
|
429 |
-
$value = wc_get_price_excluding_tax( $product, $product->get_price() );
|
430 |
-
} else {
|
431 |
-
$value = $product->get_price_excluding_tax( 1, $product->get_price() );
|
432 |
-
}
|
433 |
-
|
434 |
-
}
|
435 |
-
|
436 |
-
return $value;
|
437 |
-
|
438 |
-
}
|
439 |
-
|
440 |
-
}
|
441 |
-
|
442 |
-
if ( ! function_exists( 'pys_get_cart_total' ) ) {
|
443 |
-
|
444 |
-
function pys_get_cart_total() {
|
445 |
-
global $woocommerce;
|
446 |
-
|
447 |
-
return $woocommerce->cart->subtotal;
|
448 |
-
|
449 |
-
}
|
450 |
-
|
451 |
-
}
|
452 |
-
|
453 |
-
if ( ! function_exists( 'pys_get_order_total' ) ) {
|
454 |
-
|
455 |
-
/**
|
456 |
-
* Calculates order 'value' param depends on WooCommerce and PYS settings
|
457 |
-
*/
|
458 |
-
function pys_get_order_total( $order ) {
|
459 |
-
|
460 |
-
//wc_get_price_thousand_separator is ignored
|
461 |
-
return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
|
462 |
-
|
463 |
-
}
|
464 |
-
|
465 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
4 |
+
exit; // Exit if accessed directly.
|
5 |
+
}
|
6 |
+
|
7 |
+
if ( ! function_exists( 'pys_get_woo_ajax_addtocart_params' ) ) {
|
8 |
+
|
9 |
+
function pys_get_woo_ajax_addtocart_params( $product_id ) {
|
10 |
+
|
11 |
+
$params = array();
|
12 |
+
$params['content_type'] = 'product';
|
13 |
+
$params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
|
14 |
+
|
15 |
+
// currency, value
|
16 |
+
if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
|
17 |
+
|
18 |
+
$option = pys_get_option( 'woo', 'add_to_cart_value_option' );
|
19 |
+
switch ( $option ) {
|
20 |
+
case 'global':
|
21 |
+
$value = pys_get_option( 'woo', 'add_to_cart_global_value' );
|
22 |
+
break;
|
23 |
+
|
24 |
+
case 'price':
|
25 |
+
$value = pys_get_product_price( $product_id );
|
26 |
+
break;
|
27 |
+
|
28 |
+
default:
|
29 |
+
$value = null;
|
30 |
+
}
|
31 |
+
|
32 |
+
$params['value'] = $value;
|
33 |
+
$params['currency'] = get_woocommerce_currency();
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
return $params;
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
if ( ! function_exists( 'pys_get_post_tags' ) ) {
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Return array of product tags.
|
47 |
+
* PRO only.
|
48 |
+
*/
|
49 |
+
function pys_get_post_tags( $post_id ) {
|
50 |
+
|
51 |
+
return array(); // PRO feature
|
52 |
+
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
if ( ! function_exists( 'pys_get_woo_code' ) ) {
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Build WooCommerce related events code.
|
61 |
+
* Function adds evaluated event params to global array.
|
62 |
+
*/
|
63 |
+
function pys_get_woo_code() {
|
64 |
+
global $post, $woocommerce;
|
65 |
+
|
66 |
+
// set defaults params
|
67 |
+
$params = array();
|
68 |
+
$params['content_type'] = 'product';
|
69 |
+
|
70 |
+
// ViewContent Event
|
71 |
+
if ( pys_get_option( 'woo', 'on_view_content' ) && is_product() ) {
|
72 |
+
|
73 |
+
$product = wc_get_product( $post->ID );
|
74 |
+
|
75 |
+
$params['content_ids'] = json_encode( pys_get_product_content_id( $post->ID ) );
|
76 |
+
|
77 |
+
if ( $product->get_type() == 'variable' && pys_get_option( 'woo', 'variation_id' ) != 'main' ) {
|
78 |
+
$params['content_type'] = 'product_group';
|
79 |
+
} else {
|
80 |
+
$params['content_type'] = 'product';
|
81 |
+
}
|
82 |
+
|
83 |
+
// @since 5.0.6
|
84 |
+
$params['content_type'] = apply_filters( 'pys_fb_pixel_woo_product_content_type', $params['content_type'],
|
85 |
+
$product->get_type(), $product, pys_get_option( 'woo', 'content_id_format' ) );
|
86 |
+
|
87 |
+
// currency, value
|
88 |
+
if ( pys_get_option( 'woo', 'enable_view_content_value' ) ) {
|
89 |
+
|
90 |
+
$option = pys_get_option( 'woo', 'view_content_value_option' );
|
91 |
+
switch ( $option ) {
|
92 |
+
case 'global':
|
93 |
+
$value = pys_get_option( 'woo', 'view_content_global_value' );
|
94 |
+
break;
|
95 |
+
|
96 |
+
case 'price':
|
97 |
+
$value = pys_get_product_price( $post );
|
98 |
+
break;
|
99 |
+
|
100 |
+
default:
|
101 |
+
$value = null;
|
102 |
+
}
|
103 |
+
|
104 |
+
$params['value'] = $value;
|
105 |
+
$params['currency'] = get_woocommerce_currency();
|
106 |
+
|
107 |
+
}
|
108 |
+
|
109 |
+
pys_add_event( 'ViewContent', $params );
|
110 |
+
|
111 |
+
return;
|
112 |
+
|
113 |
+
}
|
114 |
+
|
115 |
+
// AddToCart Cart Page Event
|
116 |
+
if ( pys_get_option( 'woo', 'on_cart_page' ) && is_cart() ) {
|
117 |
+
|
118 |
+
$ids = array(); // cart items ids or sku
|
119 |
+
|
120 |
+
foreach ( $woocommerce->cart->cart_contents as $cart_item_key => $item ) {
|
121 |
+
|
122 |
+
$product_id = pys_get_woo_cart_item_product_id( $item );
|
123 |
+
$ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
|
124 |
+
|
125 |
+
}
|
126 |
+
|
127 |
+
$params['content_ids'] = json_encode( $ids );
|
128 |
+
|
129 |
+
// currency, value
|
130 |
+
if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
|
131 |
+
|
132 |
+
$option = pys_get_option( 'woo', 'add_to_cart_value_option' );
|
133 |
+
switch ( $option ) {
|
134 |
+
case 'global':
|
135 |
+
$value = pys_get_option( 'woo', 'add_to_cart_global_value' );
|
136 |
+
break;
|
137 |
+
|
138 |
+
case 'price':
|
139 |
+
$value = pys_get_cart_total();
|
140 |
+
break;
|
141 |
+
|
142 |
+
default:
|
143 |
+
$value = null;
|
144 |
+
}
|
145 |
+
|
146 |
+
$params['value'] = $value;
|
147 |
+
$params['currency'] = get_woocommerce_currency();
|
148 |
+
|
149 |
+
}
|
150 |
+
|
151 |
+
pys_add_event( 'AddToCart', $params );
|
152 |
+
|
153 |
+
return;
|
154 |
+
|
155 |
+
}
|
156 |
+
|
157 |
+
// Checkout Page Event
|
158 |
+
if ( pys_get_option( 'woo', 'on_checkout_page' ) && is_checkout() && ! is_wc_endpoint_url() ) {
|
159 |
+
|
160 |
+
$params = pys_get_woo_checkout_params( false );
|
161 |
+
|
162 |
+
// currency, value
|
163 |
+
if ( pys_get_option( 'woo', 'enable_checkout_value' ) ) {
|
164 |
+
|
165 |
+
$option = pys_get_option( 'woo', 'checkout_value_option' );
|
166 |
+
switch ( $option ) {
|
167 |
+
case 'global':
|
168 |
+
$value = pys_get_option( 'woo', 'checkout_global_value' );
|
169 |
+
break;
|
170 |
+
|
171 |
+
case 'price':
|
172 |
+
$value = pys_get_cart_total();
|
173 |
+
break;
|
174 |
+
|
175 |
+
default:
|
176 |
+
$value = null;
|
177 |
+
}
|
178 |
+
|
179 |
+
$params['value'] = $value;
|
180 |
+
$params['currency'] = get_woocommerce_currency();
|
181 |
+
|
182 |
+
}
|
183 |
+
|
184 |
+
pys_add_event( 'InitiateCheckout', $params );
|
185 |
+
|
186 |
+
return;
|
187 |
+
|
188 |
+
}
|
189 |
+
|
190 |
+
// Purchase Event
|
191 |
+
if ( pys_get_option( 'woo', 'on_thank_you_page' ) && is_wc_endpoint_url( 'order-received' ) ) {
|
192 |
+
|
193 |
+
$order_id = wc_get_order_id_by_order_key( $_REQUEST['key'] );
|
194 |
+
$order = new WC_Order( $order_id );
|
195 |
+
$items = $order->get_items( 'line_item' );
|
196 |
+
|
197 |
+
$ids = array(); // order items ids or sku
|
198 |
+
|
199 |
+
foreach ( $items as $item ) {
|
200 |
+
|
201 |
+
$product_id = pys_get_woo_cart_item_product_id( $item );
|
202 |
+
$ids = array_merge( $ids, pys_get_product_content_id( $product_id ) );
|
203 |
+
|
204 |
+
}
|
205 |
+
|
206 |
+
$params['content_ids'] = json_encode( $ids );
|
207 |
+
|
208 |
+
// currency, value
|
209 |
+
if ( pys_get_option( 'woo', 'enable_purchase_value' ) ) {
|
210 |
+
|
211 |
+
$option = pys_get_option( 'woo', 'purchase_value_option' );
|
212 |
+
switch ( $option ) {
|
213 |
+
case 'global':
|
214 |
+
$value = pys_get_option( 'woo', 'purchase_global_value' );
|
215 |
+
break;
|
216 |
+
|
217 |
+
case 'total':
|
218 |
+
$value = pys_get_order_total( $order );
|
219 |
+
break;
|
220 |
+
|
221 |
+
default:
|
222 |
+
$value = null;
|
223 |
+
}
|
224 |
+
|
225 |
+
$params['value'] = $value;
|
226 |
+
$params['currency'] = get_woocommerce_currency();
|
227 |
+
|
228 |
+
}
|
229 |
+
|
230 |
+
pys_add_event( 'Purchase', $params );
|
231 |
+
|
232 |
+
return;
|
233 |
+
|
234 |
+
}
|
235 |
+
|
236 |
+
}
|
237 |
+
|
238 |
+
}
|
239 |
+
|
240 |
+
if ( ! function_exists( 'pys_add_code_to_woo_cart_link' ) ) {
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Adds data-pixelcode attribute to "add to cart" buttons in the WooCommerce loop.
|
244 |
+
*
|
245 |
+
* @param string $tag
|
246 |
+
* @param WC_Product $product
|
247 |
+
*
|
248 |
+
* @return string
|
249 |
+
*/
|
250 |
+
function pys_add_code_to_woo_cart_link( $tag, $product ) {
|
251 |
+
global $pys_woo_ajax_events;
|
252 |
+
|
253 |
+
// do not add code if AJAX is disabled. event will be processed by another function
|
254 |
+
if ( 'yes' !== get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
|
255 |
+
return $tag;
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* @since 5.0.1
|
260 |
+
*/
|
261 |
+
if ( pys_is_wc_version_gte( '2.7' ) ) {
|
262 |
+
$is_simple_product = $product->is_type( 'simple' );
|
263 |
+
} else {
|
264 |
+
$is_simple_product = $product->product_type == 'simple';
|
265 |
+
}
|
266 |
+
|
267 |
+
if ( false == $is_simple_product ) {
|
268 |
+
return $tag;
|
269 |
+
}
|
270 |
+
|
271 |
+
$event_id = uniqid();
|
272 |
+
|
273 |
+
/**
|
274 |
+
* @since 5.0.1
|
275 |
+
*/
|
276 |
+
if ( pys_is_wc_version_gte( '2.6' ) ) {
|
277 |
+
$product_id = $product->get_id();
|
278 |
+
} else {
|
279 |
+
$product_id = $product->post->ID;
|
280 |
+
}
|
281 |
+
|
282 |
+
// common params
|
283 |
+
$params = array();
|
284 |
+
$params['content_type'] = 'product';
|
285 |
+
$params['content_ids'] = json_encode( pys_get_product_content_id( $product_id ) );
|
286 |
+
|
287 |
+
// currency, value
|
288 |
+
if ( pys_get_option( 'woo', 'enable_add_to_cart_value' ) ) {
|
289 |
+
|
290 |
+
$option = pys_get_option( 'woo', 'view_content_value_option' );
|
291 |
+
switch ( $option ) {
|
292 |
+
case 'global':
|
293 |
+
$value = pys_get_option( 'woo', 'view_content_global_value' );
|
294 |
+
break;
|
295 |
+
|
296 |
+
case 'price':
|
297 |
+
$value = pys_get_product_price( $product_id );
|
298 |
+
break;
|
299 |
+
|
300 |
+
default:
|
301 |
+
$value = null;
|
302 |
+
|
303 |
+
}
|
304 |
+
|
305 |
+
$params['value'] = $value;
|
306 |
+
$params['currency'] = get_woocommerce_currency();
|
307 |
+
|
308 |
+
}
|
309 |
+
|
310 |
+
$tag = pys_insert_attribute( 'data-pys-event-id', $event_id, $tag, true, 'any' );
|
311 |
+
|
312 |
+
$pys_woo_ajax_events[ $event_id ] = array(
|
313 |
+
'name' => 'AddToCart',
|
314 |
+
'params' => $params
|
315 |
+
);
|
316 |
+
|
317 |
+
return $tag;
|
318 |
+
|
319 |
+
}
|
320 |
+
|
321 |
+
}
|
322 |
+
|
323 |
+
if ( ! function_exists( 'pys_get_additional_matching_code' ) ) {
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Adds extra params to pixel init code. On Free always returns empty string.
|
327 |
+
* PRO only.
|
328 |
+
*
|
329 |
+
* @see: https://www.facebook.com/help/ipad-app/606443329504150
|
330 |
+
* @see: https://developers.facebook.com/ads/blog/post/2016/05/31/advanced-matching-pixel/
|
331 |
+
* @see: https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-order.php
|
332 |
+
*
|
333 |
+
* @return string
|
334 |
+
*/
|
335 |
+
function pys_get_additional_matching_code() {
|
336 |
+
|
337 |
+
return ''; // PRO feature
|
338 |
+
|
339 |
+
}
|
340 |
+
|
341 |
+
}
|
342 |
+
|
343 |
+
if ( ! function_exists( 'pys_get_additional_woo_params' ) ) {
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Adds additional post parameters like `content_name` and `category_name`.
|
347 |
+
* PRO only.
|
348 |
+
*
|
349 |
+
* @param $post WP_Post|int
|
350 |
+
* @param $params array reference to $params array
|
351 |
+
*/
|
352 |
+
function pys_get_additional_woo_params( $post, &$params ) {
|
353 |
+
|
354 |
+
// PRO only
|
355 |
+
|
356 |
+
}
|
357 |
+
|
358 |
+
}
|
359 |
+
|
360 |
+
if ( ! function_exists( 'pys_general_woo_event' ) ) {
|
361 |
+
|
362 |
+
/**
|
363 |
+
* Add General event on Woo Product page. PRO only.
|
364 |
+
*
|
365 |
+
* @param $post WP_Post|int
|
366 |
+
* @param $track_tags bool
|
367 |
+
* @param $delay int
|
368 |
+
* @param $event_name string
|
369 |
+
*/
|
370 |
+
function pys_general_woo_event( $post, $track_tags, $delay, $event_name ) {
|
371 |
+
// PRO feature
|
372 |
+
}
|
373 |
+
|
374 |
+
}
|
375 |
+
|
376 |
+
if ( ! function_exists( 'pys_general_edd_event' ) ) {
|
377 |
+
|
378 |
+
/**
|
379 |
+
* Add General event on EDD Download page. PRO only.
|
380 |
+
*
|
381 |
+
* @param $post WP_Post|int
|
382 |
+
* @param $track_tags bool
|
383 |
+
* @param $delay int
|
384 |
+
* @param $event_name string
|
385 |
+
*/
|
386 |
+
function pys_general_edd_event( $post, $track_tags, $delay, $event_name ) {
|
387 |
+
// PRO feature
|
388 |
+
}
|
389 |
+
|
390 |
+
}
|
391 |
+
|
392 |
+
if ( ! function_exists( 'pys_get_product_price' ) ) {
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Return product price depends on plugin, product and WooCommerce settings.
|
396 |
+
*
|
397 |
+
* @param $product_id
|
398 |
+
*
|
399 |
+
* @return null|int Product price
|
400 |
+
*/
|
401 |
+
function pys_get_product_price( $product_id ) {
|
402 |
+
|
403 |
+
$product = wc_get_product( $product_id );
|
404 |
+
|
405 |
+
/**
|
406 |
+
* @since 5.0.9
|
407 |
+
*/
|
408 |
+
if ( false == $product instanceof WC_Product ) {
|
409 |
+
return 0;
|
410 |
+
}
|
411 |
+
|
412 |
+
if ( $product->is_taxable() ) {
|
413 |
+
|
414 |
+
/**
|
415 |
+
* @since 5.0.8
|
416 |
+
*/
|
417 |
+
if ( pys_is_wc_version_gte( '2.7' ) ) {
|
418 |
+
$value = wc_get_price_including_tax( $product, $product->get_price() );
|
419 |
+
} else {
|
420 |
+
$value = $product->get_price_including_tax( 1, $product->get_price() );
|
421 |
+
}
|
422 |
+
|
423 |
+
} else {
|
424 |
+
|
425 |
+
/**
|
426 |
+
* @since 5.0.8
|
427 |
+
*/
|
428 |
+
if ( pys_is_wc_version_gte( '2.7' ) ) {
|
429 |
+
$value = wc_get_price_excluding_tax( $product, $product->get_price() );
|
430 |
+
} else {
|
431 |
+
$value = $product->get_price_excluding_tax( 1, $product->get_price() );
|
432 |
+
}
|
433 |
+
|
434 |
+
}
|
435 |
+
|
436 |
+
return $value;
|
437 |
+
|
438 |
+
}
|
439 |
+
|
440 |
+
}
|
441 |
+
|
442 |
+
if ( ! function_exists( 'pys_get_cart_total' ) ) {
|
443 |
+
|
444 |
+
function pys_get_cart_total() {
|
445 |
+
global $woocommerce;
|
446 |
+
|
447 |
+
return $woocommerce->cart->subtotal;
|
448 |
+
|
449 |
+
}
|
450 |
+
|
451 |
+
}
|
452 |
+
|
453 |
+
if ( ! function_exists( 'pys_get_order_total' ) ) {
|
454 |
+
|
455 |
+
/**
|
456 |
+
* Calculates order 'value' param depends on WooCommerce and PYS settings
|
457 |
+
*/
|
458 |
+
function pys_get_order_total( $order ) {
|
459 |
+
|
460 |
+
//wc_get_price_thousand_separator is ignored
|
461 |
+
return number_format( $total = $order->get_total(), wc_get_price_decimals(), '.', '' );
|
462 |
+
|
463 |
+
}
|
464 |
+
|
465 |
}
|
inc/integrations/facebook-for-woocommerce.php
CHANGED
@@ -1,222 +1,222 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Manage integration with Facebook for WooCommerce plugin.
|
5 |
-
*
|
6 |
-
* When Facebook for WooCommerce is activated this integration completely removes
|
7 |
-
* default Facebook for WooCommerce pixels and replaces them with PYS's. Also, new "Pixel ID format" option added to
|
8 |
-
* PYS WooCommerce tab where user can decide what format to use in pixel: PYS default or Facebook for WooCommerce.
|
9 |
-
*/
|
10 |
-
|
11 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
-
exit; // Exit if accessed directly.
|
13 |
-
}
|
14 |
-
|
15 |
-
if ( class_exists( 'WC_Facebookcommerce' ) && ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Declare fake WC_Facebookcommerce_EventsTracker class to remove all unwanted front-end pixel events.
|
19 |
-
*/
|
20 |
-
|
21 |
-
/** @noinspection PhpUndefinedClassInspection */
|
22 |
-
class WC_Facebookcommerce_EventsTracker {
|
23 |
-
|
24 |
-
public function __construct( $pixel_id, $user_info ) {
|
25 |
-
}
|
26 |
-
|
27 |
-
public function inject_base_pixel() {
|
28 |
-
}
|
29 |
-
|
30 |
-
public function inject_view_category_event() {
|
31 |
-
}
|
32 |
-
|
33 |
-
public function inject_search_event() {
|
34 |
-
}
|
35 |
-
|
36 |
-
public function inject_view_content_event() {
|
37 |
-
}
|
38 |
-
|
39 |
-
public function inject_add_to_cart_event() {
|
40 |
-
}
|
41 |
-
|
42 |
-
public function inject_initiate_checkout_event() {
|
43 |
-
}
|
44 |
-
|
45 |
-
public function inject_purchase_event( $order_id ) {
|
46 |
-
}
|
47 |
-
|
48 |
-
}
|
49 |
-
|
50 |
-
endif;
|
51 |
-
|
52 |
-
if ( class_exists( 'WC_Facebookcommerce' ) ) :
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Setup PYS hooks and filters for Facebook for WooCommerce related options and pixel ID output format.
|
56 |
-
*/
|
57 |
-
|
58 |
-
add_filter( 'pys_fb_pixel_woo_product_content_id', 'fb_for_woo_pys_fb_pixel_woo_product_content_id', 10, 4 );
|
59 |
-
function fb_for_woo_pys_fb_pixel_woo_product_content_id( $content_id, $product_id, $content_id_format ) {
|
60 |
-
|
61 |
-
// use value as is
|
62 |
-
if( $content_id_format !== 'facebook_for_woocommerce' ) {
|
63 |
-
return $content_id;
|
64 |
-
}
|
65 |
-
|
66 |
-
$product = wc_get_product($product_id);
|
67 |
-
|
68 |
-
if ( ! $product ) {
|
69 |
-
return $content_id;
|
70 |
-
}
|
71 |
-
|
72 |
-
// Call $product->get_id() instead of ->id to account for Variable
|
73 |
-
// products, which have their own variant_ids.
|
74 |
-
$retailer_id = $product->get_sku() ? $product->get_sku() . '_' .
|
75 |
-
$product->get_id() : 'wc_post_id_' . $product->get_id();
|
76 |
-
|
77 |
-
$ids = array(
|
78 |
-
$product->get_sku(),
|
79 |
-
'wc_post_id_' . $product->get_id(),
|
80 |
-
$retailer_id
|
81 |
-
);
|
82 |
-
|
83 |
-
return $ids;
|
84 |
-
|
85 |
-
}
|
86 |
-
|
87 |
-
add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
|
88 |
-
function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
|
89 |
-
|
90 |
-
if( $content_id_format !== 'facebook_for_woocommerce' ) {
|
91 |
-
return $content_type;
|
92 |
-
}
|
93 |
-
|
94 |
-
if ( $product_type == 'variable' ) {
|
95 |
-
return 'product_group';
|
96 |
-
} else {
|
97 |
-
return 'product';
|
98 |
-
}
|
99 |
-
|
100 |
-
}
|
101 |
-
|
102 |
-
add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
|
103 |
-
function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
|
104 |
-
|
105 |
-
if ( $content_id_format !== 'facebook_for_woocommerce' ) {
|
106 |
-
return $product_id;
|
107 |
-
}
|
108 |
-
|
109 |
-
if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
|
110 |
-
return $cart_item['variation_id'];
|
111 |
-
} else {
|
112 |
-
return $cart_item['product_id'];
|
113 |
-
}
|
114 |
-
|
115 |
-
}
|
116 |
-
|
117 |
-
add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
|
118 |
-
function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
|
119 |
-
|
120 |
-
$setting_defaults['woo']['content_id_format'] = 'default';
|
121 |
-
|
122 |
-
return $setting_defaults;
|
123 |
-
|
124 |
-
}
|
125 |
-
|
126 |
-
add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
|
127 |
-
function pys_fb_pixel_admin_woo_content_id_before() {
|
128 |
-
|
129 |
-
?>
|
130 |
-
|
131 |
-
<tr class="tall">
|
132 |
-
<td colspan="2" class="narrow">
|
133 |
-
<p><strong>It looks like you're using both PixelYourSite and Facebook Ads Extension. Good, because they can do a great job together!</strong></p>
|
134 |
-
<p>Facebook Ads Extension is a useful free tool that lets you import your products to a Facebook shop and adds a very basic Facebook pixel on your site. PixelYourSite is a dedicated plugin that supercharges your Facebook Pixel with extremely useful features.</p>
|
135 |
-
|
136 |
-
<p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
|
137 |
-
|
138 |
-
<p style="margin-top: 0;">
|
139 |
-
<input type="radio" name="pys[woo][content_id_format]" value="facebook_for_woocommerce" <?php echo pys_radio_state( 'woo', 'content_id_format', 'facebook_for_woocommerce' ); ?>><strong>Use Facebook for WooCommerce extension content_id logic</strong>
|
140 |
-
</p>
|
141 |
-
|
142 |
-
<p style="margin-top: 0;">
|
143 |
-
<input type="radio" name="pys[woo][content_id_format]" value="default" <?php echo pys_radio_state( 'woo', 'content_id_format', 'default' ); ?>><strong>PixelYourSite content_id logic</strong>
|
144 |
-
</p>
|
145 |
-
|
146 |
-
<p><em>* If you plan to use the product catalog created by Facebook for WooCommerce Extension, use the Facebook for WooCommerce Extension ID. If you plan to use older product catalogs, or new ones created with other plugins, it's better to keep the default PixelYourSite settings.</em></p>
|
147 |
-
</td>
|
148 |
-
</tr>
|
149 |
-
|
150 |
-
|
151 |
-
<script type="text/javascript">
|
152 |
-
jQuery(document).ready(function ($) {
|
153 |
-
|
154 |
-
$('input[name="pys[woo][content_id_format]"]').change(function (e) {
|
155 |
-
toggleContentIDFormatControls();
|
156 |
-
});
|
157 |
-
|
158 |
-
toggleContentIDFormatControls();
|
159 |
-
|
160 |
-
function toggleContentIDFormatControls() {
|
161 |
-
|
162 |
-
var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
|
163 |
-
|
164 |
-
if (format == 'default') {
|
165 |
-
$('.content_id', '#woo_content_id' ).show();
|
166 |
-
} else {
|
167 |
-
$('.content_id', '#woo_content_id').hide();
|
168 |
-
}
|
169 |
-
|
170 |
-
}
|
171 |
-
|
172 |
-
});
|
173 |
-
</script>
|
174 |
-
|
175 |
-
<?php
|
176 |
-
}
|
177 |
-
|
178 |
-
add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
|
179 |
-
function fb_for_woo_admin_notice_display() {
|
180 |
-
|
181 |
-
$user_id = get_current_user_id();
|
182 |
-
|
183 |
-
if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
|
184 |
-
return;
|
185 |
-
}
|
186 |
-
|
187 |
-
?>
|
188 |
-
|
189 |
-
<div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
|
190 |
-
<p>You're using both PixelYourSite and Facebook for WooCommerce Extension. Good, because they can do a great job together! <strong><a href="<?php echo admin_url( 'admin.php?page=pixel-your-site&active_tab=woo#woo_content_id' ); ?>">Click here for more details</a></strong>.</p>
|
191 |
-
</div>
|
192 |
-
|
193 |
-
<script type="text/javascript">
|
194 |
-
jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
|
195 |
-
|
196 |
-
jQuery.ajax({
|
197 |
-
url: ajaxurl,
|
198 |
-
data: {
|
199 |
-
action: 'fb_for_woo_admin_notice_dismiss',
|
200 |
-
nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
|
201 |
-
user_id: '<?php echo $user_id; ?>'
|
202 |
-
}
|
203 |
-
})
|
204 |
-
|
205 |
-
})
|
206 |
-
</script>
|
207 |
-
|
208 |
-
<?php
|
209 |
-
}
|
210 |
-
|
211 |
-
add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
|
212 |
-
function fb_for_woo_admin_notice_dismiss_handler() {
|
213 |
-
|
214 |
-
if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
|
215 |
-
return;
|
216 |
-
}
|
217 |
-
|
218 |
-
add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
|
219 |
-
|
220 |
-
}
|
221 |
-
|
222 |
endif;
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Manage integration with Facebook for WooCommerce plugin.
|
5 |
+
*
|
6 |
+
* When Facebook for WooCommerce is activated this integration completely removes
|
7 |
+
* default Facebook for WooCommerce pixels and replaces them with PYS's. Also, new "Pixel ID format" option added to
|
8 |
+
* PYS WooCommerce tab where user can decide what format to use in pixel: PYS default or Facebook for WooCommerce.
|
9 |
+
*/
|
10 |
+
|
11 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
+
exit; // Exit if accessed directly.
|
13 |
+
}
|
14 |
+
|
15 |
+
if ( class_exists( 'WC_Facebookcommerce' ) && ! class_exists( 'WC_Facebookcommerce_EventsTracker' ) ) :
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Declare fake WC_Facebookcommerce_EventsTracker class to remove all unwanted front-end pixel events.
|
19 |
+
*/
|
20 |
+
|
21 |
+
/** @noinspection PhpUndefinedClassInspection */
|
22 |
+
class WC_Facebookcommerce_EventsTracker {
|
23 |
+
|
24 |
+
public function __construct( $pixel_id, $user_info ) {
|
25 |
+
}
|
26 |
+
|
27 |
+
public function inject_base_pixel() {
|
28 |
+
}
|
29 |
+
|
30 |
+
public function inject_view_category_event() {
|
31 |
+
}
|
32 |
+
|
33 |
+
public function inject_search_event() {
|
34 |
+
}
|
35 |
+
|
36 |
+
public function inject_view_content_event() {
|
37 |
+
}
|
38 |
+
|
39 |
+
public function inject_add_to_cart_event() {
|
40 |
+
}
|
41 |
+
|
42 |
+
public function inject_initiate_checkout_event() {
|
43 |
+
}
|
44 |
+
|
45 |
+
public function inject_purchase_event( $order_id ) {
|
46 |
+
}
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
endif;
|
51 |
+
|
52 |
+
if ( class_exists( 'WC_Facebookcommerce' ) ) :
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Setup PYS hooks and filters for Facebook for WooCommerce related options and pixel ID output format.
|
56 |
+
*/
|
57 |
+
|
58 |
+
add_filter( 'pys_fb_pixel_woo_product_content_id', 'fb_for_woo_pys_fb_pixel_woo_product_content_id', 10, 4 );
|
59 |
+
function fb_for_woo_pys_fb_pixel_woo_product_content_id( $content_id, $product_id, $content_id_format ) {
|
60 |
+
|
61 |
+
// use value as is
|
62 |
+
if( $content_id_format !== 'facebook_for_woocommerce' ) {
|
63 |
+
return $content_id;
|
64 |
+
}
|
65 |
+
|
66 |
+
$product = wc_get_product($product_id);
|
67 |
+
|
68 |
+
if ( ! $product ) {
|
69 |
+
return $content_id;
|
70 |
+
}
|
71 |
+
|
72 |
+
// Call $product->get_id() instead of ->id to account for Variable
|
73 |
+
// products, which have their own variant_ids.
|
74 |
+
$retailer_id = $product->get_sku() ? $product->get_sku() . '_' .
|
75 |
+
$product->get_id() : 'wc_post_id_' . $product->get_id();
|
76 |
+
|
77 |
+
$ids = array(
|
78 |
+
$product->get_sku(),
|
79 |
+
'wc_post_id_' . $product->get_id(),
|
80 |
+
$retailer_id
|
81 |
+
);
|
82 |
+
|
83 |
+
return $ids;
|
84 |
+
|
85 |
+
}
|
86 |
+
|
87 |
+
add_filter( 'pys_fb_pixel_woo_product_content_type', 'fb_for_woo_pys_fb_pixel_woo_product_content_type', 10, 4 );
|
88 |
+
function fb_for_woo_pys_fb_pixel_woo_product_content_type( $content_type, $product_type, $product, $content_id_format ) {
|
89 |
+
|
90 |
+
if( $content_id_format !== 'facebook_for_woocommerce' ) {
|
91 |
+
return $content_type;
|
92 |
+
}
|
93 |
+
|
94 |
+
if ( $product_type == 'variable' ) {
|
95 |
+
return 'product_group';
|
96 |
+
} else {
|
97 |
+
return 'product';
|
98 |
+
}
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
add_filter( 'pys_fb_pixel_woo_cart_item_product_id', 'fb_for_woo_pys_fb_pixel_woo_cart_item_product_id', 10, 3 );
|
103 |
+
function fb_for_woo_pys_fb_pixel_woo_cart_item_product_id( $product_id, $cart_item, $content_id_format ) {
|
104 |
+
|
105 |
+
if ( $content_id_format !== 'facebook_for_woocommerce' ) {
|
106 |
+
return $product_id;
|
107 |
+
}
|
108 |
+
|
109 |
+
if ( isset( $cart_item['variation_id'] ) && $cart_item['variation_id'] !== 0 ) {
|
110 |
+
return $cart_item['variation_id'];
|
111 |
+
} else {
|
112 |
+
return $cart_item['product_id'];
|
113 |
+
}
|
114 |
+
|
115 |
+
}
|
116 |
+
|
117 |
+
add_filter( 'pys_fb_pixel_setting_defaults', 'fb_for_woo_pys_fb_pixel_setting_defaults', 10, 1 );
|
118 |
+
function fb_for_woo_pys_fb_pixel_setting_defaults( $setting_defaults ) {
|
119 |
+
|
120 |
+
$setting_defaults['woo']['content_id_format'] = 'default';
|
121 |
+
|
122 |
+
return $setting_defaults;
|
123 |
+
|
124 |
+
}
|
125 |
+
|
126 |
+
add_action( 'pys_fb_pixel_admin_woo_content_id_before', 'pys_fb_pixel_admin_woo_content_id_before' );
|
127 |
+
function pys_fb_pixel_admin_woo_content_id_before() {
|
128 |
+
|
129 |
+
?>
|
130 |
+
|
131 |
+
<tr class="tall">
|
132 |
+
<td colspan="2" class="narrow">
|
133 |
+
<p><strong>It looks like you're using both PixelYourSite and Facebook Ads Extension. Good, because they can do a great job together!</strong></p>
|
134 |
+
<p>Facebook Ads Extension is a useful free tool that lets you import your products to a Facebook shop and adds a very basic Facebook pixel on your site. PixelYourSite is a dedicated plugin that supercharges your Facebook Pixel with extremely useful features.</p>
|
135 |
+
|
136 |
+
<p>We made it possible to use both plugins together. You just have to decide what ID to use for your events.</p>
|
137 |
+
|
138 |
+
<p style="margin-top: 0;">
|
139 |
+
<input type="radio" name="pys[woo][content_id_format]" value="facebook_for_woocommerce" <?php echo pys_radio_state( 'woo', 'content_id_format', 'facebook_for_woocommerce' ); ?>><strong>Use Facebook for WooCommerce extension content_id logic</strong>
|
140 |
+
</p>
|
141 |
+
|
142 |
+
<p style="margin-top: 0;">
|
143 |
+
<input type="radio" name="pys[woo][content_id_format]" value="default" <?php echo pys_radio_state( 'woo', 'content_id_format', 'default' ); ?>><strong>PixelYourSite content_id logic</strong>
|
144 |
+
</p>
|
145 |
+
|
146 |
+
<p><em>* If you plan to use the product catalog created by Facebook for WooCommerce Extension, use the Facebook for WooCommerce Extension ID. If you plan to use older product catalogs, or new ones created with other plugins, it's better to keep the default PixelYourSite settings.</em></p>
|
147 |
+
</td>
|
148 |
+
</tr>
|
149 |
+
|
150 |
+
|
151 |
+
<script type="text/javascript">
|
152 |
+
jQuery(document).ready(function ($) {
|
153 |
+
|
154 |
+
$('input[name="pys[woo][content_id_format]"]').change(function (e) {
|
155 |
+
toggleContentIDFormatControls();
|
156 |
+
});
|
157 |
+
|
158 |
+
toggleContentIDFormatControls();
|
159 |
+
|
160 |
+
function toggleContentIDFormatControls() {
|
161 |
+
|
162 |
+
var format = $('input[name="pys[woo][content_id_format]"]:checked').val();
|
163 |
+
|
164 |
+
if (format == 'default') {
|
165 |
+
$('.content_id', '#woo_content_id' ).show();
|
166 |
+
} else {
|
167 |
+
$('.content_id', '#woo_content_id').hide();
|
168 |
+
}
|
169 |
+
|
170 |
+
}
|
171 |
+
|
172 |
+
});
|
173 |
+
</script>
|
174 |
+
|
175 |
+
<?php
|
176 |
+
}
|
177 |
+
|
178 |
+
add_action( 'admin_notices', 'fb_for_woo_admin_notice_display' );
|
179 |
+
function fb_for_woo_admin_notice_display() {
|
180 |
+
|
181 |
+
$user_id = get_current_user_id();
|
182 |
+
|
183 |
+
if( get_user_meta( $user_id, 'fb_for_woo_admin_notice_dismissed' ) ) {
|
184 |
+
return;
|
185 |
+
}
|
186 |
+
|
187 |
+
?>
|
188 |
+
|
189 |
+
<div class="notice notice-success is-dismissible fb_for_woo_admin_notice">
|
190 |
+
<p>You're using both PixelYourSite and Facebook for WooCommerce Extension. Good, because they can do a great job together! <strong><a href="<?php echo admin_url( 'admin.php?page=pixel-your-site&active_tab=woo#woo_content_id' ); ?>">Click here for more details</a></strong>.</p>
|
191 |
+
</div>
|
192 |
+
|
193 |
+
<script type="text/javascript">
|
194 |
+
jQuery(document).on('click', '.fb_for_woo_admin_notice .notice-dismiss', function () {
|
195 |
+
|
196 |
+
jQuery.ajax({
|
197 |
+
url: ajaxurl,
|
198 |
+
data: {
|
199 |
+
action: 'fb_for_woo_admin_notice_dismiss',
|
200 |
+
nonce: '<?php echo wp_create_nonce( 'fb_for_woo_admin_notice_dismiss' ); ?>',
|
201 |
+
user_id: '<?php echo $user_id; ?>'
|
202 |
+
}
|
203 |
+
})
|
204 |
+
|
205 |
+
})
|
206 |
+
</script>
|
207 |
+
|
208 |
+
<?php
|
209 |
+
}
|
210 |
+
|
211 |
+
add_action( 'wp_ajax_fb_for_woo_admin_notice_dismiss', 'fb_for_woo_admin_notice_dismiss_handler' );
|
212 |
+
function fb_for_woo_admin_notice_dismiss_handler() {
|
213 |
+
|
214 |
+
if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fb_for_woo_admin_notice_dismiss' ) ) {
|
215 |
+
return;
|
216 |
+
}
|
217 |
+
|
218 |
+
add_user_meta( $_REQUEST['user_id'], 'fb_for_woo_admin_notice_dismissed', true );
|
219 |
+
|
220 |
+
}
|
221 |
+
|
222 |
endif;
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: PixelYourSite, c0d3fev3r, themister
|
|
3 |
Tags: Facebook Pixel, New Facebook Pixel, Facebook Conversion Pixel, Facebook Pixel Events, Facebook, New Facebook Pixel Events, Dynamic Events, Standard Events, Facebook Events, Facebook Standard Events, Facebook Dynamic Product Ads, WooCommerce, WooCommerce Facebook Pixel, Facebook Custom Events, Facebook Conversion Value, WooCommerce Affiliate Products, Easy Digital Downloads Pixel, Easy Digital Downloads Facebook Pixel
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 4.8
|
6 |
-
Stable tag: 5.0.
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
@@ -318,6 +318,11 @@ We have an article about how to create Custom Reports:
|
|
318 |
|
319 |
== Changelog ==
|
320 |
|
|
|
|
|
|
|
|
|
|
|
321 |
= PixelYourSite 5.0.6 =
|
322 |
|
323 |
|
3 |
Tags: Facebook Pixel, New Facebook Pixel, Facebook Conversion Pixel, Facebook Pixel Events, Facebook, New Facebook Pixel Events, Dynamic Events, Standard Events, Facebook Events, Facebook Standard Events, Facebook Dynamic Product Ads, WooCommerce, WooCommerce Facebook Pixel, Facebook Custom Events, Facebook Conversion Value, WooCommerce Affiliate Products, Easy Digital Downloads Pixel, Easy Digital Downloads Facebook Pixel
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 4.8
|
6 |
+
Stable tag: 5.0.7
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
318 |
|
319 |
== Changelog ==
|
320 |
|
321 |
+
= PixelYourSite 5.0.7 =
|
322 |
+
|
323 |
+
* Purchase event 0 value error fixed (there wasn't any value parameter when the order value was zero)
|
324 |
+
|
325 |
+
|
326 |
= PixelYourSite 5.0.6 =
|
327 |
|
328 |
|