Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Site Design controls in Go Site Editing. #2524

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/block-migrate/class-coblocks-alert-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function migrate_attributes() {
/**
* Handle setting the migrated attributes custom colors.
*/
$result = $this->get_alert_colors( $this->block_attributes, $result );
$result = $this->get_alert_colors( $this->block_attributes, $result );

/**
* Add `coblocks-alert-paragraph` class for CoBlocks styles selector.
Expand Down
24 changes: 23 additions & 1 deletion includes/class-coblocks-labs.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ public function __construct() {
* @return boolean
*/
public static function is_go_active() {
return defined( 'GO_VERSION' ) && 'go' === get_option( 'stylesheet' );
return 'go' === get_option( 'stylesheet' );
}

/**
* Checks if the Go theme's get_design_style() method is accessible, otherwise assumes FSE context.
*
* @since 3.1.0
AnthonyLedesma marked this conversation as resolved.
Show resolved Hide resolved
* @return boolean
*/
public static function is_go_se() {
if ( ! self::is_go_active() ) {
return false;
}
// No Method = FSE || Go classic.
return ! ( function_exists( '\Go\Core\get_design_style' ) );
AnthonyLedesma marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -115,6 +129,13 @@ public function propagate_settings() {
update_option( 'coblocks_site_design_controls_enabled', 0 );
update_option( 'coblocks_layout_selector_controls_enabled', 0 );
}

// Site design is disabled when in GSE context.
$is_go_se = self::is_go_se();
eherman-godaddy marked this conversation as resolved.
Show resolved Hide resolved

if ( $is_go_se ) {
AnthonyLedesma marked this conversation as resolved.
Show resolved Hide resolved
update_option( 'coblocks_site_design_controls_enabled', 0 );
}
}

/**
Expand All @@ -129,6 +150,7 @@ public function editor_assets() {
array(
'isGoThemeActive' => self::is_go_active(),
'isGoThemeInstalled' => self::is_go_installed(),
'isGoSiteEditor' => self::is_go_se(),
'goThemeInstallUri' => admin_url( 'theme-install.php?theme=go' ),
'goThemeDetailsUri' => admin_url( 'themes.php' ) . '?theme=go',
'launchGuideEligible' => ! empty( get_option( 'wpnux_export_data' ) ),
Expand Down
2 changes: 1 addition & 1 deletion includes/class-coblocks-site-design.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function() {
* @return boolean
*/
public static function short_circuit_check() {
return 'go' !== get_stylesheet();
return ( 'go' !== get_stylesheet() ) || CoBlocks_Labs::is_go_se();
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"lint:php": "wp-env run phpunit 'composer run lint -d /var/www/html/wp-content/plugins/coblocks/'; #we use phpunit container because composer container only use php 8;",
"lint:php:fix": "wp-env run phpunit 'composer run lint:fix -d /var/www/html/wp-content/plugins/coblocks/'; #we use phpunit container because composer container only use php 8;",
"makepot": "./vendor/bin/wp i18n make-pot . --skip-audit --exclude=\".dev,.github,.wordpress-org,build,docs,dist,node_modules,vendor,wordpress\" --headers='{\"Last-Translator\":\"plugins@godaddy.com\",\"Report-Msgid-Bugs-To\":\"https://github.com/godaddy-wordpress/coblocks/issues\"}' --file-comment=\"Copyright (c) $(date +'%Y') GoDaddy Operating Company, LLC. All Rights Reserved.\" languages/coblocks.pot && yarn run pot2json",
"php:composer:install": "wp-env run phpunit 'composer install -d /var/www/html/wp-content/plugins/coblocks/'",
"po2jed": "cd languages && find . -name '*.po' -execdir /bin/bash -c 'FROM=\"$0\" && TO=\"`basename $0 .po`-coblocks-editor.json\" && echo \"$FROM > $TO\" && po2json $FROM $TO -f jed' '{}' \\;",
Expand Down
12 changes: 9 additions & 3 deletions src/extensions/coblocks-labs/coblocks-labs-toggle-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEntityProp } from '@wordpress/core-data';
* Internal dependencies
*/
import CoBlocksLabsModalControl from './coblocks-labs-slot';
import { conditionalHelpMessage, controlDisable } from './utils';
import { conditionalHelpMessage, GSEHelpMessage, disabledValue } from './utils';

function CoBlocksLabsToggleControl( {
label,
Expand All @@ -19,9 +19,15 @@ function CoBlocksLabsToggleControl( {
settingsKey,
showGoHelp,
conditionalDisable = false,
conditionalDisableFSE = false,
} ) {
const [ setting, saveSetting ] = useEntityProp( 'root', 'site', settingsKey );

// Determine the disabled value using the helper function
const disabled = disabledValue( conditionalDisable, conditionalDisableFSE );

const helpCB = ( message ) => conditionalDisableFSE ? GSEHelpMessage( message ) : conditionalHelpMessage( message );

return (
<CoBlocksLabsModalControl>
<section className="coblocks-labs-modal__section">
Expand All @@ -30,8 +36,8 @@ function CoBlocksLabsToggleControl( {
{ description && <p className="coblocks-labs-modal__section__description">{ description }</p> }
<ToggleControl
checked={ !! setting }
disabled={ conditionalDisable ? controlDisable() : false }
help={ showGoHelp ? conditionalHelpMessage( help ) : '' }
disabled={ disabled }
help={ showGoHelp ? helpCB( help ) : '' }
onChange={ saveSetting } />
</div>

Expand Down
57 changes: 57 additions & 0 deletions src/extensions/coblocks-labs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,46 @@ export const conditionalHelpMessage = ( ) => {
</> );
};

/**
* The Site Design feature is deprecated with Go FSE and is disabled when Go FSE is active.
*
* @return {string} - Conditional string to use the feature or disabled
*/
export const GSEHelpMessage = ( ) => {
const {
isGoThemeActive,
isGoThemeInstalled,
isGoSiteEditor,
goThemeDetailsUri,
goThemeInstallUri,
} = safeCoBlocksLabsData;

if ( isGoSiteEditor ) {
return __( 'This feature is deprecated and replaced with Go Site Editor.', 'coblocks' );
}

if ( isGoThemeActive && isGoThemeInstalled ) {
return __( 'This feature requires the Go Theme.', 'coblocks' );
}

if ( isGoThemeInstalled ) {
return (
<> { __( 'This feature requires the Go Theme - ', 'coblocks' ) }
<a href={ goThemeDetailsUri } rel="noopener noreferrer" target="_blank">
{ __( 'Activate', 'coblocks' ) }
</a>
</> );
}

// Feature will remain disabled with GSE but still allows user to manage site design through Go.
return (
<> { __( 'This feature requires the Go Theme - ', 'coblocks' ) }
<a href={ goThemeInstallUri } rel="noopener noreferrer" target="_blank">
{ __( 'Install now', 'coblocks' ) }
</a>
</> );
};

/**
*
* @return {boolean} Whether or not the Site Design and Layout Selector controls are enabled.
Expand All @@ -66,3 +106,20 @@ export const controlDisable = ( ) => {

return true;
};

/**
* Helper function to determine the disabled value based on the given conditions.
*
* @param {boolean} conditionalDisable - Indicates if the control should be disabled based on certain conditions.
* @param {boolean} conditionalDisableFSE - Indicates if the control should be disabled in Full Site Editor context.
* @return {boolean} - The final disabled value.
*/
export const disabledValue = ( conditionalDisable, conditionalDisableFSE ) => {
if ( conditionalDisableFSE && !! safeCoBlocksLabsData?.isGoSiteEditor ) {
return true;
}
if ( conditionalDisable ) {
return controlDisable();
}
return false;
};
1 change: 1 addition & 0 deletions src/extensions/site-design/site-design-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ registerPlugin( 'coblocks-site-design-control', {
render: () => (
<CoBlocksLabsToggleControl
conditionalDisable={ true }
conditionalDisableFSE={ true }
description={ __( 'Easily explore curated design styles, then customize your colors and fonts inside the editor to get the perfect fit.', 'coblocks' ) }
imageAlt={ __( 'Site design example', 'coblocks' ) }
imageSrc={ SiteDesignImage }
Expand Down
70 changes: 70 additions & 0 deletions src/extensions/site-design/test/site-design.cypress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Include our constants
*/
import * as helpers from '../../../../.dev/tests/cypress/helpers';

describe( 'Extension: CoBlocks Labs', () => {
it( 'should disable when Go Site Editor is active', () => {
// Intercept the request to the page and modify the response body
cy.intercept( 'http://localhost:8889/wp-admin/post-new.php?post_type=page', ( req ) => {
req.continue( ( res ) => {
// Use a regular expression to match the coblocksLabs object
const regex = /var\s+coblocksLabs\s*=\s*\{[^]*?\};/;

// Replace the original coblocksLabs object with the new values
res.body = res.body.replace(
regex,
'var coblocksLabs = { isGoSiteEditor: "1", isGoThemeActive: "1", isGoThemeInstalled: "1", goThemeInstallUri: "http://localhost:8889/wp-admin/theme-install.php?theme=go", goThemeDetailsUri: "http://localhost:8889/wp-admin/themes.php?theme=go", launchGuideEligible: "" };'
);
} );
} );

cy.visit( 'http://localhost:8889/wp-admin/post-new.php?post_type=page' );

// Open CoBlocks Labs settings
helpers.openCoBlocksLabsModal();

const assertions = [
( element ) => cy.wrap( element ).should( 'not.be.disabled' ), // Assertion for the first checkbox
( element ) => cy.wrap( element ).should( 'be.disabled' ), // Assertion for the second checkbox
( element ) => cy.wrap( element ).should( 'not.be.disabled' ), // Assertion for the third checkbox
];

cy.get( '.coblocks-labs-modal__section__vertical-group' )
.find( 'input[type="checkbox"]' )
.each( ( element, index ) => {
assertions[ index ]( element );
} );

// Intercept the request to the page and modify the response body
cy.intercept( 'http://localhost:8889/wp-admin/post-new.php?post_type=page', ( req ) => {
req.continue( ( res ) => {
// Use a regular expression to match the coblocksLabs object
const regex = /var\s+coblocksLabs\s*=\s*\{[^]*?\};/;

// Replace the original coblocksLabs object with the new values
res.body = res.body.replace(
regex,
'var coblocksLabs = { isGoSiteEditor: "", isGoThemeActive: "1", isGoThemeInstalled: "1", goThemeInstallUri: "http://localhost:8889/wp-admin/theme-install.php?theme=go", goThemeDetailsUri: "http://localhost:8889/wp-admin/themes.php?theme=go", launchGuideEligible: "" };'
);
} );
} );

cy.visit( 'http://localhost:8889/wp-admin/post-new.php?post_type=page' );

// Open CoBlocks Labs settings
helpers.openCoBlocksLabsModal();

const assertions2 = [
( element ) => cy.wrap( element ).should( 'not.be.disabled' ), // Assertion for the first checkbox
( element ) => cy.wrap( element ).should( 'not.be.disabled' ), // Assertion for the second checkbox
( element ) => cy.wrap( element ).should( 'not.be.disabled' ), // Assertion for the third checkbox
];

cy.get( '.coblocks-labs-modal__section__vertical-group' )
.find( 'input[type="checkbox"]' )
.each( ( element, index ) => {
assertions2[ index ]( element );
} );
} );
} );