Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/13/2022 12:50:54 PM (2 years ago)
Author:
imath
Message:

Improve Activity & Group Activity post_update functions

  1. Improve the bp_activity_post_update() function's extensibility including a filter name ('activity_post_update') into the bp_parse_args() function used to merge given arguments with default ones. This allows Plugins or BuddyPress add-ons such as BP Attachments to create a content from a different input than the Activity Post Form's textarea using one of these two filters:
    • 'bp_before_activity_post_update_parse_args' or
    • 'bp_after_activity_post_update_parse_args'
  1. groups_post_update() now completely respects the $error_type argument making sure to return a WP_Error object when it is defined to wp_error. If not, it returns false.
  1. To avoid code/i18n string duplication adapt bp_nouveau_ajax_post_update() so that it enjoys the 2 above improvements.

Closes https://github.com/buddypress/buddypress/pull/37
Fixes #8764

File:
1 edited

Legend:

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

    r13312 r13367  
    579579    }
    580580
    581     $content = $r['content'];
    582     $user_id = (int) $r['user_id'];
    583     if ( ! $content || ! strlen( trim( $content ) ) || ! $user_id || ! $group_id ) {
    584         return false;
    585     }
    586 
    587     $bp->groups->current_group = groups_get_group( $group_id );
    588 
    589     // Be sure the user is a member of the group before posting.
    590     if ( ! bp_current_user_can( 'bp_moderate' ) && ! groups_is_user_member( $user_id, $group_id ) ) {
     581    $content          = $r['content'];
     582    $user_id          = (int) $r['user_id'];
     583    $is_user_active   = bp_is_user_active( $user_id );
     584    $is_group_allowed = $group_id && ( bp_current_user_can( 'bp_moderate' ) || groups_is_user_member( $user_id, $group_id ) );
     585
     586    if ( ! $content || ! strlen( trim( $content ) ) || ! $is_user_active || ! $is_group_allowed ) {
     587        if ( 'wp_error' === $r['error_type'] ) {
     588            $error_code         = 'bp_activity_missing_content';
     589            $error_code_message = __( 'Please enter some content to post.', 'buddypress' );
     590
     591            if ( ! $is_user_active ) {
     592                $error_code         = 'bp_activity_inactive_user';
     593                $error_code_message = __( 'User account has not yet been activated.', 'buddypress' );
     594            } elseif ( ! $is_group_allowed ) {
     595                $error_code         = 'bp_activity_unallowed_group';
     596                $error_code_message = __( 'You need to be a member of this group to share updates with their members.', 'buddypress' );
     597            }
     598
     599            return new WP_Error( $error_code, $error_code_message );
     600        }
     601
    591602        return false;
    592603    }
Note: See TracChangeset for help on using the changeset viewer.