Skip to content

Commit 30b939b

Browse files
committed
show avatars
1 parent fd7ccb5 commit 30b939b

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Tags:** OStatus, fediverse, activitypub, activitystream
55
**Requires at least:** 4.7
66
**Tested up to:** 5.1
7-
**Stable tag:** 0.4.3
7+
**Stable tag:** 0.4.4
88
**Requires PHP:** 5.6
99
**License:** MIT
1010
**License URI:** http://opensource.org/licenses/MIT
@@ -55,6 +55,10 @@ To implement:
5555

5656
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
5757

58+
### 0.4.4 ###
59+
60+
* show avatars
61+
5862
### 0.4.3 ###
5963

6064
* finally fixed backlink in excerpt/summary posts

activitypub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: ActivityPub
44
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
55
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
6-
* Version: 0.4.3
6+
* Version: 0.4.4
77
* Author: Matthias Pfefferle
88
* Author URI: https://notiz.blog/
99
* License: MIT
@@ -31,6 +31,7 @@ function activitypub_init() {
3131
add_filter( 'template_include', array( 'Activitypub', 'render_json_template' ), 99 );
3232
add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) );
3333
add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) );
34+
add_filter( 'pre_get_avatar_data', array( 'Activitypub', 'pre_get_avatar_data' ), 11, 2 );
3435

3536
// Configure the REST API route
3637
require_once dirname( __FILE__ ) . '/includes/class-rest-activitypub-outbox.php';

includes/class-activitypub.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,58 @@ public static function schedule_post_activity( $new_status, $old_status, $post )
8383
wp_schedule_single_event( time() + wp_rand( 0, 120 ), 'activitypub_send_update_activity', array( $post->ID ) );
8484
}
8585
}
86+
87+
/**
88+
* Replaces the default avatar
89+
*
90+
* @param array $args Arguments passed to get_avatar_data(), after processing.
91+
* @param int|string|object $id_or_email A user ID, email address, or comment object
92+
*
93+
* @return array $args
94+
*/
95+
public static function pre_get_avatar_data( $args, $id_or_email ) {
96+
if ( ! $id_or_email instanceof WP_Comment ||
97+
! isset( $id_or_email->comment_type ) ||
98+
$id_or_email->user_id ) {
99+
return $args;
100+
}
101+
102+
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
103+
if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types, true ) ) {
104+
$args['url'] = false;
105+
/** This filter is documented in wp-includes/link-template.php */
106+
return apply_filters( 'get_avatar_data', $args, $id_or_email );
107+
}
108+
109+
// check if comment has an avatar
110+
$avatar = self::get_avatar_url( $id_or_email->comment_ID );
111+
112+
if ( $avatar ) {
113+
if ( ! isset( $args['class'] ) || ! is_array( $args['class'] ) ) {
114+
$args['class'] = array( 'u-photo' );
115+
} else {
116+
$args['class'][] = 'u-photo';
117+
$args['class'] = array_unique( $args['class'] );
118+
}
119+
$args['url'] = $avatar;
120+
$args['class'][] = 'avatar-activitypub';
121+
}
122+
123+
return $args;
124+
}
125+
126+
/**
127+
* Function to retrieve Avatar URL if stored in meta
128+
*
129+
*
130+
* @param int|WP_Comment $comment
131+
*
132+
* @return string $url
133+
*/
134+
public static function get_avatar_url( $comment ) {
135+
if ( is_numeric( $comment ) ) {
136+
$comment = get_comment( $comment );
137+
}
138+
return get_comment_meta( $comment->comment_ID, 'avatar_url', true );
139+
}
86140
}

languages/activitypub.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ msgid ""
44
msgstr ""
55
"Project-Id-Version: ActivityPub 0.4.3\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
7-
"POT-Creation-Date: 2019-02-20 19:25:09+00:00\n"
7+
"POT-Creation-Date: 2019-02-20 20:05:05+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/
44
Tags: OStatus, fediverse, activitypub, activitystream
55
Requires at least: 4.7
66
Tested up to: 5.1
7-
Stable tag: 0.4.3
7+
Stable tag: 0.4.4
88
Requires PHP: 5.6
99
License: MIT
1010
License URI: http://opensource.org/licenses/MIT
@@ -55,6 +55,10 @@ To implement:
5555

5656
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
5757

58+
= 0.4.4 =
59+
60+
* show avatars
61+
5862
= 0.4.3 =
5963

6064
* finally fixed backlink in excerpt/summary posts

0 commit comments

Comments
 (0)