Facebook-Pixel-for-Wordpress icon indicating copy to clipboard operation
Facebook-Pixel-for-Wordpress copied to clipboard

PHP 8 Problems

Open icgdoug opened this issue 3 years ago • 9 comments

We are constantly getting errors when using PHP 8 with the plugin.

An error of type E_ERROR was caused in line 42 of the file /httpdocs/wp-content/plugins/official-facebook-pixel/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/Normalizer.php. Error message: Uncaught TypeError: strlen(): Argument #1 ($string) must be of type string, array given in httpdocs/wp-content/plugins/official-facebook-pixel/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/Normalizer.php:42

The issue resolves by downgrading to a lower version of PHP

icgdoug avatar Dec 20 '21 12:12 icgdoug

I tried contacting their support about this issue but they don't seem to understand the problem. This plugin isn't PHP 8 compatible and I can't see how to request for its update.

scottbuscemi avatar Dec 31 '21 19:12 scottbuscemi

Hi @scottbuscemi yes I've tried as well but they don't seem to recognise support queries for the plugin on the core Facebook Business service.

Does anyone have any other contact methods?

icgdoug avatar Jan 04 '22 12:01 icgdoug

The issue, as the error suggests, is that the Normalizer::normalize($field, $data) method is expecting the $data parameter to sent in as a string, but the calling class is sending it as an array.

I don't know whether the calling class or the offending method is 'wrong'... however, a quick and dirty fix is as follows.

  1. Open the file: wp-content/plugins/official-facebook-pixel/vendor/facebook/php-business-sdk/src/FacebookAds/Object/ServerSide/Normalizer.php

  2. Find the following section (starting at line 41)

public static function normalize($field, $data) {
    if ($data == null || strlen($data) == 0) {
      return null;
    }
  1. Change it to the following (note the addition of the lines of code between the // START and // END comments):
public static function normalize($field, $data) {

    // START: Quick fix to avoid PHP Warning that breaks PHP8
    // Issue: Some data is sent as an array, but this method expects string
    if (is_array($data)) {
        $data = $data[0];
    }
    // END: Quick fix to avoid PHP Warning that breaks PHP8

    if ($data == null || strlen($data) == 0) {
      return null;
    }

That's it... what the code snippet does is check if the $data parameter is an array, and if it is, just grabs the first item.

Cheers Rob

Ps - This is a temporary solution - the proper fix is for Facebook to update / fix the php-business-sdk and re-release the plugin to WordPress :)

robwoodgate avatar Jan 06 '22 14:01 robwoodgate

The issue is actually in the plugin code, not the business sdk. It was probably introduced in this commit; I have opened PR #32 with the fix.

Invader444 avatar Mar 10 '22 01:03 Invader444

Superstar, thanks for doing that.

On 10 Mar 2022, at 01:56, Jonathan Horowitz @.***> wrote:

 The issue is actually in the plugin code, not the business sdk. It was probably introduced in this commit; I have opened PR #32 with the fix.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

robwoodgate avatar Mar 10 '22 08:03 robwoodgate

Actually, at the time the commit I referenced above was written, the business SDK didn't differentiate between single values and arrays so it would have worked. Starting at version 10.0.1 of the business SDK, they made the distinction between single values and arrays... so this commit would have introduced the bug (when they started using v10.0.1+ of the business SDK).

So it's only been broken since August 2021 (in GitHub anyway... not sure when that code made it to the WordPress repo for general distribution). Still, having this around for seven months is pretty bad; they clearly don't pay a lot of attention to this product... 👎

Invader444 avatar Mar 13 '22 20:03 Invader444

Even with the latest update (3.0.8), this bug still exists. I do not see any active development to fix issues here, unfortunately.

maximejobin avatar Jan 03 '23 16:01 maximejobin

On the bright side, the fix PR finally got merged...

1 year and 7 months for this bug (and counting since it still isn't released to wordpress.org) 🙄

Invader444 avatar Mar 28 '23 11:03 Invader444

Just FYI, this issue has been officially resolved in version 3.0.9:

2023-04-03 version 3.0.9

  • Removed hard coded OpenBridge Javascript
  • Fix async events UserData key mapping. #32
  • Delay pixel events firing, to track engaged visitors
  • Bug Fixes

burtonrhodes avatar May 27 '23 12:05 burtonrhodes