Skip to content

Commit

Permalink
Unhook the parser included with ActivityPub 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 30, 2022
1 parent c9d946f commit a6556f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ function( $m ) use ( &$protected_tags ) {

public function replace_with_links( $result ) {
$users = $this->get_possible_mentions();
if ( isset( $users[ $result[0] ] ) ) {
if ( class_exists( '\\Activitypub\\Mention' ) && isset( $users[ $result[0] ] ) ) {
return \Activitypub\Mention::replace_with_links( array( $users[ $result[0] ] ) );
}

Expand Down
17 changes: 12 additions & 5 deletions friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,23 @@ function( Feed $friends_feed ) {
add_action(
'friends_load_parsers',
function( \Friends\Feed $friends_feed ) {
if ( class_exists( 'Friends_Feed_Parser_ActivityPub' ) ) {
// Was included in ActivityPub 0.14.
return;
}

if ( ! class_exists( '\Activitypub\Activitypub' ) ) {
// ActivityPub plugin not active.
return;
}

global $wp_filter;
if ( isset( $wp_filter['friends_load_parsers']->callbacks[10] ) && class_exists( '\\ReflectionFunction' ) ) {
// Unhook the parser from ActivityPub 0.14.
foreach ( $wp_filter['friends_load_parsers']->callbacks[10] as $key => $hook ) {
$r = new \ReflectionFunction( $hook['function'] );
if ( \str_ends_with( $r->getFileName(), 'activitypub.php' ) ) {
remove_filter( 'friends_load_parsers', $hook['function'], 10 );
break;
}
}
}

require_once __DIR__ . '/feed-parsers/class-feed-parser-activitypub.php';
$friends_feed->register_parser( Feed_Parser_ActivityPub::SLUG, new Feed_Parser_ActivityPub( $friends_feed ) );
},
Expand Down

0 comments on commit a6556f1

Please sign in to comment.