activitypub.php
63 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Compatibility functions for the ActivityPub plugin. |
| 4 | * |
| 5 | * @since 0.2.2 |
| 6 | * |
| 7 | * @package automattic/jetpack-image-cdn |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Image_CDN\Compatibility; |
| 11 | |
| 12 | use Automattic\Jetpack\Image_CDN\Image_CDN; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Hook the compatibility functions into ActivityPub filters if necessary. |
| 20 | * |
| 21 | * @since 0.2.2 |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | function load_activitypub_compat() { |
| 26 | if ( |
| 27 | /** |
| 28 | * Allow disabling Jetpack's image CDN for ActivityPub requests. |
| 29 | * |
| 30 | * @since 0.2.2 |
| 31 | * |
| 32 | * @param bool $should_disable_photon Should the CDN be disabled for that request. Default to false. |
| 33 | */ |
| 34 | apply_filters( 'jetpack_activitypub_post_disable_cdn', false ) |
| 35 | ) { |
| 36 | add_action( 'activitypub_get_image_pre', __NAMESPACE__ . '\disable_photon' ); |
| 37 | add_action( 'activitypub_get_image_post', __NAMESPACE__ . '\enable_photon' ); |
| 38 | } |
| 39 | } |
| 40 | add_action( 'plugins_loaded', __NAMESPACE__ . '\load_activitypub_compat' ); |
| 41 | |
| 42 | /** |
| 43 | * Disable Jetpack's Image CDN processing for this request. |
| 44 | * |
| 45 | * @see https://github.com/pfefferle/wordpress-activitypub/pull/309 |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | function disable_photon() { |
| 50 | remove_filter( 'image_downsize', array( Image_CDN::instance(), 'filter_image_downsize' ) ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Re-enable Jetpack's Image CDN processing after the request. |
| 55 | * |
| 56 | * @see https://github.com/pfefferle/wordpress-activitypub/pull/309 |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | function enable_photon() { |
| 61 | add_filter( 'image_downsize', array( Image_CDN::instance(), 'filter_image_downsize' ), 10, 3 ); |
| 62 | } |
| 63 |