diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php index d7e4d8861543..56f99e6d324a 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php @@ -55,6 +55,29 @@ public static function get_status_permission_check( $request ) { // phpcs:ignore return true; } + /** + * Return true if these features should be active on the current site. + * Currently, it's limited to WPCOM Simple and Atomic. + */ + public static function is_enabled() { + $default = false; + + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + $default = true; + } elseif ( ( new Automattic\Jetpack\Status\Host() )->is_woa_site() ) { + $default = true; + } + + /** + * Filter whether the AI features are enabled in the Jetpack plugin. + * + * @since $$next-version$$ + * + * @param bool $default Are AI features enabled? Defaults to false. + */ + return apply_filters( 'jetpack_ai_enabled', $default ); + } + /** * Get the name of the transient for image generation. Unique per prompt and allows for reuse of results for the same prompt across entire WPCOM. * I expext "puppy" to always be from cache. diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-ai.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-ai.php index ee7fc360f0db..4ac29e0236bb 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-ai.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-ai.php @@ -28,20 +28,17 @@ class WPCOM_REST_API_V2_Endpoint_AI extends WP_REST_Controller { * WPCOM_REST_API_V2_Endpoint_AI constructor. */ public function __construct() { - $this->is_wpcom = false; - - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - $this->is_wpcom = true; - $this->wpcom_is_wpcom_only_endpoint = true; - } elseif ( ! ( new Automattic\Jetpack\Status\Host() )->is_woa_site() ) { - // If this is not an atomic site, we want to bail and not even load the endpoint for now. - return; - } + $this->is_wpcom = true; + $this->wpcom_is_wpcom_only_endpoint = true; if ( ! class_exists( 'Jetpack_AI_Helper' ) ) { require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-ai-helper.php'; } + if ( ! \Jetpack_AI_Helper::is_enabled() ) { + return; + } + add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } diff --git a/projects/plugins/jetpack/changelog/jetpack-ai-block-tweaks b/projects/plugins/jetpack/changelog/jetpack-ai-block-tweaks new file mode 100644 index 000000000000..b8f7d576450d --- /dev/null +++ b/projects/plugins/jetpack/changelog/jetpack-ai-block-tweaks @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +AI Features now have a link to the Forums thread to gather feedback, different icon and simplified way of enabling for testing diff --git a/projects/plugins/jetpack/extensions/blocks/ai-image/ai-image.php b/projects/plugins/jetpack/extensions/blocks/ai-image/ai-image.php index 136633a9fe85..55cf83ee9b87 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-image/ai-image.php +++ b/projects/plugins/jetpack/extensions/blocks/ai-image/ai-image.php @@ -10,7 +10,6 @@ namespace Automattic\Jetpack\Extensions\AIImage; use Automattic\Jetpack\Blocks; -use Automattic\Jetpack\Status\Host; use Jetpack_Gutenberg; const FEATURE_NAME = 'ai-image'; @@ -22,12 +21,18 @@ * registration if we need to. */ function register_block() { - if ( ( defined( 'IS_WPCOM' ) && IS_WPCOM ) || ( new Host() )->is_woa_site() ) { - Blocks::jetpack_register_block( - BLOCK_NAME, - array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) - ); + if ( ! class_exists( 'Jetpack_AI_Helper' ) ) { + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-ai-helper.php'; } + + if ( ! \Jetpack_AI_Helper::is_enabled() ) { + return; + } + + Blocks::jetpack_register_block( + BLOCK_NAME, + array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) + ); } add_action( 'init', __NAMESPACE__ . '\register_block' ); diff --git a/projects/plugins/jetpack/extensions/blocks/ai-image/edit.js b/projects/plugins/jetpack/extensions/blocks/ai-image/edit.js index cd526e1c2930..cfa1e948fb90 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-image/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/ai-image/edit.js @@ -105,7 +105,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) { ) } - { ! errorMessage && ! attributes.requestedPrompt && ( + { ! errorMessage && ! loadingImages && resultImages.length === 0 && (

{ __( - 'Automatically generate an illustration for your post, powered by AI magic. We are experimenting with this feature and can tweak or remove it at any point.', + 'Automatically generate an illustration for your post, powered by AI magic.', 'jetpack' ) }

+

+ { __( + 'We are experimenting with this feature and can tweak or remove it at any point.', + 'jetpack' + ) } +

+ + { __( 'Share your feedback.', 'jetpack' ) } + ), icon: { - src: 'welcome-write-blog', + src: 'superhero', foreground: getIconColor(), }, category: 'media', keywords: [ _x( 'AI', 'block search term', 'jetpack' ), + _x( 'AL', 'block search term', 'jetpack' ), _x( 'DALLe', 'block search term', 'jetpack' ), _x( 'Diffusion', 'block search term', 'jetpack' ), + _x( 'Magic', 'block search term', 'jetpack' ), ], supports: { // Support for block's alignment (left, center, right, wide, full). When true, it adds block controls to change block’s alignment. @@ -59,10 +71,7 @@ export const settings = { }, edit, /* @TODO Write the block editor output */ - save: args => { - const blockProps = useBlockProps.save(); - return
{ args.attributes.content }
; - }, + save: () => '', attributes, example: { attributes: { diff --git a/projects/plugins/jetpack/extensions/blocks/ai-paragraph/ai-paragraph.php b/projects/plugins/jetpack/extensions/blocks/ai-paragraph/ai-paragraph.php index 774f524a0feb..9ed30c936cb5 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-paragraph/ai-paragraph.php +++ b/projects/plugins/jetpack/extensions/blocks/ai-paragraph/ai-paragraph.php @@ -10,7 +10,6 @@ namespace Automattic\Jetpack\Extensions\AIParagraph; use Automattic\Jetpack\Blocks; -use Automattic\Jetpack\Status\Host; use Jetpack_Gutenberg; const FEATURE_NAME = 'ai-paragraph'; @@ -22,13 +21,18 @@ * registration if we need to. */ function register_block() { - // Only load this block on WordPress.com. - if ( ( defined( 'IS_WPCOM' ) && IS_WPCOM ) || ( new Host() )->is_woa_site() ) { - Blocks::jetpack_register_block( - BLOCK_NAME, - array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) - ); + if ( ! class_exists( 'Jetpack_AI_Helper' ) ) { + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-ai-helper.php'; } + + if ( ! \Jetpack_AI_Helper::is_enabled() ) { + return; + } + + Blocks::jetpack_register_block( + BLOCK_NAME, + array( 'render_callback' => __NAMESPACE__ . '\load_assets' ) + ); } add_action( 'init', __NAMESPACE__ . '\register_block' ); diff --git a/projects/plugins/jetpack/extensions/blocks/ai-paragraph/index.js b/projects/plugins/jetpack/extensions/blocks/ai-paragraph/index.js index 5a4d5b69ade7..d687ce3c735e 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-paragraph/index.js +++ b/projects/plugins/jetpack/extensions/blocks/ai-paragraph/index.js @@ -1,5 +1,7 @@ +import { getRedirectUrl } from '@automattic/jetpack-components'; import { useBlockProps } from '@wordpress/block-editor'; import { createBlock } from '@wordpress/blocks'; +import { ExternalLink } from '@wordpress/components'; import { Fragment } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; import { getIconColor } from '../../shared/block-icons'; @@ -20,20 +22,31 @@ export const settings = {

{ __( - 'Automatically generate new paragraphs using your existing content, powered by AI magic. We are experimenting with this feature and can tweak or remove it at any point.', + 'Automatically generate new paragraphs using your existing content, powered by AI magic.', 'jetpack' ) }

+

+ { __( + 'We are experimenting with this feature and can tweak or remove it at any point.', + 'jetpack' + ) } +

+ + { __( 'Share your feedback.', 'jetpack' ) } +
), icon: { - src: 'welcome-write-blog', + src: 'superhero', foreground: getIconColor(), }, category: 'text', keywords: [ _x( 'AI', 'block search term', 'jetpack' ), _x( 'GPT', 'block search term', 'jetpack' ), + _x( 'AL', 'block search term', 'jetpack' ), + _x( 'Magic', 'block search term', 'jetpack' ), ], supports: { // Support for block's alignment (left, center, right, wide, full). When true, it adds block controls to change block’s alignment.