Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions lib/experimental/experiments/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function gutenberg_initialize_experiments_settings() {
'items' => array(
array(
'id' => 'gutenberg-media-editor',
'label' => __( 'Media Editor', 'gutenberg' ),
'description' => __( 'Adds an "Edit media" action on image blocks for editing the attached media item (metadata and content) in the editor.', 'gutenberg' ),
'label' => __( 'Media Editor (Route)', 'gutenberg' ),
'description' => __( 'Enables a dedicated route-based media editor screen for editing media items (metadata and content).', 'gutenberg' ),
),
array(
'id' => 'gutenberg-media-editor-modal',
Expand Down
39 changes: 39 additions & 0 deletions lib/experimental/media-editor/load.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Bootstraps the Media Editor page in wp-admin.
*
* @package gutenberg
*/

add_action( 'admin_menu', 'gutenberg_register_media_editor_admin_page' );

/**
* Registers a hidden wp-admin page for direct media editor deep links.
*/
function gutenberg_register_media_editor_admin_page() {
// Register with an empty parent to create a hidden admin.php?page= route
// without adding a Media submenu item for an editor that requires an ID.
$hook_suffix = add_submenu_page(
'',
__( 'Edit media', 'gutenberg' ),
__( 'Edit media', 'gutenberg' ),
'upload_files',
'media-editor-wp-admin',
'gutenberg_media_editor_wp_admin_render_page'
);

if ( $hook_suffix ) {
// Hidden pages do not resolve a title from a visible menu item, so set
// one before admin-header.php formats the page title.
add_action( "load-$hook_suffix", 'gutenberg_media_editor_wp_admin_set_title' );
}
}

/**
* Sets the admin page title before wp-admin/admin-header.php renders.
*/
function gutenberg_media_editor_wp_admin_set_title() {
global $title;

$title = __( 'Edit media', 'gutenberg' );
}
3 changes: 3 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/pages/site-editor.php';
require __DIR__ . '/experimental/extensible-site-editor.php';
require __DIR__ . '/experimental/fonts/load.php';
if ( gutenberg_is_experiment_enabled( 'gutenberg-media-editor' ) ) {
require __DIR__ . '/experimental/media-editor/load.php';
}
if ( class_exists( '\WordPress\AiClient\AiClient' ) ) {
require __DIR__ . '/experimental/connectors/load.php';
}
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
],
"experimental": true
},
"media-editor",
"font-library",
"options-connectors",
"guidelines",
Expand Down
38 changes: 1 addition & 37 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default function Image( {
const setRefs = useMergeRefs( [ setImageElement, setResizeObserved ] );
const { allowResize = true } = context;

const { image, canUserEdit, attachmentResolutionError } = useSelect(
const { image, attachmentResolutionError } = useSelect(
( select ) => {
const imageRecord =
id && isSingleSelected
Expand Down Expand Up @@ -345,20 +345,8 @@ export default function Image( {
)
: null;

// Check edit permissions when the media editor experiment is enabled.
// Only check when imageRecord is available to avoid unnecessary API requests.
let canEdit = false;
if ( imageRecord && window?.__experimentalMediaEditor ) {
canEdit = !! select( coreStore ).canUser( 'update', {
kind: 'postType',
name: 'attachment',
id,
} );
}

return {
image: imageRecord,
canUserEdit: canEdit,
attachmentResolutionError: resolutionError,
};
},
Expand Down Expand Up @@ -394,7 +382,6 @@ export default function Image( {
);
const { getBlock, getSettings } = useSelect( blockEditorStore );
const settings = getSettings();
const { onNavigateToEntityRecord } = settings;
const openMediaEditorModal = settings[ openMediaEditorModalKey ];

const handleMediaUpdate = useCallback(
Expand Down Expand Up @@ -848,28 +835,6 @@ export default function Image( {
const hasDataFormBlockFields =
window?.__experimentalContentOnlyInspectorFields;

const editMediaButton = window?.__experimentalMediaEditor &&
id &&
isSingleSelected &&
canUserEdit &&
!! editMediaEntity &&
! isExternalImage( id, url ) &&
! isEditingImage &&
onNavigateToEntityRecord && (
<BlockControls group="other">
<ToolbarButton
onClick={ () => {
onNavigateToEntityRecord( {
postId: id,
postType: 'attachment',
} );
} }
>
{ __( 'Edit media' ) }
</ToolbarButton>
</BlockControls>
);

const controls = (
<>
{ showBlockControls && (
Expand Down Expand Up @@ -1356,7 +1321,6 @@ export default function Image( {

return (
<>
{ editMediaButton }
{ mediaReplaceFlow }
{ controls }
{ featuredImageControl }
Expand Down
Loading
Loading