Skip to:
Content

BuddyPress.org

Changeset 10721


Ignore:
Timestamp:
04/27/2016 03:59:26 PM (8 years ago)
Author:
boonebgorges
Message:

Introduce 'mystery group' avatar for groups without custom avatar.

This nifty new image is totally grouperiffic, and it's gonna supercharge
your BuddyPress community, to the extreme.

As part of the improvement, Gravatar requests for group avatars have been
disabled by default. Gravatar requests never match for groups, anyway, so
this should save HTTP requests in most cases. Filter 'bp_core_fetch_avatar_no_grav'
to restore the previous behavior.

Props sooskriszta, abweb.
Fixes #6372.

Location:
trunk/src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-avatars.php

    r10688 r10721  
    176176 *                                   case 'no_grav' should be set to true. To disable Gravatar
    177177 *                                   fallbacks globally, see the 'bp_core_fetch_avatar_no_grav' filter.
    178  *                                   Default: false.
     178 *                                   Default: true for groups, otherwise false.
    179179 *     @type bool       $html        Whether to return an <img> HTML element, vs a raw URL
    180180 *                                   to an avatar. If false, <img>-specific arguments (like 'css_id')
     
    212212        'alt'           => '',
    213213        'email'         => false,
    214         'no_grav'       => false,
     214        'no_grav'       => null,
    215215        'html'          => true,
    216216        'title'         => '',
     
    565565    }
    566566
     567    // By default, Gravatar is not pinged for groups.
     568    if ( null === $params['no_grav'] ) {
     569        $params['no_grav'] = 'group' === $params['object'];
     570    }
     571
    567572    /**
    568573     * Filters whether or not to skip Gravatar check.
     
    672677         * @param array  $params Array of parameters for the avatar request.
    673678         */
    674         $gravatar = apply_filters( 'bp_core_default_avatar_' . $params['object'], bp_core_avatar_default( 'local' ), $params );
     679        $gravatar = apply_filters( 'bp_core_default_avatar_' . $params['object'], bp_core_avatar_default( 'local', $params ), $params );
    675680    }
    676681
     
    18461851 *
    18471852 * @since 1.5.0
    1848  *
    1849  * @param string $type 'local' if the fallback should be the locally-hosted version
    1850  *                     of the mystery-person, 'gravatar' if the fallback should be
    1851  *                     Gravatar's version. Default: 'gravatar'.
     1853 * @since 2.6.0 Introduced `$params` and `$object_type` parameters.
     1854 *
     1855 * @param string $type   'local' if the fallback should be the locally-hosted version
     1856 *                       of the mystery person, 'gravatar' if the fallback should be
     1857 *                       Gravatar's version. Default: 'gravatar'.
     1858 * @param array  $params Parameters passed to bp_core_fetch_avatar().
    18521859 * @return string The URL of the default avatar.
    18531860 */
    1854 function bp_core_avatar_default( $type = 'gravatar' ) {
     1861function bp_core_avatar_default( $type = 'gravatar', $params = array() ) {
    18551862    // Local override.
    18561863    if ( defined( 'BP_AVATAR_DEFAULT' ) ) {
     
    18701877     *
    18711878     * @since 1.5.0
     1879     * @since 2.6.0 Added `$params`.
    18721880     *
    18731881     * @param string $avatar URL of the default avatar.
    1874      */
    1875     return apply_filters( 'bp_core_avatar_default', $avatar );
     1882     * @param array  $params Params provided to bp_core_fetch_avatar().
     1883     */
     1884    return apply_filters( 'bp_core_avatar_default', $avatar, $params );
    18761885}
    18771886
     
    18831892 *
    18841893 * @since 1.5.0
    1885  *
    1886  * @param string $type 'local' if the fallback should be the locally-hosted version
    1887  *                     of the mystery-person, 'gravatar' if the fallback should be
    1888  *                     Gravatar's version. Default: 'gravatar'.
     1894 * @since 2.6.0 Introduced `$object_type` parameter.
     1895 *
     1896 * @param string $type   'local' if the fallback should be the locally-hosted version
     1897 *                       of the mystery person, 'gravatar' if the fallback should be
     1898 *                       Gravatar's version. Default: 'gravatar'.
     1899 * @param array  $params Parameters passed to bp_core_fetch_avatar().
    18891900 * @return string The URL of the default avatar thumb.
    18901901 */
    1891 function bp_core_avatar_default_thumb( $type = 'gravatar' ) {
     1902function bp_core_avatar_default_thumb( $type = 'gravatar', $params = array() ) {
    18921903    // Local override.
    18931904    if ( defined( 'BP_AVATAR_DEFAULT_THUMB' ) ) {
     
    19071918     *
    19081919     * @since 1.5.0
     1920     * @since 2.6.0 Added `$params`.
    19091921     *
    19101922     * @param string $avatar URL of the default avatar.
    1911      */
    1912     return apply_filters( 'bp_core_avatar_thumb', $avatar );
     1923     * @param string $params Params provided to bp_core_fetch_avatar().
     1924     */
     1925    return apply_filters( 'bp_core_avatar_thumb', $avatar, $params );
    19131926}
    19141927
  • trunk/src/bp-groups/bp-groups-filters.php

    r10572 r10721  
    7373// Activity component integration.
    7474add_filter( 'bp_activity_at_name_do_notifications', 'bp_groups_disable_at_mention_notification_for_non_public_groups', 10, 4 );
     75
     76// Default group avatar.
     77add_filter( 'bp_core_avatar_default',       'bp_groups_default_avatar', 10, 3 );
     78add_filter( 'bp_core_avatar_default_thumb', 'bp_groups_default_avatar', 10, 3 );
    7579
    7680/**
     
    320324    return $send;
    321325}
     326
     327/**
     328 * Use the mystery group avatar for groups.
     329 *
     330 * @since 2.6.0
     331 *
     332 * @param string $avatar Current avatar src.
     333 * @param array  $params Avatar params.
     334 * @return string
     335 */
     336function bp_groups_default_avatar( $avatar, $params ) {
     337    if ( isset( $params['object'] ) && 'group' === $params['object'] ) {
     338        if ( isset( $params['type'] ) && 'thumb' === $params['type'] ) {
     339            $file = 'mystery-group-50.png';
     340        } else {
     341            $file = 'mystery-group.png';
     342        }
     343
     344        $avatar = buddypress()->plugin_url . "bp-core/images/$file";
     345    }
     346
     347    return $avatar;
     348}
  • trunk/src/bp-groups/bp-groups-template.php

    r10652 r10721  
    600600            'class'      => $r['class'],
    601601            'width'      => $r['width'],
    602             'height'     => $r['height']
     602            'height'     => $r['height'],
    603603        ) );
    604604
     
    47064706            'id'      => 'avatar-crop-preview',
    47074707            'alt'     => __( 'Group photo', 'buddypress' ),
    4708             'no_grav' => false
    47094708        ), 'get_new_group_avatar' );
    47104709
     
    51495148    }
    51505149
    5151     $group_avatar = bp_core_fetch_avatar( array(
     5150    $avatar_args = array(
    51525151        'item_id' => $group_id,
    51535152        'object'  => 'group',
    51545153        'no_grav' => true,
    51555154        'html'    => false,
    5156     ) );
    5157 
    5158     if ( bp_core_avatar_default( 'local' ) === $group_avatar ) {
     5155        'type'    => 'thumb',
     5156    );
     5157
     5158    $group_avatar = bp_core_fetch_avatar( $avatar_args );
     5159
     5160    if ( bp_core_avatar_default( 'local', $avatar_args ) === $group_avatar ) {
    51595161        return false;
    51605162    }
Note: See TracChangeset for help on using the changeset viewer.