facebookincubator / Facebook-Pixel-for-Wordpress

A plugin for advertisers who use Wordpress to enable them easily setup the facebook pixel.
GNU General Public License v2.0
37 stars 34 forks source link

PHP 8 Problems #29

Open icgdoug opened 2 years ago

icgdoug commented 2 years ago

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

scottbuscemi commented 2 years ago

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.

icgdoug commented 2 years ago

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?

robwoodgate commented 2 years ago

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 :)

Invader444 commented 2 years ago

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.

robwoodgate commented 2 years ago

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.

Invader444 commented 2 years ago

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... 👎

maximejobin commented 1 year ago

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

Invader444 commented 1 year ago

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) 🙄

burtonrhodes commented 1 year ago

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

2023-04-03 version 3.0.9