#6749 closed enhancement (fixed)
bp_get_group_avatar() needs to work outside the loop
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 10.0.0 | Priority: | normal |
Severity: | normal | Version: | 1.0 |
Component: | Groups | Keywords: | has-patch has-unit-tests dev-reviewed |
Cc: |
Description
Currently bp_get_group_avatar()
function doesn't check $groups_template
global var, although using it extensively.
If you try to use this function not in a loop scope - it will generate lots of notices.
It makes it impossible to use outside of the loop more relevant bp_get_group_avatar()
comparing to bp_core_fetch_avatar()
.
Attachments (5)
Change History (21)
#1
@
9 years ago
- Keywords 2nd-opinion added
- Milestone changed from Awaiting Review to Under Consideration
#2
@
9 years ago
The bp_get_group_from_param()
function would be pretty awesome.
Also, check out a related, crappy patch here - ticket:6387#comment:6 - that only adds groups_get_current_group()
as a fallback and doesn't do any group lookups.
#5
@
9 years ago
- Component changed from Core to Groups
- Keywords 2nd-opinion removed
- Milestone changed from Awaiting Review to Future Release
- Summary changed from bp_get_group_avatar() needs extra error checking to bp_get_group_avatar() needs to work outside the loop
#6
@
4 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Contributions to 10.0.0
- Owner set to espellcaste
- Status changed from new to assigned
- Version set to 9.0.0
I like @boonebgorges suggestions and I'll work on a patch. On the BP REST API and BP CLI, I opted to use bp_core_fetch_avatar
precisely because I noticed you could not use bp_get_group_avatar
properly outside of the loop.
#7
@
4 years ago
- Keywords has-patch has-unit-tests added; needs-patch removed
- Type changed from defect (bug) to enhancement
This is the first patch, of a few more I'm sure, introducing the new helper function, bp_get_group_from_param
, to grab a group using one of the identifiers: slug, ID, BP_Groups_Group
which defaults to the current group in the BP_Groups_Template
loop.
This is a preliminary patch which accounts to:
- creating the helper function
- updating a few functions to use this new function (more needs to be updated)
- adding basic support to unit tests (support will be improved in future patches)
Some notes:
- PHPDoc was updated to remove references of getting the ID from the current loop;
bp_group_is_visible
was updated to check against a specific user ID;bp_get_group_avatar
was updated to pass other parameter tobp_core_fetch_avatar
which were missing.
The goal is to gather preliminary feedback before diving even deeper. =P
#8
@
4 years ago
- Version changed from 9.0.0 to 1.0
Hi @espellcaste
Thanks a lot for your work and patch about this improvement. I'll look at it in detail asap. Here's some first thoughts:
- what about
bp_get_group_by( $field, $value )
like the WPget_user_by()
function? - It seems weird to have the
from_param
suffix and being able to pass the entire Group object. I would probably have used abp_get_group( $group_id_or_group_object )
and usedbp_get_group_by( 'id', $value )
function inside it in case a Group ID was passed.
I've changed the version to 1.0 as this was the BuddyPress version when bp_get_group_avatar()
was introduced.
#9
@
4 years ago
I think those are good suggestions, particularly the bp_get_group_by
one (other objects/components would benefit from having similar instances).
I'll update the patch while the rest of the diff is reviewed. :)
#10
@
4 years ago
Second patch with the code suggestions applied. Minor tweaks were made to the PHPDoc and unit tests. :)
#11
@
4 years ago
- Keywords dev-reviewed added
Hi @espellcaste
Thanks a lot for your work on this second patch. It looks nice, you'll find some suggestions mainly about DocBlocks into the patch I suggest to use to compliment yours below.
NB: the patch also fixes an issue with how you edited bp_get_group_avatar()
: the html
argument needs to default to true
otherwise the avatar image is not output, and we get instead the avatar URL (which can be retrieved using bp_get_group_avatar_url()
.
Once you've fixed the bp_get_group_avatar()
issue and If you're confident with the patch, feel free to commit it.
#13
@
4 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
I mistakenly fixed this ticket where I had other patches to send.
I agree that there should be a way to get a group avatar outside of a group loop.
I'm not 100% sure that
bp_get_group_avatar()
is the way to do it. Our-template.php
functions are pretty inconsistent throughout BuddyPress. In some places, these functions accept an argument so that they can be used outside of the loop, and in other places they do not. Many of thebp-groups-template.php
functions, for example, accept a$group
object. It's easy for us to add this functionality tobp_get_group_avatar()
, but this might also be a good time to take a moment and see whether we'd like to take a step toward greater consistency here. What if, for example, we introduced a function like this:Then, within each template function:
This way, devs have the option of passing a group object, passing a group ID, or passing nothing and having the group determined from the group loop context.