Hi i want to create a custom trigger using the notifications plugin and i cant extract data from my action (witch is a buddboss group post update )

Question

I want to create the merge tags and a conditional rule depending on the group id or user id

///buddyboss code

function groups_post_update( $args = ” ) {
if ( ! bp_is_active( ‘activity’ ) ) {
return false;
}

$bp = buddypress();

$r = bp_parse_args( $args, array(
    'content'    => false,
    'user_id'    => bp_loggedin_user_id(),
    'group_id'   => 0,
    'error_type' => 'bool'
), 'groups_post_update' );
extract( $r, EXTR_SKIP );

if ( empty( $group_id ) && !empty( $bp->groups->current_group->id ) )
    $group_id = $bp->groups->current_group->id;

if ( //empty( $content ) || !strlen( trim( $content ) ) ||
     empty( $user_id ) ||
     empty( $group_id )
)
    return false;

$bp->groups->current_group = groups_get_group( $group_id );

// Be sure the user is a member of the group before posting.
if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) && ! groups_is_user_allowed_posting( $user_id, $group_id ) )
    return false;

// Record this in activity feeds.
$activity_action  = sprintf( __( '%1$s posted an update in the group %2$s', 'buddyboss'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
$activity_content = $content;

/**
 * Filters the action for the new group activity update.
 *
 * @since BuddyPress 1.2.0
 *
 * @param string $activity_action The new group activity update.
 */
$action = apply_filters( 'groups_activity_new_update_action',  $activity_action  );

/**
 * Filters the content for the new group activity update.
 *
 * @since BuddyPress 1.2.0
 *
 * @param string $activity_content The content of the update.
 */
$content_filtered = apply_filters( 'groups_activity_new_update_content', $activity_content );

$activity_id = groups_record_activity( array(
    'user_id'    => $user_id,
    'action'     => $action,
    'content'    => $content_filtered,
    'type'       => 'activity_update',
    'item_id'    => $group_id,
    'error_type' => $error_type
) );

groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );

/**
 * Fires after posting of an Activity status update affiliated with a group.
 *
 * @since BuddyPress 1.2.0
 *
 * @param string $content     The content of the update.
 * @param int    $user_id     ID of the user posting the update.
 * @param int    $group_id    ID of the group being posted to.
 * @param bool   $activity_id Whether or not the activity recording succeeded.
 */
do_action( 'bp_groups_posted_update', $content, $user_id, $group_id, $activity_id );

return $activity_id;

}

//Custom triger for post updates

class PostUpdate extends BracketSpaceNotificationAbstractsTrigger {

public function __construct() {

    // Add slug and the title.
    parent::__construct(
        'bp_groups_posted_update',
        __( 'New Post Update', 'bp_groups_posted_update' )
    );

    // Hook to the action.
    $this->add_action( 'bp_groups_posted_update', $content, 10, 2);
    $this->set_group( __( 'ImpactDM Custom Triggers', 'textdomain' ) );

}

public function action( $content,$user_id ) {


// Set the trigger properties.

$this->content = $content;

}

public function merge_tags() {
    
   
$this->add_merge_tag( new BracketSpaceNotificationDefaultsMergeTagHtmlTag( array(
    'slug'        => 'content',
    'name'        => __( 'Content', 'textdomain' ),
    'resolver'    => function( $trigger ) {
        return nl2br( $trigger->bp_groups_posted_update->content );
    },
) ) );
}

}

register_trigger( new PostUpdate() );

0
Ariseld Shehaj 5 months 2020-12-22T05:10:23-05:00 0 Answers 7 views 0

Leave an answer

Browse
Browse