PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-image-cdn / src / compatibility / photon.php

photon.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at jetpack_vendor/automattic/jetpack-image-cdn/src/compatibility/photon.php

54 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Compatibility for Photon
4 *
5 * Replace photon with image-cdn.
6 *
7 * @package automattic/jetpack-image-cdn
8 */
9
10 namespace Automattic\Jetpack\Image_CDN\Compatibility;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit( 0 );
14 }
15
16 /**
17 * Disable the unpackaged photon version living in Jetpack.
18 *
19 * Before the package, Jetpack had the photon functionality within the plugin. To avoid double
20 * activation, we need to disable the photon functionality in Jetpack to avoid potential conflicts.
21 *
22 * If this package is installed via a different plugin, e.g. Boost, Image CDN should be served instead
23 * of the photon module in Jetpack.
24 */
25 function jetpack_image_cdn_photon_compat() {
26 /*
27 * Photon used have different functions names. They are later replaced by methods in
28 * Image_CDN_Core class. And the filters are now handled by the Image_CDN_Core class itself.
29 */
30 remove_filter( 'jetpack_photon_url', 'jetpack_photon_url', 10 );
31 remove_filter( 'jetpack_photon_pre_args', 'jetpack_photon_parse_wpcom_query_args', 10 );
32 remove_filter( 'jetpack_photon_skip_for_url', 'jetpack_photon_banned_domains', 9 );
33 remove_filter( 'widget_text', 'jetpack_photon_support_text_widgets' );
34
35 /*
36 * If photon is active in an old version of Jetpack which is using the unpackaged photon
37 * fake loading the module in Jetpack itself. This will prevent jetpack from loading
38 * the photon module, and we will use the image CDN package instead.
39 *
40 * When this is happening, the package is likely being loaded from a different plugin, e.g. Boost.
41 */
42 if ( class_exists( 'Jetpack' ) && defined( 'JETPACK__VERSION' ) && ( version_compare( JETPACK__VERSION, '12.1', '<=' ) ) ) {
43 do_action( 'jetpack_module_loaded_photon' );
44 }
45 }
46
47 /*
48 * Remove the hooks that Jetpack uses to load photon and pretend that the module is already loaded.
49 *
50 * Jetpack hooks the filters as it loads. So, we can remove the filters when `plugins_loaded` fires.
51 * This would make sure Jetpack has already loaded and hooked the filters.
52 */
53 add_action( 'plugins_loaded', __NAMESPACE__ . '\jetpack_image_cdn_photon_compat' );
54