Skip to content

Commit 7f9ed05

Browse files
committed
some small refactorings
1 parent 905867b commit 7f9ed05

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

includes/class-activitypub.php

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static function init() {
5454

5555
// Register several post_types.
5656
self::register_post_types();
57+
58+
self::register_oembed_providers();
5759
}
5860

5961
/**
@@ -584,4 +586,16 @@ public static function updated_postmeta( $meta_id, $object_id, $meta_key, $meta_
584586
\delete_post_meta( $object_id, 'activitypub_content_visibility' );
585587
}
586588
}
589+
590+
/**
591+
* Register some Mastodon oEmbed providers.
592+
*/
593+
public static function register_oembed_providers() {
594+
\wp_oembed_add_provider( '#https?://mastodon\.social/(@.+)/([0-9]+)#i', 'https://mastodon.social/api/oembed', true );
595+
\wp_oembed_add_provider( '#https?://mastodon\.online/(@.+)/([0-9]+)#i', 'https://mastodon.online/api/oembed', true );
596+
\wp_oembed_add_provider( '#https?://mastodon\.cloud/(@.+)/([0-9]+)#i', 'https://mastodon.cloud/api/oembed', true );
597+
\wp_oembed_add_provider( '#https?://mstdn\.social/(@.+)/([0-9]+)#i', 'https://mstdn.social/api/oembed', true );
598+
\wp_oembed_add_provider( '#https?://mastodon\.world/(@.+)/([0-9]+)#i', 'https://mastodon.world/api/oembed', true );
599+
\wp_oembed_add_provider( '#https?://mas\.to/(@.+)/([0-9]+)#i', 'https://mas.to/api/oembed', true );
600+
}
587601
}

includes/class-blocks.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Activitypub;
99

10-
use Activitypub\Collection\Followers;
1110
use Activitypub\Collection\Actors;
11+
use Activitypub\Collection\Followers;
1212

1313
/**
1414
* Block class.
@@ -339,14 +339,7 @@ public static function render_reply_block( $attrs ) {
339339
$html = '';
340340

341341
if ( ! empty( $attrs['url'] ) ) {
342-
wp_oembed_add_provider( '#https?://mastodon\.social/(@.+)/([0-9]+)#i', 'https://mastodon.social/api/oembed', true );
343-
344-
/**
345-
* Fires to add an oEmbed provider for the reply block.
346-
*/
347-
do_action( 'activitypub_reply_block_add_oembed_provider' );
348-
349-
$embed = wp_oembed_get( $attrs['url'] );
342+
$embed = embed_get( $attrs['url'] );
350343
if ( $embed ) {
351344
$html .= $embed;
352345
}

includes/functions.php

+16
Original file line numberDiff line numberDiff line change
@@ -1568,3 +1568,19 @@ function is_self_ping( $id ) {
15681568

15691569
return false;
15701570
}
1571+
1572+
/**
1573+
* Get the embed of a URL.
1574+
*
1575+
* This function supports oEmbed URLs, but it is planned to also
1576+
* support ActivityPub in the future.
1577+
*
1578+
* @todo Add ActivityPub support.
1579+
*
1580+
* @param string $url The URL to get the embed of.
1581+
*
1582+
* @return string|false The embed of the URL or false if not found.
1583+
*/
1584+
function embed_get( $url ) {
1585+
return wp_oembed_get( $url );
1586+
}

0 commit comments

Comments
 (0)