// Make sure Activitypub services embed videos // plugin will skip embedding videos if it detects a feat. image // @param obj $ap_obj An object array of the post for Activitypub to use add_filter('activitypub_activity_object_array', function($ap_obj){ // The "id" key is actually the URL/permalink of the post, not the post ID. // Get post ID from the permalink $post_id = url_to_postid($ap_obj['id']); // Check if a #video micropost if (has_tag('video', $post_id) && has_category('microblog', $post_id)) { // Remove any media attachments $ap_obj['attachment'] = []; } return $ap_obj; }, 100);
This code assumes you categorize and tag your posts the same way I do (“Microblog” for as the category, and “video” for tag). You might want to change it to fit your own system.
Change this line: if (has_tag('video', $post_id) && has_category('microblog', $post_id)) {
The Activitypub Object Array?
The filter activitypub_activity_object_array
is used to modify the object array of the post. This is completely different from WP_Post. You can see the object array of each post by appending /activitypub to a post. Ex. https://giantpaper.org/microblog/10766/200-kids-sing-civilization-theme/activitypub/
(source)
Background
I have a lot of “video” type posts, where the main content is a single video. If the post contains a “post thumbnail”, the Activitypub plugin automatically considers it media (along with any other images you might have added).
In video posts, this is usually the poster image/thumbnail/preview image of the video. Which would be great, EXCEPT I want the video itself (as in, actually embedded) to be the main feature, not the video thumbnail. The above code removes the featured image from the media array, so the video gets embedded instead.