Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/changelog/2973-from-description
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 16 additions & 1 deletion includes/class-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion includes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/tests/includes/class-test-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down