Skip to content
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
23 changes: 23 additions & 0 deletions projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Comment thread
artpi marked this conversation as resolved.
Resolved
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}

Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/jetpack-ai-block-tweaks
Original file line number Diff line number Diff line change
@@ -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
17 changes: 11 additions & 6 deletions projects/plugins/jetpack/extensions/blocks/ai-image/ai-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
</Flex>
</Placeholder>
) }
{ ! errorMessage && ! attributes.requestedPrompt && (
{ ! errorMessage && ! loadingImages && resultImages.length === 0 && (
<Placeholder label={ __( 'AI Image', 'jetpack' ) }>
<div>
<TextareaControl
Expand Down
23 changes: 16 additions & 7 deletions projects/plugins/jetpack/extensions/blocks/ai-image/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useBlockProps } from '@wordpress/block-editor';
import { getRedirectUrl } from '@automattic/jetpack-components';
import { ExternalLink } from '@wordpress/components';
import { Fragment } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import { getIconColor } from '../../shared/block-icons';
Expand All @@ -19,21 +20,32 @@ export const settings = {
<Fragment>
<p>
{ __(
'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'
) }
</p>
<p>
{ __(
'We are experimenting with this feature and can tweak or remove it at any point.',
'jetpack'
) }
</p>
<ExternalLink href={ getRedirectUrl( 'jetpack_ai_feedback' ) }>
{ __( 'Share your feedback.', 'jetpack' ) }
</ExternalLink>
</Fragment>
),
icon: {
src: 'welcome-write-blog',
src: 'superhero',
foreground: getIconColor(),
},
category: 'media',
keywords: [
_x( 'AI', 'block search term', 'jetpack' ),
_x( 'AL', 'block search term', 'jetpack' ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a stupid question, but does "AL" stand for? Should we add more info in the context? I assume I won't be the only one who doesn't know :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will post @jobthomas feedback that led to this:

This is pretty awesome. As the tiniest of comments, and not sure how to fix it. Given the font of the block name, I think several of our users may read this as “AL IMAGE” rather than “AI IMAGE” (using all caps to avoid confusion). I’m not sure what would be a good way to fix that though.

If you think this is harmful, I can remove this change :)

_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.
Expand All @@ -59,10 +71,7 @@ export const settings = {
},
edit,
/* @TODO Write the block editor output */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* @TODO Write the block editor output */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to lose @jeherve approval and really want to merge it because testing is pain. Can you remove that line in your PR?

save: args => {
const blockProps = useBlockProps.save();
return <div { ...blockProps }>{ args.attributes.content }</div>;
},
save: () => '',
attributes,
example: {
attributes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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' );

Expand Down
17 changes: 15 additions & 2 deletions projects/plugins/jetpack/extensions/blocks/ai-paragraph/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,20 +22,31 @@ export const settings = {
<Fragment>
<p>
{ __(
'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'
) }
</p>
<p>
{ __(
'We are experimenting with this feature and can tweak or remove it at any point.',
'jetpack'
) }
</p>
<ExternalLink href={ getRedirectUrl( 'jetpack_ai_feedback' ) }>
{ __( 'Share your feedback.', 'jetpack' ) }
</ExternalLink>
</Fragment>
),
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.
Expand Down