abilities
1 week ago
class-deprecate.php
8 months ago
class-jetpack-crm-data.php
2 years ago
class-jetpack-modules-overrides.php
9 months ago
class-jetpack-script-data.php
1 week ago
class-tracking.php
1 year ago
class-jetpack-script-data.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack_Script_Data. |
| 4 | * |
| 5 | * Adds Jetpack-plugin-specific data to the consolidated JetpackScriptData object. |
| 6 | * |
| 7 | * @package automattic/jetpack |
| 8 | */ |
| 9 | |
| 10 | namespace Automattic\Jetpack\Plugin; |
| 11 | |
| 12 | use Automattic\Jetpack\Current_Plan as Jetpack_Plan; |
| 13 | |
| 14 | /** |
| 15 | * Jetpack_Script_Data class. |
| 16 | */ |
| 17 | class Jetpack_Script_Data { |
| 18 | |
| 19 | /** |
| 20 | * Configure script data. |
| 21 | */ |
| 22 | public static function configure() { |
| 23 | add_filter( 'jetpack_admin_js_script_data', array( __CLASS__, 'set_admin_script_data' ), 10, 1 ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Add Jetpack-plugin-specific data to the consolidated JetpackScriptData object. |
| 28 | * |
| 29 | * @since 15.6 |
| 30 | * |
| 31 | * @param array $data The script data. |
| 32 | * @return array |
| 33 | */ |
| 34 | public static function set_admin_script_data( $data ) { |
| 35 | /** |
| 36 | * Whether to show the Jetpack branding in editor panels (e.g., SEO, AI Assistant). |
| 37 | * |
| 38 | * @since 15.6 |
| 39 | * |
| 40 | * @param bool $show Whether to show the Jetpack editor panel branding. Defaults to true. |
| 41 | */ |
| 42 | $data['jetpack'] = array( |
| 43 | 'flags' => array( |
| 44 | 'showJetpackBranding' => (bool) apply_filters( 'jetpack_show_editor_panel_branding', true ), |
| 45 | 'skipPhotonDomain' => self::should_skip_photon_domain( $data ), |
| 46 | ), |
| 47 | ); |
| 48 | |
| 49 | return $data; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Whether image-serving blocks should skip the external Photon domain (i0.wp.com) and build |
| 54 | * URLs on the site's own Photon-like host instead. |
| 55 | * |
| 56 | * VIP sites serve images from a host of their own, and images routed through the public Photon |
| 57 | * domain are not reachable there. |
| 58 | * |
| 59 | * This is read by the Tiled Gallery block's skipPhotonDomain(), which runs inside the block's |
| 60 | * save() output — including when the editor regenerates that output to validate saved content. |
| 61 | * That regeneration happens while the post is being parsed, before any editor store holds |
| 62 | * settings, so the value has to travel in the script data rather than in editor settings. |
| 63 | * |
| 64 | * The signal is the plan slug rather than Host::is_vip_site(): it is what the block's previous |
| 65 | * isVIP() check used, and switching to the WPCOM_IS_VIP_ENV constant would change which sites get |
| 66 | * site-host URLs — and so which existing galleries need a deprecation to stay valid. |
| 67 | * |
| 68 | * @since 16.2 |
| 69 | * |
| 70 | * @param array $data The script data, which may already carry the site plan. |
| 71 | * @return bool |
| 72 | */ |
| 73 | private static function should_skip_photon_domain( $data ) { |
| 74 | // Another package may have put the plan in the payload already (see Publicize_Script_Data); |
| 75 | // only look it up when it hasn't. |
| 76 | $product_slug = $data['site']['plan']['product_slug'] ?? ''; |
| 77 | if ( '' === $product_slug ) { |
| 78 | $jetpack_plan = Jetpack_Plan::get(); |
| 79 | $product_slug = $jetpack_plan['product_slug']; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Filter whether the Tiled Gallery and Image Compare blocks should skip the external |
| 84 | * Photon (i0.wp.com) domain and build image URLs on the site's own host instead. |
| 85 | * |
| 86 | * Defaults to true on VIP sites only, and false everywhere else. |
| 87 | * |
| 88 | * Changing this changes the markup Tiled Gallery saves, because it bakes the image URLs into its |
| 89 | * save() output. Galleries saved under the previous value stay valid — the block ships a |
| 90 | * deprecation for each image host, so flipping this either way is safe — and they are |
| 91 | * re-serialized with the new URLs the next time they are saved. |
| 92 | * |
| 93 | * Image Compare only uses this for its editor previews; its save() writes the attachment URLs |
| 94 | * through untouched, so its saved markup does not depend on this value. |
| 95 | * |
| 96 | * @module tiled-gallery |
| 97 | * |
| 98 | * @since 16.2 |
| 99 | * |
| 100 | * @param bool $skip_photon_domain Whether to skip the external Photon domain. |
| 101 | */ |
| 102 | return (bool) apply_filters( 'jetpack_skip_photon_domain', 'vip' === $product_slug ); |
| 103 | } |
| 104 | } |
| 105 |