Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/29/2016 07:38:58 PM (8 years ago)
Author:
boonebgorges
Message:

Discard activity filter values that are invalid for the current context.

Activity filters are stored in a cookie that persists across
activity pages. But some filter values are not valid in all contexts,
such as new_member (valid in the sitewide feed, but not in a group).
This changeset ensures that filter values sent via AJAX are discarded
if they aren't valid in the current context.

Props lakrisgubben.
Fixes #4062.

File:
1 edited

Legend:

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

    r11351 r11356  
    838838     */
    839839    return apply_filters( 'bp_activity_get_types', $actions );
     840}
     841
     842/**
     843 * Gets the current activity context.
     844 *
     845 * The "context" is the current view type, corresponding roughly to the
     846 * current component. Use this context to determine which activity actions
     847 * should be whitelisted for the filter dropdown.
     848 *
     849 * @since 2.8.0
     850 *
     851 * @return string Activity context. 'member', 'member_groups', 'group', 'activity'.
     852 */
     853function bp_activity_get_current_context() {
     854    // On member pages, default to 'member', unless this is a user's Groups activity.
     855    if ( bp_is_user() ) {
     856        if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
     857            $context = 'member_groups';
     858        } else {
     859            $context = 'member';
     860        }
     861
     862    // On individual group pages, default to 'group'.
     863    } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
     864        $context = 'group';
     865
     866    // 'activity' everywhere else.
     867    } else {
     868        $context = 'activity';
     869    }
     870
     871    return $context;
     872}
     873
     874/**
     875 * Gets a flat list of activity actions compatible with a given context.
     876 *
     877 * @since 2.8.0
     878 *
     879 * @param string $context Optional. Name of the context. Defaults to the current context.
     880 * @return array
     881 */
     882function bp_activity_get_actions_for_context( $context = '' ) {
     883    if ( ! $context ) {
     884        $context = bp_activity_get_current_context();
     885    }
     886
     887    $actions = array();
     888    foreach ( bp_activity_get_actions() as $component_actions ) {
     889        foreach ( $component_actions as $component_action ) {
     890            if ( in_array( $context, (array) $component_action['context'], true ) ) {
     891                $actions[] = $component_action;
     892            }
     893        }
     894    }
     895
     896    return $actions;
    840897}
    841898
Note: See TracChangeset for help on using the changeset viewer.