Skip to:
Content

BuddyPress.org

Changeset 12906


Ignore:
Timestamp:
04/27/2021 04:11:45 AM (9 months ago)
Author:
imath
Message:

Replace the bp_core_avatar_default filter with 2 new filters

The bp_core_avatar_default filter was used for two different purposes:

  1. to edit the default BuddyPress avatar [7769].
  2. to edit the default Gravatar [10688].

To avoid confusion or generate misleading behaviors, we are deprecating this filter in favor of 2 new filters :

  1. Use bp_core_default_avatar to edit the default BuddyPress avatar.
  2. Use bp_core_avatar_gravatar_default to edit the default Gravatar.

Props r-a-y

Fixes #8437

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-filters.php

    r12772 r12906  
    159159    return $avatar;
    160160}
    161 add_filter( 'bp_core_avatar_default',       'bp_blogs_default_avatar', 10, 2 );
     161add_filter( 'bp_core_default_avatar',       'bp_blogs_default_avatar', 10, 2 );
    162162add_filter( 'bp_core_avatar_default_thumb', 'bp_blogs_default_avatar', 10, 2 );
    163163
  • trunk/src/bp-core/bp-core-avatars.php

    r12894 r12906  
    9595}
    9696add_action( 'bp_setup_globals', 'bp_core_set_avatar_globals' );
     97
     98/**
     99 * Checks whether a given gravatar is one of the default ones.
     100 *
     101 * @since 8.0.0
     102 *
     103 * @param string $d The name of the default gravatar.
     104 * @return bool True if it's a default gravatar. False otherwise.
     105 */
     106function bp_core_is_default_gravatar( $d = '' ) {
     107    if ( ! $d ) {
     108        return false;
     109    }
     110
     111    /** this filter is documented in wp-admin/options-discussion.php */
     112    $gravatar_defaults = apply_filters(
     113        'avatar_defaults',
     114        array_fill_keys(
     115            array(
     116                'mystery',
     117                'blank',
     118                'gravatar_default',
     119                'identicon',
     120                'wavatar',
     121                'monsterid',
     122                'retro',
     123            ),
     124            ''
     125        )
     126    );
     127
     128    return isset( $gravatar_defaults[ $d ] );
     129}
    97130
    98131/**
     
    645678        }
    646679
     680        /** This filter is documented in wp-includes/deprecated.php */
     681        $d = apply_filters_deprecated(
     682            'bp_core_avatar_default',
     683            array( $default_grav, $params ),
     684            '8.0.0',
     685            'bp_core_avatar_gravatar_default||bp_core_default_avatar',
     686            __( 'This filter was used for 2 different purposes. If your goal was to filter the default *Gravatar*, please use `bp_core_avatar_gravatar_default` instead. Otherwise, please use `bp_core_default_avatar` instead.', 'buddypress' )
     687        );
     688
     689        if ( bp_core_is_default_gravatar( $d ) ) {
     690            $default_grav = $d;
     691        }
     692
    647693        /**
    648694         * Filters the Gravatar "d" parameter.
    649695         *
    650696         * @since 2.6.0
     697         * @since 8.0.0 The name of the filter was changed to `bp_core_avatar_gravatar_default`.
    651698         *
    652699         * @param string $default_grav The avatar default.
    653700         * @param array  $params       The avatar's data.
    654701         */
    655         $default_grav = apply_filters( 'bp_core_avatar_default', $default_grav, $params );
     702        $default_grav = apply_filters( 'bp_core_avatar_gravatar_default', $default_grav, $params );
    656703
    657704        // Only set default image if 'Gravatar Logo' is not requested.
     
    18421889    }
    18431890
     1891    /** This filter is documented in wp-includes/deprecated.php */
     1892    $a = apply_filters_deprecated(
     1893        'bp_core_avatar_default',
     1894        array( $avatar, $params ),
     1895        '8.0.0',
     1896        'bp_core_avatar_gravatar_default||bp_core_default_avatar',
     1897        __( 'This filter was used for 2 different purposes. If your goal was to filter the default *Gravatar*, please use `bp_core_avatar_gravatar_default` instead. Otherwise, please use `bp_core_default_avatar` instead.', 'buddypress' )
     1898    );
     1899
     1900    if ( ! bp_core_is_default_gravatar( $a ) && false !== strpos( $avatar, '//' ) ) {
     1901        $avatar = $a;
     1902    }
     1903
    18441904    /**
    18451905     * Filters the URL of the 'full' default avatar.
     
    18471907     * @since 1.5.0
    18481908     * @since 2.6.0 Added `$params`.
     1909     * @since 8.0.0 The name of the filter was changed to `bp_core_default_avatar`.
    18491910     *
    18501911     * @param string $avatar URL of the default avatar.
    18511912     * @param array  $params Params provided to bp_core_fetch_avatar().
    18521913     */
    1853     return apply_filters( 'bp_core_avatar_default', $avatar, $params );
     1914    return apply_filters( 'bp_core_default_avatar', $avatar, $params );
    18541915}
    18551916
  • trunk/src/bp-groups/bp-groups-filters.php

    r12745 r12906  
    7070
    7171// Default group avatar.
    72 add_filter( 'bp_core_avatar_default',       'bp_groups_default_avatar', 10, 3 );
     72add_filter( 'bp_core_default_avatar',       'bp_groups_default_avatar', 10, 3 );
    7373add_filter( 'bp_core_avatar_default_thumb', 'bp_groups_default_avatar', 10, 3 );
    7474
Note: See TracChangeset for help on using the changeset viewer.