|
| 1 | +<?php |
| 2 | +namespace Activitypub\Integration; |
| 3 | + |
| 4 | +class Buddypress { |
| 5 | + public static function init() { |
| 6 | + \add_filter( 'activitypub_json_author_array', array( 'Activitypub\Integration\Buddypress', 'add_user_metadata' ), 11, 2 ); |
| 7 | + } |
| 8 | + |
| 9 | + public static function add_user_metadata( $object, $author_id ) { |
| 10 | + $object->url = bp_core_get_user_domain( $author_id ); //add BP member profile URL as user URL |
| 11 | + |
| 12 | + // add BuddyPress' cover_image instead of WordPress' header_image |
| 13 | + $cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) ); |
| 14 | + |
| 15 | + if ( $cover_image_url ) { |
| 16 | + $object->image = array( |
| 17 | + 'type' => 'Image', |
| 18 | + 'url' => $cover_image_url, |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + // change profile URL to BuddyPress' profile URL |
| 23 | + $object->attachment['profile_url'] = array( |
| 24 | + 'type' => 'PropertyValue', |
| 25 | + 'name' => \__( 'Profile', 'activitypub' ), |
| 26 | + 'value' => \html_entity_decode( |
| 27 | + '<a rel="me" title="' . \esc_attr( bp_core_get_user_domain( $author_id ) ) . '" target="_blank" href="' . \bp_core_get_user_domain( $author_id ) . '">' . \wp_parse_url( \bp_core_get_user_domain( $author_id ), \PHP_URL_HOST ) . '</a>', |
| 28 | + \ENT_QUOTES, |
| 29 | + 'UTF-8' |
| 30 | + ), |
| 31 | + ); |
| 32 | + |
| 33 | + // replace blog URL on multisite |
| 34 | + if ( is_multisite() ) { |
| 35 | + $user_blogs = get_blogs_of_user( $author_id ); //get sites of user to send as AP metadata |
| 36 | + |
| 37 | + if ( ! empty( $user_blogs ) ) { |
| 38 | + unset( $object->attachment['blog_url'] ); |
| 39 | + |
| 40 | + foreach ( $user_blogs as $blog ) { |
| 41 | + if ( 1 !== $blog->userblog_id ) { |
| 42 | + $object->attachment[] = array( |
| 43 | + 'type' => 'PropertyValue', |
| 44 | + 'name' => $blog->blogname, |
| 45 | + 'value' => \html_entity_decode( |
| 46 | + '<a rel="me" title="' . \esc_attr( $blog->siteurl ) . '" target="_blank" href="' . $blog->siteurl . '">' . \wp_parse_url( $blog->siteurl, \PHP_URL_HOST ) . '</a>', |
| 47 | + \ENT_QUOTES, |
| 48 | + 'UTF-8' |
| 49 | + ), |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + return $object; |
| 57 | + } |
| 58 | +} |
0 commit comments