Ads Insights
diff --git a/core/class-facebookwordpresssettingsrecorder.php b/core/class-facebookwordpresssettingsrecorder.php
index 44904c4c..e8e49608 100644
--- a/core/class-facebookwordpresssettingsrecorder.php
+++ b/core/class-facebookwordpresssettingsrecorder.php
@@ -30,34 +30,34 @@ public function init() {
'wp_ajax_save_fbe_settings',
array( $this, 'save_fbe_settings' )
);
- add_action(
- 'wp_ajax_delete_fbe_settings',
- array(
- $this,
- 'delete_fbe_settings',
- )
- );
- add_action(
- 'wp_ajax_save_capi_integration_status',
- array(
- $this,
- 'save_capi_integration_status',
- )
- );
- add_action(
- 'wp_ajax_save_capi_integration_events_filter',
- array(
- $this,
- 'save_capi_integration_events_filter',
- )
- );
- add_action(
- 'wp_ajax_save_capi_pii_caching_status',
- array(
- $this,
- 'save_capi_pii_caching_status',
- )
- );
+ add_action(
+ 'wp_ajax_delete_fbe_settings',
+ array(
+ $this,
+ 'delete_fbe_settings',
+ )
+ );
+ add_action(
+ 'wp_ajax_save_capi_integration_status',
+ array(
+ $this,
+ 'save_capi_integration_status',
+ )
+ );
+ add_action(
+ 'wp_ajax_save_capi_integration_events_filter',
+ array(
+ $this,
+ 'save_capi_integration_events_filter',
+ )
+ );
+ add_action(
+ 'wp_ajax_save_capi_pii_caching_status',
+ array(
+ $this,
+ 'save_capi_pii_caching_status',
+ )
+ );
}
/**
@@ -119,29 +119,29 @@ private function handle_invalid_request() {
* @return array response data
*/
public function save_fbe_settings() {
- if ( ! current_user_can( 'manage_options' ) ) {
- return $this->handle_unauthorized_request();
- }
- check_admin_referer(
- FacebookPluginConfig::SAVE_FBE_SETTINGS_ACTION_NAME
- );
- $pixel_id = sanitize_text_field(
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return $this->handle_unauthorized_request();
+ }
+ check_admin_referer(
+ FacebookPluginConfig::SAVE_FBE_SETTINGS_ACTION_NAME
+ );
+ $pixel_id = sanitize_text_field(
isset( $_POST['pixelId'] ) ?
wp_unslash( $_POST['pixelId'] ) : ''
);
- $access_token = sanitize_text_field(
+ $access_token = sanitize_text_field(
isset( $_POST['accessToken'] ) ?
wp_unslash( $_POST['accessToken'] ) : ''
);
- $external_business_id = sanitize_text_field(
- isset( $_POST['externalBusinessId'] ) ?
- wp_unslash( $_POST['externalBusinessId'] ) : ''
- );
- if ( empty( $pixel_id )
- || empty( $access_token )
- || empty( $external_business_id ) ) {
- return $this->handle_invalid_request();
- }
+ $external_business_id = sanitize_text_field(
+ isset( $_POST['externalBusinessId'] ) ?
+ wp_unslash( $_POST['externalBusinessId'] ) : ''
+ );
+ if ( empty( $pixel_id )
+ || empty( $access_token )
+ || empty( $external_business_id ) ) {
+ return $this->handle_invalid_request();
+ }
$settings = array(
FacebookPluginConfig::PIXEL_ID_KEY => $pixel_id,
FacebookPluginConfig::ACCESS_TOKEN_KEY => $access_token,
@@ -149,10 +149,10 @@ public function save_fbe_settings() {
$external_business_id,
FacebookPluginConfig::IS_FBE_INSTALLED_KEY => '1',
);
- \update_option(
- FacebookPluginConfig::SETTINGS_KEY,
- $settings
- );
+ \update_option(
+ FacebookPluginConfig::SETTINGS_KEY,
+ $settings
+ );
return $this->handle_success_request( $settings );
}
@@ -169,29 +169,29 @@ public function save_fbe_settings() {
* @return array response data
*/
public function save_capi_integration_status() {
- if ( ! current_user_can( 'manage_options' ) ) {
- return $this->handle_unauthorized_request();
- }
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return $this->handle_unauthorized_request();
+ }
- if ( empty( FacebookWordpressOptions::get_pixel_id() ) ) {
- \update_option(
- FacebookPluginConfig::CAPI_INTEGRATION_STATUS,
- FacebookPluginConfig::CAPI_INTEGRATION_STATUS_DEFAULT
- );
- return $this->handle_invalid_request();
- }
+ if ( empty( FacebookWordpressOptions::get_pixel_id() ) ) {
+ \update_option(
+ FacebookPluginConfig::CAPI_INTEGRATION_STATUS,
+ FacebookPluginConfig::CAPI_INTEGRATION_STATUS_DEFAULT
+ );
+ return $this->handle_invalid_request();
+ }
- check_admin_referer(
- FacebookPluginConfig::SAVE_CAPI_INTEGRATION_STATUS_ACTION_NAME
- );
+ check_admin_referer(
+ FacebookPluginConfig::SAVE_CAPI_INTEGRATION_STATUS_ACTION_NAME
+ );
$val = sanitize_text_field(
isset( $_POST['val'] ) ?
wp_unslash( $_POST['val'] ) : ''
);
- if ( ! ( '0' === $val || '1' === $val ) ) {
- return $this->handle_invalid_request();
- }
+ if ( ! ( '0' === $val || '1' === $val ) ) {
+ return $this->handle_invalid_request();
+ }
\update_option( FacebookPluginConfig::CAPI_INTEGRATION_STATUS, $val );
return $this->handle_success_request( $val );
@@ -210,21 +210,21 @@ public function save_capi_integration_status() {
* @return array response data
*/
public function save_capi_integration_events_filter() {
- if ( ! current_user_can( 'manage_options' ) ) {
- return $this->handle_unauthorized_request();
- }
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return $this->handle_unauthorized_request();
+ }
- if ( empty( FacebookWordpressOptions::get_pixel_id() ) ) {
- \update_option(
- FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER,
- FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT
- );
- return $this->handle_invalid_request();
- }
+ if ( empty( FacebookWordpressOptions::get_pixel_id() ) ) {
+ \update_option(
+ FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER,
+ FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT
+ );
+ return $this->handle_invalid_request();
+ }
- check_admin_referer(
- FacebookPluginConfig::SAVE_CAPI_INTEGRATION_EVENTS_FILTER_ACTION_NAME
- );
+ check_admin_referer(
+ FacebookPluginConfig::SAVE_CAPI_INTEGRATION_EVENTS_FILTER_ACTION_NAME
+ );
$val = sanitize_text_field(
isset( $_POST['val'] ) ?
wp_unslash( $_POST['val'] ) : ''
@@ -234,26 +234,26 @@ public function save_capi_integration_events_filter() {
$const_keep_page_view =
FacebookPluginConfig::CAPI_INTEGRATION_KEEP_PAGE_VIEW_EVENT;
- if ( ! ( $val === $const_filter_page_view
- || $val === $const_keep_page_view ) ) {
- return $this->handle_invalid_request();
- }
+ if ( ! ( $val === $const_filter_page_view
+ || $val === $const_keep_page_view ) ) {
+ return $this->handle_invalid_request();
+ }
$page_view_filtered =
FacebookWordpressOptions::get_capi_integration_page_view_filtered();
- if ( $val === $const_keep_page_view && $page_view_filtered ) {
- \update_option(
- FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER,
- FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT
- );
- } elseif ( $val === $const_filter_page_view && ! $page_view_filtered ) {
- \update_option(
- FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER,
- FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT .
- ',PageView'
- );
- }
+ if ( $val === $const_keep_page_view && $page_view_filtered ) {
+ \update_option(
+ FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER,
+ FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT
+ );
+ } elseif ( $val === $const_filter_page_view && ! $page_view_filtered ) {
+ \update_option(
+ FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER,
+ FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT .
+ ',PageView'
+ );
+ }
return $this->handle_success_request( $val );
}
@@ -271,29 +271,29 @@ public function save_capi_integration_events_filter() {
* @return array response data
*/
public function save_capi_pii_caching_status() {
- if ( ! current_user_can( 'manage_options' ) ) {
- return $this->handle_unauthorized_request();
- }
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return $this->handle_unauthorized_request();
+ }
- if ( empty( FacebookWordpressOptions::get_pixel_id() ) ) {
- \update_option(
- FacebookPluginConfig::CAPI_PII_CACHING_STATUS,
- FacebookPluginConfig::CAPI_PII_CACHING_STATUS_DEFAULT
- );
- return $this->handle_invalid_request();
- }
+ if ( empty( FacebookWordpressOptions::get_pixel_id() ) ) {
+ \update_option(
+ FacebookPluginConfig::CAPI_PII_CACHING_STATUS,
+ FacebookPluginConfig::CAPI_PII_CACHING_STATUS_DEFAULT
+ );
+ return $this->handle_invalid_request();
+ }
- check_admin_referer(
- FacebookPluginConfig::SAVE_CAPI_PII_CACHING_STATUS_ACTION_NAME
- );
+ check_admin_referer(
+ FacebookPluginConfig::SAVE_CAPI_PII_CACHING_STATUS_ACTION_NAME
+ );
$val = sanitize_text_field(
isset( $_POST['val'] ) ?
wp_unslash( $_POST['val'] ) : ''
);
- if ( ! ( '0' === $val || '1' === $val ) ) {
- return $this->handle_invalid_request();
- }
+ if ( ! ( '0' === $val || '1' === $val ) ) {
+ return $this->handle_invalid_request();
+ }
\update_option( FacebookPluginConfig::CAPI_PII_CACHING_STATUS, $val );
return $this->handle_success_request( $val );
@@ -313,12 +313,12 @@ public function save_capi_pii_caching_status() {
* @return array response data
*/
public function delete_fbe_settings() {
- if ( ! current_user_can( 'manage_options' ) ) {
- return $this->handle_unauthorized_request();
- }
- check_admin_referer(
- FacebookPluginConfig::DELETE_FBE_SETTINGS_ACTION_NAME
- );
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return $this->handle_unauthorized_request();
+ }
+ check_admin_referer(
+ FacebookPluginConfig::DELETE_FBE_SETTINGS_ACTION_NAME
+ );
\delete_option( FacebookPluginConfig::SETTINGS_KEY );
\delete_transient( FacebookPluginConfig::AAM_SETTINGS_KEY );
diff --git a/core/class-pixelrenderer.php b/core/class-pixelrenderer.php
index 06ea01bc..dc4ecd65 100644
--- a/core/class-pixelrenderer.php
+++ b/core/class-pixelrenderer.php
@@ -66,17 +66,17 @@ public static function render(
$fb_integration_tracking,
$script_tag = true
) {
- if ( empty( $events ) ) {
- return '';
- }
- $code = sprintf(
- self::FBQ_AGENT_CODE,
- FacebookWordpressOptions::get_agent_string(),
- FacebookWordpressOptions::get_pixel_id()
- );
- foreach ( $events as $event ) {
- $code .= self::get_pixel_track_code( $event, $fb_integration_tracking );
- }
+ if ( empty( $events ) ) {
+ return '';
+ }
+ $code = sprintf(
+ self::FBQ_AGENT_CODE,
+ FacebookWordpressOptions::get_agent_string(),
+ FacebookWordpressOptions::get_pixel_id()
+ );
+ foreach ( $events as $event ) {
+ $code .= self::get_pixel_track_code( $event, $fb_integration_tracking );
+ }
return $script_tag ? sprintf( self::SCRIPT_TAG, $code ) : $code;
}
@@ -101,21 +101,21 @@ private static function get_pixel_track_code(
$event->getCustomData() : new CustomData();
$normalized_custom_data = $custom_data->normalize();
- if ( ! is_null( $fb_integration_tracking ) ) {
- $normalized_custom_data[ self::FB_INTEGRATION_TRACKING ] =
- $fb_integration_tracking;
- }
+ if ( ! is_null( $fb_integration_tracking ) ) {
+ $normalized_custom_data[ self::FB_INTEGRATION_TRACKING ] =
+ $fb_integration_tracking;
+ }
$class = new ReflectionClass(
'FacebookPixelPlugin\Core\FacebookPixel'
);
- return sprintf(
- self::FBQ_EVENT_CODE,
- $class->getConstant( strtoupper( $event->getEventName() ) ) !== false ?
- self::TRACK : self::TRACK_CUSTOM,
- $event->getEventName(),
- wp_json_encode( $normalized_custom_data, JSON_PRETTY_PRINT ),
- wp_json_encode( $event_data, JSON_PRETTY_PRINT )
- );
+ return sprintf(
+ self::FBQ_EVENT_CODE,
+ $class->getConstant( strtoupper( $event->getEventName() ) ) !== false ?
+ self::TRACK : self::TRACK_CUSTOM,
+ $event->getEventName(),
+ wp_json_encode( $normalized_custom_data, JSON_PRETTY_PRINT ),
+ wp_json_encode( $event_data, JSON_PRETTY_PRINT )
+ );
}
}
diff --git a/core/class-servereventasynctask.php b/core/class-servereventasynctask.php
index a3433c73..e65f4a7c 100644
--- a/core/class-servereventasynctask.php
+++ b/core/class-servereventasynctask.php
@@ -65,11 +65,11 @@ private function convert_user_data( $user_data_normalized ) {
);
$user_data = array();
foreach ( $user_data_normalized as $norm_key => $field ) {
- if ( isset( $norm_key_to_key[ $norm_key ] ) ) {
- $user_data[ $norm_key_to_key[ $norm_key ] ] = $field;
- } else {
- $user_data[ $norm_key ] = $field;
- }
+ if ( isset( $norm_key_to_key[ $norm_key ] ) ) {
+ $user_data[ $norm_key_to_key[ $norm_key ] ] = $field;
+ } else {
+ $user_data[ $norm_key ] = $field;
+ }
}
return $user_data;
}
@@ -91,38 +91,38 @@ private function convert_user_data( $user_data_normalized ) {
*/
private function convert_array_to_event( $event_as_array ) {
$event = new Event( $event_as_array );
- if ( isset( $event_as_array['user_data'] ) ) {
- $user_data = new UserData(
- $this->convert_user_data(
- $event_as_array['user_data']
- )
- );
- $event->setUserData( $user_data );
- }
- if ( isset( $event_as_array['custom_data'] ) ) {
- $custom_data = new CustomData( $event_as_array['custom_data'] );
- if ( isset( $event_as_array['custom_data']['contents'] ) ) {
- $contents = array();
- foreach (
- $event_as_array['custom_data']['contents'] as $contents_as_array
- ) {
- if ( isset( $contents_as_array['id'] ) ) {
- $contents_as_array['product_id'] = $contents_as_array['id'];
- }
- $contents[] = new Content( $contents_as_array );
- }
- $custom_data->setContents( $contents );
+ if ( isset( $event_as_array['user_data'] ) ) {
+ $user_data = new UserData(
+ $this->convert_user_data(
+ $event_as_array['user_data']
+ )
+ );
+ $event->setUserData( $user_data );
}
- if ( isset(
- $event_as_array['custom_data']['fb_integration_tracking']
- ) ) {
- $custom_data->addCustomProperty(
- 'fb_integration_tracking',
- $event_as_array['custom_data']['fb_integration_tracking']
- );
+ if ( isset( $event_as_array['custom_data'] ) ) {
+ $custom_data = new CustomData( $event_as_array['custom_data'] );
+ if ( isset( $event_as_array['custom_data']['contents'] ) ) {
+ $contents = array();
+ foreach (
+ $event_as_array['custom_data']['contents'] as $contents_as_array
+ ) {
+ if ( isset( $contents_as_array['id'] ) ) {
+ $contents_as_array['product_id'] = $contents_as_array['id'];
+ }
+ $contents[] = new Content( $contents_as_array );
+ }
+ $custom_data->setContents( $contents );
+ }
+ if ( isset(
+ $event_as_array['custom_data']['fb_integration_tracking']
+ ) ) {
+ $custom_data->addCustomProperty(
+ 'fb_integration_tracking',
+ $event_as_array['custom_data']['fb_integration_tracking']
+ );
+ }
+ $event->setCustomData( $custom_data );
}
- $event->setCustomData( $custom_data );
- }
return $event;
}
@@ -182,32 +182,32 @@ protected function prepare_data( $data ) {
* @throws \Exception If there was an preprocessing error.
*/
protected function run_action() {
- try {
- $num_events = isset( $_POST['num_events'] ) ? // phpcs:ignore WordPress.Security.NonceVerification.Missing
- sanitize_text_field(
- wp_unslash( $_POST['num_events'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
- ) : null;
- if ( 0 === $num_events ) {
- return;
- }
- $events_as_array = json_decode(
- base64_decode( // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
- isset( $_POST['event_data'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
- ? $_POST['event_data'] : null // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
- ),
- true
- );
- if ( ! $events_as_array ) {
+ try {
+ $num_events = isset( $_POST['num_events'] ) ? // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ sanitize_text_field(
+ wp_unslash( $_POST['num_events'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ ) : null;
+ if ( 0 === $num_events ) {
return;
+ }
+ $events_as_array = json_decode(
+ base64_decode( // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ isset( $_POST['event_data'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ ? $_POST['event_data'] : null // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ ),
+ true
+ );
+ if ( ! $events_as_array ) {
+ return;
+ }
+ $events = array();
+ foreach ( $events_as_array as $event_as_array ) {
+ $event = $this->convert_array_to_event( $event_as_array );
+ $events[] = $event;
+ }
+ FacebookServerSideEvent::send( $events );
+ } catch ( \Exception $ex ) {
+ throw $ex;
}
- $events = array();
- foreach ( $events_as_array as $event_as_array ) {
- $event = $this->convert_array_to_event( $event_as_array );
- $events[] = $event;
- }
- FacebookServerSideEvent::send( $events );
- } catch ( \Exception $ex ) {
- throw $ex;
- }
}
}
diff --git a/core/class-servereventfactory.php b/core/class-servereventfactory.php
index efa2e5da..7d7fa646 100644
--- a/core/class-servereventfactory.php
+++ b/core/class-servereventfactory.php
@@ -87,15 +87,15 @@ private static function get_ip_address() {
);
foreach ( $headers_to_scan as $header ) {
- if ( isset( $_SERVER[ $header ] ) ) {
- $ip_list = explode( ',', $_SERVER[ $header ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- foreach ( $ip_list as $ip ) {
- $trimmed_ip = trim( $ip );
- if ( self::is_valid_ip_address( $trimmed_ip ) ) {
- return $trimmed_ip;
+ if ( isset( $_SERVER[ $header ] ) ) {
+ $ip_list = explode( ',', $_SERVER[ $header ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ foreach ( $ip_list as $ip ) {
+ $trimmed_ip = trim( $ip );
+ if ( self::is_valid_ip_address( $trimmed_ip ) ) {
+ return $trimmed_ip;
+ }
+ }
}
- }
- }
}
return null;
@@ -109,9 +109,9 @@ private static function get_ip_address() {
private static function get_http_user_agent() {
$user_agent = null;
- if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
- $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- }
+ if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
+ $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ }
return $user_agent;
}
@@ -131,23 +131,23 @@ private static function get_http_user_agent() {
* URL if preferred.
*/
private static function get_request_uri( $prefer_referrer_for_event_src ) {
- if ( $prefer_referrer_for_event_src
- && ! empty( $_SERVER['HTTP_REFERER'] ) ) {
- return sanitize_text_field( $_SERVER['HTTP_REFERER'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- }
+ if ( $prefer_referrer_for_event_src
+ && ! empty( $_SERVER['HTTP_REFERER'] ) ) {
+ return sanitize_text_field( $_SERVER['HTTP_REFERER'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ }
- $url = 'http://';
- if ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) {
- $url = 'https://';
- }
+ $url = 'http://';
+ if ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) {
+ $url = 'https://';
+ }
- if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
- $url .= sanitize_text_field( $_SERVER['HTTP_HOST'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- }
+ if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
+ $url .= sanitize_text_field( $_SERVER['HTTP_HOST'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ }
- if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
- $url .= sanitize_text_field( $_SERVER['REQUEST_URI'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- }
+ if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
+ $url .= sanitize_text_field( $_SERVER['REQUEST_URI'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ }
return $url;
}
@@ -166,9 +166,9 @@ private static function get_request_uri( $prefer_referrer_for_event_src ) {
private static function get_fbp() {
$fbp = null;
- if ( ! empty( $_COOKIE['_fbp'] ) ) {
- $fbp = sanitize_text_field( $_COOKIE['_fbp'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- }
+ if ( ! empty( $_COOKIE['_fbp'] ) ) {
+ $fbp = sanitize_text_field( $_COOKIE['_fbp'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ }
return $fbp;
}
@@ -189,26 +189,26 @@ private static function get_fbp() {
private static function get_fbc() {
$fbc = null;
- if ( ! empty( $_COOKIE['_fbc'] ) ) {
- $fbc = sanitize_text_field(
- wp_unslash( $_COOKIE['_fbc'] )
- );
- $_SESSION['_fbc'] = $fbc;
- }
+ if ( ! empty( $_COOKIE['_fbc'] ) ) {
+ $fbc = sanitize_text_field(
+ wp_unslash( $_COOKIE['_fbc'] )
+ );
+ $_SESSION['_fbc'] = $fbc;
+ }
- if ( ! $fbc && isset( $_GET['fbclid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
- $fbclid = sanitize_text_field( wp_unslash( $_GET['fbclid'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
- $cur_time = (int) ( microtime( true ) * 1000 );
- $fbc = 'fb.1.' . $cur_time . '.' . rawurldecode( $fbclid );
- }
+ if ( ! $fbc && isset( $_GET['fbclid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
+ $fbclid = sanitize_text_field( wp_unslash( $_GET['fbclid'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
+ $cur_time = (int) ( microtime( true ) * 1000 );
+ $fbc = 'fb.1.' . $cur_time . '.' . rawurldecode( $fbclid );
+ }
- if ( ! $fbc && isset( $_SESSION['_fbc'] ) ) {
- $fbc = sanitize_text_field( $_SESSION['_fbc'] );
- }
+ if ( ! $fbc && isset( $_SESSION['_fbc'] ) ) {
+ $fbc = sanitize_text_field( $_SESSION['_fbc'] );
+ }
- if ( $fbc ) {
- $_SESSION['_fbc'] = $fbc;
- }
+ if ( $fbc ) {
+ $_SESSION['_fbc'] = $fbc;
+ }
return $fbc;
}
@@ -224,14 +224,14 @@ private static function get_fbc() {
* @return bool True if the IP address is valid, false otherwise.
*/
private static function is_valid_ip_address( $ip_address ) {
- return filter_var(
- $ip_address,
- FILTER_VALIDATE_IP,
- FILTER_FLAG_IPV4 |
- FILTER_FLAG_IPV6 |
- FILTER_FLAG_NO_PRIV_RANGE |
- FILTER_FLAG_NO_RES_RANGE
- );
+ return filter_var(
+ $ip_address,
+ FILTER_VALIDATE_IP,
+ FILTER_FLAG_IPV4 |
+ FILTER_FLAG_IPV6 |
+ FILTER_FLAG_NO_PRIV_RANGE |
+ FILTER_FLAG_NO_RES_RANGE
+ );
}
/**
@@ -260,11 +260,11 @@ private static function split_user_data_and_custom_data( $data ) {
'external_id' => AAMSettingsFields::EXTERNAL_ID,
);
foreach ( $data as $key => $value ) {
- if ( isset( $key_to_aam_field[ $key ] ) ) {
- $user_data[ $key_to_aam_field[ $key ] ] = $value;
- } else {
- $custom_data[ $key ] = $value;
- }
+ if ( isset( $key_to_aam_field[ $key ] ) ) {
+ $user_data[ $key_to_aam_field[ $key ] ] = $value;
+ } else {
+ $custom_data[ $key ] = $value;
+ }
}
return array(
'user_data' => $user_data,
@@ -303,149 +303,149 @@ public static function safe_create_event(
) {
$event = self::new_event( $event_name, $prefer_referrer_for_event_src );
- try {
- $data = call_user_func_array( $callback, $arguments );
- $data_split = self::split_user_data_and_custom_data( $data );
- $user_data_array = $data_split['user_data'];
- $custom_data_array = $data_split['custom_data'];
- $user_data_array = AAMFieldsExtractor::get_normalized_user_data(
- $user_data_array
- );
+ try {
+ $data = call_user_func_array( $callback, $arguments );
+ $data_split = self::split_user_data_and_custom_data( $data );
+ $user_data_array = $data_split['user_data'];
+ $custom_data_array = $data_split['custom_data'];
+ $user_data_array = AAMFieldsExtractor::get_normalized_user_data(
+ $user_data_array
+ );
- $user_data = $event->getUserData();
- if (
- isset( $user_data_array[ AAMSettingsFields::EMAIL ] )
- ) {
- $user_data->setEmail(
- $user_data_array[ AAMSettingsFields::EMAIL ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::FIRST_NAME ] )
- ) {
- $user_data->setFirstName(
- $user_data_array[ AAMSettingsFields::FIRST_NAME ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::LAST_NAME ] )
- ) {
- $user_data->setLastName(
- $user_data_array[ AAMSettingsFields::LAST_NAME ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::GENDER ] )
- ) {
- $user_data->setGender(
- $user_data_array[ AAMSettingsFields::GENDER ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::DATE_OF_BIRTH ] )
- ) {
- $user_data->setDateOfBirth(
- $user_data_array[ AAMSettingsFields::DATE_OF_BIRTH ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::EXTERNAL_ID ] ) &&
- ! is_null( $user_data_array[ AAMSettingsFields::EXTERNAL_ID ] )
- ) {
- if ( is_array( $user_data_array[ AAMSettingsFields::EXTERNAL_ID ] ) ) {
- $external_ids = $user_data_array[ AAMSettingsFields::EXTERNAL_ID ];
- $hashed_eids = array();
- foreach ( $external_ids as $k => $v ) {
- $hashed_eids[ $k ] = hash( 'sha256', $v );
+ $user_data = $event->getUserData();
+ if (
+ isset( $user_data_array[ AAMSettingsFields::EMAIL ] )
+ ) {
+ $user_data->setEmail(
+ $user_data_array[ AAMSettingsFields::EMAIL ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::FIRST_NAME ] )
+ ) {
+ $user_data->setFirstName(
+ $user_data_array[ AAMSettingsFields::FIRST_NAME ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::LAST_NAME ] )
+ ) {
+ $user_data->setLastName(
+ $user_data_array[ AAMSettingsFields::LAST_NAME ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::GENDER ] )
+ ) {
+ $user_data->setGender(
+ $user_data_array[ AAMSettingsFields::GENDER ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::DATE_OF_BIRTH ] )
+ ) {
+ $user_data->setDateOfBirth(
+ $user_data_array[ AAMSettingsFields::DATE_OF_BIRTH ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::EXTERNAL_ID ] ) &&
+ ! is_null( $user_data_array[ AAMSettingsFields::EXTERNAL_ID ] )
+ ) {
+ if ( is_array( $user_data_array[ AAMSettingsFields::EXTERNAL_ID ] ) ) {
+ $external_ids = $user_data_array[ AAMSettingsFields::EXTERNAL_ID ];
+ $hashed_eids = array();
+ foreach ( $external_ids as $k => $v ) {
+ $hashed_eids[ $k ] = hash( 'sha256', $v );
+ }
+ $user_data->setExternalIds( $hashed_eids );
+ } else {
+ $user_data->setExternalId(
+ hash(
+ 'sha256',
+ $user_data_array[ AAMSettingsFields::EXTERNAL_ID ]
+ )
+ );
+ }
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::PHONE ] )
+ ) {
+ $user_data->setPhone(
+ $user_data_array[ AAMSettingsFields::PHONE ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::CITY ] )
+ ) {
+ $user_data->setCity(
+ $user_data_array[ AAMSettingsFields::CITY ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::STATE ] )
+ ) {
+ $user_data->setState(
+ $user_data_array[ AAMSettingsFields::STATE ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::ZIP_CODE ] )
+ ) {
+ $user_data->setZipCode(
+ $user_data_array[ AAMSettingsFields::ZIP_CODE ]
+ );
+ }
+ if (
+ isset( $user_data_array[ AAMSettingsFields::COUNTRY ] )
+ ) {
+ $user_data->setCountryCode(
+ $user_data_array[ AAMSettingsFields::COUNTRY ]
+ );
}
- $user_data->setExternalIds( $hashed_eids );
- } else {
- $user_data->setExternalId(
- hash(
- 'sha256',
- $user_data_array[ AAMSettingsFields::EXTERNAL_ID ]
- )
- );
- }
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::PHONE ] )
- ) {
- $user_data->setPhone(
- $user_data_array[ AAMSettingsFields::PHONE ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::CITY ] )
- ) {
- $user_data->setCity(
- $user_data_array[ AAMSettingsFields::CITY ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::STATE ] )
- ) {
- $user_data->setState(
- $user_data_array[ AAMSettingsFields::STATE ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::ZIP_CODE ] )
- ) {
- $user_data->setZipCode(
- $user_data_array[ AAMSettingsFields::ZIP_CODE ]
- );
- }
- if (
- isset( $user_data_array[ AAMSettingsFields::COUNTRY ] )
- ) {
- $user_data->setCountryCode(
- $user_data_array[ AAMSettingsFields::COUNTRY ]
- );
- }
- $custom_data = $event->getCustomData();
- $custom_data->addCustomProperty(
- 'fb_integration_tracking',
- $integration
- );
+ $custom_data = $event->getCustomData();
+ $custom_data->addCustomProperty(
+ 'fb_integration_tracking',
+ $integration
+ );
- if ( ! empty( $data['currency'] ) ) {
- $custom_data->setCurrency( $custom_data_array['currency'] );
- }
+ if ( ! empty( $data['currency'] ) ) {
+ $custom_data->setCurrency( $custom_data_array['currency'] );
+ }
- if ( ! empty( $data['value'] ) ) {
- $custom_data->setValue( $custom_data_array['value'] );
- }
+ if ( ! empty( $data['value'] ) ) {
+ $custom_data->setValue( $custom_data_array['value'] );
+ }
- if ( ! empty( $data['contents'] ) ) {
- $custom_data->setContents( $custom_data_array['contents'] );
- }
+ if ( ! empty( $data['contents'] ) ) {
+ $custom_data->setContents( $custom_data_array['contents'] );
+ }
- if ( ! empty( $data['content_ids'] ) ) {
- $custom_data->setContentIds( $custom_data_array['content_ids'] );
- }
+ if ( ! empty( $data['content_ids'] ) ) {
+ $custom_data->setContentIds( $custom_data_array['content_ids'] );
+ }
- if ( ! empty( $data['content_type'] ) ) {
- $custom_data->setContentType( $custom_data_array['content_type'] );
- }
+ if ( ! empty( $data['content_type'] ) ) {
+ $custom_data->setContentType( $custom_data_array['content_type'] );
+ }
- if ( ! empty( $data['num_items'] ) ) {
- $custom_data->setNumItems( $custom_data_array['num_items'] );
- }
+ if ( ! empty( $data['num_items'] ) ) {
+ $custom_data->setNumItems( $custom_data_array['num_items'] );
+ }
- if ( ! empty( $data['content_name'] ) ) {
- $custom_data->setContentName( $custom_data_array['content_name'] );
- }
+ if ( ! empty( $data['content_name'] ) ) {
+ $custom_data->setContentName( $custom_data_array['content_name'] );
+ }
- if ( ! empty( $data['content_category'] ) ) {
- $custom_data->setContentCategory(
- $custom_data_array['content_category']
- );
+ if ( ! empty( $data['content_category'] ) ) {
+ $custom_data->setContentCategory(
+ $custom_data_array['content_category']
+ );
+ }
+ } catch ( \Exception $e ) {
+ throw $e;
}
- } catch ( \Exception $e ) {
- throw $e;
- }
return $event;
}
@@ -465,10 +465,10 @@ public static function split_name( $name ) {
$first_name = $name;
$last_name = null;
$index = strpos( $name, ' ' );
- if ( false !== $index ) {
- $first_name = substr( $name, 0, $index );
- $last_name = substr( $name, $index + 1 );
- }
+ if ( false !== $index ) {
+ $first_name = substr( $name, 0, $index );
+ $last_name = substr( $name, $index + 1 );
+ }
return array( $first_name, $last_name );
}
diff --git a/integration/class-facebookwordpresscalderaform.php b/integration/class-facebookwordpresscalderaform.php
index 5010eda1..81dbd56f 100644
--- a/integration/class-facebookwordpresscalderaform.php
+++ b/integration/class-facebookwordpresscalderaform.php
@@ -53,12 +53,12 @@ class FacebookWordpressCalderaForm extends FacebookWordpressIntegrationBase {
* @since 0.9.0
*/
public static function inject_pixel_code() {
- add_action(
- 'caldera_forms_ajax_return',
- array( __CLASS__, 'injectLeadEvent' ),
- 10,
- 2
- );
+ add_action(
+ 'caldera_forms_ajax_return',
+ array( __CLASS__, 'injectLeadEvent' ),
+ 10,
+ 2
+ );
}
/**
@@ -77,37 +77,37 @@ public static function inject_pixel_code() {
* @return array The modified Caldera Forms response.
*/
public static function injectLeadEvent( $out, $form ) {
- if (
- FacebookPluginUtils::is_internal_user() ||
- 'complete' !== $out['status']
- ) {
- return $out;
- }
+ if (
+ FacebookPluginUtils::is_internal_user() ||
+ 'complete' !== $out['status']
+ ) {
+ return $out;
+ }
+
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Lead',
+ array( __CLASS__, 'readFormData' ),
+ array( $form ),
+ self::TRACKING_NAME,
+ true
+ );
+ FacebookServerSideEvent::get_instance()->track( $server_event );
- $server_event = ServerEventFactory::safe_create_event(
- 'Lead',
- array( __CLASS__, 'readFormData' ),
- array( $form ),
- self::TRACKING_NAME,
- true
- );
- FacebookServerSideEvent::get_instance()->track( $server_event );
-
- $code = PixelRenderer::render(
- array( $server_event ),
- self::TRACKING_NAME
- );
- $code = sprintf(
- '
-
- %s
-
- ',
- $code
- );
-
- $out['html'] .= $code;
- return $out;
+ $code = PixelRenderer::render(
+ array( $server_event ),
+ self::TRACKING_NAME
+ );
+ $code = sprintf(
+ '
+
+ %s
+
+ ',
+ $code
+ );
+
+ $out['html'] .= $code;
+ return $out;
}
/**
@@ -119,16 +119,16 @@ public static function injectLeadEvent( $out, $form ) {
* expected by the `FacebookServerSideEvent` class.
*/
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 ),
- );
+ 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 ),
+ );
}
/**
@@ -139,7 +139,7 @@ public static function readFormData( $form ) {
* @return string The email address.
*/
private static function getEmail( $form ) {
- return self::getFieldValue( $form, 'type', 'email' );
+ return self::getFieldValue( $form, 'type', 'email' );
}
/**
@@ -150,7 +150,7 @@ private static function getEmail( $form ) {
* @return string The first name.
*/
private static function getFirstName( $form ) {
- return self::getFieldValue( $form, 'slug', 'first_name' );
+ return self::getFieldValue( $form, 'slug', 'first_name' );
}
/**
@@ -161,7 +161,7 @@ private static function getFirstName( $form ) {
* @return string The last name.
*/
private static function getLastName( $form ) {
- return self::getFieldValue( $form, 'slug', 'last_name' );
+ return self::getFieldValue( $form, 'slug', 'last_name' );
}
/**
@@ -172,7 +172,7 @@ private static function getLastName( $form ) {
* @return string|null The state, or null if not found.
*/
private static function getState( $form ) {
- return self::getFieldValue( $form, 'type', 'states' );
+ return self::getFieldValue( $form, 'type', 'states' );
}
/**
@@ -186,9 +186,9 @@ private static function getState( $form ) {
* @return string|null The phone number, or null if not found.
*/
private static function getPhone( $form ) {
- $phone = self::getFieldValue( $form, 'type', 'phone_better' );
- return empty( $phone ) ?
- self::getFieldValue( $form, 'type', 'phone' ) : $phone;
+ $phone = self::getFieldValue( $form, 'type', 'phone_better' );
+ return empty( $phone ) ?
+ self::getFieldValue( $form, 'type', 'phone' ) : $phone;
}
/**
@@ -206,20 +206,20 @@ private static function getPhone( $form ) {
* if not found.
*/
private static function getFieldValue( $form, $attr, $attr_value ) {
- if ( empty( $form['fields'] ) ) {
- return null;
- }
+ if ( empty( $form['fields'] ) ) {
+ return null;
+ }
- foreach ( $form['fields'] as $field ) {
- if ( isset( $field[ $attr ] ) && $field[ $attr ] === $attr_value ) {
- return sanitize_text_field(
- wp_unslash(
- $_POST[ $field['ID'] ] ?? '' // phpcs:ignore WordPress.Security.NonceVerification.Missing
- )
- );
+ foreach ( $form['fields'] as $field ) {
+ if ( isset( $field[ $attr ] ) && $field[ $attr ] === $attr_value ) {
+ return sanitize_text_field(
+ wp_unslash(
+ $_POST[ $field['ID'] ] ?? '' // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ )
+ );
+ }
}
- }
- return null;
+ return null;
}
}
diff --git a/integration/class-facebookwordpresscontactform7.php b/integration/class-facebookwordpresscontactform7.php
index 6c459202..c227f568 100644
--- a/integration/class-facebookwordpresscontactform7.php
+++ b/integration/class-facebookwordpresscontactform7.php
@@ -52,18 +52,18 @@ class FacebookWordpressContactForm7 extends FacebookWordpressIntegrationBase {
* - wp_footer: Injects the mail sent listener.
*/
public static function inject_pixel_code() {
- add_action(
- 'wpcf7_submit',
- array( __CLASS__, 'trackServerEvent' ),
- 10,
- 2
- );
- add_action(
- 'wp_footer',
- array( __CLASS__, 'injectMailSentListener' ),
- 10,
- 2
- );
+ add_action(
+ 'wpcf7_submit',
+ array( __CLASS__, 'trackServerEvent' ),
+ 10,
+ 2
+ );
+ add_action(
+ 'wp_footer',
+ array( __CLASS__, 'injectMailSentListener' ),
+ 10,
+ 2
+ );
}
/**
@@ -106,25 +106,25 @@ public static function injectMailSentListener() {
public static function trackServerEvent( $form, $result ) {
$is_internal_user = FacebookPluginUtils::is_internal_user();
$submit_failed = 'mail_sent' !== $result['status'];
- if ( $is_internal_user || $submit_failed ) {
- return $result;
- }
+ if ( $is_internal_user || $submit_failed ) {
+ return $result;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Lead',
- array( __CLASS__, 'readFormData' ),
- array( $form ),
- self::TRACKING_NAME,
- true
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Lead',
+ array( __CLASS__, 'readFormData' ),
+ array( $form ),
+ self::TRACKING_NAME,
+ true
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
- add_action(
- 'wpcf7_feedback_response',
- array( __CLASS__, 'injectLeadEvent' ),
- 20,
- 2
- );
+ add_action(
+ 'wpcf7_feedback_response',
+ array( __CLASS__, 'injectLeadEvent' ),
+ 20,
+ 2
+ );
return $result;
}
@@ -143,14 +143,14 @@ public static function trackServerEvent( $form, $result ) {
* @return array The modified Contact Form 7 response.
*/
public static function injectLeadEvent( $response, $result ) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return $response;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return $response;
+ }
- $events = FacebookServerSideEvent::get_instance()->get_tracked_events();
- if ( count( $events ) === 0 ) {
- return $response;
- }
+ $events = FacebookServerSideEvent::get_instance()->get_tracked_events();
+ if ( count( $events ) === 0 ) {
+ return $response;
+ }
$event_id = $events[0]->getEventId();
$fbq_calls = PixelRenderer::render(
$events,
@@ -183,9 +183,9 @@ public static function injectLeadEvent( $response, $result ) {
* by the `FacebookServerSideEvent` class.
*/
public static function readFormData( $form ) {
- if ( empty( $form ) ) {
- return array();
- }
+ if ( empty( $form ) ) {
+ return array();
+ }
$form_tags = $form->scan_form_tags();
$name = self::getName( $form_tags );
@@ -206,15 +206,15 @@ public static function readFormData( $form ) {
* @return string|null The email address, or null if no email tag found.
*/
private static function getEmail( $form_tags ) {
- if ( empty( $form_tags ) ) {
- return null;
- }
+ if ( empty( $form_tags ) ) {
+ return null;
+ }
- foreach ( $form_tags as $tag ) {
- if ( 'email' === $tag->basetype && isset( $_POST[ $tag->name ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- return sanitize_text_field( wp_unslash( $_POST[ $tag->name ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ foreach ( $form_tags as $tag ) {
+ if ( 'email' === $tag->basetype && isset( $_POST[ $tag->name ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ return sanitize_text_field( wp_unslash( $_POST[ $tag->name ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ }
}
- }
return null;
}
@@ -228,20 +228,20 @@ private static function getEmail( $form_tags ) {
* last name, or null if no name tag found.
*/
private static function getName( $form_tags ) {
- if ( empty( $form_tags ) ) {
- return null;
- }
+ if ( empty( $form_tags ) ) {
+ return null;
+ }
- foreach ( $form_tags as $tag ) {
- if ( 'text' === $tag->basetype
- && strpos( strtolower( $tag->name ), 'name' ) !== false ) {
- return ServerEventFactory::split_name(
- sanitize_text_field(
- wp_unslash( $_POST[ $tag->name ] ?? null ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
- )
- );
+ foreach ( $form_tags as $tag ) {
+ if ( 'text' === $tag->basetype
+ && strpos( strtolower( $tag->name ), 'name' ) !== false ) {
+ return ServerEventFactory::split_name(
+ sanitize_text_field(
+ wp_unslash( $_POST[ $tag->name ] ?? null ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ )
+ );
+ }
}
- }
return null;
}
@@ -254,18 +254,18 @@ private static function getName( $form_tags ) {
* @return string|null The phone number, or null if no phone tag found.
*/
private static function getPhone( $form_tags ) {
- if ( empty( $form_tags ) ) {
- return null;
- }
+ if ( empty( $form_tags ) ) {
+ return null;
+ }
- foreach ( $form_tags as $tag ) {
- if ( 'tel' === $tag->basetype ) {
- return isset( $_POST[ $tag->name ] ) ? // phpcs:ignore WordPress.Security.NonceVerification.Missing
- sanitize_text_field(
- wp_unslash( $_POST[ $tag->name ] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
- ) : null;
+ foreach ( $form_tags as $tag ) {
+ if ( 'tel' === $tag->basetype ) {
+ return isset( $_POST[ $tag->name ] ) ? // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ sanitize_text_field(
+ wp_unslash( $_POST[ $tag->name ] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ ) : null;
+ }
}
- }
return null;
}
diff --git a/integration/class-facebookwordpresseasydigitaldownloads.php b/integration/class-facebookwordpresseasydigitaldownloads.php
index e60f0898..3ffdf6d3 100644
--- a/integration/class-facebookwordpresseasydigitaldownloads.php
+++ b/integration/class-facebookwordpresseasydigitaldownloads.php
@@ -58,53 +58,53 @@ class FacebookWordpressEasyDigitalDownloads extends FacebookWordpressIntegration
* - ViewContent: Injects view content events after download content.
*/
public static function inject_pixel_code() {
- add_action(
- 'edd_after_download_content',
- array( __CLASS__, 'injectAddToCartListener' )
- );
- add_action(
- 'edd_downloads_list_after',
- array( __CLASS__, 'injectAddToCartListener' )
- );
+ add_action(
+ 'edd_after_download_content',
+ array( __CLASS__, 'injectAddToCartListener' )
+ );
+ add_action(
+ 'edd_downloads_list_after',
+ array( __CLASS__, 'injectAddToCartListener' )
+ );
- add_action(
- 'wp_ajax_edd_add_to_cart',
- array( __CLASS__, 'injectAddToCartEventAjax' ),
- 5
- );
+ 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
- );
+ add_action(
+ 'wp_ajax_nopriv_edd_add_to_cart',
+ array( __CLASS__, 'injectAddToCartEventAjax' ),
+ 5
+ );
- add_action(
- 'edd_purchase_link_top',
- array( __CLASS__, 'injectAddToCartEventId' )
- );
+ add_action(
+ 'edd_purchase_link_top',
+ array( __CLASS__, 'injectAddToCartEventId' )
+ );
- self::add_pixel_fire_for_hook(
- array(
- 'hook_name' => 'edd_after_checkout_cart',
- 'classname' => __CLASS__,
- 'inject_function' => 'injectInitiateCheckoutEvent',
- )
- );
+ self::add_pixel_fire_for_hook(
+ array(
+ 'hook_name' => 'edd_after_checkout_cart',
+ 'classname' => __CLASS__,
+ 'inject_function' => 'injectInitiateCheckoutEvent',
+ )
+ );
- add_action(
- 'edd_payment_receipt_after',
- array( __CLASS__, 'trackPurchaseEvent' ),
- 10,
- 2
- );
+ add_action(
+ 'edd_payment_receipt_after',
+ array( __CLASS__, 'trackPurchaseEvent' ),
+ 10,
+ 2
+ );
- add_action(
- 'edd_after_download_content',
- array( __CLASS__, 'injectViewContentEvent' ),
- 40,
- 1
- );
+ add_action(
+ 'edd_after_download_content',
+ array( __CLASS__, 'injectViewContentEvent' ),
+ 40,
+ 1
+ );
}
/**
@@ -116,14 +116,14 @@ public static function inject_pixel_code() {
* @return void
*/
public static function injectAddToCartEventId() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
- $event_id = EventIdGenerator::guidv4();
- printf(
- '',
- esc_attr( $event_id )
- );
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
+ $event_id = EventIdGenerator::guidv4();
+ printf(
+ '',
+ esc_attr( $event_id )
+ );
}
/**
@@ -137,27 +137,27 @@ public static function injectAddToCartEventId() {
* @since 1.0.0
*/
public static function injectAddToCartEventAjax() {
- if ( isset( $_POST['nonce'] ) && isset( $_POST['download_id'] )
- && isset( $_POST['post_data'] ) ) {
- $download_id = absint( $_POST['download_id'] );
- $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) );
- if ( wp_verify_nonce( $nonce, 'edd-add-to-cart-' . $download_id )
- === false ) {
- return;
+ if ( isset( $_POST['nonce'] ) && isset( $_POST['download_id'] )
+ && isset( $_POST['post_data'] ) ) {
+ $download_id = absint( $_POST['download_id'] );
+ $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) );
+ if ( wp_verify_nonce( $nonce, 'edd-add-to-cart-' . $download_id )
+ === false ) {
+ return;
+ }
+ parse_str( $_POST['post_data'], $post_data ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
+ if ( isset( $post_data['facebook_event_id'] ) ) {
+ $event_id = $post_data['facebook_event_id'];
+ $server_event = ServerEventFactory::safe_create_event(
+ 'AddToCart',
+ array( __CLASS__, 'createAddToCartEvent' ),
+ array( $download_id ),
+ self::TRACKING_NAME
+ );
+ $server_event->setEventId( $event_id );
+ FacebookServerSideEvent::get_instance()->track( $server_event );
+ }
}
- parse_str( $_POST['post_data'], $post_data ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
- if ( isset( $post_data['facebook_event_id'] ) ) {
- $event_id = $post_data['facebook_event_id'];
- $server_event = ServerEventFactory::safe_create_event(
- 'AddToCart',
- array( __CLASS__, 'createAddToCartEvent' ),
- array( $download_id ),
- self::TRACKING_NAME
- );
- $server_event->setEventId( $event_id );
- FacebookServerSideEvent::get_instance()->track( $server_event );
- }
- }
}
/**
@@ -174,28 +174,28 @@ public static function injectAddToCartEventAjax() {
* @since 1.0.0
*/
public static function injectAddToCartListener( $download_id ) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- wp_register_script(
- 'facebook-pixel-add-to-cart',
- plugins_url( '../js/facebook_pixel_add_to_cart.js', __FILE__ ),
- array( 'jquery' ),
- '1.0',
- true
- );
+ wp_register_script(
+ 'facebook-pixel-add-to-cart',
+ plugins_url( '../js/facebook_pixel_add_to_cart.js', __FILE__ ),
+ array( 'jquery' ),
+ '1.0',
+ true
+ );
- wp_localize_script(
- 'facebook-pixel-add-to-cart',
- 'facebookPixelData',
- array(
- 'fbIntegrationKey' => FacebookPixel::FB_INTEGRATION_TRACKING_KEY,
- 'trackingName' => self::TRACKING_NAME,
- 'agentString' => FacebookWordpressOptions::get_agent_string(),
- 'pixelId' => FacebookWordpressOptions::get_pixel_id(),
- )
- );
+ wp_localize_script(
+ 'facebook-pixel-add-to-cart',
+ 'facebookPixelData',
+ array(
+ 'fbIntegrationKey' => FacebookPixel::FB_INTEGRATION_TRACKING_KEY,
+ 'trackingName' => self::TRACKING_NAME,
+ 'agentString' => FacebookWordpressOptions::get_agent_string(),
+ 'pixelId' => FacebookWordpressOptions::get_pixel_id(),
+ )
+ );
wp_enqueue_script( 'facebook-pixel-add-to-cart' );
}
@@ -210,17 +210,17 @@ public static function injectAddToCartListener( $download_id ) {
* @since 1.0.0
*/
public static function injectInitiateCheckoutEvent() {
- if ( FacebookPluginUtils::is_internal_user() ||
- ! function_exists( 'EDD' ) ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ||
+ ! function_exists( 'EDD' ) ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'InitiateCheckout',
- array( __CLASS__, 'createInitiateCheckoutEvent' ),
- array(),
- self::TRACKING_NAME
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'InitiateCheckout',
+ array( __CLASS__, 'createInitiateCheckoutEvent' ),
+ array(),
+ self::TRACKING_NAME
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
$code = PixelRenderer::render(
@@ -249,23 +249,23 @@ public static function injectInitiateCheckoutEvent() {
* @since 1.0.0
*/
public static function trackPurchaseEvent( $payment, $edd_receipt_args ) {
- if ( FacebookPluginUtils::is_internal_user() || empty( $payment->ID ) ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() || empty( $payment->ID ) ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Purchase',
- array( __CLASS__, 'createPurchaseEvent' ),
- array( $payment ),
- self::TRACKING_NAME
- );
- FacebookServerSideEvent::get_instance()->track( $server_event );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Purchase',
+ array( __CLASS__, 'createPurchaseEvent' ),
+ array( $payment ),
+ self::TRACKING_NAME
+ );
+ FacebookServerSideEvent::get_instance()->track( $server_event );
- add_action(
- 'wp_footer',
- array( __CLASS__, 'injectPurchaseEvent' ),
- 20
- );
+ add_action(
+ 'wp_footer',
+ array( __CLASS__, 'injectPurchaseEvent' ),
+ 20
+ );
}
/**
@@ -281,14 +281,14 @@ public static function injectPurchaseEvent() {
$events = FacebookServerSideEvent::get_instance()->get_tracked_events();
$code = PixelRenderer::render( $events, self::TRACKING_NAME );
- printf(
- '
-
-%s
-
- ',
- $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ printf(
+ '
+
+ %s
+
+ ',
+ $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -305,28 +305,28 @@ public static function injectPurchaseEvent() {
* @since 1.0.0
*/
public static function injectViewContentEvent( $download_id ) {
- if ( FacebookPluginUtils::is_internal_user() || empty( $download_id ) ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() || empty( $download_id ) ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'ViewContent',
- array( __CLASS__, 'createViewContentEvent' ),
- array( $download_id ),
- self::TRACKING_NAME
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'ViewContent',
+ array( __CLASS__, 'createViewContentEvent' ),
+ array( $download_id ),
+ self::TRACKING_NAME
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
$code = PixelRenderer::render( array( $server_event ), self::TRACKING_NAME );
- printf(
- '
-
-%s
-
- ',
- $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ printf(
+ '
+
+ %s
+
+ ',
+ $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -365,9 +365,9 @@ public static function createPurchaseEvent( $payment ) {
$event_data = array();
$payment_meta = \edd_get_payment_meta( $payment->ID );
- if ( empty( $payment_meta ) ) {
- return $event_data;
- }
+ if ( empty( $payment_meta ) ) {
+ return $event_data;
+ }
$event_data['email'] = $payment_meta['email'];
$event_data['first_name'] = $payment_meta['user_info']['first_name'];
@@ -375,10 +375,10 @@ public static function createPurchaseEvent( $payment ) {
$content_ids = array();
$value = 0;
- foreach ( $payment_meta['cart_details'] as $item ) {
- $content_ids[] = $item['id'];
- $value += $item['price'];
- }
+ foreach ( $payment_meta['cart_details'] as $item ) {
+ $content_ids[] = $item['id'];
+ $value += $item['price'];
+ }
$event_data['currency'] = $payment_meta['currency'];
$event_data['value'] = $value;
@@ -406,16 +406,16 @@ public static function createViewContentEvent( $download_id ) {
$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;
- }
+ 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'] = array( (string) $download_id );
$event_data['content_type'] = 'product';
$event_data['currency'] = $currency;
@@ -442,16 +442,16 @@ public static function createAddToCartEvent( $download_id ) {
$currency = EDDUtils::get_currency();
$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;
- }
+ 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'] = array( (string) $download_id );
$event_data['content_type'] = 'product';
$event_data['currency'] = $currency;
diff --git a/integration/class-facebookwordpressformidableform.php b/integration/class-facebookwordpressformidableform.php
index d9063845..c8bf7ac4 100644
--- a/integration/class-facebookwordpressformidableform.php
+++ b/integration/class-facebookwordpressformidableform.php
@@ -56,12 +56,12 @@ class FacebookWordpressFormidableForm extends FacebookWordpressIntegrationBase {
* @return void
*/
public static function inject_pixel_code() {
- add_action(
- 'frm_after_create_entry',
- array( __CLASS__, 'trackServerEvent' ),
- 20,
- 2
- );
+ add_action(
+ 'frm_after_create_entry',
+ array( __CLASS__, 'trackServerEvent' ),
+ 20,
+ 2
+ );
}
/**
@@ -78,24 +78,24 @@ public static function inject_pixel_code() {
* @return void
*/
public static function trackServerEvent( $entry_id, $form_id ) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Lead',
- array( __CLASS__, 'readFormData' ),
- array( $entry_id ),
- self::TRACKING_NAME,
- true
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Lead',
+ array( __CLASS__, 'readFormData' ),
+ array( $entry_id ),
+ self::TRACKING_NAME,
+ true
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
- add_action(
- 'wp_footer',
- array( __CLASS__, 'injectLeadEvent' ),
- 20
- );
+ add_action(
+ 'wp_footer',
+ array( __CLASS__, 'injectLeadEvent' ),
+ 20
+ );
}
/**
@@ -110,21 +110,21 @@ public static function trackServerEvent( $entry_id, $form_id ) {
* @return void
*/
public static function injectLeadEvent() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
$events = FacebookServerSideEvent::get_instance()->get_tracked_events();
$code = PixelRenderer::render( $events, self::TRACKING_NAME );
- printf(
- '
-
-%s
-
- ',
- $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ printf(
+ '
+
+ %s
+
+ ',
+ $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -151,16 +151,16 @@ public static function readFormData( $entry_id ) {
IntegrationUtils::get_formidable_forms_entry_values( $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 );
- }
+ 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();
}
@@ -234,23 +234,23 @@ private static function getAddressInformation( $field_values ) {
'address'
);
$address_data = array();
- if ( $address_saved_value ) {
- if ( isset( $address_saved_value['city'] ) ) {
- $address_data['city'] = $address_saved_value['city'];
- }
- if ( isset( $address_saved_value['state'] ) ) {
- $address_data['state'] = $address_saved_value['state'];
- }
- if (
- isset( $address_saved_value['country'] )
- && strlen( $address_saved_value['country'] ) === 2
- ) {
- $address_data['country'] = $address_saved_value['country'];
+ if ( $address_saved_value ) {
+ if ( isset( $address_saved_value['city'] ) ) {
+ $address_data['city'] = $address_saved_value['city'];
+ }
+ if ( isset( $address_saved_value['state'] ) ) {
+ $address_data['state'] = $address_saved_value['state'];
+ }
+ if (
+ isset( $address_saved_value['country'] )
+ && strlen( $address_saved_value['country'] ) === 2
+ ) {
+ $address_data['country'] = $address_saved_value['country'];
+ }
+ if ( isset( $address_saved_value['zip'] ) ) {
+ $address_data['zip'] = $address_saved_value['zip'];
+ }
}
- if ( isset( $address_saved_value['zip'] ) ) {
- $address_data['zip'] = $address_saved_value['zip'];
- }
- }
return $address_data;
}
@@ -269,12 +269,12 @@ private static function getAddressInformation( $field_values ) {
* or null if no matching field is found.
*/
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();
+ foreach ( $field_values as $field_value ) {
+ $field = $field_value->get_field();
+ if ( $field->type === $type ) {
+ return $field_value->get_saved_value();
+ }
}
- }
return null;
}
@@ -304,14 +304,14 @@ private static function getFieldValue(
$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();
+ 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;
}
diff --git a/integration/class-facebookwordpressmailchimpforwp.php b/integration/class-facebookwordpressmailchimpforwp.php
index 3191003a..b0e43665 100644
--- a/integration/class-facebookwordpressmailchimpforwp.php
+++ b/integration/class-facebookwordpressmailchimpforwp.php
@@ -69,31 +69,31 @@ public static function inject_pixel_code() {
* @return void
*/
public static function injectLeadEvent() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Lead',
- array( __CLASS__, 'readFormData' ),
- array(),
- self::TRACKING_NAME,
- true
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Lead',
+ array( __CLASS__, 'readFormData' ),
+ array(),
+ self::TRACKING_NAME,
+ true
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
$code = PixelRenderer::render(
array( $server_event ),
self::TRACKING_NAME
);
- printf(
- '
-
- %s
-
- ',
- $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ printf(
+ '
+
+ %s
+
+ ',
+ $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -118,45 +118,45 @@ public static function injectLeadEvent() {
*/
public static function readFormData() {
$event_data = array();
- if ( ! empty( $_POST['EMAIL'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $event_data['email'] = sanitize_email( wp_unslash( $_POST['EMAIL'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
- }
+ if ( ! empty( $_POST['EMAIL'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $event_data['email'] = sanitize_email( wp_unslash( $_POST['EMAIL'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ }
- if ( ! empty( $_POST['FNAME'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $event_data['first_name'] = sanitize_text_field( wp_unslash( $_POST['FNAME'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
- }
+ if ( ! empty( $_POST['FNAME'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $event_data['first_name'] = sanitize_text_field( wp_unslash( $_POST['FNAME'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ }
- if ( ! empty( $_POST['LNAME'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $event_data['last_name'] = sanitize_text_field( wp_unslash( $_POST['LNAME'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
- }
+ if ( ! empty( $_POST['LNAME'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $event_data['last_name'] = sanitize_text_field( wp_unslash( $_POST['LNAME'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ }
- if ( ! empty( $_POST['PHONE'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $event_data['phone'] = sanitize_text_field( wp_unslash( $_POST['PHONE'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
- }
+ if ( ! empty( $_POST['PHONE'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $event_data['phone'] = sanitize_text_field( wp_unslash( $_POST['PHONE'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ }
- if ( ! empty( $_POST['ADDRESS'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
- $address_data = sanitize_text_field( wp_unslash( $_POST['ADDRESS'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ if ( ! empty( $_POST['ADDRESS'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ $address_data = sanitize_text_field( wp_unslash( $_POST['ADDRESS'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
- if ( ! empty( $address_data['city'] ) ) {
- $event_data['city'] = sanitize_text_field( $address_data['city'] );
- }
+ if ( ! empty( $address_data['city'] ) ) {
+ $event_data['city'] = sanitize_text_field( $address_data['city'] );
+ }
- if ( ! empty( $address_data['state'] ) ) {
- $event_data['state'] =
- sanitize_text_field( $address_data['state'] );
- }
+ if ( ! empty( $address_data['state'] ) ) {
+ $event_data['state'] =
+ sanitize_text_field( $address_data['state'] );
+ }
- if ( ! empty( $address_data['zip'] ) ) {
- $event_data['zip'] = sanitize_text_field( $address_data['zip'] );
- }
+ if ( ! empty( $address_data['zip'] ) ) {
+ $event_data['zip'] = sanitize_text_field( $address_data['zip'] );
+ }
- if (
- ! empty( $address_data['country'] )
- && strlen( $address_data['country'] ) === 2
- ) {
- $event_data['country'] = $address_data['country'];
+ if (
+ ! empty( $address_data['country'] )
+ && strlen( $address_data['country'] ) === 2
+ ) {
+ $event_data['country'] = $address_data['country'];
+ }
}
- }
return $event_data;
}
}
diff --git a/integration/class-facebookwordpressninjaforms.php b/integration/class-facebookwordpressninjaforms.php
index ce484be7..ad5e3ec0 100644
--- a/integration/class-facebookwordpressninjaforms.php
+++ b/integration/class-facebookwordpressninjaforms.php
@@ -56,12 +56,12 @@ class FacebookWordpressNinjaForms extends FacebookWordpressIntegrationBase {
* @return void
*/
public static function inject_pixel_code() {
- add_action(
- 'ninja_forms_submission_actions',
- array( __CLASS__, 'injectLeadEvent' ),
- 10,
- 3
- );
+ add_action(
+ 'ninja_forms_submission_actions',
+ array( __CLASS__, 'injectLeadEvent' ),
+ 10,
+ 3
+ );
}
/**
@@ -87,48 +87,48 @@ public static function injectLeadEvent(
$form_cache,
$form_data
) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return $actions;
- }
-
- foreach ( $actions as $key => $action ) {
- if ( ! isset( $action['settings'] ) ||
- ! isset( $action['settings']['type'] ) ) {
- continue;
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return $actions;
}
- $type = $action['settings']['type'];
- if ( ! is_string( $type ) ) {
- continue;
- }
+ foreach ( $actions as $key => $action ) {
+ if ( ! isset( $action['settings'] ) ||
+ ! isset( $action['settings']['type'] ) ) {
+ continue;
+ }
- if ( 'successmessage' === $type ) {
- $event = ServerEventFactory::safe_create_event(
- 'Lead',
- array( __CLASS__, 'readFormData' ),
- array( $form_data ),
- self::TRACKING_NAME,
- true
- );
- FacebookServerSideEvent::get_instance()->track( $event );
+ $type = $action['settings']['type'];
+ if ( ! is_string( $type ) ) {
+ continue;
+ }
- $pixel_code = PixelRenderer::render(
- array( $event ),
- self::TRACKING_NAME
+ if ( 'successmessage' === $type ) {
+ $event = ServerEventFactory::safe_create_event(
+ 'Lead',
+ array( __CLASS__, 'readFormData' ),
+ array( $form_data ),
+ self::TRACKING_NAME,
+ true
+ );
+ FacebookServerSideEvent::get_instance()->track( $event );
+
+ $pixel_code = PixelRenderer::render(
+ array( $event ),
+ self::TRACKING_NAME
+ );
+ $code = sprintf(
+ '
+
+ %s
+
+ ',
+ $pixel_code
);
- $code = sprintf(
- '
-
-%s
-
- ',
- $pixel_code
- );
- $action['settings']['success_msg'] .= $code;
- $actions[ $key ] = $action;
+ $action['settings']['success_msg'] .= $code;
+ $actions[ $key ] = $action;
+ }
}
- }
return $actions;
}
@@ -155,19 +155,19 @@ public static function injectLeadEvent(
* @return array An associative array of form data.
*/
public static function readFormData( $form_data ) {
- if ( empty( $form_data ) ) {
- return array();
- }
+ 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 = 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 );
@@ -199,10 +199,10 @@ private static function getEmail( $form_data ) {
*/
private static function getName( $form_data ) {
$name = self::getField( $form_data, 'name' );
- if ( $name ) {
- return ServerEventFactory::split_name( $name );
- }
- return null;
+ if ( $name ) {
+ return ServerEventFactory::split_name( $name );
+ }
+ return null;
}
/**
@@ -311,15 +311,15 @@ private static function hasPrefix( $text, $prefix ) {
* if no matching field is found.
*/
private static function getField( $form_data, $key ) {
- if ( empty( $form_data['fields'] ) ) {
- return null;
- }
+ if ( empty( $form_data['fields'] ) ) {
+ return null;
+ }
- foreach ( $form_data['fields'] as $field ) {
- if ( self::hasPrefix( $field['key'], $key ) ) {
- return $field['value'];
+ foreach ( $form_data['fields'] as $field ) {
+ if ( self::hasPrefix( $field['key'], $key ) ) {
+ return $field['value'];
+ }
}
- }
return null;
}
diff --git a/integration/class-facebookwordpresswoocommerce.php b/integration/class-facebookwordpresswoocommerce.php
index 81055e6f..a6907e91 100644
--- a/integration/class-facebookwordpresswoocommerce.php
+++ b/integration/class-facebookwordpresswoocommerce.php
@@ -67,43 +67,43 @@ class FacebookWordpressWooCommerce extends FacebookWordpressIntegrationBase {
* @return void
*/
public static function inject_pixel_code() {
- 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
- );
-
- add_action(
- 'wp_footer',
- array( __CLASS__, 'addDivForAjaxPixelEvent' )
- );
- }
+ 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
+ );
+
+ add_action(
+ 'wp_footer',
+ array( __CLASS__, 'addDivForAjaxPixelEvent' )
+ );
+ }
}
/**
@@ -112,14 +112,14 @@ public static function inject_pixel_code() {
* This div is used to inject pixel events via AJAX requests.
*/
public static function addDivForAjaxPixelEvent() {
- echo wp_kses(
- self::getDivForAjaxPixelEvent(),
- array(
- 'div' => array(
- 'id' => array(),
- ),
- )
- );
+ echo wp_kses(
+ self::getDivForAjaxPixelEvent(),
+ array(
+ 'div' => array(
+ 'id' => array(),
+ ),
+ )
+ );
}
/**
@@ -157,26 +157,26 @@ public static function getDivForAjaxPixelEvent( $content = '' ) {
* @return void
*/
public static function trackViewContentEvent() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
global $post;
- if ( ! isset( $post->ID ) ) {
- return;
- }
+ if ( ! isset( $post->ID ) ) {
+ return;
+ }
$product = wc_get_product( $post->ID );
- if ( ! $product ) {
- return;
- }
+ if ( ! $product ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'ViewContent',
- array( __CLASS__, 'createViewContentEvent' ),
- array( $product ),
- self::TRACKING_NAME
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'ViewContent',
+ array( __CLASS__, 'createViewContentEvent' ),
+ array( $product ),
+ self::TRACKING_NAME
+ );
FacebookServerSideEvent::get_instance()->track( $server_event, false );
@@ -224,10 +224,10 @@ public static function createViewContentEvent( $product ) {
* associated with the product, or null.
*/
private static function getProductCategory( $product_id ) {
- $categories = get_the_terms(
- $product_id,
- 'product_cat'
- );
+ $categories = get_the_terms(
+ $product_id,
+ 'product_cat'
+ );
return count( $categories ) > 0 ? $categories[0]->name : null;
}
@@ -242,16 +242,16 @@ private static function getProductCategory( $product_id ) {
* @since 1.0.0
*/
public static function trackPurchaseEvent( $order_id ) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Purchase',
- array( __CLASS__, 'createPurchaseEvent' ),
- array( $order_id ),
- self::TRACKING_NAME
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Purchase',
+ array( __CLASS__, 'createPurchaseEvent' ),
+ array( $order_id ),
+ self::TRACKING_NAME
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
@@ -282,24 +282,24 @@ public static function createPurchaseEvent( $order_id ) {
$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';
- }
+ 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 );
+ $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 );
+ $content = new Content();
+ $content->setProductId( $product_id );
+ $content->setQuantity( $quantity );
+ $content->setItemPrice( $item->get_total() / $quantity );
- $contents[] = $content;
- $product_ids[] = $product_id;
- }
+ $contents[] = $content;
+ $product_ids[] = $product_id;
+ }
$event_data = self::getPiiFromBillingInformation(
$order
@@ -339,36 +339,36 @@ public static function trackAddToCartEvent(
$quantity,
$variation_id
) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
-
- $server_event = ServerEventFactory::safe_create_event(
- 'AddToCart',
- array( __CLASS__, 'createAddToCartEvent' ),
- array( $cart_item_key, $product_id, $quantity ),
- self::TRACKING_NAME
- );
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $is_ajax_request = wp_doing_ajax();
+ $server_event = ServerEventFactory::safe_create_event(
+ 'AddToCart',
+ array( __CLASS__, 'createAddToCartEvent' ),
+ array( $cart_item_key, $product_id, $quantity ),
+ self::TRACKING_NAME
+ );
- FacebookServerSideEvent::get_instance()->track(
- $server_event,
- $is_ajax_request
- );
+ $is_ajax_request = wp_doing_ajax();
- if ( ! $is_ajax_request ) {
- self::enqueuePixelCode( $server_event );
- } else {
- FacebookServerSideEvent::get_instance()->set_pending_pixel_event(
- 'addPixelCodeToAddToCartFragment',
- $server_event
- );
- add_filter(
- 'woocommerce_add_to_cart_fragments',
- array( __CLASS__, 'addPixelCodeToAddToCartFragment' )
+ FacebookServerSideEvent::get_instance()->track(
+ $server_event,
+ $is_ajax_request
);
- }
+
+ if ( ! $is_ajax_request ) {
+ self::enqueuePixelCode( $server_event );
+ } else {
+ FacebookServerSideEvent::get_instance()->set_pending_pixel_event(
+ 'addPixelCodeToAddToCartFragment',
+ $server_event
+ );
+ add_filter(
+ 'woocommerce_add_to_cart_fragments',
+ array( __CLASS__, 'addPixelCodeToAddToCartFragment' )
+ );
+ }
}
/**
@@ -388,11 +388,11 @@ public static function trackAddToCartEvent(
public static function addPixelCodeToAddToCartFragment( $fragments ) {
$server_event = FacebookServerSideEvent::get_instance()
->get_pending_pixel_event( '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 );
- }
+ 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;
}
@@ -421,17 +421,17 @@ public static function createAddToCartEvent(
$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
- );
- }
+ 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;
}
@@ -446,16 +446,16 @@ public static function createAddToCartEvent(
* @since 1.0.0
*/
public static function trackInitiateCheckout() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'InitiateCheckout',
- array( __CLASS__, 'createInitiateCheckoutEvent' ),
- array(),
- self::TRACKING_NAME
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'InitiateCheckout',
+ array( __CLASS__, 'createInitiateCheckoutEvent' ),
+ array(),
+ self::TRACKING_NAME
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
@@ -484,14 +484,14 @@ public static function createInitiateCheckoutEvent() {
$event_data['content_type'] = 'product';
$event_data['currency'] = \get_woocommerce_currency();
- if ( WC()->cart ) {
- $cart = WC()->cart;
+ if ( WC()->cart ) {
+ $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 );
- }
+ $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;
}
@@ -548,10 +548,10 @@ private static function getPiiFromBillingInformation( $order ) {
* or null if the cart item is empty.
*/
private static function getAddToCartValue( $cart_item, $quantity ) {
- if ( ! empty( $cart_item ) ) {
- $price = $cart_item['line_total'] / $cart_item['quantity'];
- return $quantity * $price;
- }
+ if ( ! empty( $cart_item ) ) {
+ $price = $cart_item['line_total'] / $cart_item['quantity'];
+ return $quantity * $price;
+ }
return null;
}
@@ -569,12 +569,12 @@ private static function getAddToCartValue( $cart_item, $quantity ) {
* or null if the cart item is not found.
*/
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 ];
+ if ( WC()->cart ) {
+ $cart = WC()->cart->get_cart();
+ if ( ! empty( $cart ) && ! empty( $cart[ $cart_item_key ] ) ) {
+ return $cart[ $cart_item_key ];
+ }
}
- }
return null;
}
@@ -590,11 +590,11 @@ private static function getCartItem( $cart_item_key ) {
*/
private static function getContentIds( $cart ) {
$product_ids = array();
- foreach ( $cart->get_cart() as $item ) {
- if ( ! empty( $item['data'] ) ) {
- $product_ids[] = self::getProductId( $item['data'] );
+ foreach ( $cart->get_cart() as $item ) {
+ if ( ! empty( $item['data'] ) ) {
+ $product_ids[] = self::getProductId( $item['data'] );
+ }
}
- }
return $product_ids;
}
@@ -615,16 +615,16 @@ private static function getContentIds( $cart ) {
*/
private static function getContents( $cart ) {
$contents = array();
- 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;
+ 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;
}
@@ -659,33 +659,33 @@ private static function getProductId( $product ) {
private static function getPIIFromSession() {
$event_data = FacebookPluginUtils::get_logged_in_user_info();
$user_id = get_current_user_id();
- if ( 0 !== $user_id ) {
- $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
- );
- }
+ if ( 0 !== $user_id ) {
+ $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 );
}
@@ -697,11 +697,11 @@ private static function getPIIFromSession() {
* @since 1.0.0
*/
private static function isFacebookForWooCommerceActive() {
- return in_array(
- 'facebook-for-woocommerce/facebook-for-woocommerce.php',
- get_option( 'active_plugins' ),
- true
- );
+ return in_array(
+ 'facebook-for-woocommerce/facebook-for-woocommerce.php',
+ get_option( 'active_plugins' ),
+ true
+ );
}
/**
@@ -720,19 +720,19 @@ public static function generatePixelCode(
$server_event,
$script_tag = false
) {
- $code = PixelRenderer::render(
- array( $server_event ),
- self::TRACKING_NAME,
- $script_tag
- );
- $code = sprintf(
- '
-
-%s
-
- ',
- $code
- );
+ $code = PixelRenderer::render(
+ array( $server_event ),
+ self::TRACKING_NAME,
+ $script_tag
+ );
+ $code = sprintf(
+ '
+
+ %s
+
+ ',
+ $code
+ );
return $code;
}
diff --git a/integration/class-facebookwordpresswpecommerce.php b/integration/class-facebookwordpresswpecommerce.php
index 80494626..aa093e3c 100644
--- a/integration/class-facebookwordpresswpecommerce.php
+++ b/integration/class-facebookwordpresswpecommerce.php
@@ -59,26 +59,26 @@ class FacebookWordpressWPECommerce extends FacebookWordpressIntegrationBase {
* to ensure correct execution order.
*/
public static function inject_pixel_code() {
- add_action(
- 'wpsc_add_to_cart_json_response',
- array( __CLASS__, 'injectAddToCartEvent' ),
- 11
- );
-
- self::add_pixel_fire_for_hook(
- array(
- 'hook_name' => 'wpsc_before_shopping_cart_page',
- 'classname' => __CLASS__,
- 'inject_function' => 'injectInitiateCheckoutEvent',
- )
- );
-
- add_action(
- 'wpsc_transaction_results_shutdown',
- array( __CLASS__, 'injectPurchaseEvent' ),
- 11,
- 3
- );
+ add_action(
+ 'wpsc_add_to_cart_json_response',
+ array( __CLASS__, 'injectAddToCartEvent' ),
+ 11
+ );
+
+ self::add_pixel_fire_for_hook(
+ array(
+ 'hook_name' => 'wpsc_before_shopping_cart_page',
+ 'classname' => __CLASS__,
+ 'inject_function' => 'injectInitiateCheckoutEvent',
+ )
+ );
+
+ add_action(
+ 'wpsc_transaction_results_shutdown',
+ array( __CLASS__, 'injectPurchaseEvent' ),
+ 11,
+ 3
+ );
}
/**
@@ -95,31 +95,31 @@ public static function inject_pixel_code() {
* @return array The modified response with the Facebook Pixel code added.
*/
public static function injectAddToCartEvent( $response ) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return $response;
- }
-
- $product_id = $response['product_id'];
- $server_event = ServerEventFactory::safe_create_event(
- 'AddToCart',
- array( __CLASS__, 'createAddToCartEvent' ),
- array( $product_id ),
- self::TRACKING_NAME
- );
- FacebookServerSideEvent::get_instance()->track( $server_event );
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return $response;
+ }
- $code = PixelRenderer::render(
- array( $server_event ),
+ $product_id = $response['product_id'];
+ $server_event = ServerEventFactory::safe_create_event(
+ 'AddToCart',
+ array( __CLASS__, 'createAddToCartEvent' ),
+ array( $product_id ),
self::TRACKING_NAME
);
- $code = sprintf(
- '
-
- %s
-
- ',
- $code
- );
+ FacebookServerSideEvent::get_instance()->track( $server_event );
+
+ $code = PixelRenderer::render(
+ array( $server_event ),
+ self::TRACKING_NAME
+ );
+ $code = sprintf(
+ '
+
+ %s
+
+ ',
+ $code
+ );
$response['widget_output'] .= $code;
return $response;
}
@@ -135,32 +135,32 @@ public static function injectAddToCartEvent( $response ) {
* @since 1.0.0
*/
public static function injectInitiateCheckoutEvent() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
-
- $server_event = ServerEventFactory::safe_create_event(
- 'InitiateCheckout',
- array( __CLASS__, 'createInitiateCheckoutEvent' ),
- array(),
- self::TRACKING_NAME
- );
- FacebookServerSideEvent::get_instance()->track( $server_event );
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $code = PixelRenderer::render(
- array(
- $server_event,
- ),
+ $server_event = ServerEventFactory::safe_create_event(
+ 'InitiateCheckout',
+ array( __CLASS__, 'createInitiateCheckoutEvent' ),
+ array(),
self::TRACKING_NAME
);
- printf(
- '
-
-%s
-
- ',
- $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ FacebookServerSideEvent::get_instance()->track( $server_event );
+
+ $code = PixelRenderer::render(
+ array(
+ $server_event,
+ ),
+ self::TRACKING_NAME
+ );
+ printf(
+ '
+
+ %s
+
+ ',
+ $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -188,16 +188,16 @@ public static function injectPurchaseEvent(
$session_id,
$display_to_screen
) {
- if ( FacebookPluginUtils::is_internal_user() || ! $display_to_screen ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() || ! $display_to_screen ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Purchase',
- array( __CLASS__, 'createPurchaseEvent' ),
- array( $purchase_log_object ),
- self::TRACKING_NAME
- );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Purchase',
+ array( __CLASS__, 'createPurchaseEvent' ),
+ array( $purchase_log_object ),
+ self::TRACKING_NAME
+ );
FacebookServerSideEvent::get_instance()->track( $server_event );
$code = PixelRenderer::render(
@@ -207,14 +207,14 @@ public static function injectPurchaseEvent(
self::TRACKING_NAME
);
- printf(
- '
-
-%s
-
- ',
- $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ printf(
+ '
+
+ %s
+
+ ',
+ $code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -244,10 +244,10 @@ public static function createPurchaseEvent( $purchase_log_object ) {
\wpsc_get_currency_code() : '';
$item_ids = array();
- foreach ( $cart_items as $item ) {
- $item_array = (array) $item;
- $item_ids[] = $item_array['prodid'];
- }
+ foreach ( $cart_items as $item ) {
+ $item_array = (array) $item;
+ $item_ids[] = $item_array['prodid'];
+ }
$event_data['content_ids'] = $item_ids;
$event_data['content_type'] = 'product';
@@ -280,12 +280,12 @@ public static function createAddToCartEvent( $product_id ) {
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;
+ 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';
@@ -319,10 +319,10 @@ public static function createInitiateCheckoutEvent() {
$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;
- }
+ foreach ( $cart_items as $item ) {
+ $content_ids[] = $item->product_id;
+ $value += $item->unit_price;
+ }
$event_data['currency'] =
function_exists( '\wpsc_get_currency_code' ) ?
diff --git a/integration/class-facebookwordpresswpforms.php b/integration/class-facebookwordpresswpforms.php
index 993ad786..1b53c718 100644
--- a/integration/class-facebookwordpresswpforms.php
+++ b/integration/class-facebookwordpresswpforms.php
@@ -53,12 +53,12 @@ class FacebookWordpressWPForms extends FacebookWordpressIntegrationBase {
* the Pixel code is injected during the form processing stage.
*/
public static function inject_pixel_code() {
- add_action(
- 'wpforms_process_before',
- array( __CLASS__, 'trackEvent' ),
- 20,
- 2
- );
+ add_action(
+ 'wpforms_process_before',
+ array( __CLASS__, 'trackEvent' ),
+ 20,
+ 2
+ );
}
/**
@@ -79,24 +79,24 @@ public static function inject_pixel_code() {
* @return void
*/
public static function trackEvent( $entry, $form_data ) {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $server_event = ServerEventFactory::safe_create_event(
- 'Lead',
- array( __CLASS__, 'readFormData' ),
- array( $entry, $form_data ),
- self::TRACKING_NAME,
- true
- );
- FacebookServerSideEvent::get_instance()->track( $server_event );
+ $server_event = ServerEventFactory::safe_create_event(
+ 'Lead',
+ array( __CLASS__, 'readFormData' ),
+ array( $entry, $form_data ),
+ self::TRACKING_NAME,
+ true
+ );
+ FacebookServerSideEvent::get_instance()->track( $server_event );
- add_action(
- 'wp_footer',
- array( __CLASS__, 'injectLeadEvent' ),
- 20
- );
+ add_action(
+ 'wp_footer',
+ array( __CLASS__, 'injectLeadEvent' ),
+ 20
+ );
}
/**
@@ -111,22 +111,22 @@ public static function trackEvent( $entry, $form_data ) {
* @return void
*/
public static function injectLeadEvent() {
- if ( FacebookPluginUtils::is_internal_user() ) {
- return;
- }
+ if ( FacebookPluginUtils::is_internal_user() ) {
+ return;
+ }
- $events =
- FacebookServerSideEvent::get_instance()->get_tracked_events();
- $pixel_code = PixelRenderer::render( $events, self::TRACKING_NAME );
+ $events =
+ FacebookServerSideEvent::get_instance()->get_tracked_events();
+ $pixel_code = PixelRenderer::render( $events, self::TRACKING_NAME );
- printf(
- '
-
-%s
-
- ',
- $pixel_code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- );
+ printf(
+ '
+
+ %s
+
+ ',
+ $pixel_code // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ );
}
/**
@@ -150,25 +150,25 @@ public static function injectLeadEvent() {
* extracted from the form entry.
*/
public static function readFormData( $entry, $form_data ) {
- if ( empty( $entry ) || empty( $form_data ) ) {
- return array();
- }
+ if ( empty( $entry ) || empty( $form_data ) ) {
+ return array();
+ }
- $name = self::getName( $entry, $form_data );
+ $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(
+ '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 )
- );
+ $event_data = array_merge(
+ $event_data,
+ self::getAddress( $entry, $form_data )
+ );
- return $event_data;
+ return $event_data;
}
/**
@@ -183,7 +183,7 @@ public static function readFormData( $entry, $form_data ) {
* @return string|null The phone number, or null if no phone field is found.
*/
private static function getPhone( $entry, $form_data ) {
- return self::getField( $entry, $form_data, 'phone' );
+ return self::getField( $entry, $form_data, 'phone' );
}
/**
@@ -199,7 +199,7 @@ private static function getPhone( $entry, $form_data ) {
* if no email field is found.
*/
private static function getEmail( $entry, $form_data ) {
- return self::getField( $entry, $form_data, 'email' );
+ return self::getField( $entry, $form_data, 'email' );
}
/**
@@ -218,30 +218,30 @@ private static function getEmail( $entry, $form_data ) {
* @return array The address data.
*/
private static function getAddress( $entry, $form_data ) {
- $address_field_data = self::getField( $entry, $form_data, 'address' );
- if ( is_null( $address_field_data ) ) {
- return array();
- }
- $address_data = array();
- if ( isset( $address_field_data['city'] ) ) {
- $address_data['city'] = $address_field_data['city'];
- }
- if ( isset( $address_field_data['state'] ) ) {
- $address_data['state'] = $address_field_data['state'];
- }
+ $address_field_data = self::getField( $entry, $form_data, 'address' );
+ if ( is_null( $address_field_data ) ) {
+ return array();
+ }
+ $address_data = array();
+ if ( isset( $address_field_data['city'] ) ) {
+ $address_data['city'] = $address_field_data['city'];
+ }
+ if ( isset( $address_field_data['state'] ) ) {
+ $address_data['state'] = $address_field_data['state'];
+ }
- if ( isset( $address_field_data['country'] ) ) {
- $address_data['country'] = $address_field_data['country'];
- } else {
- $address_scheme = self::getAddressScheme( $form_data );
- if ( 'us' === $address_scheme ) {
- $address_data['country'] = 'US';
+ if ( isset( $address_field_data['country'] ) ) {
+ $address_data['country'] = $address_field_data['country'];
+ } else {
+ $address_scheme = self::getAddressScheme( $form_data );
+ if ( 'us' === $address_scheme ) {
+ $address_data['country'] = 'US';
+ }
}
- }
- if ( isset( $address_field_data['postal'] ) ) {
- $address_data['zip'] = $address_field_data['postal'];
- }
- return $address_data;
+ if ( isset( $address_field_data['postal'] ) ) {
+ $address_data['zip'] = $address_field_data['postal'];
+ }
+ return $address_data;
}
/**
@@ -261,27 +261,27 @@ private static function getAddress( $entry, $form_data ) {
* last name, or null if no name field is found.
*/
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 ( 'name' === $field['type'] ) {
- if ( 'simple' === $field['format'] ) {
- return ServerEventFactory::split_name(
- $entries[ $field['id'] ]
- );
- } elseif ( 'first-last' === $field['format'] ) {
- return array(
- $entries[ $field['id'] ]['first'],
- $entries[ $field['id'] ]['last'],
- );
+ if ( empty( $form_data['fields'] ) || empty( $entry['fields'] ) ) {
+ return null;
}
+
+ $entries = $entry['fields'];
+ foreach ( $form_data['fields'] as $field ) {
+ if ( 'name' === $field['type'] ) {
+ if ( 'simple' === $field['format'] ) {
+ return ServerEventFactory::split_name(
+ $entries[ $field['id'] ]
+ );
+ } elseif ( 'first-last' === $field['format'] ) {
+ return array(
+ $entries[ $field['id'] ]['first'],
+ $entries[ $field['id'] ]['last'],
+ );
+ }
+ }
}
- }
- return null;
+ return null;
}
/**
@@ -299,17 +299,17 @@ private static function getName( $entry, $form_data ) {
* field of the specified type is found.
*/
private static function getField( $entry, $form_data, $type ) {
- if ( empty( $form_data['fields'] ) || empty( $entry['fields'] ) ) {
- return null;
- }
+ 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'] ];
+ foreach ( $form_data['fields'] as $field ) {
+ if ( $field['type'] === $type ) {
+ return $entry['fields'][ $field['id'] ];
+ }
}
- }
- return null;
+ return null;
}
/**
@@ -326,13 +326,13 @@ private static function getField( $entry, $form_data, $type ) {
* null if no address field is found.
*/
private static function getAddressScheme( $form_data ) {
- foreach ( $form_data['fields'] as $field ) {
- if ( 'address' === $field['type'] ) {
- if ( isset( $field['scheme'] ) ) {
- return $field['scheme'];
+ foreach ( $form_data['fields'] as $field ) {
+ if ( 'address' === $field['type'] ) {
+ if ( isset( $field['scheme'] ) ) {
+ return $field['scheme'];
+ }
+ }
}
- }
- }
- return null;
+ return null;
}
}
diff --git a/js/fbe_allinone.js b/js/fbe_allinone.js
index b746be6a..d9b41d52 100644
--- a/js/fbe_allinone.js
+++ b/js/fbe_allinone.js
@@ -332,10 +332,16 @@ var FBEFlowContainer = React.createClass({
},
hideEventsManagerSection: function hideEventsManagerSection() {
jQuery(".events-manager-wrapper").hide();
+ jQuery('#ad-creation-plugin').hide();
+ jQuery('#ad-insights-plugin').hide();
+ jQuery("#fb-adv-conf").hide();
jQuery(".events-manager-wrapper input#pixel-id").val('');
},
showEventsManagerSection: function showEventsManagerSection(pixelId) {
jQuery(".events-manager-wrapper").show();
+ jQuery('#ad-creation-plugin').show();
+ jQuery('#ad-insights-plugin').show();
+ jQuery("#fb-adv-conf").show();
jQuery(".events-manager-wrapper input#pixel-id").val(pixelId);
}
});