Skip to:
Content

BuddyPress.org

Changeset 12362


Ignore:
Timestamp:
04/24/2019 02:07:21 PM (5 years ago)
Author:
boonebgorges
Message:

Introduce functions to fetch group avatar and cover image URLs.

Props truchot.
Fixes #7244.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-template.php

    r12281 r12362  
    876876    }
    877877
     878/**
     879 * Returns the group avatar URL.
     880 *
     881 * @since 5.0.0
     882 *
     883 * @param object|bool $group Optional. Group object. Default current group in loop.
     884 * @param string      $type  Optional. The type of the avatar ('full' or 'thumb'). Default 'full'.
     885 * @return string The avatar URL.
     886 */
     887function bp_get_group_avatar_url( $group = false, $type = 'full' ) {
     888    $group_id = bp_get_group_id( $group );
     889
     890    if ( ! $group_id ) {
     891        return '';
     892    }
     893
     894    return bp_core_fetch_avatar(
     895        array(
     896            'type'    => $type,
     897            'object'  => 'group',
     898            'item_id' => $group_id,
     899            'html'    => false,
     900        )
     901    );
     902}
     903
    878904/** Group cover image *********************************************************/
    879905
     
    888914function bp_group_use_cover_image_header() {
    889915    return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads() && bp_attachments_is_wp_version_supported();
     916}
     917
     918/**
     919 * Returns the group cover image URL.
     920 *
     921 * @since 5.0.0
     922 *
     923 * @param object|bool $group Optional. Group object. Default current group in loop.
     924 * @return string The cover image URL or empty string if not found.
     925 */
     926function bp_get_group_cover_url( $group = false ) {
     927    $group_id = bp_get_group_id( $group );
     928
     929    if ( ! $group_id ) {
     930        return '';
     931    }
     932
     933    $cover_url = bp_attachments_get_attachment(
     934        'url',
     935        array(
     936            'object_dir' => 'groups',
     937            'item_id'    => $group_id,
     938        )
     939    );
     940
     941    if ( ! $cover_url ) {
     942        return '';
     943    }
     944
     945    return $cover_url;
    890946}
    891947
Note: See TracChangeset for help on using the changeset viewer.