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

AI Logo Generator: improve extension availability check #38603

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

AI Logo Generator: only extend the logo block when the AI Assistant is available and not hidden on the editor.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*/
import { GeneratorModal } from '@automattic/jetpack-ai-client';
import { BlockControls } from '@wordpress/block-editor';
import { getBlockType } from '@wordpress/blocks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch, useSelect, select } from '@wordpress/data';
import { useCallback, useEffect, useState } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';
/*
Expand Down Expand Up @@ -69,8 +70,8 @@ const useSetLogo = () => {
};

const useSiteDetails = () => {
const siteSettings = useSelect( select => {
return ( select( 'core' ) as CoreSelect ).getEntityRecord( 'root', 'site' );
const siteSettings = useSelect( selectData => {
return ( selectData( 'core' ) as CoreSelect ).getEntityRecord( 'root', 'site' );
}, [] );

return {
Expand Down Expand Up @@ -137,21 +138,54 @@ const siteLogoEditWithAiComponents = createHigherOrderComponent( BlockEdit => {
}, 'SiteLogoEditWithAiComponents' );

/**
* Function to override the core Site Logo block edit settings.
* Will create a HOC to use as the edit implementation.
* Function to check if the block can be extended.
*
* @param {object} settings - The block settings.
* @param {string} name - The block name.
* @returns {object} The new block settings.
* @returns {boolean} True if the block can be extended.
*/
function jetpackSiteLogoWithAiSupport( settings, name: string ) {
// Only extend the core Site Logo block.
function canExtendBlock( name: string ): boolean {
if ( name !== 'core/site-logo' ) {
return settings;
return false;
}

// Check if the AI Assistant block is registered. If not, we understand that Jetpack AI is not active.
const isAIAssistantBlockRegistered = getBlockType( 'jetpack/ai-assistant' );

if ( ! isAIAssistantBlockRegistered ) {
return false;
}

// Disable if the feature is not available.
if ( ! getFeatureAvailability( SITE_LOGO_BLOCK_AI_EXTENSION ) ) {
return false;
}

/*
* Do not extend if the AI Assistant block is hidden,
* as a way for the user to hide the extension.
* TODO: the `editPostStore` is undefined for P2 sites.
* Let's find a way to check if the block is hidden there.
*/
const { getHiddenBlockTypes } = select( 'core/edit-post' ) || {};
const hiddenBlocks = getHiddenBlockTypes?.() || []; // It will extend the block if the function is undefined

if ( hiddenBlocks.includes( 'jetpack/ai-assistant' ) ) {
return false;
}

return true;
}

/**
* Function to override the core Site Logo block edit settings.
* Will create a HOC to use as the edit implementation.
*
* @param {object} settings - The block settings.
* @param {string} name - The block name.
* @returns {object} The new block settings.
*/
function jetpackSiteLogoWithAiSupport( settings, name: string ) {
if ( ! canExtendBlock( name ) ) {
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Just bumping versions to comply with changelogger checks.


2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"composer/installers": true,
"roots/wordpress-core-installer": true
},
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_1"
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_2_alpha"
},
"extra": {
"mirror-repo": "Automattic/wpcom-site-helper",
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@automattic/jetpack-wpcomsh",
"description": "A helper for connecting WordPress.com sites to external host infrastructure.",
"homepage": "https://jetpack.com",
"version": "5.1.1",
"version": "5.1.2-alpha",
"bugs": {
"url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Plugin Name: WordPress.com Site Helper
* Description: A helper for connecting WordPress.com sites to external host infrastructure.
* Version: 5.1.1
* Version: 5.1.2-alpha
* Author: Automattic
* Author URI: http://automattic.com/
*
* @package wpcomsh
*/

define( 'WPCOMSH_VERSION', '5.1.1' );
define( 'WPCOMSH_VERSION', '5.1.2-alpha' );

// If true, Typekit fonts will be available in addition to Google fonts
add_filter( 'jetpack_fonts_enable_typekit', '__return_true' );
Expand Down
Loading