Created
September 9, 2019 10:51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Attach media with comments on a mediapress activity. | |
* | |
* @param int $comment_id comment id. | |
* @param array $r args. | |
* @param BP_Activity_Activity $activity activity object. | |
*/ | |
function mpp_custom_comment_posted( $comment_id, $r, $activity ) { | |
$comment = new BP_Activity_Activity( $comment_id ); | |
$parent_id = $comment->item_id; | |
$parent = new BP_Activity_Activity( $parent_id ); | |
if ( 'mpp_media_upload' !== $parent->type ) { | |
return; | |
} | |
$attached_ids = mpp_activity_get_attached_media_ids( $comment->item_id ); | |
if ( ! $attached_ids || count( $attached_ids ) > 1 ) { | |
return; | |
} | |
$media_id = current( $attached_ids ); | |
mpp_activity_update_media_id( $comment_id, $media_id ); | |
} | |
add_action( 'bp_activity_comment_posted', 'mpp_custom_comment_posted', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment