Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/19/2022 09:21:45 PM (3 years ago)
Author:
imath
Message:

Make it possible to disable Avatar history & richer logging activities

Advanced users wishing to:

  1. disable the Avatar history feature, can do so returning true when filtering 'bp_disable_avatar_history',
  2. prevent one or more logging activity types to have a richer output, can return an array of the allowed activity types (or an empty array to completely disable the feature) when filtering 'bp_activity_get_types_supporting_generated_content'.

Props sbrajesh, oztaser

Fixes #8617

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r13181 r13215  
    633633
    634634/**
     635 * Gets the list of activity types name supporting the requested feature.
     636 *
     637 * This function is still a WIP, please don't use it into your plugins or themes.
     638 *
     639 * @since 10.0.0
     640 *
     641 * @access private
     642 * @todo `bp_activity_set_action()` should be improved to include a supports
     643 * argument or best we should create a `bp_register_activity_type()` function
     644 * to mimic the way WordPress registers post types. For now we'll use a non
     645 * extendable workaround.
     646 *
     647 * @param string $feature The feature activity types should support.
     648 * @return array          The list of activity types name supporting the requested feature.
     649 */
     650function _bp_activity_get_types_by_support( $feature = 'generated-content' ) {
     651    $activity_types = array();
     652
     653    if ( 'generated-content' === $feature ) {
     654        $activity_types = array( 'new_member', 'new_avatar' );
     655
     656        if ( bp_is_active( 'friends' ) ) {
     657            array_push( $activity_types, 'friendship_created' );
     658        }
     659
     660        if ( bp_is_active( 'groups' ) ) {
     661            array_push( $activity_types, 'created_group', 'joined_group' );
     662        }
     663
     664        if ( bp_is_active( 'xprofile' ) ) {
     665            array_push( $activity_types, 'updated_profile' );
     666        }
     667    }
     668
     669    $filter_key = str_replace( '-', '_', $feature );
     670
     671    /**
     672     * Use this filter to add/remove activity types supporting the requested feature.
     673     *
     674     * The dynamic portion of the filter is the name of the requested feature where hyphens are
     675     * replaced by underscores. Eg. use `bp_activity_get_types_supporting_generated_content` to
     676     * edit the list of activities supporting the `generated-content` feature.
     677     *
     678     * @since 10.0.0
     679     *
     680     * @param array $activity_types The list of activity types name supporting the requested feature.
     681     */
     682    return apply_filters( "bp_activity_get_types_supporting_{$filter_key}", $activity_types );
     683}
     684
     685/**
    635686 * Check if the *Post Type* activity supports a specific feature.
    636687 *
     
    715766         */
    716767        case 'generated-content' :
    717             /*
    718              * @todo `bp_activity_set_action()` should be improved to include a supports
    719              * argument or best we should create a `bp_register_activity_type()` function
    720              * to mimic the way WordPress registers post types. For now we'll use a non
    721              * extendable workaround.
    722              */
    723             $activity_types = array( 'new_member', 'new_avatar' );
    724 
    725             if ( bp_is_active( 'friends' ) ) {
    726                 array_push( $activity_types, 'friendship_created' );
    727             }
    728 
    729             if ( bp_is_active( 'groups' ) ) {
    730                 array_push( $activity_types, 'created_group', 'joined_group' );
    731             }
    732 
    733             if ( bp_is_active( 'xprofile' ) ) {
    734                 array_push( $activity_types, 'updated_profile' );
    735             }
     768            $activity_types = _bp_activity_get_types_by_support( 'generated-content' );
    736769
    737770            $retval = in_array( $activity_type, $activity_types, true );
Note: See TracChangeset for help on using the changeset viewer.