Skip to content

Commit

Permalink
Earn: do not register premium content blocks when newer gutenberg fea…
Browse files Browse the repository at this point in the history
…tures are not available (#44191)
  • Loading branch information
gwwar committed Jul 17, 2020
1 parent 4b0f4df commit 6c73f50
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const alignmentHooksSetting = {
};

function ButtonsEdit( { context, subscribeButton, setSubscribeButtonPlan } ) {
const planId = context[ 'premium-content/planId' ];
const planId = context ? context[ 'premium-content/planId' ] : null;

const template = [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { button as icon } from '@wordpress/icons';
*/
import edit from './edit';
import save from './save';
import { getCategoryWithFallbacks } from '../../../block-helpers';

const name = 'premium-content/buttons';
const category = 'design';
const category = getCategoryWithFallbacks( 'design', 'common' );

const settings = {
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { __ } from '@wordpress/i18n';
*/
import edit from './edit';
import save from './save';
import { getCategoryWithFallbacks } from '../../../block-helpers';

const name = 'premium-content/login-button';
const category = 'design';
const category = getCategoryWithFallbacks( 'design', 'common' );

/**
* @typedef {object} Attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { mergeWith } from 'lodash';
import apiFetch from '@wordpress/api-fetch';
import { getBlockType, registerBlockType, unregisterBlockType } from '@wordpress/blocks';
import { _x } from '@wordpress/i18n';
import {
__experimentalAlignmentHookSettingsProvider,
__experimentalBlock,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -19,6 +23,10 @@ import * as loggedOutView from './blocks/logged-out-view';
import * as buttons from './blocks/buttons';
import * as loginButton from './blocks/login-button';

const supportsDecoupledBlocks = !! (
__experimentalAlignmentHookSettingsProvider && __experimentalBlock
);

/**
* Function to register an individual block.
*
Expand Down Expand Up @@ -129,5 +137,7 @@ export const registerPremiumContentBlocks = () => {
[ container, loggedOutView, subscriberView, buttons, loginButton ].forEach( registerBlock );
};

registerPremiumContentBlocks();
configurePremiumContentBlocks();
if ( supportsDecoupledBlocks ) {
registerPremiumContentBlocks();
configurePremiumContentBlocks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function premium_content_current_visitor_can_access( $attributes, $block ) {
$selected_plan_id = (int) $attributes['selectedPlanId'];
}

if ( isset( $block->context['premium-content/planId'] ) ) {
if ( isset( $block ) && isset( $block->context['premium-content/planId'] ) ) {
$selected_plan_id = (int) $block->context['premium-content/planId'];
}

Expand Down Expand Up @@ -217,7 +217,7 @@ function premium_content_container_render( $attributes, $content ) {
*
* @return string Content to render.
*/
function premium_content_block_logged_out_view_render( $attributes, $content, $block ) {
function premium_content_block_logged_out_view_render( $attributes, $content, $block = null ) {
if ( ! premium_content_pre_render_checks() ) {
return '';
}
Expand Down Expand Up @@ -246,7 +246,7 @@ function premium_content_block_logged_out_view_render( $attributes, $content, $b
*
* @return string Final content to render.
*/
function premium_content_block_subscriber_view_render( $attributes, $content, $block ) {
function premium_content_block_subscriber_view_render( $attributes, $content, $block = null ) {
if ( ! premium_content_pre_render_checks() ) {
return '';
}
Expand Down

0 comments on commit 6c73f50

Please sign in to comment.