Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/27/2016 03:59:26 PM (9 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.