bp_activity_create_parent_media_activity( $media_ids )

Create main activity for the media uploaded and saved.

Description

Parameters

$media_ids

(Required)

Return

(mixed)

Source

File: bp-activity/bp-activity-filters.php

1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
function bp_activity_create_parent_media_activity( $media_ids ) {
    global $bp_media_upload_count;
 
    if ( ! empty( $media_ids ) && ! isset( $_POST['bp_activity_update'] ) ) {
 
        $added_media_ids = $media_ids;
        $content         = false;
 
        if ( ! empty( $_POST['content'] ) ) {
 
            /**
             * Filters the content provided in the activity input field.
             *
             * @param string $value Activity message being posted.
             *
             * @since BuddyPress 1.2.0
             *
             */
            $content = apply_filters( 'bp_activity_post_update_content', $_POST['content'] );
        }
 
        $group_id = FILTER_INPUT( INPUT_POST, 'group_id', FILTER_SANITIZE_NUMBER_INT );
        $album_id = false;
 
        if ( bp_is_active( 'groups' ) && ! empty( $group_id ) && $group_id > 0 ) {
            $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $group_id ) );
        } else {
            $activity_id = bp_activity_post_update( array( 'content' => $content ) );
        }
 
        //save media meta for activity
        if ( ! empty( $activity_id ) ) {
            $privacy = 'public';
 
            foreach ( (array) $added_media_ids as $media_id ) {
                $media = new BP_Media( $media_id );
 
                // get one of the media's privacy for the activity privacy
                $privacy = $media->privacy;
 
                // get media album id
                if ( ! empty( $media->album_id ) ) {
                    $album_id = $media->album_id;
                }
 
                if ( 1 === $bp_media_upload_count ) {
                    //save media activity id in media
                    $media->activity_id = $activity_id;
                    $media->save();
                }
 
                //save parent activity id in attachment meta
                update_post_meta( $media->attachment_id, 'bp_media_parent_activity_id', $activity_id );
            }
 
            bp_activity_update_meta( $activity_id, 'bp_media_ids', implode( ',', $added_media_ids ) );
 
            // if media is from album then save album id in activity media
            if ( ! empty( $album_id ) ) {
                bp_activity_update_meta( $activity_id, 'bp_media_album_activity', $album_id );
            }
 
            if ( empty( $group_id ) ) {
                $main_activity = new BP_Activity_Activity( $activity_id );
                if ( ! empty( $main_activity ) ) {
                    $main_activity->privacy = $privacy;
                    $main_activity->save();
                }
            }
        }
    }
 
    return $media_ids;
}

Changelog

Changelog
Version Description
BuddyBoss 1.2.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.