diff --git a/build.xml b/build.xml index a48ec6d0..b033409c 100644 --- a/build.xml +++ b/build.xml @@ -16,12 +16,7 @@ - - - - - - + @@ -54,9 +49,6 @@ - - - diff --git a/composer.json b/composer.json index 021156c7..e4a05090 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,10 @@ "FacebookPixelPlugin\\": "./", "FacebookPixelPlugin\\Core\\": "core/", "FacebookPixelPlugin\\Integration\\": "integration/" - } + }, + "classmap": [ + "./" + ] }, "autoload-dev": { "classmap": [ diff --git a/core/class-facebookcapievent.php b/core/class-facebookcapievent.php index 60faccb3..2e4b9dd5 100644 --- a/core/class-facebookcapievent.php +++ b/core/class-facebookcapievent.php @@ -257,9 +257,9 @@ public function send_capi_event() { public function get_invalid_event_custom_data( $custom_data ) { $invalid_custom_data = array(); foreach ( $custom_data as $key => $value ) { - if ( ! in_array( $key, self::VALID_CUSTOM_DATA, true ) ) { - array_push( $invalid_custom_data, $key ); - } + if ( ! in_array( $key, self::VALID_CUSTOM_DATA, true ) ) { + array_push( $invalid_custom_data, $key ); + } } return $invalid_custom_data; } @@ -293,15 +293,15 @@ public function validate_payload( $payload ) { foreach ( $payload['data'] as $event ) { foreach ( self::REQUIRED_EVENT_DATA as $attribute ) { if ( ! array_key_exists( $attribute, $event ) ) { - if ( ! empty( $response['message'] ) ) { - $response['error_user_msg'] .= - ", {$attribute} attribute is missing"; - } else { - $response['valid'] = false; - $response['message'] = 'Missing required attribute'; - $response['error_user_msg'] = - "{$attribute} attribute is missing"; - } + if ( ! empty( $response['message'] ) ) { + $response['error_user_msg'] .= + ", {$attribute} attribute is missing"; + } else { + $response['valid'] = false; + $response['message'] = 'Missing required attribute'; + $response['error_user_msg'] = + "{$attribute} attribute is missing"; + } } } diff --git a/core/class-facebookpixel.php b/core/class-facebookpixel.php index d633c5bf..92b7dea3 100644 --- a/core/class-facebookpixel.php +++ b/core/class-facebookpixel.php @@ -140,16 +140,16 @@ public static function get_pixel_base_code() { * Gets OpenBridge set config code */ public static function get_open_bridge_config_code() { - if ( empty( self::$pixel_id ) ) { - return; - } + if ( empty( self::$pixel_id ) ) { + return; + } $code = " - - "; + + "; return sprintf( $code, self::$pixel_id ); } @@ -169,9 +169,9 @@ public static function get_pixel_init_code( $param = array(), $with_script_tag = true ) { - if ( empty( self::$pixel_id ) ) { - return; - } + if ( empty( self::$pixel_id ) ) { + return; + } $pixel_fbq_code_without_script = "fbq('%s', '%s'%s%s)"; @@ -179,20 +179,20 @@ public static function get_pixel_init_code( $pixel_fbq_code_without_script . '' : $pixel_fbq_code_without_script; $param_str = $param; - if ( is_array( $param ) ) { - $param_str = wp_json_encode( - $param, - JSON_PRETTY_PRINT | JSON_FORCE_OBJECT - ); - } + if ( is_array( $param ) ) { + $param_str = wp_json_encode( + $param, + JSON_PRETTY_PRINT | JSON_FORCE_OBJECT + ); + } $agent_param = array( 'agent' => $agent_string ); - return sprintf( - $code, - 'init', - self::$pixel_id, - ', ' . $param_str, - ', ' . wp_json_encode( $agent_param, JSON_PRETTY_PRINT ) - ); + return sprintf( + $code, + 'init', + self::$pixel_id, + ', ' . $param_str, + ', ' . wp_json_encode( $agent_param, JSON_PRETTY_PRINT ) + ); } /** @@ -217,30 +217,30 @@ public static function get_pixel_track_code( $tracking_name = '', $with_script_tag = true ) { - if ( empty( self::$pixel_id ) ) { - return; - } + if ( empty( self::$pixel_id ) ) { + return; + } $code = $with_script_tag ? "' : self::$pixel_fbq_code_without_script; $param_str = $param; - if ( is_array( $param ) ) { - if ( ! empty( $tracking_name ) ) { - $param[ self::FB_INTEGRATION_TRACKING_KEY ] = $tracking_name; + if ( is_array( $param ) ) { + if ( ! empty( $tracking_name ) ) { + $param[ self::FB_INTEGRATION_TRACKING_KEY ] = $tracking_name; + } + $param_str = wp_json_encode( $param, JSON_PRETTY_PRINT ); } - $param_str = wp_json_encode( $param, JSON_PRETTY_PRINT ); - } $class = new ReflectionClass( __CLASS__ ); - return sprintf( - $code, - $class->getConstant( - strtoupper( $event ) - ) !== false ? 'track' : 'trackCustom', - $event, - ', ' . $param_str, - '' - ); + return sprintf( + $code, + $class->getConstant( + strtoupper( $event ) + ) !== false ? 'track' : 'trackCustom', + $event, + ', ' . $param_str, + '' + ); } /** @@ -255,24 +255,24 @@ public static function get_pixel_noscript_code( $cd = array(), $tracking_name = '' ) { - if ( empty( self::$pixel_id ) ) { - return; - } + if ( empty( self::$pixel_id ) ) { + return; + } - $data = ''; - foreach ( $cd as $k => $v ) { - $data .= '&cd[' . $k . ']=' . $v; - } - if ( ! empty( $tracking_name ) ) { - $data .= '&cd[' . self::FB_INTEGRATION_TRACKING_KEY . ']=' . - $tracking_name; - } - return sprintf( - self::$pixel_noscript_code, - self::$pixel_id, - $event, - $data - ); + $data = ''; + foreach ( $cd as $k => $v ) { + $data .= '&cd[' . $k . ']=' . $v; + } + if ( ! empty( $tracking_name ) ) { + $data .= '&cd[' . self::FB_INTEGRATION_TRACKING_KEY . ']=' . + $tracking_name; + } + return sprintf( + self::$pixel_noscript_code, + self::$pixel_id, + $event, + $data + ); } /** @@ -288,12 +288,12 @@ public static function get_pixel_add_to_cart_code( $tracking_name = '', $with_script_tag = true ) { - return self::get_pixel_track_code( - self::ADDTOCART, - $param, - $tracking_name, - $with_script_tag - ); + return self::get_pixel_track_code( + self::ADDTOCART, + $param, + $tracking_name, + $with_script_tag + ); } /** @@ -309,12 +309,12 @@ public static function get_pixel_initiate_checkout_code( $tracking_name = '', $with_script_tag = true ) { - return self::get_pixel_track_code( - self::INITIATECHECKOUT, - $param, - $tracking_name, - $with_script_tag - ); + return self::get_pixel_track_code( + self::INITIATECHECKOUT, + $param, + $tracking_name, + $with_script_tag + ); } /** @@ -330,12 +330,12 @@ public static function get_pixel_lead_code( $tracking_name = '', $with_script_tag = true ) { - return self::get_pixel_track_code( - self::LEAD, - $param, - $tracking_name, - $with_script_tag - ); + return self::get_pixel_track_code( + self::LEAD, + $param, + $tracking_name, + $with_script_tag + ); } /** @@ -351,12 +351,12 @@ public static function get_pixel_page_view_code( $tracking_name = '', $with_script_tag = true ) { - return self::get_pixel_track_code( - self::PAGEVIEW, - $param, - $tracking_name, - $with_script_tag - ); + return self::get_pixel_track_code( + self::PAGEVIEW, + $param, + $tracking_name, + $with_script_tag + ); } /** @@ -372,12 +372,12 @@ public static function get_pixel_purchase_code( $tracking_name = '', $with_script_tag = true ) { - return self::get_pixel_track_code( - self::PURCHASE, - $param, - $tracking_name, - $with_script_tag - ); + return self::get_pixel_track_code( + self::PURCHASE, + $param, + $tracking_name, + $with_script_tag + ); } /** @@ -393,11 +393,11 @@ public static function get_pixel_view_content_code( $tracking_name = '', $with_script_tag = true ) { - return self::get_pixel_track_code( - self::VIEWCONTENT, - $param, - $tracking_name, - $with_script_tag - ); + return self::get_pixel_track_code( + self::VIEWCONTENT, + $param, + $tracking_name, + $with_script_tag + ); } } diff --git a/core/class-facebookpluginutils.php b/core/class-facebookpluginutils.php index 47c529a1..3651bc66 100644 --- a/core/class-facebookpluginutils.php +++ b/core/class-facebookpluginutils.php @@ -57,9 +57,9 @@ public static function is_positive_integer( $pixel_id ) { */ public static function get_logged_in_user_info() { $current_user = wp_get_current_user(); - if ( empty( $current_user ) ) { - return array(); - } + if ( empty( $current_user ) ) { + return array(); + } return array( 'email' => $current_user->user_email, @@ -75,21 +75,21 @@ public static function get_logged_in_user_info() { * @return string The generated GUID. */ public static function new_guid() { - if ( function_exists( 'com_create_guid' ) === true ) { - return trim( com_create_guid(), '{}' ); - } + if ( function_exists( 'com_create_guid' ) === true ) { + return trim( com_create_guid(), '{}' ); + } - return sprintf( - '%04X%04X-%04X-%04X-%04X-%04X%04X%04X', - wp_rand( 0, 65535 ), - wp_rand( 0, 65535 ), - wp_rand( 0, 65535 ), - wp_rand( 16384, 20479 ), - wp_rand( 32768, 49151 ), - wp_rand( 0, 65535 ), - wp_rand( 0, 65535 ), - wp_rand( 0, 65535 ) - ); + return sprintf( + '%04X%04X-%04X-%04X-%04X-%04X%04X%04X', + wp_rand( 0, 65535 ), + wp_rand( 0, 65535 ), + wp_rand( 0, 65535 ), + wp_rand( 16384, 20479 ), + wp_rand( 32768, 49151 ), + wp_rand( 0, 65535 ), + wp_rand( 0, 65535 ), + wp_rand( 0, 65535 ) + ); } /** @@ -117,9 +117,9 @@ public static function is_internal_user() { */ public static function ends_with( $haystack, $needle ) { $length = strlen( $needle ); - if ( ! $length ) { - return false; - } + if ( ! $length ) { + return false; + } return substr( $haystack, -$length ) === $needle; } diff --git a/core/class-facebookserversideevent.php b/core/class-facebookserversideevent.php index c8adfe1b..96301df3 100644 --- a/core/class-facebookserversideevent.php +++ b/core/class-facebookserversideevent.php @@ -92,15 +92,15 @@ public static function get_instance() { */ public function track( $event, $send_now = true ) { $this->tracked_events[] = $event; - if ( $send_now ) { - do_action( - 'send_server_events', - array( $event ), - 1 - ); - } else { - $this->pending_events[] = $event; - } + if ( $send_now ) { + do_action( + 'send_server_events', + array( $event ), + 1 + ); + } else { + $this->pending_events[] = $event; + } } /** @@ -172,32 +172,32 @@ public function get_pending_pixel_event( $callback_name ) { */ public static function send( $events ) { $events = apply_filters( 'before_conversions_api_event_sent', $events ); - if ( empty( $events ) ) { - return; - } + if ( empty( $events ) ) { + return; + } $pixel_id = FacebookWordpressOptions::get_pixel_id(); $access_token = FacebookWordpressOptions::get_access_token(); $agent = FacebookWordpressOptions::get_agent_string(); - if ( self::is_open_bridge_event( $events ) ) { - $agent .= '_ob'; // agent suffix is openbridge. - } + if ( self::is_open_bridge_event( $events ) ) { + $agent .= '_ob'; // agent suffix is openbridge. + } - if ( empty( $pixel_id ) || empty( $access_token ) ) { - return; - } - try { - $api = Api::init( null, null, $access_token ); + if ( empty( $pixel_id ) || empty( $access_token ) ) { + return; + } + try { + $api = Api::init( null, null, $access_token ); - $request = ( new EventRequest( $pixel_id ) ) - ->setEvents( $events ) - ->setPartnerAgent( $agent ); + $request = ( new EventRequest( $pixel_id ) ) + ->setEvents( $events ) + ->setPartnerAgent( $agent ); - $response = $request->execute(); - } catch ( \Exception $e ) { - throw $e; - } + $response = $request->execute(); + } catch ( \Exception $e ) { + throw $e; + } } /** @@ -217,15 +217,15 @@ private static function is_open_bridge_event( $events ) { } $custom_data = $events[0]->getCustomData(); - if ( ! $custom_data ) { - return false; - } + if ( ! $custom_data ) { + return false; + } $custom_properties = $custom_data->getCustomProperties(); - if ( ! $custom_properties || - ! isset( $custom_properties['fb_integration_tracking'] ) ) { - return false; - } + if ( ! $custom_properties || + ! isset( $custom_properties['fb_integration_tracking'] ) ) { + return false; + } return 'wp-cloudbridge-plugin' === $custom_properties['fb_integration_tracking']; diff --git a/core/class-facebookwordpressopenbridge.php b/core/class-facebookwordpressopenbridge.php index eb89f122..03da13c4 100644 --- a/core/class-facebookwordpressopenbridge.php +++ b/core/class-facebookwordpressopenbridge.php @@ -72,9 +72,9 @@ public function __construct() { * FacebookWordpressOpenBridge class. */ public static function get_instance() { - if ( null === self::$instance ) { - self::$instance = new FacebookWordpressOpenBridge(); - } + if ( null === self::$instance ) { + self::$instance = new FacebookWordpressOpenBridge(); + } return self::$instance; } @@ -90,44 +90,44 @@ public static function get_instance() { * @return void */ private static function start_new_php_session_if_needed() { - if ( session_id() ) { - return; - } + if ( session_id() ) { + return; + } $secure = false; $httponly = true; $samesite = 'lax'; $maxlifetime = 7776000; - if ( PHP_VERSION_ID < 70300 ) { - session_set_cookie_params( - $maxlifetime, - '/; samesite=' . $samesite, - isset( $_SERVER['HTTP_HOST'] ) - ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : - '', - $secure, - $httponly - ); - } else { - session_set_cookie_params( - array( - 'lifetime' => $maxlifetime, - 'path' => '/', - 'domain' => isset( $_SERVER['HTTP_HOST'] ) ? - sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '', - 'secure' => $secure, - 'httponly' => $httponly, - 'samesite' => $samesite, - ) - ); - } + if ( PHP_VERSION_ID < 70300 ) { + session_set_cookie_params( + $maxlifetime, + '/; samesite=' . $samesite, + isset( $_SERVER['HTTP_HOST'] ) + ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : + '', + $secure, + $httponly + ); + } else { + session_set_cookie_params( + array( + 'lifetime' => $maxlifetime, + 'path' => '/', + 'domain' => isset( $_SERVER['HTTP_HOST'] ) ? + sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '', + 'secure' => $secure, + 'httponly' => $httponly, + 'samesite' => $samesite, + ) + ); + } session_start(); - $_SESSION[ self::EXTERNAL_ID_COOKIE ] = isset( - $_SESSION[ self::EXTERNAL_ID_COOKIE ] - ) ? sanitize_text_field( $_SESSION[ self::EXTERNAL_ID_COOKIE ] ) : - FacebookPluginUtils::new_guid(); + $_SESSION[ self::EXTERNAL_ID_COOKIE ] = isset( + $_SESSION[ self::EXTERNAL_ID_COOKIE ] + ) ? sanitize_text_field( $_SESSION[ self::EXTERNAL_ID_COOKIE ] ) : + FacebookPluginUtils::new_guid(); } /** @@ -148,16 +148,16 @@ public function handle_open_bridge_req( $data ) { self::start_new_php_session_if_needed(); $event_name = $data['event_name']; - if ( in_array( $event_name, self::$blocked_events, true ) ) { - return; - } - $event = ServerEventFactory::safe_create_event( - $event_name, - array( $this, 'extract_from_databag' ), - array( $data ), - 'wp-cloudbridge-plugin', - true - ); + if ( in_array( $event_name, self::$blocked_events, true ) ) { + return; + } + $event = ServerEventFactory::safe_create_event( + $event_name, + array( $this, 'extract_from_databag' ), + array( $data ), + 'wp-cloudbridge-plugin', + true + ); $event->setEventId( $data['event_id'] ); FacebookServerSideEvent::send( array( $event ) ); } @@ -216,66 +216,66 @@ public function extract_from_databag( $databag ) { * @since 1.0.0 */ private static function get_pii_from_session() { - $current_user = array_filter( - FacebookPluginUtils::get_logged_in_user_info() - ); + $current_user = array_filter( + FacebookPluginUtils::get_logged_in_user_info() + ); $capi_pii_caching_status = FacebookWordpressOptions::get_capi_pii_caching_status(); - if ( empty( $current_user ) && '1' === $capi_pii_caching_status ) { + if ( empty( $current_user ) && '1' === $capi_pii_caching_status ) { - if ( isset( $_SESSION[ AAMSettingsFields::EMAIL ] ) ) { - $current_user['email'] = sanitize_text_field( - $_SESSION[ AAMSettingsFields::EMAIL ] - ); - } + if ( isset( $_SESSION[ AAMSettingsFields::EMAIL ] ) ) { + $current_user['email'] = sanitize_text_field( + $_SESSION[ AAMSettingsFields::EMAIL ] + ); + } - if ( isset( $_SESSION[ AAMSettingsFields::FIRST_NAME ] ) ) { - $current_user['first_name'] = - sanitize_text_field( $_SESSION[ AAMSettingsFields::FIRST_NAME ] ); - } + if ( isset( $_SESSION[ AAMSettingsFields::FIRST_NAME ] ) ) { + $current_user['first_name'] = + sanitize_text_field( $_SESSION[ AAMSettingsFields::FIRST_NAME ] ); + } - if ( isset( $_SESSION[ AAMSettingsFields::LAST_NAME ] ) ) { - $current_user['last_name'] = - sanitize_text_field( $_SESSION[ AAMSettingsFields::LAST_NAME ] ); - } + if ( isset( $_SESSION[ AAMSettingsFields::LAST_NAME ] ) ) { + $current_user['last_name'] = + sanitize_text_field( $_SESSION[ AAMSettingsFields::LAST_NAME ] ); + } - if ( isset( $_SESSION[ AAMSettingsFields::PHONE ] ) ) { - $current_user['phone'] = - sanitize_text_field( $_SESSION[ AAMSettingsFields::PHONE ] ); - } + if ( isset( $_SESSION[ AAMSettingsFields::PHONE ] ) ) { + $current_user['phone'] = + sanitize_text_field( $_SESSION[ AAMSettingsFields::PHONE ] ); + } - return array_filter( $current_user ); - } + return array_filter( $current_user ); + } $user_id = get_current_user_id(); - if ( 0 !== $user_id ) { - $current_user['city'] = get_user_meta( - $user_id, - 'billing_city', - true - ); - $current_user['zip'] = get_user_meta( - $user_id, - 'billing_postcode', - true - ); - $current_user['country'] = get_user_meta( - $user_id, - 'billing_country', - true - ); - $current_user['state'] = get_user_meta( - $user_id, - 'billing_state', - true - ); - $current_user['phone'] = get_user_meta( - $user_id, - 'billing_phone', - true - ); - } + if ( 0 !== $user_id ) { + $current_user['city'] = get_user_meta( + $user_id, + 'billing_city', + true + ); + $current_user['zip'] = get_user_meta( + $user_id, + 'billing_postcode', + true + ); + $current_user['country'] = get_user_meta( + $user_id, + 'billing_country', + true + ); + $current_user['state'] = get_user_meta( + $user_id, + 'billing_state', + true + ); + $current_user['phone'] = get_user_meta( + $user_id, + 'billing_phone', + true + ); + } return array_filter( $current_user ); } @@ -291,9 +291,9 @@ private static function get_pii_from_session() { * @return string The user's email address. */ private static function get_email( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['email'] ) ) { - return $current_user_data['email']; - } + if ( isset( $current_user_data['email'] ) ) { + return $current_user_data['email']; + } return self::get_aam_field( AAMSettingsFields::EMAIL, $pixel_data ); } @@ -309,9 +309,9 @@ private static function get_email( $current_user_data, $pixel_data ) { * @return string The user's first name. */ private static function get_first_name( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['first_name'] ) ) { - return $current_user_data['first_name']; - } + if ( isset( $current_user_data['first_name'] ) ) { + return $current_user_data['first_name']; + } return self::get_aam_field( AAMSettingsFields::FIRST_NAME, $pixel_data @@ -330,9 +330,9 @@ private static function get_first_name( $current_user_data, $pixel_data ) { * @return string The user's last name. */ private static function get_last_name( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['last_name'] ) ) { - return $current_user_data['last_name']; - } + if ( isset( $current_user_data['last_name'] ) ) { + return $current_user_data['last_name']; + } return self::get_aam_field( AAMSettingsFields::LAST_NAME, $pixel_data ); } @@ -351,24 +351,24 @@ private static function get_last_name( $current_user_data, $pixel_data ) { private static function get_external_id( $current_user_data, $pixel_data ) { $external_ids = array(); - if ( isset( $current_user_data['id'] ) ) { - $external_ids[] = (string) $current_user_data['id']; - } + if ( isset( $current_user_data['id'] ) ) { + $external_ids[] = (string) $current_user_data['id']; + } - $temp_external_id = self::get_aam_field( - AAMSettingsFields::EXTERNAL_ID, - $pixel_data - ); + $temp_external_id = self::get_aam_field( + AAMSettingsFields::EXTERNAL_ID, + $pixel_data + ); - if ( $temp_external_id ) { - $external_ids[] = $temp_external_id; - } + if ( $temp_external_id ) { + $external_ids[] = $temp_external_id; + } - if ( isset( $_SESSION[ self::EXTERNAL_ID_COOKIE ] ) ) { - $external_ids[] = sanitize_text_field( - $_SESSION[ self::EXTERNAL_ID_COOKIE ] - ); - } + if ( isset( $_SESSION[ self::EXTERNAL_ID_COOKIE ] ) ) { + $external_ids[] = sanitize_text_field( + $_SESSION[ self::EXTERNAL_ID_COOKIE ] + ); + } return $external_ids; } @@ -384,9 +384,9 @@ private static function get_external_id( $current_user_data, $pixel_data ) { * @return string The user's phone. */ private static function get_phone( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['phone'] ) ) { - return $current_user_data['phone']; - } + if ( isset( $current_user_data['phone'] ) ) { + return $current_user_data['phone']; + } return self::get_aam_field( AAMSettingsFields::PHONE, $pixel_data ); } @@ -402,9 +402,9 @@ private static function get_phone( $current_user_data, $pixel_data ) { * @return string The user's city. */ private static function get_city( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['city'] ) ) { - return $current_user_data['city']; - } + if ( isset( $current_user_data['city'] ) ) { + return $current_user_data['city']; + } return self::get_aam_field( AAMSettingsFields::CITY, $pixel_data ); } @@ -420,9 +420,9 @@ private static function get_city( $current_user_data, $pixel_data ) { * @return string The user's zip code. */ private static function get_zip( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['zip'] ) ) { - return $current_user_data['zip']; - } + if ( isset( $current_user_data['zip'] ) ) { + return $current_user_data['zip']; + } return self::get_aam_field( AAMSettingsFields::ZIP_CODE, $pixel_data ); } @@ -438,9 +438,9 @@ private static function get_zip( $current_user_data, $pixel_data ) { * @return string The user's country. */ private static function get_country( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['country'] ) ) { - return $current_user_data['country']; - } + if ( isset( $current_user_data['country'] ) ) { + return $current_user_data['country']; + } return self::get_aam_field( AAMSettingsFields::COUNTRY, $pixel_data ); } @@ -456,9 +456,9 @@ private static function get_country( $current_user_data, $pixel_data ) { * @return string The user's state. */ private static function get_state( $current_user_data, $pixel_data ) { - if ( isset( $current_user_data['state'] ) ) { - return $current_user_data['state']; - } + if ( isset( $current_user_data['state'] ) ) { + return $current_user_data['state']; + } return self::get_aam_field( AAMSettingsFields::STATE, $pixel_data ); } @@ -477,15 +477,15 @@ private static function get_state( $current_user_data, $pixel_data ) { * if found, otherwise an empty string. */ private static function get_aam_field( $key, $pixel_data ) { - if ( ! isset( $pixel_data[ self::ADVANCED_MATCHING_LABEL ] ) ) { - return ''; - } - if ( isset( $pixel_data[ self::ADVANCED_MATCHING_LABEL ][ $key ] ) ) { - $value = - $pixel_data[ self::ADVANCED_MATCHING_LABEL ][ $key ]; - $_SESSION[ $key ] = $value; - return $value; - } + if ( ! isset( $pixel_data[ self::ADVANCED_MATCHING_LABEL ] ) ) { + return ''; + } + if ( isset( $pixel_data[ self::ADVANCED_MATCHING_LABEL ][ $key ] ) ) { + $value = + $pixel_data[ self::ADVANCED_MATCHING_LABEL ][ $key ]; + $_SESSION[ $key ] = $value; + return $value; + } return ''; } @@ -498,12 +498,12 @@ private static function get_aam_field( $key, $pixel_data ) { * @return string The custom data value if found, otherwise an empty string. */ private static function get_custom_data( $key, $pixel_data ) { - if ( ! isset( $pixel_data[ self::CUSTOM_DATA_LABEL ] ) ) { - return ''; - } - if ( isset( $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ] ) ) { - return $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ]; - } + if ( ! isset( $pixel_data[ self::CUSTOM_DATA_LABEL ] ) ) { + return ''; + } + if ( isset( $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ] ) ) { + return $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ]; + } return ''; } @@ -523,12 +523,12 @@ private static function get_custom_data( $key, $pixel_data ) { * found, otherwise an empty array. */ private static function get_custom_data_array( $key, $pixel_data ) { - if ( ! isset( $pixel_data[ self::CUSTOM_DATA_LABEL ] ) ) { - return ''; - } - if ( isset( $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ] ) ) { - return $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ]; - } + if ( ! isset( $pixel_data[ self::CUSTOM_DATA_LABEL ] ) ) { + return ''; + } + if ( isset( $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ] ) ) { + return $pixel_data[ self::CUSTOM_DATA_LABEL ][ $key ]; + } return array(); } } diff --git a/core/class-facebookwordpressoptions.php b/core/class-facebookwordpressoptions.php index 363574ce..10a111fa 100644 --- a/core/class-facebookwordpressoptions.php +++ b/core/class-facebookwordpressoptions.php @@ -194,10 +194,10 @@ public static function get_capi_integration_events_filter() { * events filter. */ public static function get_capi_integration_page_view_filtered() { - return FacebookPluginUtils::string_contains( - self::get_capi_integration_events_filter(), - 'PageView' - ); + return FacebookPluginUtils::string_contains( + self::get_capi_integration_events_filter(), + 'PageView' + ); } /** @@ -234,9 +234,9 @@ public static function get_default_access_token() { * @return string The default external business ID. */ public static function get_default_external_business_id() { - return uniqid( - FacebookPluginConfig::DEFAULT_EXTERNAL_BUSINESS_ID_PREFIX . time() . '_' - ); + return uniqid( + FacebookPluginConfig::DEFAULT_EXTERNAL_BUSINESS_ID_PREFIX . time() . '_' + ); } /** @@ -263,51 +263,51 @@ public static function get_default_is_fbe_installed() { private static function init_options() { $old_options = \get_option( FacebookPluginConfig::OLD_SETTINGS_KEY ); $new_options = \get_option( FacebookPluginConfig::SETTINGS_KEY ); - if ( $new_options ) { - self::$options = $new_options; - } elseif ( $old_options ) { - self::$options = array( - FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY => - self::get_default_external_business_id(), - FacebookPluginConfig::IS_FBE_INSTALLED_KEY => - self::get_default_is_fbe_installed(), - ); - if ( - isset( $old_options[ FacebookPluginConfig::OLD_ACCESS_TOKEN_KEY ] ) - && ! empty( $old_options[ FacebookPluginConfig::OLD_ACCESS_TOKEN_KEY ] ) - ) { - self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ] = - $old_options[ FacebookPluginConfig::OLD_ACCESS_TOKEN_KEY ]; - } else { - self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ] = - self::get_default_access_token(); - } - if ( - isset( $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ] ) - && ! empty( $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ] ) - && is_numeric( $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ] ) - ) { - self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ] = - $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ]; - } else { - self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ] = - self::get_default_pixel_id(); - } - } else { - self::$options = \get_option( - FacebookPluginConfig::SETTINGS_KEY, - array( - FacebookPluginConfig::PIXEL_ID_KEY => - self::get_default_pixel_id(), - FacebookPluginConfig::ACCESS_TOKEN_KEY => - self::get_default_access_token(), + if ( $new_options ) { + self::$options = $new_options; + } elseif ( $old_options ) { + self::$options = array( FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY => self::get_default_external_business_id(), FacebookPluginConfig::IS_FBE_INSTALLED_KEY => self::get_default_is_fbe_installed(), - ) - ); - } + ); + if ( + isset( $old_options[ FacebookPluginConfig::OLD_ACCESS_TOKEN_KEY ] ) + && ! empty( $old_options[ FacebookPluginConfig::OLD_ACCESS_TOKEN_KEY ] ) + ) { + self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ] = + $old_options[ FacebookPluginConfig::OLD_ACCESS_TOKEN_KEY ]; + } else { + self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ] = + self::get_default_access_token(); + } + if ( + isset( $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ] ) + && ! empty( $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ] ) + && is_numeric( $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ] ) + ) { + self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ] = + $old_options[ FacebookPluginConfig::OLD_PIXEL_ID_KEY ]; + } else { + self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ] = + self::get_default_pixel_id(); + } + } else { + self::$options = \get_option( + FacebookPluginConfig::SETTINGS_KEY, + array( + FacebookPluginConfig::PIXEL_ID_KEY => + self::get_default_pixel_id(), + FacebookPluginConfig::ACCESS_TOKEN_KEY => + self::get_default_access_token(), + FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY => + self::get_default_external_business_id(), + FacebookPluginConfig::IS_FBE_INSTALLED_KEY => + self::get_default_is_fbe_installed(), + ) + ); + } } /** @@ -319,9 +319,9 @@ private static function init_options() { * @return string The Facebook pixel ID. */ public static function get_pixel_id() { - if ( isset( self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ] ) ) { - return self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ]; - } + if ( isset( self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ] ) ) { + return self::$options[ FacebookPluginConfig::PIXEL_ID_KEY ]; + } return self::get_default_pixel_id(); } @@ -336,13 +336,13 @@ public static function get_pixel_id() { * @return string The external business ID. */ public static function get_external_business_id() { - if ( - isset( - self::$options[ FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY ] - ) - ) { - return self::$options[ FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY ]; - } + if ( + isset( + self::$options[ FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY ] + ) + ) { + return self::$options[ FacebookPluginConfig::EXTERNAL_BUSINESS_ID_KEY ]; + } return self::get_default_external_business_id(); } @@ -357,11 +357,11 @@ public static function get_external_business_id() { * @return string The FBE installed status. */ public static function get_is_fbe_installed() { - if ( - isset( self::$options[ FacebookPluginConfig::IS_FBE_INSTALLED_KEY ] ) - ) { - return self::$options[ FacebookPluginConfig::IS_FBE_INSTALLED_KEY ]; - } + if ( + isset( self::$options[ FacebookPluginConfig::IS_FBE_INSTALLED_KEY ] ) + ) { + return self::$options[ FacebookPluginConfig::IS_FBE_INSTALLED_KEY ]; + } return self::get_default_is_fbe_installed(); } @@ -375,9 +375,9 @@ public static function get_is_fbe_installed() { * @return string The Facebook access token. */ public static function get_access_token() { - if ( isset( self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ] ) ) { - return self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ]; - } + if ( isset( self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ] ) ) { + return self::$options[ FacebookPluginConfig::ACCESS_TOKEN_KEY ]; + } return self::get_default_access_token(); } @@ -406,14 +406,14 @@ public static function get_user_info() { * @return void */ public static function set_user_info() { - add_action( - 'init', - array( - 'FacebookPixelPlugin\\Core\\FacebookWordpressOptions', - 'register_user_info', - ), - 0 - ); + add_action( + 'init', + array( + 'FacebookPixelPlugin\\Core\\FacebookWordpressOptions', + 'register_user_info', + ), + 0 + ); } /** @@ -428,22 +428,22 @@ public static function set_user_info() { */ public static function register_user_info() { $current_user = wp_get_current_user(); - if ( 0 === $current_user->ID ) { - self::$user_info = array(); - } else { - $user_info = array_filter( - array( - AAMSettingsFields::EMAIL => $current_user->user_email, - AAMSettingsFields::FIRST_NAME => $current_user->user_firstname, - AAMSettingsFields::LAST_NAME => $current_user->user_lastname, - ), - function ( $value ) { - return null !== $value && '' !== $value; - } - ); - self::$user_info = - AAMFieldsExtractor::get_normalized_user_data( $user_info ); - } + if ( 0 === $current_user->ID ) { + self::$user_info = array(); + } else { + $user_info = array_filter( + array( + AAMSettingsFields::EMAIL => $current_user->user_email, + AAMSettingsFields::FIRST_NAME => $current_user->user_firstname, + AAMSettingsFields::LAST_NAME => $current_user->user_lastname, + ), + function ( $value ) { + return null !== $value && '' !== $value; + } + ); + self::$user_info = + AAMFieldsExtractor::get_normalized_user_data( $user_info ); + } } /** @@ -524,40 +524,40 @@ private static function set_fbe_based_aam_settings() { $installed_pixel = self::get_pixel_id(); $settings_as_array = get_transient( FacebookPluginConfig::AAM_SETTINGS_KEY ); - if ( false !== $settings_as_array ) { - $aam_settings = new AdsPixelSettings(); - $aam_settings->setPixelId( $settings_as_array['pixelId'] ); - $aam_settings->setEnableAutomaticMatching( - $settings_as_array['enableAutomaticMatching'] - ); - $aam_settings->setEnabledAutomaticMatchingFields( - $settings_as_array['enabledAutomaticMatchingFields'] - ); - if ( $installed_pixel === $aam_settings->getPixelId() ) { - self::$aam_settings = $aam_settings; - } - } - if ( ! self::$aam_settings ) { - $refresh_interval = - self::AAM_SETTINGS_REFRESH_IN_MINUTES * MINUTE_IN_SECONDS; - $aam_settings = - AdsPixelSettings::buildFromPixelId( $installed_pixel ); - if ( $aam_settings ) { - $settings_as_array = array( - 'pixelId' => $aam_settings->getPixelId(), - 'enableAutomaticMatching' => - $aam_settings->getEnableAutomaticMatching(), - 'enabledAutomaticMatchingFields' => - $aam_settings->getEnabledAutomaticMatchingFields(), + if ( false !== $settings_as_array ) { + $aam_settings = new AdsPixelSettings(); + $aam_settings->setPixelId( $settings_as_array['pixelId'] ); + $aam_settings->setEnableAutomaticMatching( + $settings_as_array['enableAutomaticMatching'] ); - set_transient( - FacebookPluginConfig::AAM_SETTINGS_KEY, - $settings_as_array, - $refresh_interval + $aam_settings->setEnabledAutomaticMatchingFields( + $settings_as_array['enabledAutomaticMatchingFields'] ); + if ( $installed_pixel === $aam_settings->getPixelId() ) { self::$aam_settings = $aam_settings; + } + } + if ( ! self::$aam_settings ) { + $refresh_interval = + self::AAM_SETTINGS_REFRESH_IN_MINUTES * MINUTE_IN_SECONDS; + $aam_settings = + AdsPixelSettings::buildFromPixelId( $installed_pixel ); + if ( $aam_settings ) { + $settings_as_array = array( + 'pixelId' => $aam_settings->getPixelId(), + 'enableAutomaticMatching' => + $aam_settings->getEnableAutomaticMatching(), + 'enabledAutomaticMatchingFields' => + $aam_settings->getEnabledAutomaticMatchingFields(), + ); + set_transient( + FacebookPluginConfig::AAM_SETTINGS_KEY, + $settings_as_array, + $refresh_interval + ); + self::$aam_settings = $aam_settings; + } } - } } /** @@ -568,24 +568,24 @@ private static function set_fbe_based_aam_settings() { */ private static function set_old_aam_settings() { $old_options = \get_option( FacebookPluginConfig::OLD_SETTINGS_KEY ); - if ( $old_options - && isset( $old_options[ FacebookPluginConfig::OLD_USE_PII ] ) - && $old_options[ FacebookPluginConfig::OLD_USE_PII ] ) { - self::$aam_settings = new AdsPixelSettings( - array( - 'enableAutomaticMatching' => true, - 'enabledAutomaticMatchingFields' => - AAMSettingsFields::get_all_fields(), - ) - ); - } else { - self::$aam_settings = new AdsPixelSettings( - array( - 'enableAutomaticMatching' => false, - 'enabledAutomaticMatchingFields' => array(), - ) - ); - } + if ( $old_options + && isset( $old_options[ FacebookPluginConfig::OLD_USE_PII ] ) + && $old_options[ FacebookPluginConfig::OLD_USE_PII ] ) { + self::$aam_settings = new AdsPixelSettings( + array( + 'enableAutomaticMatching' => true, + 'enabledAutomaticMatchingFields' => + AAMSettingsFields::get_all_fields(), + ) + ); + } else { + self::$aam_settings = new AdsPixelSettings( + array( + 'enableAutomaticMatching' => false, + 'enabledAutomaticMatchingFields' => array(), + ) + ); + } } /** @@ -603,13 +603,13 @@ private static function set_old_aam_settings() { */ private static function set_aam_settings() { self::$aam_settings = null; - if ( empty( self::get_pixel_id() ) ) { - return; - } - if ( self::get_is_fbe_installed() ) { - self::set_fbe_based_aam_settings(); - } else { - self::set_old_aam_settings(); - } + if ( empty( self::get_pixel_id() ) ) { + return; + } + if ( self::get_is_fbe_installed() ) { + self::set_fbe_based_aam_settings(); + } else { + self::set_old_aam_settings(); + } } } diff --git a/core/class-facebookwordpresspixelinjection.php b/core/class-facebookwordpresspixelinjection.php index b5e9f860..85a35d90 100644 --- a/core/class-facebookwordpresspixelinjection.php +++ b/core/class-facebookwordpresspixelinjection.php @@ -58,26 +58,26 @@ public function __construct() { */ public function inject() { $pixel_id = FacebookWordpressOptions::get_pixel_id(); - if ( FacebookPluginUtils::is_positive_integer( $pixel_id ) ) { - add_action( - 'wp_head', - array( $this, 'inject_pixel_code' ) - ); - add_action( - 'wp_head', - array( $this, 'inject_pixel_noscript_code' ) - ); - foreach ( - FacebookPluginConfig::integration_config() as $key => $value - ) { - $class_name = 'FacebookPixelPlugin\\Integration\\' . $value; - $class_name::inject_pixel_code(); + if ( FacebookPluginUtils::is_positive_integer( $pixel_id ) ) { + add_action( + 'wp_head', + array( $this, 'inject_pixel_code' ) + ); + add_action( + 'wp_head', + array( $this, 'inject_pixel_noscript_code' ) + ); + foreach ( + FacebookPluginConfig::integration_config() as $key => $value + ) { + $class_name = 'FacebookPixelPlugin\\Integration\\' . $value; + $class_name::inject_pixel_code(); + } + add_action( + 'wp_footer', + array( $this, 'send_pending_events' ) + ); } - add_action( - 'wp_footer', - array( $this, 'send_pending_events' ) - ); - } } /** @@ -91,13 +91,13 @@ public function inject() { public function send_pending_events() { $pending_events = FacebookServerSideEvent::get_instance()->get_pending_events(); - if ( count( $pending_events ) > 0 ) { - do_action( - 'send_server_events', - $pending_events, - count( $pending_events ) - ); - } + if ( count( $pending_events ) > 0 ) { + do_action( + 'send_server_events', + $pending_events, + count( $pending_events ) + ); + } } /** @@ -114,28 +114,28 @@ public function send_pending_events() { */ public function inject_pixel_code() { $pixel_id = FacebookPixel::get_pixel_id(); - if ( - ( isset( - self::$render_cache[ FacebookPluginConfig::IS_PIXEL_RENDERED ] - ) && - true === self::$render_cache[ FacebookPluginConfig::IS_PIXEL_RENDERED ] ) - || - empty( $pixel_id ) - ) { - return; - } + if ( + ( isset( + self::$render_cache[ FacebookPluginConfig::IS_PIXEL_RENDERED ] + ) && + true === self::$render_cache[ FacebookPluginConfig::IS_PIXEL_RENDERED ] ) + || + empty( $pixel_id ) + ) { + return; + } self::$render_cache[ FacebookPluginConfig::IS_PIXEL_RENDERED ] = true; echo FacebookPixel::get_pixel_base_code(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $capi_integration_status = FacebookWordpressOptions::get_capi_integration_status(); - if ( '1' === $capi_integration_status ) { - FacebookPixel::get_open_bridge_config_code(); - } - echo FacebookPixel::get_pixel_init_code( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - FacebookWordpressOptions::get_agent_string(), - FacebookWordpressOptions::get_user_info() // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - ); + if ( '1' === $capi_integration_status ) { + FacebookPixel::get_open_bridge_config_code(); + } + echo FacebookPixel::get_pixel_init_code( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + FacebookWordpressOptions::get_agent_string(), + FacebookWordpressOptions::get_user_info() // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + ); echo FacebookPixel::get_pixel_page_view_code(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } diff --git a/core/class-facebookwordpresssettingspage.php b/core/class-facebookwordpresssettingspage.php index d1b4beb9..e5ca1156 100644 --- a/core/class-facebookwordpresssettingspage.php +++ b/core/class-facebookwordpresssettingspage.php @@ -448,7 +448,12 @@ class="advanced-edit-toggle" ); ?>
-
+

Ads Creation

@@ -462,7 +467,12 @@ class="my-3 p-3 bg-white rounded shadow-sm"> >
-
+

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); } });