Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
37.50% covered (danger)
37.50%
3 / 8
33.33% covered (danger)
33.33%
1 / 3
CRAP
n/a
0 / 0
Automattic\Jetpack\Image_CDN\Compatibility\load_activitypub_compat
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
Automattic\Jetpack\Image_CDN\Compatibility\disable_photon
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack\Image_CDN\Compatibility\enable_photon
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
10namespace Automattic\Jetpack\Image_CDN\Compatibility;
11
12use Automattic\Jetpack\Image_CDN\Image_CDN;
13
14if ( ! 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 */
25function 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}
40add_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 */
49function 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 */
60function enable_photon() {
61    add_filter( 'image_downsize', array( Image_CDN::instance(), 'filter_image_downsize' ), 10, 3 );
62}