| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cache class. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub; |
| 9 |
|
| 10 |
use Activitypub\Cache\Avatar; |
| 11 |
use Activitypub\Cache\Emoji; |
| 12 |
use Activitypub\Cache\Media; |
| 13 |
|
| 14 |
/** |
| 15 |
* Cache orchestrator class. |
| 16 |
* |
| 17 |
* Manages registration and initialization of remote media cache handlers. |
| 18 |
* Each cache type (Avatar, Media, Emoji) handles specific remote media caching |
| 19 |
* needs for ActivityPub content. |
| 20 |
* |
| 21 |
* Cache types can be disabled globally via constant or filter, or individually |
| 22 |
* via type-specific filters. |
| 23 |
* |
| 24 |
* @since 5.6.0 |
| 25 |
*/ |
| 26 |
class Cache { |
| 27 |
/** |
| 28 |
* Initialize the class, registering WordPress hooks. |
| 29 |
*/ |
| 30 |
public static function init() { |
| 31 |
if ( ! self::is_enabled() ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
self::register_caches(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Check if remote caching is enabled globally. |
| 40 |
* |
| 41 |
* @return bool True if caching is enabled, false otherwise. |
| 42 |
*/ |
| 43 |
public static function is_enabled() { |
| 44 |
// Check constant first. |
| 45 |
if ( ACTIVITYPUB_DISABLE_REMOTE_CACHE ) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Filters whether sideloading is enabled. |
| 51 |
* |
| 52 |
* This filter was introduced in 7.9.1 and replaced by |
| 53 |
* {@see 'activitypub_remote_cache_enabled'} in a subsequent release. |
| 54 |
* |
| 55 |
* @since 7.9.1 |
| 56 |
* @deprecated 8.0.0 Use {@see 'activitypub_remote_cache_enabled'} instead. |
| 57 |
* |
| 58 |
* @param bool $enabled Whether sideloading is enabled. Default true. |
| 59 |
*/ |
| 60 |
if ( ! \apply_filters_deprecated( 'activitypub_sideloading_enabled', array( true ), '8.0.0', 'activitypub_remote_cache_enabled' ) ) { |
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Filters whether remote media caching is enabled. |
| 66 |
* |
| 67 |
* @since 5.6.0 |
| 68 |
* |
| 69 |
* @param bool $enabled Whether caching is enabled. Default true. |
| 70 |
*/ |
| 71 |
return (bool) \apply_filters( 'activitypub_remote_cache_enabled', true ); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Register all cache handlers. |
| 76 |
*/ |
| 77 |
public static function register_caches() { |
| 78 |
Avatar::init(); |
| 79 |
Media::init(); |
| 80 |
Emoji::init(); |
| 81 |
|
| 82 |
/** |
| 83 |
* Fires after all built-in cache handlers are registered. |
| 84 |
* |
| 85 |
* Use this hook to register additional cache handlers. |
| 86 |
* |
| 87 |
* @since 5.6.0 |
| 88 |
*/ |
| 89 |
\do_action( 'activitypub_register_caches' ); |
| 90 |
} |
| 91 |
} |
| 92 |
|