Merge pull request #328 from Automattic/add/activitypub-conditional
Compat: introduce a conditional to detect ActivityPub requests
This commit is contained in:
commit
bc7129ec55
2 changed files with 45 additions and 0 deletions
|
@ -228,3 +228,47 @@ function is_tombstone( $wp_error ) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a request is for an ActivityPub request.
|
||||||
|
*
|
||||||
|
* @return bool False by default.
|
||||||
|
*/
|
||||||
|
function is_activitypub_request() {
|
||||||
|
global $wp_query;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ActivityPub requests are currently only made for
|
||||||
|
* author archives, singular posts, and the homepage.
|
||||||
|
*/
|
||||||
|
if ( ! \is_author() && ! \is_singular() && ! \is_home() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// One can trigger an ActivityPub request by adding ?activitypub to the URL.
|
||||||
|
global $wp_query;
|
||||||
|
if ( isset( $wp_query->query_vars['activitypub'] ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The other (more common) option to make an ActivityPub request
|
||||||
|
* is to send an Accept header.
|
||||||
|
*/
|
||||||
|
if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
|
||||||
|
$accept = $_SERVER['HTTP_ACCEPT'];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $accept can be a single value, or a comma separated list of values.
|
||||||
|
* We want to support both scenarios,
|
||||||
|
* and return true when the header includes at least one of the following:
|
||||||
|
* - application/activity+json
|
||||||
|
* - application/ld+json
|
||||||
|
*/
|
||||||
|
if ( preg_match( '/(application\/(ld\+json|activity\+json))/', $accept ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
|
||||||
|
|
||||||
= Next =
|
= Next =
|
||||||
|
|
||||||
|
* Compatibility: add a new conditional, `\Activitypub\is_activitypub_request()`, to allow third-party plugins to detect ActivityPub requests.
|
||||||
* Compatibility: add hooks to allow modifying images returned in ActivityPub requests.
|
* Compatibility: add hooks to allow modifying images returned in ActivityPub requests.
|
||||||
* Compatibility: indicate that the plugin is compatible and has been tested with the latest version of WordPress, 6.2.
|
* Compatibility: indicate that the plugin is compatible and has been tested with the latest version of WordPress, 6.2.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue