Skip to:
Content

BuddyPress.org

Changeset 13531


Ignore:
Timestamp:
07/28/2023 04:15:02 PM (3 years ago)
Author:
dcavins
Message:

Introduce bp_view capability.

Introduce a new, base-level capability, bp_view,
that by default maps to the most base-level WordPress
capability, exist.

See #8734.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r13436 r13531  
    33053305    }
    33063306
     3307    if ( ! bp_current_user_can( 'bp_view', array( 'bp_component' => 'activity' ) ) ) {
     3308        $retval = false;
     3309    }
     3310
    33073311    // If activity is from a group, do extra cap checks.
    3308     if ( bp_is_active( 'groups' ) && buddypress()->groups->id === $activity->component ) {
     3312    if ( bp_is_active( 'groups' ) && buddypress()->groups->id === $activity->component && bp_current_user_can( 'bp_view', array( 'bp_component' => 'groups' ) ) ) {
    33093313        // Check to see if the user has access to the activity's parent group.
    33103314        $group = groups_get_group( $activity->item_id );
     
    44834487 *
    44844488 * @since 8.0.0
     4489 * @since 12.0.0 Added bp_current_user_can( 'bp_view' ) check.
    44854490 *
    44864491 * @param string $feed_id The feed identifier. Possible values are:
     
    44884493 */
    44894494function bp_activity_is_feed_enable( $feed_id = '' ) {
     4495    $retval = bp_current_user_can( 'bp_view', array( 'bp_component' => 'activity' ) );
     4496
    44904497    /**
    44914498     * Filters if BuddyPress should consider feeds enabled. If disabled, it will return early.
     
    44944501     * @since 8.0.0 Adds the `$feed_id` parameter.
    44954502     *
    4496      * @param bool   $value   Defaults to true aka feeds are enabled.
     4503     * @param bool   $retval  Whether this feed is enabled or not.
    44974504     * @param string $feed_id The feed identifier.
    44984505     */
    4499     return (bool) apply_filters( 'bp_activity_enable_feeds', true, $feed_id );
    4500 }
     4506    return (bool) apply_filters( 'bp_activity_enable_feeds', $retval, $feed_id );
     4507}
  • trunk/src/bp-core/bp-core-caps.php

    r13450 r13531  
    125125 *
    126126 * @since 1.6.0
     127 * @since 12.0.0 Added mapping for `bp_view` capability.
    127128 *
    128129 * @see WP_User::has_cap() for description of the arguments passed to the
     
    137138 */
    138139function bp_map_meta_caps( $caps, $cap, $user_id, $args ) {
     140
     141    switch ( $cap ) {
     142        case 'bp_view' :
     143            $caps = array( 'exist' );
     144            if ( ! $user_id ) {
     145
     146                // A BuddyPress component ID may be optionally passed with the `bp_view` check.
     147                $component = isset( $args['bp_component'] ) ? $args['bp_component'] : '';
     148
     149                if ( 'members' === bp_get_community_visibility( $component ) ) {
     150                    $caps = array( 'do_not_allow' );
     151                }
     152            }
     153            break;
     154    }
    139155
    140156    /**
Note: See TracChangeset for help on using the changeset viewer.