has_membership() PHP error

As of this morning, there appears to be an issue with the API function has_membership(). I thought it was my custom code, but after I resolved the errors from my code, I'm getting errors code I haven't edited.

Specifically in eab-events-membership2-integration.php (plugins/events-and-bookings/lib/plugins). The error says "Call to a member function has_membership() on boolean"

There are three instances of the function in that file, and they're all called on the object $user.

I encounter the error when trying to load an event page in the Admin. The page fails to load the RSVP section properly (because this is where the code which calls has_membership() is located).

  • Nithin

    Hi JessycaFrederick,

    Hope you are doing good today. :slight_smile:

    Specifically in eab-events-membership2-integration.php (plugins/events-and-bookings/lib/plugins). The error says "Call to a member function has_membership() on boolean"

    Where are you seeing this error? I'm not able to notice such error in your system, is it in your log files? Or you only notice that the RSVP doesn't work in admin? The error what you have mentioned seems to be related to the Membership 2 Integration add-on, however I'm not able to replicate such issues in my system. It does seems to work fine.

    Just to be sure, and since I don't see you mention about performing plugin conflict test, could you please run a quick plugin/theme conflict test as illustrated in getting support manual (flowchart), and rule out whether any plugin is causing this issue.
    http://premium.wpmudev.org/manuals/using-wpmu-dev/getting-support/

    Please let us know how that goes, so that we could have a better idea about this issue. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • JessycaFrederick

    Hello,

    I didn't install any new plugins to cause the error (nor did I update any).

    I use a plugin called WP PHP Console to show PHP errors in Chrome that are otherwise suppressed by WP. It's similar to a log file, but uses Chrome notifications to surface PHP and JS errors.

    When you log in to our DHSCV admin, are you able to load the 12th Annual Desert Garden Tour event? The RSVP section doesn't show the RSVPs and everything after that section fails to load.

    Thanks,
    Jessyca

  • Kasia Swiderska

    Hello Jessyca,

    I can see issue on your site - I tried to make another test on my website but even with similar settings I could not replicate problem. Error does not show up and I can see all the RSVPs on admin side.
    Can you show us custom code you are using? Did you maybe enabled any new add-ons in Events+?

    Could you also check full debug log to see if there are no more errors related to that add-on? To enable it, open your wp-config.php file and look for define(‘WP_DEBUG’, false);. Change it to:

    define('WP_DEBUG', true);

    In order to enable the error logging to a file on the server you need to add yet one more similar line:

    define( 'WP_DEBUG_LOG', true );

    In this case the errors will be saved to a debug.log log file inside the /wp-content/directory.

    Depending on whether you want your errors to be only logged or also displayed on the screen you should also have this line there, immediately after the line mentioned above:

    define( 'WP_DEBUG_DISPLAY', false );

    The wp-config.php is located in your WordPress root directory. It’s the same file where the database configuration settings are. You will have to access it by FTP or SFTP in order to edit it. I would need then to see content of the debug.log file - so please upload it to dropbox like a service and paste link here.

    kind regards,
    Kasia

  • JessycaFrederick

    Also, the custom code I've written is not in this file. I have made the following modifications to the following files.

    /*
    LOCATION: /public_html/wp-content/plugins/events-and-bookings/lib/class_eab_template.php
    */
    // LINE 293 - RSVP LIST PRINTOUT ON ADMIN
    // If user has membership, add it

    $membership = 'Guest';
    $ms_api = ms_api();
    $member = $ms_api->get_member( $booking->user_id );
    if ( $member->has_membership() ) $membership = 'Member';
    $content .= '<br />'. $membership .'<br />';

    In the conditional, $member->has_membership() was causing the same error reported above so I changed to the check to if ( $member ) for now.

    /*
    LOCATION: /public_html/wp-content/plugins/events-and-bookings/lib/class_eab_exporter.php
    */
    // ADDED FUNCTIONALITY FOR MEMBERS DISPLAY AND MEMBERS EXPORTS
    // Starting at LINE 165

    $payment_status = $event->user_paid($booking->user_id) ? __('Yes', Eab_EventsHub::TEXT_DOMAIN) : __('No', Eab_EventsHub::TEXT_DOMAIN);
    // If user has membership, add it to $payment_status
    $ms_api = ms_api();
    $member = $ms_api->get_member( $booking->user_id );
    if ( $member->has_membership() ) $payment_status .= ' - Member';

    In the conditional, $member->has_membership() was causing the same error reported above so I changed to the check to if ( $member ) for now.

  • Nithin

    Hi JessycaFrederick,

    In the conditional, $member->has_membership() was causing the same error reported above so I changed to the check to if ( $member ) for now.

    Thank you for sharing your observation, so editing the mentioned files solved the current issue? I'm still not able to replicate this in a fresh install, are you able to replicate the same in another install?

    I'm pinging the developer regarding this, and bringing this in developers attention. Will keep you posted once I get a feedback regarding this. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Nithin

    Hi JessycaFrederick,

    The code modifications I made to eliminate the error were in my own code edits.

    I have even tried commenting out my code edits entirely, but the error persists in a file where I did not change the code.

    Thanks for making it clear, I have already pinged the developer regarding this, and will keep you posted once I get an update from him asap.

    Could you please send us your credentials so that we could have a better understanding regarding this. You can send credentials by using our secure contact form: https://premium.wpmudev.org/contact/#i-have-a-different-question

    - To Mark to my attention, the subject line should contain only: ATTN: Nithin Ramdas
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Please let us know once you have send the credentials, have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Nithin

    Hi JessycaFrederick,

    Hope you are doing good today. :slight_smile:

    Thank you for sending in the credentials, however I was able to notice 500 Internal Server Error in the console, and also the following error:
    Uncaught TypeError: jQuery(...).datepicker is not a function

    I'm did try to setup the exact configuration of yours, but I'm not able to replicate the exact issue in my system, maybe I'm missing something here.

    Are you able to replicate the same issue in another site? Is this a live site? Is it okay, if I could perform plugin conflict test in your system, and see how that goes?

    I would like to rule out whether any other plugin is causing this issue, and also would like to test this extensively with other plugins/themes disabled.

    If you think, it's not possible to perform plugin conflict test, maybe you could setup a staging website, on which we could give a closer look? You can use a plugin like Duplicator to setup a staging website.

    Please let us know how you want us to troubleshoot this further, so that we could help get this fixed asap. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • JessycaFrederick

    Hi Nithin,

    I suspect the jQuery error is coming from the page not completing its load after the PHP error as it was not present before the PHP error cropped up.

    I do have a staging server sort-of set-up on my regular server. If I get my other work done today I can attempt to get that set up like the current site is. I'll check out Duplicator, thank you for the advice on that!

    I don't mind if you run a plugin conflict test, but I suspect you can't do that on a live site without taking it down for maintenance? I'd rather not do that if that's the case. We've just begun registering people for our biggest online event, which is why I'm sort of freaked out about this particular problem.

    Thanks,
    Jessyca

  • Kasia Swiderska

    Hello Jessyca,

    It would be better indeed to run test on staging site - if that error will be visible on staging site. Plugin test might take some time, especially when there is quite some plugins there to test (we have to enable plugin one by one and check each time if error shows).
    If you could create that staging then we can run our tested there. Please let me know.

    kind regards,
    Kasia

  • JessycaFrederick

    I tried using Duplicator to get the staging server set up, but it wouldn't complete the package and their support team was not helpful. I haven't had time to figure that part out yet.

    Given that you seem disinclined to debug it without a plugin collision test, I decided my easiest course of action was to debug it myself in the live code.

    After a few minutes, I solved the problem. Your team should know about the problem and how I fixed it, so here goes.

    Filename: /events-and-bookings/lib/plugins/eab-events-membership2-integration.php

    On line 310, the PHP is complaining about calling a member function on a boolean. This means the $user object was not properly instantiated on line 307. So, I looked at the function above and noticed that when it tries to retrieve the user on line 280 it uses the get_current_member() method and the one that was breaking on line 307 uses get_member(). I swapped out get_member() for get_current_member() and now it works.

  • Nithin

    Hi JessycaFrederick,

    Hope you are doing good today. :slight_smile:

    Glad to know that you have figured the issue out, we were looking to perform a plugin conflict test, because we weren't able to replicate the exact issue in our system, I even checked this with the developer, and he wasn't able to replicate it, so we wanted to make sure whether any other plugin is causing a conflict, or not.

    Thanks for sharing the quick workaround, I hope your tip would be helpful for other members. If you are able to replicate the same issue in another system, please do let us know the exact steps to replicate it, so that we could report this issue to the developer.

    Kind Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.