Skip to content

Commit

Permalink
Photon: Ensure VIP site are correctly identified within isVIP. (#39941)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Mitroshin <[email protected]>
  • Loading branch information
coder-karen and sergeymitr authored Dec 18, 2024
1 parent f52f223 commit 64ab237
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-photon-on-vip
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Photon: Ensure VIP sites are correctly identified, to prevent unnecessary early Photonization of URLs.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ public static function enqueue_block_editor_assets() {
$modules = $module_list_endpoint->get_modules();
}

$jetpack_plan = Jetpack_Plan::get();
$initial_state = array(
'available_blocks' => self::get_availability(),
'blocks_variation' => $blocks_variation,
Expand All @@ -731,6 +732,9 @@ public static function enqueue_block_editor_assets() {
// this is the equivalent of JP initial state siteData.showMyJetpack (class-jetpack-redux-state-helper)
// used to determine if we can link to My Jetpack from the block editor
'is_my_jetpack_available' => My_Jetpack_Initializer::should_initialize(),
'jetpack_plan' => array(
'data' => $jetpack_plan['product_slug'],
),
/**
* Enable the RePublicize UI in the block editor context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public static function render( $attr, $content ) {
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );

$is_squareish_layout = self::is_squareish_layout( $attr );

// For backward compatibility (ensuring Tiled Galleries using now deprecated versions of the block are not affected).
// See isVIP() in utils/index.js.
$jetpack_plan = Jetpack_Plan::get();
wp_localize_script( 'jetpack-gallery-settings', 'jetpack_plan', array( 'data' => $jetpack_plan['product_slug'] ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ import {
isSimpleSite,
} from '@automattic/jetpack-shared-extension-utils';
import { isBlobURL } from '@wordpress/blob';
import { select } from '@wordpress/data';
import { range } from 'lodash';
import photon from 'photon';
import isOfflineMode from '../../../shared/is-offline-mode';
import { PHOTON_MAX_RESIZE } from '../constants';

let jetpackPlanFromState;

window.addEventListener( 'load', function () {
const hasImageCompare = select( 'core/block-editor' )
.getBlocks()
.some( block => block.name === 'jetpack/image-compare' );
if ( hasImageCompare && ! jetpackPlanFromState ) {
jetpackPlanFromState = window?.Jetpack_Editor_Initial_State?.jetpack?.jetpack_plan;
}
} );

export function isSquareishLayout( layout ) {
return [ 'circle', 'square' ].includes( layout );
}
Expand Down Expand Up @@ -112,9 +124,14 @@ export function photonizedImgProps( img, galleryAtts = {} ) {
}
function isVIP() {
/*global jetpack_plan*/
if ( typeof jetpack_plan !== 'undefined' && jetpack_plan.data === 'vip' ) {
return true;
// Use `jetpackPlanFromState` if available, otherwise fall back to `jetpack_plan` defined within the render function in tiled-gallery.php.
let jetpackPlan;
if ( typeof jetpackPlanFromState !== 'undefined' ) {
jetpackPlan = jetpackPlanFromState;
} else if ( typeof jetpack_plan !== 'undefined' ) {
jetpackPlan = jetpack_plan;
}
return jetpackPlan && jetpackPlan?.data === 'vip';
}

/**
Expand Down

0 comments on commit 64ab237

Please sign in to comment.