@@ -267,50 +267,41 @@ protected function get_request_url() {
267267 * @return bool True if the request is an ActivityPub request, false otherwise.
268268 */
269269 public function is_activitypub_request () {
270- if ( isset ( $ this ->is_activitypub_request ) ) {
271- return $ this ->is_activitypub_request ;
272- }
273-
274- global $ wp_query ;
270+ if ( ! isset ( $ this ->is_activitypub_request ) ) {
271+ global $ wp_query ;
275272
276- // One can trigger an ActivityPub request by adding `?activitypub` to the URL.
277- if (
278- isset ( $ wp_query ->query_vars ['activitypub ' ] ) ||
279- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
280- isset ( $ _GET ['activitypub ' ] )
281- ) {
282- \defined ( 'ACTIVITYPUB_REQUEST ' ) || \define ( 'ACTIVITYPUB_REQUEST ' , true );
283- $ this ->is_activitypub_request = true ;
273+ $ this ->is_activitypub_request = false ;
284274
285- return true ;
286- }
287-
288- /*
289- * The other (more common) option to make an ActivityPub request
290- * is to send an Accept header.
291- */
292- if ( isset ( $ _SERVER ['HTTP_ACCEPT ' ] ) ) {
293- $ accept = \sanitize_text_field ( \wp_unslash ( $ _SERVER ['HTTP_ACCEPT ' ] ) );
294-
295- /*
296- * $accept can be a single value, or a comma separated list of values.
297- * We want to support both scenarios,
298- * and return true when the header includes at least one of the following:
299- * - application/activity+json
300- * - application/ld+json
301- * - application/json
302- */
303- if ( \preg_match ( '/(application\/(ld\+json|activity\+json|json))/i ' , $ accept ) ) {
275+ // One can trigger an ActivityPub request by adding `?activitypub` to the URL.
276+ if ( isset ( $ wp_query ->query_vars ['activitypub ' ] ) || isset ( $ _GET ['activitypub ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
304277 \defined ( 'ACTIVITYPUB_REQUEST ' ) || \define ( 'ACTIVITYPUB_REQUEST ' , true );
305278 $ this ->is_activitypub_request = true ;
306279
307- return true ;
280+ // The other (more common) option to make an ActivityPub request is to send an Accept header.
281+ } elseif ( isset ( $ _SERVER ['HTTP_ACCEPT ' ] ) ) {
282+ $ accept = \sanitize_text_field ( \wp_unslash ( $ _SERVER ['HTTP_ACCEPT ' ] ) );
283+
284+ /*
285+ * $accept can be a single value, or a comma separated list of values.
286+ * We want to support both scenarios,
287+ * and return true when the header includes at least one of the following:
288+ * - application/activity+json
289+ * - application/ld+json
290+ * - application/json
291+ */
292+ if ( \preg_match ( '/(application\/(ld\+json|activity\+json|json))/i ' , $ accept ) ) {
293+ \defined ( 'ACTIVITYPUB_REQUEST ' ) || \define ( 'ACTIVITYPUB_REQUEST ' , true );
294+ $ this ->is_activitypub_request = true ;
295+ }
308296 }
309297 }
310298
311- $ this ->is_activitypub_request = false ;
312-
313- return false ;
299+ /**
300+ * Filters whether the current request is an ActivityPub request.
301+ *
302+ * @param bool $is_activitypub_request True if the request is an ActivityPub request, false otherwise.
303+ */
304+ return \apply_filters ( 'activitypub_is_activitypub_request ' , $ this ->is_activitypub_request );
314305 }
315306
316307 /**
0 commit comments