• Resolved reasonx

    (@reasonx)


    Wordpress 6.1
    ProfilePress 4.3.1
    PHP 8.1

    Hi,

    we are upgrading to PHP 8.1 at the moment because the PHP 7.4 security support is ending in a few days. The switch to 8.1 was successful with WordPress 6.1 so far but the only plugin left that throws an error is ProfilePress :D.

    The error occurs in that file:

    wp-content/plugins/wp-user-avatar/src/ShortcodeParser/Builder/FieldsShortcodeCallback.php

    on line 39

    if (method_exists($this->current_user, 'exists') && $this->current_user->exists()) $flag = true;

    this is the error message:

    TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given

    So it seems like $this->current_user is null at that point which throws the error. But the error is only thrown if we switch to PHP 8.1 – As soon as we switch back to 7.4 the error has gone away. Indeed method_exists() was updated in PHP8 and it now throws an error in such a case apparently.

    It would be nice, if you could provide a fix for that in an upcoming version. Thank you very much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Collins Agbonghama

    (@collizo4sky)

    We’ve fixed this and will ensure compatibility with PHP 8 in other areas in the next update. Below is the fix

    $flag = false;
            if (function_exists('wp_get_current_user')) {
                $this->get_current_user();
                if (is_object($this->current_user) && method_exists($this->current_user, 'exists') && $this->current_user->exists()) {
                    $flag = true;
                }
            }

    Thanks for letting us know.

    Thread Starter reasonx

    (@reasonx)

    Wow, what a fast answer 🙂 Thank you very much.

    Plugin Author Collins Agbonghama

    (@collizo4sky)

    @reasonx happy to always help. Maybe consider leaving us a review.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP Error in ShortcodeParser with PHP 8.1’ is closed to new replies.