bp_activity_edit_update_media( $media_ids )
Update media and activity for media updation and deletion while editing the activity.
Description
Parameters
- $media_ids
-
(Required)
Return
(mixed)
Source
File: bp-activity/bp-activity-filters.php
function bp_activity_edit_update_media( $media_ids ) { global $bp_activity_edit, $bp_activity_post_update_id; if ( ( true === $bp_activity_edit || isset( $_POST['edit'] ) ) && ! empty( $bp_activity_post_update_id ) ) { $old_media_ids = bp_activity_get_meta( $bp_activity_post_update_id, 'bp_media_ids', true ); $old_media_ids = explode( ',', $old_media_ids ); if ( ! empty( $old_media_ids ) ) { // old media count 1 and new media uploaded count is greater than 1. if ( 1 === count( $old_media_ids ) && 1 < count( $media_ids ) ) { $old_media_id = $old_media_ids[0]; // check if old media id is in new media uploaded. if ( in_array( $old_media_id, $media_ids ) ) { // Create new media activity for old media because it has only parent activity to show right now. $old_media = new BP_Media( $old_media_id ); $args = array( 'hide_sitewide' => true, 'privacy' => 'media' ); if ( ! empty( $old_media->group_id ) && bp_is_active( 'groups' ) ) { $args['item_id'] = $old_media->group_id; $args['type'] = 'activity_update'; $current_group = groups_get_group( $old_media->group_id ); $args['action'] = sprintf( __( '%1$s posted an update in the group %2$s', 'buddyboss' ), bp_core_get_userlink( $old_media->user_id ), '<a href="' . bp_get_group_permalink( $current_group ) . '">' . esc_attr( $current_group->name ) . '</a>' ); $activity_id = groups_record_activity( $args ); } else { $activity_id = bp_activity_post_update( $args ); } // media activity for old media is created and it is being assigned to the old media. // And media activity is being saved with needed data to figure out everything for it. if ( $activity_id ) { $old_media->activity_id = $activity_id; $old_media->save(); $media_activity = new BP_Activity_Activity( $activity_id ); $media_activity->secondary_item_id = $bp_activity_post_update_id; $media_activity->save(); // update activity meta to tell it is media activity. bp_activity_update_meta( $activity_id, 'bp_media_activity', '1' ); // save attachment meta for activity. update_post_meta( $old_media->attachment_id, 'bp_media_activity_id', $activity_id ); //save parent activity id in attachment meta. update_post_meta( $old_media->attachment_id, 'bp_media_parent_activity_id', $bp_activity_post_update_id ); } } // old media count is greater than 1 and new media uploaded count is only 1 now. } else if ( 1 < count( $old_media_ids ) && 1 === count( $media_ids ) ) { $new_media_id = $media_ids[0]; // check if new media is in old media uploaded, if yes then delete that media's media activity first. if ( in_array( $new_media_id, $old_media_ids ) ) { $new_media = new BP_Media( $new_media_id ); $media_activity_id = $new_media->activity_id; // delete media's assigned media activity. remove_action( 'bp_activity_after_delete', 'bp_media_delete_activity_media' ); bp_activity_delete( array( 'id' => $media_activity_id ) ); add_action( 'bp_activity_after_delete', 'bp_media_delete_activity_media' ); //save parent activity id in media. $new_media->activity_id = $bp_activity_post_update_id; $new_media->save(); //save parent activity id in attachment meta. update_post_meta( $new_media->attachment_id, 'bp_media_parent_activity_id', $bp_activity_post_update_id ); } } } } return $media_ids; }
Changelog
Version | Description |
---|---|
BuddyBoss 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.