Skip to content

Commit 07ab03c

Browse files
authored
Refactor: Reorganize integration loader and Stream integration (#2383)
1 parent 08a0fd7 commit 07ab03c

File tree

6 files changed

+226
-148
lines changed

6 files changed

+226
-148
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Reorganize integration loader and move Stream integration into dedicated folder structure.

integration/load.php

Lines changed: 76 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
* Initialize the ActivityPub integrations.
1616
*/
1717
function plugin_init() {
18+
/**
19+
* Adds Akismet support.
20+
*
21+
* This class handles the compatibility with the Akismet plugin.
22+
*
23+
* @see https://wordpress.org/plugins/akismet/
24+
*/
25+
if ( \defined( 'AKISMET_VERSION' ) ) {
26+
Akismet::init();
27+
}
28+
1829
/**
1930
* Adds Classic Editor support.
2031
*
@@ -27,26 +38,6 @@ function plugin_init() {
2738
Classic_Editor::init();
2839
}
2940

30-
/**
31-
* Adds WebFinger (plugin) support.
32-
*
33-
* This class handles the compatibility with the WebFinger plugin
34-
* and coordinates the internal WebFinger implementation.
35-
*
36-
* @see https://wordpress.org/plugins/webfinger/
37-
*/
38-
Webfinger::init();
39-
40-
/**
41-
* Adds NodeInfo (plugin) support.
42-
*
43-
* This class handles the compatibility with the NodeInfo plugin
44-
* and coordinates the internal NodeInfo implementation.
45-
*
46-
* @see https://wordpress.org/plugins/nodeinfo/
47-
*/
48-
Nodeinfo::init();
49-
5041
/**
5142
* Adds Enable Mastodon Apps support.
5243
*
@@ -58,17 +49,6 @@ function plugin_init() {
5849
Enable_Mastodon_Apps::init();
5950
}
6051

61-
/**
62-
* Adds OpenGraph support.
63-
*
64-
* This class handles the compatibility with the OpenGraph plugin.
65-
*
66-
* @see https://wordpress.org/plugins/opengraph/
67-
*/
68-
if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) {
69-
Opengraph::init();
70-
}
71-
7252
/**
7353
* Adds Jetpack support.
7454
*
@@ -81,15 +61,13 @@ function plugin_init() {
8161
}
8262

8363
/**
84-
* Adds Akismet support.
64+
* Adds LiteSpeed Cache support.
8565
*
86-
* This class handles the compatibility with the Akismet plugin.
66+
* The check for whether LiteSpeed Cache is loaded and initialized happens inside Litespeed_Cache::init().
8767
*
88-
* @see https://wordpress.org/plugins/akismet/
68+
* @see https://wordpress.org/plugins/litespeed-cache/
8969
*/
90-
if ( \defined( 'AKISMET_VERSION' ) ) {
91-
Akismet::init();
92-
}
70+
Litespeed_Cache::init();
9371

9472
/**
9573
* Adds Multisite Language Switcher support.
@@ -102,6 +80,27 @@ function plugin_init() {
10280
Multisite_Language_Switcher::init();
10381
}
10482

83+
/**
84+
* Adds NodeInfo (plugin) support.
85+
*
86+
* This class handles the compatibility with the NodeInfo plugin
87+
* and coordinates the internal NodeInfo implementation.
88+
*
89+
* @see https://wordpress.org/plugins/nodeinfo/
90+
*/
91+
Nodeinfo::init();
92+
93+
/**
94+
* Adds OpenGraph support.
95+
*
96+
* This class handles the compatibility with the OpenGraph plugin.
97+
*
98+
* @see https://wordpress.org/plugins/opengraph/
99+
*/
100+
if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) {
101+
Opengraph::init();
102+
}
103+
105104
/**
106105
* Adds Seriously Simple Podcasting support.
107106
*
@@ -127,48 +126,65 @@ function ( $transformer, $data, $object_class ) {
127126
}
128127

129128
/**
130-
* Adds WPML Multilingual CMS (plugin) support.
129+
* Adds Stream support.
131130
*
132-
* This class handles the compatibility with the WPML plugin.
131+
* This class handles the compatibility with the Stream plugin.
133132
*
134-
* @see https://wpml.org/
133+
* @see https://wordpress.org/plugins/stream/
135134
*/
136-
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
137-
WPML::init();
138-
}
135+
Stream\Stream::init();
139136

140-
if ( \class_exists( 'WP_Rest_Cache_Plugin\Includes\Plugin' ) ) {
141-
WP_Rest_Cache::init();
142-
}
137+
/**
138+
* Adds Surge support.
139+
*
140+
* Only load code that needs Surge to run once Surge is loaded and initialized.
141+
*
142+
* @see https://wordpress.org/plugins/surge/
143+
*/
144+
Surge::init();
143145

144146
/**
145-
* Adds Yoast SEO support.
147+
* Adds WebFinger (plugin) support.
146148
*
147-
* This class handles the compatibility with Yoast SEO.
149+
* This class handles the compatibility with the WebFinger plugin
150+
* and coordinates the internal WebFinger implementation.
148151
*
149-
* @see https://wordpress.org/plugins/wordpress-seo/
152+
* @see https://wordpress.org/plugins/webfinger/
150153
*/
151-
if ( \defined( 'WPSEO_VERSION' ) ) {
152-
Yoast_Seo::init();
154+
Webfinger::init();
155+
156+
/**
157+
* Adds WP REST Cache support.
158+
*
159+
* This class handles the compatibility with the WP REST Cache plugin.
160+
*
161+
* @see https://wordpress.org/plugins/wp-rest-cache/
162+
*/
163+
if ( \class_exists( 'WP_Rest_Cache_Plugin\Includes\Plugin' ) ) {
164+
WP_Rest_Cache::init();
153165
}
154166

155167
/**
156-
* Load the Surge integration.
168+
* Adds WPML Multilingual CMS (plugin) support.
157169
*
158-
* Only load code that needs Surge to run once Surge is loaded and initialized.
170+
* This class handles the compatibility with the WPML plugin.
159171
*
160-
* @see https://wordpress.org/plugins/surge/
172+
* @see https://wpml.org/
161173
*/
162-
Surge::init();
174+
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
175+
WPML::init();
176+
}
163177

164178
/**
165-
* Load the LiteSpeed Cache integration.
179+
* Adds Yoast SEO support.
166180
*
167-
* The check for whether LiteSpeed Cache is loaded and initialized happens inside Litespeed_Cache::init().
181+
* This class handles the compatibility with Yoast SEO.
168182
*
169-
* @see https://wordpress.org/plugins/litespeed-cache/
183+
* @see https://wordpress.org/plugins/wordpress-seo/
170184
*/
171-
Litespeed_Cache::init();
185+
if ( \defined( 'WPSEO_VERSION' ) ) {
186+
Yoast_Seo::init();
187+
}
172188
}
173189
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
174190

@@ -180,43 +196,11 @@ function ( $transformer, $data, $object_class ) {
180196
\register_activation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'add_htaccess_rules' ) );
181197
\register_deactivation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'remove_htaccess_rules' ) );
182198

183-
184-
/**
185-
* Register the Stream Connector for ActivityPub.
186-
*
187-
* @param array $classes The Stream connectors.
188-
*
189-
* @return array The Stream connectors with the ActivityPub connector.
190-
*/
191-
function register_stream_connector( $classes ) {
192-
$class = new Stream_Connector();
193-
194-
if ( method_exists( $class, 'is_dependency_satisfied' ) && $class->is_dependency_satisfied() ) {
195-
$classes[] = $class;
196-
}
197-
198-
return $classes;
199-
}
200-
add_filter( 'wp_stream_connectors', __NAMESPACE__ . '\register_stream_connector' );
201-
202-
// Excluded ActivityPub post types from the Stream.
203-
add_filter(
204-
'wp_stream_posts_exclude_post_types',
205-
function ( $post_types ) {
206-
$post_types[] = 'ap_actor';
207-
$post_types[] = 'ap_extrafield';
208-
$post_types[] = 'ap_extrafield_blog';
209-
$post_types[] = 'ap_post';
210-
211-
return $post_types;
212-
}
213-
);
214-
215199
/**
216200
* Load the BuddyPress integration.
217201
*
218202
* Only load code that needs BuddyPress to run once BP is loaded and initialized.
219203
*
220204
* @see https://buddypress.org/
221205
*/
222-
add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 );
206+
\add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 );

integration/class-stream-connector.php renamed to integration/stream/class-connector.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @package Activitypub
66
*/
77

8-
namespace Activitypub\Integration;
8+
namespace Activitypub\Integration\Stream;
99

1010
use Activitypub\Collection\Actors;
1111

@@ -19,7 +19,7 @@
1919
*
2020
* @see https://wordpress.org/plugins/stream/
2121
*/
22-
class Stream_Connector extends \WP_Stream\Connector {
22+
class Connector extends \WP_Stream\Connector {
2323
/**
2424
* Connector slug.
2525
*
@@ -45,7 +45,7 @@ class Stream_Connector extends \WP_Stream\Connector {
4545
* @return string
4646
*/
4747
public function get_label() {
48-
return __( 'ActivityPub', 'activitypub' );
48+
return \__( 'ActivityPub', 'activitypub' );
4949
}
5050

5151
/**
@@ -64,7 +64,7 @@ public function get_context_labels() {
6464
*/
6565
public function get_action_labels() {
6666
return array(
67-
'processed' => __( 'Processed', 'activitypub' ),
67+
'processed' => \__( 'Processed', 'activitypub' ),
6868
);
6969
}
7070

@@ -80,25 +80,25 @@ public function get_action_labels() {
8080
*/
8181
public function action_links( $links, $record ) {
8282
if ( 'processed' === $record->action ) {
83-
$error = json_decode( $record->get_meta( 'error', true ), true );
83+
$error = \json_decode( $record->get_meta( 'error', true ), true );
8484

8585
if ( $error ) {
86-
$message = sprintf(
86+
$message = \sprintf(
8787
'<details><summary>%1$s</summary><pre>%2$s</pre></details>',
88-
__( 'Inbox Error', 'activitypub' ),
89-
wp_json_encode( $error )
88+
\__( 'Inbox Error', 'activitypub' ),
89+
\wp_json_encode( $error )
9090
);
9191

9292
$links[ $message ] = '';
9393
}
9494

95-
$debug = json_decode( $record->get_meta( 'debug', true ), true );
95+
$debug = \json_decode( $record->get_meta( 'debug', true ), true );
9696

9797
if ( $debug ) {
98-
$message = sprintf(
98+
$message = \sprintf(
9999
'<details><summary>%1$s</summary><pre>%2$s</pre></details>',
100-
__( 'Debug', 'activitypub' ),
101-
wp_json_encode( $debug )
100+
\__( 'Debug', 'activitypub' ),
101+
\wp_json_encode( $debug )
102102
);
103103

104104
$links[ $message ] = '';
@@ -149,13 +149,13 @@ public function callback_activitypub_outbox_processing_complete( $inboxes, $json
149149
$outbox_data = $this->prepare_outbox_data_for_response( $outbox_item );
150150

151151
$this->log(
152-
sprintf(
152+
\sprintf(
153153
// translators: %s is a URL.
154-
__( 'Outbox processing complete: %s', 'activitypub' ),
154+
\__( 'Outbox processing complete: %s', 'activitypub' ),
155155
$outbox_data['title']
156156
),
157157
array(
158-
'debug' => wp_json_encode(
158+
'debug' => \wp_json_encode(
159159
array(
160160
'actor_id' => $actor_id,
161161
'outbox_item_id' => $outbox_item_id,
@@ -183,13 +183,10 @@ public function callback_activitypub_outbox_processing_batch_complete( $inboxes,
183183
$outbox_data = $this->prepare_outbox_data_for_response( $outbox_item );
184184

185185
$this->log(
186-
sprintf(
187-
// translators: %s is a URL.
188-
__( 'Outbox processing batch complete: %s', 'activitypub' ),
189-
$outbox_data['title']
190-
),
186+
// translators: %s is a URL.
187+
\sprintf( \__( 'Outbox processing batch complete: %s', 'activitypub' ), $outbox_data['title'] ),
191188
array(
192-
'debug' => wp_json_encode(
189+
'debug' => \wp_json_encode(
193190
array(
194191
'actor_id' => $actor_id,
195192
'outbox_item_id' => $outbox_item_id,
@@ -216,17 +213,17 @@ protected function prepare_outbox_data_for_response( $outbox_item ) {
216213
$object_type = $outbox_item->post_type;
217214
$object_title = $outbox_item->post_title;
218215

219-
$post_id = url_to_postid( $outbox_item->post_title );
216+
$post_id = \url_to_postid( $outbox_item->post_title );
220217
if ( $post_id ) {
221-
$post = get_post( $post_id );
218+
$post = \get_post( $post_id );
222219

223220
$object_id = $post_id;
224221
$object_type = $post->post_type;
225222
$object_title = $post->post_title;
226223
} else {
227224
$comment_id = url_to_commentid( $outbox_item->post_title );
228225
if ( $comment_id ) {
229-
$comment = get_comment( $comment_id );
226+
$comment = \get_comment( $comment_id );
230227

231228
$object_id = $comment_id;
232229
$object_type = 'comments';
@@ -238,11 +235,11 @@ protected function prepare_outbox_data_for_response( $outbox_item ) {
238235
$object_type = 'profiles';
239236

240237
if ( $author_id ) {
241-
$object_title = get_userdata( $author_id )->display_name;
238+
$object_title = \get_userdata( $author_id )->display_name;
242239
} elseif ( Actors::BLOG_USER_ID === $author_id ) {
243-
$object_title = __( 'Blog User', 'activitypub' );
240+
$object_title = \__( 'Blog User', 'activitypub' );
244241
} elseif ( Actors::APPLICATION_USER_ID === $author_id ) {
245-
$object_title = __( 'Application User', 'activitypub' );
242+
$object_title = \__( 'Application User', 'activitypub' );
246243
}
247244
}
248245
}

0 commit comments

Comments
 (0)