Skip to content

Support for WP REST Cache #1630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions integration/class-wp-rest-cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* WP REST Cache integration file.
*
* @package Activitypub
*/

namespace Activitypub\Integration;

use Activitypub\Collection\Actors;

/**
* Compatibility with the WP REST Cache plugin
*
* @see https://wordpress.org/plugins/wp-rest-cache/
*/
class WP_Rest_Cache {
/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_filter( 'wp_rest_cache/allowed_endpoints', array( self::class, 'add_activitypub_endpoints' ) );
}

/**
* Add ActivityPub endpoints to the list of allowed endpoints.
*
* @param array $endpoints List of allowed endpoints.
*
* @return array
*/
public static function add_activitypub_endpoints( $endpoints ) {
$endpoints[ ACTIVITYPUB_REST_NAMESPACE ] = array( 'actors', 'users', 'posts' );

return $endpoints;
}
}
4 changes: 4 additions & 0 deletions integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ function ( $transformer, $data, $object_class ) {
if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) {
WPML::init();
}

if ( class_exists( 'WP_Rest_Cache_Plugin\Includes\Plugin' ) ) {
WP_Rest_Cache::init();
}
}
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );

Expand Down
Loading