Skip to content
Open
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: minor
Type: enhancement

Image Studio: Add an "Edit with AI" row action in the Media Library list view and disable overlapping Jetpack AI image extensions globally when Image Studio is available.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,71 @@ function enqueue_image_studio_admin() {
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_image_studio_admin' );

/**
* Adds an "Edit with AI" row action for supported image types in the media library list view.
*
* Inserts the action before the default "Edit" link so it's prominently visible.
* Only appears for image MIME types that Image Studio supports.
*
* @param array $actions Row actions array.
* @param \WP_Post $post The attachment post object.
* @return array Modified row actions.
*/
function add_image_studio_row_action( $actions, $post ) {
// Keep in sync with IMAGE_STUDIO_SUPPORTED_MIME_TYPES in wp-calypso/packages/image-studio/src/types/index.ts.
$supported_mime_types = array(
'image/jpeg',
'image/jpg',
'image/png',
'image/webp',
'image/bmp',
'image/tiff',
);

if ( ! in_array( $post->post_mime_type, $supported_mime_types, true ) ) {
return $actions;
}

if ( ! current_user_can( 'edit_post', $post->ID ) ) {
return $actions;
}

$link = sprintf(
'<a href="#" class="big-sky-image-studio-link" data-attachment-id="%d">%s</a>',
absint( $post->ID ),
esc_html__( 'Edit with AI', 'jetpack' )
);

// Insert before the 'edit' action, or append if 'edit' is not present.
$new_actions = array();
foreach ( $actions as $key => $value ) {
if ( 'edit' === $key ) {
$new_actions['edit-with-ai'] = $link;
}
$new_actions[ $key ] = $value;
}

if ( ! isset( $new_actions['edit-with-ai'] ) ) {
$new_actions['edit-with-ai'] = $link;
}

return $new_actions;
}

/**
* Register the "Edit with AI" row action on the Media Library screen.
*
* @return void
*/
function register_row_action() {
if ( ! is_image_studio_enabled() || ! is_media_library() ) {
return;
}

add_filter( 'media_row_actions', __NAMESPACE__ . '\add_image_studio_row_action', 10, 2 );
}
add_action( 'current_screen', __NAMESPACE__ . '\register_row_action' );

/**
* Get the list of AI image extensions that conflict with Image Studio.
*
Expand All @@ -296,30 +361,15 @@ function get_ai_image_extensions() {
}

/**
* Disable Jetpack AI image extensions when Image Studio is active on the current screen.
*
* This hook fires on `jetpack_register_gutenberg_extensions` which may run multiple
* times: once during initial module load (before get_current_screen() is available)
* and again inside Jetpack_Gutenberg::get_availability() during enqueue (where the
* screen IS available).
*
* Only disables AI extensions when we can confirm Image Studio will actually load
* on the current screen (i.e. screen is available and should_load_on_current_screen()
* returns true). If the screen is not available or Image Studio won't load on this
* screen, AI extensions remain enabled.
* Disable Jetpack AI image extensions when Image Studio is available.
*
* This ensures AI extensions are available on screens where Image Studio won't load
* (e.g. dashboard, other non-editor screens, or early initialization).
* When Image Studio is available (via Jetpack_Gutenberg::is_available), AI image
* extensions are disabled globally to avoid duplicate functionality.
*
* @return void
*/
function disable_jetpack_ai_image_extensions() {
if ( ! is_image_studio_enabled() ) {
return;
}

// Only disable if screen is available and Image Studio will actually load.
if ( ! function_exists( 'get_current_screen' ) || ! get_current_screen() || ! should_load_on_current_screen() ) {
if ( ! \Jetpack_Gutenberg::is_available( FEATURE_NAME ) ) {
return;
}

Expand Down
Loading
Loading