show avatars

This commit is contained in:
Matthias Pfefferle 2019-02-20 21:05:29 +01:00
parent fd7ccb5b42
commit 30b939b5a1
5 changed files with 67 additions and 4 deletions

View file

@ -4,7 +4,7 @@
**Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7
**Tested up to:** 5.1
**Stable tag:** 0.4.3
**Stable tag:** 0.4.4
**Requires PHP:** 5.6
**License:** MIT
**License URI:** http://opensource.org/licenses/MIT
@ -55,6 +55,10 @@ To implement:
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
### 0.4.4 ###
* show avatars
### 0.4.3 ###
* finally fixed backlink in excerpt/summary posts

View file

@ -3,7 +3,7 @@
* Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
* Version: 0.4.3
* Version: 0.4.4
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
@ -31,6 +31,7 @@ function activitypub_init() {
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 );
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) );
add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) );
add_filter( 'pre_get_avatar_data', array( 'Activitypub', 'pre_get_avatar_data' ), 11, 2 );
// Configure the REST API route
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';

View file

@ -83,4 +83,58 @@ class Activitypub {
wp_schedule_single_event( time() + wp_rand( 0, 120 ), 'activitypub_send_update_activity', array( $post->ID ) );
}
}
/**
* Replaces the default avatar
*
* @param array $args Arguments passed to get_avatar_data(), after processing.
* @param int|string|object $id_or_email A user ID, email address, or comment object
*
* @return array $args
*/
public static function pre_get_avatar_data( $args, $id_or_email ) {
if ( ! $id_or_email instanceof WP_Comment ||
! isset( $id_or_email->comment_type ) ||
$id_or_email->user_id ) {
return $args;
}
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types, true ) ) {
$args['url'] = false;
/** This filter is documented in wp-includes/link-template.php */
return apply_filters( 'get_avatar_data', $args, $id_or_email );
}
// check if comment has an avatar
$avatar = self::get_avatar_url( $id_or_email->comment_ID );
if ( $avatar ) {
if ( ! isset( $args['class'] ) || ! is_array( $args['class'] ) ) {
$args['class'] = array( 'u-photo' );
} else {
$args['class'][] = 'u-photo';
$args['class'] = array_unique( $args['class'] );
}
$args['url'] = $avatar;
$args['class'][] = 'avatar-activitypub';
}
return $args;
}
/**
* Function to retrieve Avatar URL if stored in meta
*
*
* @param int|WP_Comment $comment
*
* @return string $url
*/
public static function get_avatar_url( $comment ) {
if ( is_numeric( $comment ) ) {
$comment = get_comment( $comment );
}
return get_comment_meta( $comment->comment_ID, 'avatar_url', true );
}
}

View file

@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ActivityPub 0.4.3\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
"POT-Creation-Date: 2019-02-20 19:25:09+00:00\n"
"POT-Creation-Date: 2019-02-20 20:05:05+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

View file

@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
Tags: OStatus, fediverse, activitypub, activitystream
Requires at least: 4.7
Tested up to: 5.1
Stable tag: 0.4.3
Stable tag: 0.4.4
Requires PHP: 5.6
License: MIT
License URI: http://opensource.org/licenses/MIT
@ -55,6 +55,10 @@ To implement:
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
= 0.4.4 =
* show avatars
= 0.4.3 =
* finally fixed backlink in excerpt/summary posts