Skip to content

Commit

Permalink
Allow media upload without text from group activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Utsav-Ladani committed Jan 2, 2024
1 parent b3ca591 commit da73b7e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/main/RTMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,9 @@ public function init() {

$this->set_allowed_types(); // Define allowed types.

global $rtmedia_buddypress_activity;
global $rtmedia_buddypress_activity, $rtmedia_buddypress_group_activity;
$rtmedia_buddypress_activity = new RTMediaBuddyPressActivity();
$rtmedia_buddypress_group_activity = new RTMediaBuddyPressGroupActivity();
$media = new RTMediaMedia();
$media->delete_hook();

Expand Down
43 changes: 43 additions & 0 deletions app/main/controllers/group/RTMediaBuddyPressGroupActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Handle/change BuddyPress group activities behaviour.
*
* @package rtMedia
*/

/**
* Class to handle/change BuddyPress group activities behaviour.
*
* @author utsavladani
*/
class RTMediaBuddyPressGroupActivity {

/**
* RTMediaBuddyPressGroupActivity constructor.
*/
public function __construct() {
// Allow only media uploading without text in activity.
add_filter( 'bp_before_groups_post_update_parse_args', array( $this, 'bp_before_groups_post_update_parse_args' ) );
}

/**
* Filter content before processing in group activity.
* It adds the '&nbsp;' if content is empty, when we are only uploading media from activity.
*
* @param array $args Activity arguments.
*
* @return array
*/
public function bp_before_groups_post_update_parse_args( $args ) {
// if content is non-breaking space then set it to empty.
if ( isset( $args['content'] ) && '' === $args['content'] ) {

// Nonce verification is not required here as it is already done in previously.
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$args['content'] = '&nbsp;';
}
}

return $args;
}
}

0 comments on commit da73b7e

Please sign in to comment.