Merge pull request #132 from pfefferle/buddypress
Add basic BuddyPress support
This commit is contained in:
commit
a9aed5bc2d
3 changed files with 73 additions and 3 deletions
|
@ -106,3 +106,12 @@ function flush_rewrite_rules() {
|
||||||
}
|
}
|
||||||
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
|
\register_activation_hook( __FILE__, '\Activitypub\flush_rewrite_rules' );
|
||||||
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
|
\register_deactivation_hook( __FILE__, '\flush_rewrite_rules' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only load code that needs BuddyPress to run once BP is loaded and initialized.
|
||||||
|
*/
|
||||||
|
function enable_buddypress_features() {
|
||||||
|
require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php';
|
||||||
|
\Activitypub\Integration\Buddypress::init();
|
||||||
|
}
|
||||||
|
add_action( 'bp_include', '\Activitypub\enable_buddypress_features' );
|
||||||
|
|
58
integration/class-buddypress.php
Normal file
58
integration/class-buddypress.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
namespace Activitypub\Integration;
|
||||||
|
|
||||||
|
class Buddypress {
|
||||||
|
public static function init() {
|
||||||
|
\add_filter( 'activitypub_json_author_array', array( 'Activitypub\Integration\Buddypress', 'add_user_metadata' ), 11, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add_user_metadata( $object, $author_id ) {
|
||||||
|
$object->url = bp_core_get_user_domain( $author_id ); //add BP member profile URL as user URL
|
||||||
|
|
||||||
|
// add BuddyPress' cover_image instead of WordPress' header_image
|
||||||
|
$cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) );
|
||||||
|
|
||||||
|
if ( $cover_image_url ) {
|
||||||
|
$object->image = array(
|
||||||
|
'type' => 'Image',
|
||||||
|
'url' => $cover_image_url,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// change profile URL to BuddyPress' profile URL
|
||||||
|
$object->attachment['profile_url'] = array(
|
||||||
|
'type' => 'PropertyValue',
|
||||||
|
'name' => \__( 'Profile', 'activitypub' ),
|
||||||
|
'value' => \html_entity_decode(
|
||||||
|
'<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>',
|
||||||
|
\ENT_QUOTES,
|
||||||
|
'UTF-8'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// replace blog URL on multisite
|
||||||
|
if ( is_multisite() ) {
|
||||||
|
$user_blogs = get_blogs_of_user( $author_id ); //get sites of user to send as AP metadata
|
||||||
|
|
||||||
|
if ( ! empty( $user_blogs ) ) {
|
||||||
|
unset( $object->attachment['blog_url'] );
|
||||||
|
|
||||||
|
foreach ( $user_blogs as $blog ) {
|
||||||
|
if ( 1 !== $blog->userblog_id ) {
|
||||||
|
$object->attachment[] = array(
|
||||||
|
'type' => 'PropertyValue',
|
||||||
|
'name' => $blog->blogname,
|
||||||
|
'value' => \html_entity_decode(
|
||||||
|
'<a rel="me" title="' . \esc_attr( $blog->siteurl ) . '" target="_blank" href="' . $blog->siteurl . '">' . \wp_parse_url( $blog->siteurl, \PHP_URL_HOST ) . '</a>',
|
||||||
|
\ENT_QUOTES,
|
||||||
|
'UTF-8'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,7 +43,7 @@ $json->publicKey = array(
|
||||||
$json->tag = array();
|
$json->tag = array();
|
||||||
$json->attachment = array();
|
$json->attachment = array();
|
||||||
|
|
||||||
$json->attachment[] = array(
|
$json->attachment['blog_url'] = array(
|
||||||
'type' => 'PropertyValue',
|
'type' => 'PropertyValue',
|
||||||
'name' => \__( 'Blog', 'activitypub' ),
|
'name' => \__( 'Blog', 'activitypub' ),
|
||||||
'value' => \html_entity_decode(
|
'value' => \html_entity_decode(
|
||||||
|
@ -53,7 +53,7 @@ $json->attachment[] = array(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$json->attachment[] = array(
|
$json->attachment['profile_url'] = array(
|
||||||
'type' => 'PropertyValue',
|
'type' => 'PropertyValue',
|
||||||
'name' => \__( 'Profile', 'activitypub' ),
|
'name' => \__( 'Profile', 'activitypub' ),
|
||||||
'value' => \html_entity_decode(
|
'value' => \html_entity_decode(
|
||||||
|
@ -64,7 +64,7 @@ $json->attachment[] = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( \get_the_author_meta( 'user_url', $author_id ) ) {
|
if ( \get_the_author_meta( 'user_url', $author_id ) ) {
|
||||||
$json->attachment[] = array(
|
$json->attachment['user_url'] = array(
|
||||||
'type' => 'PropertyValue',
|
'type' => 'PropertyValue',
|
||||||
'name' => \__( 'Website', 'activitypub' ),
|
'name' => \__( 'Website', 'activitypub' ),
|
||||||
'value' => \html_entity_decode(
|
'value' => \html_entity_decode(
|
||||||
|
@ -84,6 +84,9 @@ $json->endpoints = array(
|
||||||
// filter output
|
// filter output
|
||||||
$json = \apply_filters( 'activitypub_json_author_array', $json, $author_id );
|
$json = \apply_filters( 'activitypub_json_author_array', $json, $author_id );
|
||||||
|
|
||||||
|
// migrate to ActivityPub standard
|
||||||
|
$json->attachment = array_values( $json->attachment );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
* Action triggerd prior to the ActivityPub profile being created and sent to the client
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue