diff --git a/.github/changelog/2973-from-description b/.github/changelog/2973-from-description new file mode 100644 index 000000000..d5f525f4e --- /dev/null +++ b/.github/changelog/2973-from-description @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +Add backwards compatibility for the `ACTIVITYPUB_DISABLE_SIDELOADING` constant and `activitypub_sideloading_enabled` filter from version 7.9.1. diff --git a/includes/class-cache.php b/includes/class-cache.php index 4e81fac5e..1bbaaeaad 100644 --- a/includes/class-cache.php +++ b/includes/class-cache.php @@ -42,7 +42,22 @@ public static function init() { */ public static function is_enabled() { // Check constant first. - if ( ACTIVITYPUB_DISABLE_MEDIA_CACHE ) { + if ( ACTIVITYPUB_DISABLE_REMOTE_CACHE ) { + return false; + } + + /** + * Filters whether sideloading is enabled. + * + * This filter was introduced in 7.9.1 and replaced by + * {@see 'activitypub_remote_cache_enabled'} in a subsequent release. + * + * @since 7.9.1 + * @deprecated unreleased Use {@see 'activitypub_remote_cache_enabled'} instead. + * + * @param bool $enabled Whether sideloading is enabled. Default true. + */ + if ( ! \apply_filters_deprecated( 'activitypub_sideloading_enabled', array( true ), 'unreleased', 'activitypub_remote_cache_enabled' ) ) { return false; } diff --git a/includes/constants.php b/includes/constants.php index 5c251d3d9..7a40b895b 100644 --- a/includes/constants.php +++ b/includes/constants.php @@ -20,7 +20,11 @@ defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false ); defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' ); defined( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE' ) || define( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE', 100 ); -defined( 'ACTIVITYPUB_DISABLE_MEDIA_CACHE' ) || define( 'ACTIVITYPUB_DISABLE_MEDIA_CACHE', false ); +// Backwards compatibility: map old ACTIVITYPUB_DISABLE_SIDELOADING to ACTIVITYPUB_DISABLE_REMOTE_CACHE. +if ( ! defined( 'ACTIVITYPUB_DISABLE_REMOTE_CACHE' ) && defined( 'ACTIVITYPUB_DISABLE_SIDELOADING' ) ) { + define( 'ACTIVITYPUB_DISABLE_REMOTE_CACHE', ACTIVITYPUB_DISABLE_SIDELOADING ); +} +defined( 'ACTIVITYPUB_DISABLE_REMOTE_CACHE' ) || define( 'ACTIVITYPUB_DISABLE_REMOTE_CACHE', false ); // The following constants are invariable and define values used throughout the plugin. diff --git a/readme.txt b/readme.txt index d814e222e..eff895694 100644 --- a/readme.txt +++ b/readme.txt @@ -89,6 +89,7 @@ The plugin uses PHP Constants to enable, disable or change its default behaviour * `ACTIVITYPUB_DISABLE_REWRITES` - Disable auto generation of `mod_rewrite` rules. Default: `false`. * `ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS` - Block incoming replies/comments/likes. Default: `false`. * `ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS` - Disable outgoing replies/comments/likes. Default: `false`. +* `ACTIVITYPUB_DISABLE_REMOTE_CACHE` - Disable remote media caching (avatars, media, emoji). Default: `false`. Replaces `ACTIVITYPUB_DISABLE_SIDELOADING` from 7.9.1. * `ACTIVITYPUB_SHARED_INBOX_FEATURE` - Enable the shared inbox. Default: `false`. * `ACTIVITYPUB_SEND_VARY_HEADER` - Enable to send the `Vary: Accept` header. Default: `false`. diff --git a/tests/phpunit/tests/includes/class-test-cache.php b/tests/phpunit/tests/includes/class-test-cache.php index 77abd74cb..c9fd278d1 100644 --- a/tests/phpunit/tests/includes/class-test-cache.php +++ b/tests/phpunit/tests/includes/class-test-cache.php @@ -36,6 +36,17 @@ public function test_is_enabled_filter() { $this->assertTrue( Cache::is_enabled() ); } + /** + * Test is_enabled respects deprecated sideloading filter. + */ + public function test_is_enabled_deprecated_sideloading_filter() { + $this->setExpectedDeprecated( 'activitypub_sideloading_enabled' ); + + add_filter( 'activitypub_sideloading_enabled', '__return_false' ); + $this->assertFalse( Cache::is_enabled() ); + remove_filter( 'activitypub_sideloading_enabled', '__return_false' ); + } + /** * Test init does not run when disabled. */