Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/integration.tar
Назад
FacebookWordpressWPForms.php 0000755 00000012246 14720352624 0012172 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\FacebookWordPressOptions; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\UserData; class FacebookWordpressWPForms extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'wpforms-lite/wpforms.php'; const TRACKING_NAME = 'wpforms-lite'; public static function injectPixelCode() { add_action( 'wpforms_process_before', array(__CLASS__, 'trackEvent'), 20, 2 ); } public static function trackEvent($entry, $form_data) { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'Lead', array(__CLASS__, 'readFormData'), array($entry, $form_data), self::TRACKING_NAME, true ); FacebookServerSideEvent::getInstance()->track($server_event); add_action( 'wp_footer', array(__CLASS__, 'injectLeadEvent'), 20 ); } public static function injectLeadEvent() { if (FacebookPluginUtils::isInternalUser()) { return; } $events = FacebookServerSideEvent::getInstance()->getTrackedEvents(); $pixel_code = PixelRenderer::render($events, self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $pixel_code); } public static function readFormData($entry, $form_data) { if (empty($entry) || empty($form_data)) { return array(); } $name = self::getName($entry, $form_data); $event_data = array( 'email' => self::getEmail($entry, $form_data), 'first_name' => !empty($name) ? $name[0] : null, 'last_name' => !empty($name) ? $name[1] : null, 'phone' => self::getPhone($entry, $form_data) ); $event_data = array_merge( $event_data, self::getAddress($entry, $form_data) ); return $event_data; } private static function getPhone($entry, $form_data) { return self::getField($entry, $form_data, 'phone'); } private static function getEmail($entry, $form_data) { return self::getField($entry, $form_data, 'email'); } private static function getAddress($entry, $form_data){ $address_field_data = self::getField($entry, $form_data, 'address'); if($address_field_data == null){ return array(); } $address_data = array(); if(array_key_exists('city', $address_field_data)){ $address_data['city'] = $address_field_data['city']; } if(array_key_exists('state', $address_field_data)){ $address_data['state'] = $address_field_data['state']; } //Country values are sent in ISO format if(array_key_exists('country', $address_field_data)){ $address_data['country'] = $address_field_data['country']; } else{ // When country is not present, it could be that address scheme is us // so country will be US $address_scheme = self::getAddressScheme($form_data); if( $address_scheme == 'us'){ $address_data['country'] = 'US'; } } if(array_key_exists('postal', $address_field_data)){ $address_data['zip'] = $address_field_data['postal']; } return $address_data; } private static function getName($entry, $form_data) { if (empty($form_data['fields']) || empty($entry['fields'])) { return null; } $entries = $entry['fields']; foreach ($form_data['fields'] as $field) { if ($field['type'] == 'name') { if ($field['format'] == 'simple') { return ServerEventFactory::splitName($entries[$field['id']]); } else if ($field['format'] == 'first-last') { return array( $entries[$field['id']]['first'], $entries[$field['id']]['last'] ); } } } return null; } private static function getField($entry, $form_data, $type) { if (empty($form_data['fields']) || empty($entry['fields'])) { return null; } foreach ($form_data['fields'] as $field) { if ($field['type'] == $type) { return $entry['fields'][$field['id']]; } } return null; } private static function getAddressScheme($form_data){ foreach ($form_data['fields'] as $field) { if ($field['type'] == 'address') { if(array_key_exists('scheme', $field)){ return $field['scheme']; } } } return null; } } FacebookWordpressEasyDigitalDownloads.php 0000755 00000023650 14720352624 0014710 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookPixelPlugin\Core\FacebookWordpressOptions; use FacebookPixelPlugin\Core\EventIdGenerator; class FacebookWordpressEasyDigitalDownloads extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'easy-digital-downloads/easy-digital-downloads.php'; const TRACKING_NAME = 'easy-digital-downloads'; private static $addToCartJS = " jQuery(document).ready(function ($) { $('.edd-add-to-cart').click(function (e) { e.preventDefault(); var _this = $(this), form = _this.closest('form'); var download = _this.data('download-id'); var currency = $('.edd_purchase_' + download + ' meta[itemprop=\'priceCurrency\']').attr('content'); var form = _this.parents('form').last(); var value = 0; var variable_price = _this.data('variable-price'); var event_id = form.find(\"input[name='facebook_event_id']\").val(); if( variable_price == 'yes' ) { form.find('.edd_price_option_' + download + ':checked', form).each(function(index) { value = $(this).data('price'); }); } else { if ( _this.data('price') && _this.data('price') > 0 ) { value = _this.data('price'); } } var param = { 'content_ids': [download], 'content_type': 'product', 'currency': currency, '%s': '%s', 'value': value }; fbq('set', 'agent', '%s', '%s'); if(event_id){ fbq('track', 'AddToCart', param, {'eventID': event_id}); } else{ fbq('track', 'AddToCart', param); } }); }); "; public static function injectPixelCode() { // AddToCart JS listener add_action( 'edd_after_download_content', array(__CLASS__, 'injectAddToCartListener') ); add_action( 'edd_downloads_list_after', array(__CLASS__, 'injectAddToCartListener') ); //Hooks to AddToCart ajax requests add_action( 'wp_ajax_edd_add_to_cart', array(__CLASS__, 'injectAddToCartEventAjax'), 5 ); add_action( 'wp_ajax_nopriv_edd_add_to_cart', array(__CLASS__, 'injectAddToCartEventAjax'), 5 ); //Injects a hidden field with event id to send it in AddToCart ajax request add_action( 'edd_purchase_link_top', array(__CLASS__, 'injectAddToCartEventId') ); // InitiateCheckout self::addPixelFireForHook(array( 'hook_name' => 'edd_after_checkout_cart', 'classname' => __CLASS__, 'inject_function' => 'injectInitiateCheckoutEvent')); // Purchase add_action( 'edd_payment_receipt_after', array(__CLASS__, 'trackPurchaseEvent'), 10, 2); // ViewContent add_action( 'edd_after_download_content', array(__CLASS__, 'injectViewContentEvent'), 40, 1 ); } public static function injectAddToCartEventId(){ if(FacebookPluginUtils::isInternalUser()){ return; } $eventId = EventIdGenerator::guidv4(); printf("<input type=\"hidden\" name=\"facebook_event_id\" value=\"%s\">", $eventId); } public static function injectAddToCartEventAjax(){ if( isset($_POST['nonce']) && isset($_POST['download_id']) && isset($_POST['post_data'])){ $download_id = absint( $_POST['download_id'] ); //Adding form validations $nonce = sanitize_text_field( $_POST['nonce'] ); if( wp_verify_nonce($nonce, 'edd-add-to-cart-'.$download_id) === false ){ return; } //Getting form data parse_str( $_POST['post_data'], $post_data ); if(isset($post_data['facebook_event_id'])){ //Starting Conversions API event creation $event_id = $post_data['facebook_event_id']; $server_event = ServerEventFactory::safeCreateEvent( 'AddToCart', array(__CLASS__, 'createAddToCartEvent'), array($download_id), self::TRACKING_NAME ); $server_event->setEventId($event_id); FacebookServerSideEvent::getInstance()->track($server_event); } } } public static function injectAddToCartListener($download_id) { if (FacebookPluginUtils::isInternalUser()) { return; } $listener_code = sprintf( self::$addToCartJS, FacebookPixel::FB_INTEGRATION_TRACKING_KEY, self::TRACKING_NAME, FacebookWordpressOptions::getAgentString(), FacebookWordpressOptions::getPixelId() ); printf(" <!-- Meta Pixel Event Code --> <script> %s </script> <!-- End Meta Pixel Event Code --> ", $listener_code); } public static function injectInitiateCheckoutEvent() { if (FacebookPluginUtils::isInternalUser() || !function_exists('EDD')) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'InitiateCheckout', array(__CLASS__, 'createInitiateCheckoutEvent'), array(), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function trackPurchaseEvent($payment, $edd_receipt_args) { if (FacebookPluginUtils::isInternalUser() || empty($payment->ID)) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'Purchase', array(__CLASS__, 'createPurchaseEvent'), array($payment), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); add_action( 'wp_footer', array(__CLASS__, 'injectPurchaseEvent'), 20 ); } public static function injectPurchaseEvent() { $events = FacebookServerSideEvent::getInstance()->getTrackedEvents(); $code = PixelRenderer::render($events, self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function injectViewContentEvent($download_id) { if (FacebookPluginUtils::isInternalUser() || empty($download_id)) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'ViewContent', array(__CLASS__, 'createViewContentEvent'), array($download_id), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function createInitiateCheckoutEvent() { $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $event_data['currency'] = EDDUtils::getCurrency(); $event_data['value'] = EDDUtils::getCartTotal(); return $event_data; } public static function createPurchaseEvent($payment) { $event_data = array(); $payment_meta = \edd_get_payment_meta($payment->ID); if (empty($payment_meta)) { return $event_data; } $event_data['email'] = $payment_meta['email']; $event_data['first_name'] = $payment_meta['user_info']['first_name']; $event_data['last_name'] = $payment_meta['user_info']['last_name']; $content_ids = array(); $value = 0; foreach ($payment_meta['cart_details'] as $item) { $content_ids[] = $item['id']; $value += $item['price']; } $event_data['currency'] = $payment_meta['currency']; $event_data['value'] = $value; $event_data['content_ids'] = $content_ids; $event_data['content_type'] = 'product'; return $event_data; } public static function createViewContentEvent($download_id){ $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $currency = EDDUtils::getCurrency(); $download = edd_get_download($download_id); $title = $download ? $download->post_title : ''; if (get_post_meta($download_id, '_variable_pricing', true)) { $prices = get_post_meta($download_id, 'edd_variable_prices', true); $price = array_shift($prices); $value = $price['amount']; } else { $value = get_post_meta($download_id, 'edd_price', true); } if (!$value) { $value = 0; } $event_data['content_ids'] = [(string)$download_id]; $event_data['content_type'] = 'product'; $event_data['currency'] = $currency; $event_data['value'] = floatval($value); $event_data['content_name'] = $title; return $event_data; } public static function createAddToCartEvent($download_id){ $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $currency = EDDUtils::getCurrency(); $download = edd_get_download($download_id); $title = $download ? $download->post_title : ''; if ( get_post_meta($download_id, '_variable_pricing', true) ) { $prices = get_post_meta($download_id, 'edd_variable_prices', true); $price = array_shift($prices); $value = $price['amount']; } else { $value = get_post_meta($download_id, 'edd_price', true); } if (!$value) { $value = 0; } $event_data['content_ids'] = [(string)$download_id]; $event_data['content_type'] = 'product'; $event_data['currency'] = $currency; $event_data['value'] = $value; $event_data['content_name'] = $title; return $event_data; } } FacebookWordpressFormidableForm.php 0000755 00000011624 14720352624 0013524 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\FacebookWordPressOptions; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\UserData; class FacebookWordpressFormidableForm extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'formidable/formidable.php'; const TRACKING_NAME = 'formidable-lite'; public static function injectPixelCode() { add_action( 'frm_after_create_entry', array(__CLASS__, 'trackServerEvent'), 20, 2 ); } public static function trackServerEvent($entry_id, $form_id) { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'Lead', array(__CLASS__, 'readFormData'), array($entry_id), self::TRACKING_NAME, true ); FacebookServerSideEvent::getInstance()->track($server_event); add_action( 'wp_footer', array(__CLASS__, 'injectLeadEvent'), 20 ); } public static function injectLeadEvent() { if (FacebookPluginUtils::isInternalUser()) { return; } $events = FacebookServerSideEvent::getInstance()->getTrackedEvents(); $code = PixelRenderer::render($events, self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function readFormData($entry_id) { if (empty($entry_id)) { return array(); } $entry_values = IntegrationUtils::getFormidableFormsEntryValues($entry_id); $field_values = $entry_values->get_field_values(); if (!empty($field_values)) { $user_data = array( 'email' => self::getEmail($field_values), 'first_name' => self::getFirstName($field_values), 'last_name' => self::getLastName($field_values), 'phone' => self::getPhone($field_values) ); $address_data = self::getAddressInformation($field_values); return array_merge($user_data, $address_data); } return array(); } private static function getEmail($field_values) { return self::getFieldValueByType($field_values, 'email'); } private static function getFirstName($field_values) { return self::getFieldValue($field_values, 'text', 'Name', 'First'); } private static function getLastName($field_values) { return self::getFieldValue($field_values, 'text', 'Last', 'Last'); } private static function getPhone($field_values) { return self::getFieldValueByType($field_values, 'phone'); } private static function getAddressInformation($field_values){ $address_saved_value = self::getFieldValueByType($field_values, 'address'); $address_data = array(); if($address_saved_value){ if(array_key_exists('city', $address_saved_value)){ $address_data['city'] = $address_saved_value['city']; } if(array_key_exists('state', $address_saved_value)){ $address_data['state'] = $address_saved_value['state']; } // Validating ISO code // In current version, country field saves the full name if( array_key_exists('country', $address_saved_value) && strlen($address_saved_value['country']) == 2 ){ $address_data['country'] = $address_saved_value['country']; } if(array_key_exists('zip', $address_saved_value)){ $address_data['zip'] = $address_saved_value['zip']; } } return $address_data; } private static function getFieldValueByType($field_values, $type){ foreach ($field_values as $field_value) { $field = $field_value->get_field(); if ($field->type == $type) { return $field_value->get_saved_value(); } } return null; } private static function getFieldValue( $field_values, $type, $name, $description) { foreach ($field_values as $field_value) { $field = $field_value->get_field(); if ($field->type == $type && $field->name == $name && $field->description == $description) { return $field_value->get_saved_value(); } } return null; } } IntegrationUtils.php 0000755 00000001430 14720352624 0010567 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); class IntegrationUtils { public static function getFormidableFormsEntryValues($entry_id) { return new \FrmEntryValues($entry_id); } } EDDUtils.php 0000755 00000001475 14720352624 0006711 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); class EDDUtils { public static function getCurrency() { return edd_get_currency(); } public static function getCartTotal() { return EDD()->cart->get_total(); } } FacebookWordpressNinjaForms.php 0000755 00000011410 14720352624 0012673 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\FacebookWordPressOptions; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\UserData; class FacebookWordpressNinjaForms extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'ninja-forms/ninja-forms.php'; const TRACKING_NAME = 'ninja-forms'; public static function injectPixelCode() { add_action( 'ninja_forms_submission_actions', array(__CLASS__, 'injectLeadEvent'), 10, 3); } public static function injectLeadEvent($actions, $form_cache, $form_data) { if (FacebookPluginUtils::isInternalUser()) { return $actions; } foreach ($actions as $key => $action) { if (!isset($action['settings']) || !isset($action['settings']['type'])) { continue; } $type = $action['settings']['type']; if (!is_string($type)) { continue; } // inject code when form is submitted successfully if ($type == 'successmessage') { $event = ServerEventFactory::safeCreateEvent( 'Lead', array(__CLASS__, 'readFormData'), array($form_data), self::TRACKING_NAME, true ); FacebookServerSideEvent::getInstance()->track($event); $pixel_code = PixelRenderer::render(array($event), self::TRACKING_NAME); $code = sprintf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $pixel_code); $action['settings']['success_msg'] .= $code; $actions[$key] = $action; } } return $actions; } public static function readFormData($form_data) { if (empty($form_data)) { return array(); } $event_data = array(); $name = self::getName($form_data); if( $name ){ $event_data['first_name'] = $name[0]; $event_data['last_name'] = $name[1]; } else{ $event_data['first_name'] = self::getFirstName($form_data); $event_data['last_name'] = self::getLastName($form_data); } $event_data['email'] = self::getEmail($form_data); $event_data['phone'] = self::getPhone($form_data); $event_data['city'] = self::getCity($form_data); $event_data['zip'] = self::getZipCode($form_data); $event_data['state'] = self::getState($form_data); $event_data['country'] = self::getCountry($form_data); $event_data['gender'] = self::getGender($form_data); return $event_data; } private static function getEmail($form_data) { return self::getField($form_data, 'email'); } private static function getName($form_data) { $name = self::getField($form_data, 'name'); if($name){ return ServerEventFactory::splitName($name); } return null; } private static function getFirstName($form_data){ return self::getField($form_data, 'firstname'); } private static function getLastName($form_data){ return self::getField($form_data, 'lastname'); } private static function getPhone($form_data) { return self::getField($form_data, 'phone'); } private static function getCity($form_data) { return self::getField($form_data, 'city'); } private static function getZipCode($form_data) { return self::getField($form_data, 'zip'); } private static function getState($form_data) { return self::getField($form_data, 'liststate'); } private static function getCountry($form_data) { return self::getField($form_data, 'listcountry'); } private static function getGender($form_data) { return self::getField($form_data, 'gender'); } private static function hasPrefix($string, $prefix){ $len = strlen($prefix); return substr($string, 0, $len) === $prefix; } private static function getField($form_data, $key) { if (empty($form_data['fields'])) { return null; } foreach ($form_data['fields'] as $field) { if ( self::hasPrefix( $field['key'], $key) ) { return $field['value']; } } return null; } } FacebookWordpressContactForm7.php 0000755 00000010533 14720352624 0013140 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\FacebookWordPressOptions; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\UserData; class FacebookWordpressContactForm7 extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'contact-form-7/wp-contact-form-7.php'; const TRACKING_NAME = 'contact-form-7'; public static function injectPixelCode() { add_action( 'wpcf7_submit', array(__CLASS__, 'trackServerEvent'), 10, 2); add_action( 'wp_footer', array(__CLASS__, 'injectMailSentListener'), 10, 2); } public static function injectMailSentListener(){ ob_start(); ?> <!-- Meta Pixel Event Code --> <script type='text/javascript'> document.addEventListener( 'wpcf7mailsent', function( event ) { if( "fb_pxl_code" in event.detail.apiResponse){ eval(event.detail.apiResponse.fb_pxl_code); } }, false ); </script> <!-- End Meta Pixel Event Code --> <?php $listenerCode = ob_get_clean(); echo $listenerCode; } public static function trackServerEvent($form, $result) { $isInternalUser = FacebookPluginUtils::isInternalUser(); $submitFailed = $result['status'] !== 'mail_sent'; if ($isInternalUser || $submitFailed) { return $result; } $server_event = ServerEventFactory::safeCreateEvent( 'Lead', array(__CLASS__, 'readFormData'), array($form), self::TRACKING_NAME, true ); FacebookServerSideEvent::getInstance()->track($server_event); add_action( 'wpcf7_feedback_response', array(__CLASS__, 'injectLeadEvent'), 20, 2); return $result; } public static function injectLeadEvent($response, $result) { if (FacebookPluginUtils::isInternalUser()) { return $response; } $events = FacebookServerSideEvent::getInstance()->getTrackedEvents(); if( count($events) == 0 ){ return $response; } $event_id = $events[0]->getEventId(); $fbq_calls = PixelRenderer::render($events, self::TRACKING_NAME, false); $code = sprintf(" if( typeof window.pixelLastGeneratedLeadEvent === 'undefined' || window.pixelLastGeneratedLeadEvent != '%s' ){ window.pixelLastGeneratedLeadEvent = '%s'; %s } ", $event_id , $event_id , $fbq_calls); $response['fb_pxl_code'] = $code; return $response; } public static function readFormData($form) { if (empty($form)) { return array(); } $form_tags = $form->scan_form_tags(); $name = self::getName($form_tags); return array( 'email' => self::getEmail($form_tags), 'first_name' => $name[0], 'last_name' => $name[1], 'phone' => self::getPhone($form_tags) ); } private static function getEmail($form_tags) { if (empty($form_tags)) { return null; } foreach ($form_tags as $tag) { if ($tag->basetype == "email") { return $_POST[$tag->name]; } } return null; } private static function getName($form_tags) { if (empty($form_tags)) { return null; } foreach ($form_tags as $tag) { if ($tag->basetype === "text" && strpos(strtolower($tag->name), 'name') !== false) { return ServerEventFactory::splitName($_POST[$tag->name]); } } return null; } private static function getPhone($form_tags) { if (empty($form_tags)) { return null; } foreach ($form_tags as $tag) { if ($tag->basetype === "tel") { return $_POST[$tag->name]; } } return null; } } FacebookWordpressCalderaForm.php 0000755 00000006526 14720352624 0013020 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\FacebookWordPressOptions; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookAds\Object\ServerSide\Event; use FacebookAds\Object\ServerSide\UserData; class FacebookWordpressCalderaForm extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'caldera-forms/caldera-core.php'; const TRACKING_NAME = 'caldera-forms'; public static function injectPixelCode() { add_action( 'caldera_forms_ajax_return', array(__CLASS__, 'injectLeadEvent'), 10, 2); } public static function injectLeadEvent($out, $form) { if ( FacebookPluginUtils::isInternalUser() || $out['status'] !== 'complete' ) { return $out; } $server_event = ServerEventFactory::safeCreateEvent( 'Lead', array(__CLASS__, 'readFormData'), array($form), self::TRACKING_NAME, true ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); $code = sprintf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); $out['html'] .= $code; return $out; } public static function readFormData($form) { if (empty($form)) { return array(); } return array( 'email' => self::getEmail($form), 'first_name' => self::getFirstName($form), 'last_name' => self::getLastName($form), 'phone' => self::getPhone($form), 'state' => self::getState($form) ); } private static function getEmail($form) { return self::getFieldValue($form, 'type', 'email'); } private static function getFirstName($form) { return self::getFieldValue($form, 'slug', 'first_name'); } private static function getLastName($form) { return self::getFieldValue($form, 'slug', 'last_name'); } private static function getState($form){ return self::getFieldValue($form, 'type', 'states'); } private static function getPhone($form) { // Extract phone number from the better version first, fallback to the basic // version if it's null $phone = self::getFieldValue($form, 'type', 'phone_better'); return empty($phone) ? self::getFieldValue($form, 'type', 'phone') : $phone; } private static function getFieldValue($form, $attr, $attr_value) { if (empty($form['fields'])) { return null; } foreach ($form['fields'] as $field) { if (array_key_exists($attr, $field) && $field[$attr] == $attr_value) { return $_POST[$field['ID']]; } } return null; } } FacebookWordpressWooCommerce.php 0000755 00000027021 14720352624 0013051 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\PixelRenderer; use FacebookAds\Object\ServerSide\Content; class FacebookWordpressWooCommerce extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'facebook-for-woocommerce/facebook-for-woocommerce.php'; const TRACKING_NAME = 'woocommerce'; // Being consistent with the WooCommerce plugin const FB_ID_PREFIX = 'wc_post_id_'; const DIV_ID_FOR_AJAX_PIXEL_EVENTS = 'fb-pxl-ajax-code'; public static function injectPixelCode() { // Add the hooks only if the WooCommerce plugin is not active if(!self::isFacebookForWooCommerceActive()) { add_action('woocommerce_after_checkout_form', array(__CLASS__, 'trackInitiateCheckout'), 40); add_action( 'woocommerce_add_to_cart', array(__CLASS__, 'trackAddToCartEvent'), 40, 4); add_action( 'woocommerce_thankyou', array(__CLASS__, 'trackPurchaseEvent'), 40); add_action( 'woocommerce_payment_complete', array(__CLASS__, 'trackPurchaseEvent'), 40); add_action( 'woocommerce_after_single_product', array(__CLASS__, 'trackViewContentEvent'), 40); // This div will be used to insert the fbq calls // when an event is triggered by an AJAX request add_action( 'wp_footer', array(__CLASS__, 'addDivForAjaxPixelEvent') ); } } public static function addDivForAjaxPixelEvent(){ echo self::getDivForAjaxPixelEvent(); } public static function getDivForAjaxPixelEvent($content = ''){ return "<div id='".self::DIV_ID_FOR_AJAX_PIXEL_EVENTS."'>" .$content."</div>"; } public static function trackViewContentEvent(){ if(FacebookPluginUtils::isInternalUser()){ return; } global $post; if (!isset($post->ID)){ return; } $product = wc_get_product($post->ID); if(!$product){ return; } $server_event = ServerEventFactory::safeCreateEvent( 'ViewContent', array(__CLASS__, 'createViewContentEvent'), array($product), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event, false); self::enqueuePixelCode($server_event); } public static function createViewContentEvent($product){ $event_data = self::getPIIFromSession(); $product_id = self::getProductId($product); $content_type = $product->is_type('variable') ? 'product_group' : 'product'; $event_data['content_type'] = $content_type; $event_data['currency'] = \get_woocommerce_currency(); $event_data['value'] = $product->get_price(); $event_data['content_ids'] = array($product_id); $event_data['content_name'] = $product->get_title(); $event_data['content_category'] = self::getProductCategory($product->get_id()); return array_filter($event_data); } private static function getProductCategory($product_id){ $categories = get_the_terms( $product_id, 'product_cat' ); return count($categories) > 0 ? $categories[0]->name : null; } public static function trackPurchaseEvent($order_id) { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'Purchase', array(__CLASS__, 'createPurchaseEvent'), array($order_id), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); self::enqueuePixelCode($server_event); } public static function createPurchaseEvent($order_id) { $order = wc_get_order($order_id); $content_type = 'product'; $product_ids = array(); $contents = array(); foreach ($order->get_items() as $item) { $product = wc_get_product($item->get_product_id()); if ('product_group' !== $content_type && $product->is_type('variable')) { $content_type = 'product_group'; } $quantity = $item->get_quantity(); $product_id = self::getProductId($product); $content = new Content(); $content->setProductId($product_id); $content->setQuantity($quantity); $content->setItemPrice($item->get_total() / $quantity); $contents[] = $content; $product_ids[] = $product_id; } $event_data = self::getPiiFromBillingInformation($order); $event_data['content_type'] = $content_type; $event_data['currency'] = \get_woocommerce_currency(); $event_data['value'] = $order->get_total(); $event_data['content_ids'] = $product_ids; $event_data['contents'] = $contents; return $event_data; } public static function trackAddToCartEvent( $cart_item_key, $product_id, $quantity, $variation_id) { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'AddToCart', array(__CLASS__, 'createAddToCartEvent'), array($cart_item_key, $product_id, $quantity), self::TRACKING_NAME ); // When AJAX is used to add an item to the cart // The Conversions API event should be sent inmediately // because the wp_footer action is not executed $is_ajax_request = wp_doing_ajax(); FacebookServerSideEvent::getInstance()->track($server_event, $is_ajax_request); // If it is not an ajax request // We show the pixel call in the footer // Otherwise we add a filter // to modify the ajax response // and show the fbq call in the div #fb-pxl-ajax-code if(!$is_ajax_request){ self::enqueuePixelCode($server_event); } else{ FacebookServerSideEvent::getInstance()->setPendingPixelEvent( 'addPixelCodeToAddToCartFragment', $server_event ); add_filter('woocommerce_add_to_cart_fragments', array(__CLASS__, 'addPixelCodeToAddToCartFragment')); } } public static function addPixelCodeToAddToCartFragment($fragments) { $server_event = FacebookServerSideEvent::getInstance() ->getPendingPixelEvent('addPixelCodeToAddToCartFragment'); if( !is_null($server_event) ){ $pixel_code = self::generatePixelCode($server_event, true); $fragments['#'.self::DIV_ID_FOR_AJAX_PIXEL_EVENTS] = self::getDivForAjaxPixelEvent($pixel_code); } return $fragments; } public static function createAddToCartEvent( $cart_item_key, $product_id, $quantity) { $event_data = self::getPIIFromSession(); $event_data['content_type'] = 'product'; $event_data['currency'] = \get_woocommerce_currency(); $cart_item = self::getCartItem($cart_item_key); if (!empty($cart_item_key)) { $event_data['content_ids'] = array(self::getProductId($cart_item['data'])); $event_data['value'] = self::getAddToCartValue($cart_item, $quantity); } return $event_data; } public static function trackInitiateCheckout() { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'InitiateCheckout', array(__CLASS__, 'createInitiateCheckoutEvent'), array(), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); self::enqueuePixelCode($server_event); } public static function createInitiateCheckoutEvent() { $event_data = self::getPIIFromSession(); $event_data['content_type'] = 'product'; $event_data['currency'] = \get_woocommerce_currency(); if ($cart = WC()->cart) { $event_data['num_items'] = $cart->get_cart_contents_count(); $event_data['value'] = $cart->total; $event_data['content_ids'] = self::getContentIds($cart); $event_data['contents'] = self::getContents($cart); } return $event_data; } private static function getPiiFromBillingInformation($order) { $pii = array(); $pii['first_name'] = $order->get_billing_first_name(); $pii['last_name'] = $order->get_billing_last_name(); $pii['email'] = $order->get_billing_email(); $pii['zip'] = $order->get_billing_postcode(); $pii['state'] = $order->get_billing_state(); $pii['country'] = $order->get_billing_country(); $pii['city'] = $order->get_billing_city(); $pii['phone'] = $order->get_billing_phone(); return $pii; } private static function getAddToCartValue($cart_item, $quantity) { if (!empty($cart_item)) { $price = $cart_item['line_total'] / $cart_item['quantity']; return $quantity * $price; } return null; } private static function getCartItem($cart_item_key) { if (WC()->cart) { $cart = WC()->cart->get_cart(); if (!empty($cart) && !empty($cart[$cart_item_key])) { return $cart[$cart_item_key]; } } return null; } private static function getContentIds($cart) { $product_ids = []; foreach ($cart->get_cart() as $item) { if (!empty($item['data'])) { $product_ids[] = self::getProductId($item['data']); } } return $product_ids; } private static function getContents($cart) { $contents = []; foreach ($cart->get_cart() as $item) { if (!empty($item['data']) && !empty($item['quantity'])) { $content = new Content(); $content->setProductId(self::getProductId($item['data'])); $content->setQuantity($item['quantity']); $content->setItemPrice($item['line_total'] / $item['quantity']); $contents[] = $content; } } return $contents; } private static function getProductId($product) { $woo_id = $product->get_id(); return $product->get_sku() ? $product->get_sku() . '_' . $woo_id : self::FB_ID_PREFIX . $woo_id; } private static function getPIIFromSession(){ $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $user_id = get_current_user_id(); if($user_id != 0){ $event_data['city'] = get_user_meta($user_id, 'billing_city', true); $event_data['zip'] = get_user_meta($user_id, 'billing_postcode', true); $event_data['country'] = get_user_meta($user_id, 'billing_country', true); $event_data['state'] = get_user_meta($user_id, 'billing_state', true); $event_data['phone'] = get_user_meta($user_id, 'billing_phone', true); } return array_filter($event_data); } private static function isFacebookForWooCommerceActive() { return in_array( 'facebook-for-woocommerce/facebook-for-woocommerce.php', get_option('active_plugins')); } public static function generatePixelCode($server_event, $script_tag = false){ $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME, $script_tag); $code = sprintf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); return $code; } public static function enqueuePixelCode($server_event){ $code = self::generatePixelCode($server_event, false); wc_enqueue_js($code); return $code; } } FacebookWordpressWPECommerce.php 0000755 00000012572 14720352624 0012745 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\PixelRenderer; class FacebookWordpressWPECommerce extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'wp-e-commerce/wp-e-commerce.php'; const TRACKING_NAME = 'wp-e-commerce'; public static function injectPixelCode() { // AddToCart add_action('wpsc_add_to_cart_json_response', array(__CLASS__, 'injectAddToCartEvent'), 11); // InitiateCheckout self::addPixelFireForHook(array( 'hook_name' => 'wpsc_before_shopping_cart_page', 'classname' => __CLASS__, 'inject_function' => 'injectInitiateCheckoutEvent')); // Purchase add_action( 'wpsc_transaction_results_shutdown', array(__CLASS__, 'injectPurchaseEvent'), 11, 3); } // Event hook for AddToCart. public static function injectAddToCartEvent($response) { if (FacebookPluginUtils::isInternalUser()) { return $response; } $product_id = $response['product_id']; $server_event = ServerEventFactory::safeCreateEvent( 'AddToCart', array(__CLASS__, 'createAddToCartEvent'), array($product_id), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); $code = sprintf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); $response['widget_output'] .= $code; return $response; } public static function injectInitiateCheckoutEvent() { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'InitiateCheckout', array(__CLASS__, 'createInitiateCheckoutEvent'), array(), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function injectPurchaseEvent( $purchase_log_object, $session_id, $display_to_screen) { if (FacebookPluginUtils::isInternalUser() || !$display_to_screen) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'Purchase', array(__CLASS__, 'createPurchaseEvent'), array($purchase_log_object), self::TRACKING_NAME ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function createPurchaseEvent($purchase_log_object) { $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $cart_items = $purchase_log_object->get_items(); $total_price = $purchase_log_object->get_total(); $currency = function_exists('\wpsc_get_currency_code') ? \wpsc_get_currency_code() : ''; $item_ids = array(); foreach ($cart_items as $item) { // This is for backwards compatibility $item_array = (array) $item; $item_ids[] = $item_array['prodid']; } $event_data['content_ids'] = $item_ids; $event_data['content_type'] = 'product'; $event_data['currency'] = $currency; $event_data['value'] = $total_price; return $event_data; } public static function createAddToCartEvent($product_id) { $event_data = FacebookPluginUtils::getLoggedInUserInfo(); global $wpsc_cart; $cart_items = $wpsc_cart->get_items(); foreach ($cart_items as $item) { if ($item->product_id === $product_id) { $unit_price = $item->unit_price; break; } } $event_data['content_ids'] = array($product_id); $event_data['content_type'] = 'product'; $event_data['currency'] = function_exists('\wpsc_get_currency_code') ? \wpsc_get_currency_code() : ''; $event_data['value'] = $unit_price; return $event_data; } public static function createInitiateCheckoutEvent() { $event_data = FacebookPluginUtils::getLoggedInUserInfo(); $content_ids = array(); $value = 0; global $wpsc_cart; $cart_items = $wpsc_cart->get_items(); foreach ($cart_items as $item) { $content_ids[] = $item->product_id; $value += $item->unit_price; } $event_data['currency'] = function_exists('\wpsc_get_currency_code') ? \wpsc_get_currency_code() : ''; $event_data['value'] = $value; $event_data['content_ids'] = $content_ids; return $event_data; } } FacebookWordpressMailchimpForWp.php 0000755 00000005647 14720352624 0013525 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use FacebookPixelPlugin\Core\FacebookPixel; use FacebookPixelPlugin\Core\FacebookPluginUtils; use FacebookPixelPlugin\Core\ServerEventFactory; use FacebookPixelPlugin\Core\FacebookServerSideEvent; use FacebookPixelPlugin\Core\PixelRenderer; class FacebookWordpressMailchimpForWp extends FacebookWordpressIntegrationBase { const PLUGIN_FILE = 'mailchimp-for-wp/mailchimp-for-wp.php'; const TRACKING_NAME = 'mailchimp-for-wp'; public static function injectPixelCode() { self::addPixelFireForHook(array( 'hook_name' => 'mc4wp_form_subscribed', 'classname' => __CLASS__, 'inject_function' => 'injectLeadEvent')); } public static function injectLeadEvent() { if (FacebookPluginUtils::isInternalUser()) { return; } $server_event = ServerEventFactory::safeCreateEvent( 'Lead', array(__CLASS__, 'readFormData'), array(), self::TRACKING_NAME, true ); FacebookServerSideEvent::getInstance()->track($server_event); $code = PixelRenderer::render(array($server_event), self::TRACKING_NAME); printf(" <!-- Meta Pixel Event Code --> %s <!-- End Meta Pixel Event Code --> ", $code); } public static function readFormData() { $event_data = array(); if (!empty($_POST['EMAIL'])) { $event_data['email'] = $_POST['EMAIL']; } if (!empty($_POST['FNAME'])) { $event_data['first_name'] = $_POST['FNAME']; } if (!empty($_POST['LNAME'])) { $event_data['last_name'] = $_POST['LNAME']; } if(!empty($_POST['PHONE'])){ $event_data['phone'] = $_POST['PHONE']; } if(!empty($_POST['ADDRESS'])){ $address_data = $_POST['ADDRESS']; if(!empty($address_data['city'])){ $event_data['city'] = $address_data['city']; } if(!empty($address_data['state'])){ $event_data['state'] = $address_data['state']; } if(!empty($address_data['zip'])){ $event_data['zip'] = $address_data['zip']; } // You can edit the country field in the plugin editor // and do not use ISO code // Validating this case if( !empty($address_data['country']) && strlen($address_data['country'])==2 ){ $event_data['country'] = $address_data['country']; } } return $event_data; } } FacebookWordpressIntegrationBase.php 0000755 00000003621 14720352624 0013710 0 ustar 00 <?php /* * Copyright (C) 2017-present, Meta, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ /** * @package FacebookPixelPlugin */ namespace FacebookPixelPlugin\Integration; defined('ABSPATH') or die('Direct access not allowed'); use ReflectionMethod; abstract class FacebookWordpressIntegrationBase { const PLUGIN_FILE = ''; const TRACKING_NAME = ''; /** * inject the pixel code for the plugin */ public static function injectPixelCode() { } // TODO(T39560845): Add unit test for addPixelFireForHook public static function addPixelFireForHook($pixel_fire_for_hook_params) { $hook_name = $pixel_fire_for_hook_params['hook_name']; $classname = $pixel_fire_for_hook_params['classname']; $inject_function = $pixel_fire_for_hook_params['inject_function']; $priority = isset($pixel_fire_for_hook_params['priority']) ? $pixel_fire_for_hook_params['priority'] : 11; $user_function = array( // get derived class in base class $classname, $inject_function); $reflection = new ReflectionMethod($classname, $inject_function); $argc = $reflection->getNumberOfParameters(); $argv = $reflection->getParameters(); $callback = function () use ($user_function, $argv) { $hook_wp_footer = function () use ($user_function, $argv) { \call_user_func_array($user_function, $argv); }; add_action( 'wp_footer', $hook_wp_footer, 11); }; add_action($hook_name, $callback, $priority, $argc); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка