Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Error while fetching all members of a group #260

Closed
ExoGeek opened this issue Jan 13, 2020 · 11 comments · Fixed by #265
Closed

PHP Error while fetching all members of a group #260

ExoGeek opened this issue Jan 13, 2020 · 11 comments · Fixed by #265
Assignees

Comments

@ExoGeek
Copy link

@ExoGeek ExoGeek commented Jan 13, 2020

GET {{host}}/wp-json/buddypress/v1/groups/76/members

Notice: Trying to get property 'ID' of non-object in class-bp-rest-group-membership-endpoint.php on line 337

The code below is not correct when we want to fetch all members of group

$user = bp_rest_get_user( $request['user_id'] );

@ExoGeek

This comment has been minimized.

Copy link
Author

@ExoGeek ExoGeek commented Jan 13, 2020

Actually, it seems that the parameter "User_id" is required.

For your information, this parameter is not displayed when you show the schema via the request below.

OPTIONS {{host}}/wp-json/buddypress/v1/groups/76/members?user_id=1

@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 14, 2020

Hi @ExoGeek

Thanks for your feedback! I'm taking a look at this bug and will provide a feedback shortly. :)

@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 14, 2020

Hi @ExoGeek

I have been unable to reproduce your error. I tried accessing group members with the url below:

https://site.test/wp-json/buddypress/v1/groups/3/members

The 3 is the group ID. I'm able to get the members correctly.

[
  {
    "id": 1,
    "name": "test_user",
    "user_login": "test_user",
    "link": "http:\/\/site.\/members\/test_user\/",
    "member_types": [
      "foo"
    ],
    "xprofile": {
      "groups": {
        "1": {
          "name": "Base",
          "fields": {
            "1": {
              "name": "Name",
              "value": {
                "raw": "",
                "unserialized": [],
                "rendered": ""
              }
            }
          }
        }
      }
    },
    "mention_name": "test_user",
    "avatar_urls": {
      "full": "\/\/www.gravatar.com\/avatar\/ad5dd285560221a7302608c74c690035?s=150&r=g&d=mm",
      "thumb": "\/\/www.gravatar.com\/avatar\/ad5dd285560221a7302608c74c690035?s=50&r=g&d=mm"
    },
    "is_mod": false,
    "is_admin": true,
    "is_banned": false,
    "is_confirmed": true,
    "date_modified": "2019-10-27T18:19:36",
    "_links": {
      "self": [
        {
          "href": "http:\/\/site.\/wp-json\/buddypress\/v1\/groups\/1"
        }
      ],
      "collection": [
        {
          "href": "http:\/\/site.\/wp-json\/buddypress\/v1\/groups\/"
        }
      ]
    }
  }
]
@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 14, 2020

By the way, the line you are referring to 337, is from the create_item. I assume you are using a POST method instead of GET method. And that's why you are seeing a required param for user_id, which is required to add a member to a group.

@ExoGeek

This comment has been minimized.

Copy link
Author

@ExoGeek ExoGeek commented Jan 14, 2020

  1. You have to call https://site.test/wp-json/buddypress/v1/groups/3/members without beeing logged in.
  • $retval is error (on line 299).
  • $user is false on line 308
  • On line 337, you try to access $user->ID but $user is not an object ===> Error !
  1. I make a request like this (not logged in) :

OPTIONS {{host}}/wp-json/buddypress/v1/groups/76/members

@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 14, 2020

@ExoGeek This is how I did it. Without being logged in.

Is the group private or hidden?

@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 14, 2020

@ExoGeek Just to reinforce, you need to make a GET request and not a OPTIONS request. Those are not the same thing.

:)

@ExoGeek

This comment has been minimized.

Copy link
Author

@ExoGeek ExoGeek commented Jan 14, 2020

  • I've tested with private, public, hidden and not existing groups => I've received the error for all of them
  • I've tested with GET and it doesn't make any difference : Error is shown.

Actually, it's only a 'notice' php error. Maybe your server doesn't display that kind of error.

For you information, that error is written in debug.log stored in the wp-content folder.

@ExoGeek

This comment has been minimized.

Copy link
Author

@ExoGeek ExoGeek commented Jan 14, 2020

Am I wrong whith my analysis below when a call to that route is made ?

File : class-bp-rest-group-membership-endpoint.php

  • $retval is error (on line 299).
    
  • $user is false on line 308
    
  • On line 337, you try to access $user->ID but $user is not an object ===> Error !
    
@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 14, 2020

@ExoGeek My notice log was turned off. Sorry! I can see what you mean now.

I'm gonna investigate what's happening. In theory, the error shouldn't be happening, since the code is happening in a GET context instead of a POST context.

@renatonascalves

This comment has been minimized.

Copy link
Member

@renatonascalves renatonascalves commented Jan 18, 2020

@ExoGeek Thanks for reporting the bug. We were able to patch things up. :)

@renatonascalves renatonascalves moved this from In Development to Done in BP REST - V2 Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.