Skip to content

Commit

Permalink
Place "Write mode" functionality behind a Gutenberg experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Nov 18, 2024
1 parent 134e4b4 commit 923e1d9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-media-processing', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalMediaProcessing = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-editor-write-mode', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEditorWriteMode = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experiments' );
Expand Down
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-editor-write-mode',
__( 'Editor write mode', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable write mode in editor.', 'gutenberg' ),
'id' => 'gutenberg-editor-write-mode',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
3 changes: 3 additions & 0 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,9 @@ export function isNavigationMode( state ) {
*/
export const __unstableGetEditorMode = createRegistrySelector(
( select ) => ( state ) => {
if ( ! window?.__experimentalEditorWriteMode ) {
return 'edit';
}
return (
state.settings.editorTool ??
select( preferencesStore ).get( 'core', 'editorTool' )
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/components/document-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ function DocumentTools( { className, disableBlockTools = false } ) {
isDistractionFree: get( 'core', 'distractionFree' ),
isVisualMode: getEditorMode() === 'visual',
showTools:
getRenderingMode() !== 'post-only' ||
getCurrentPostType() === 'wp_template',
!! window?.__experimentalEditorWriteMode &&
( getRenderingMode() !== 'post-only' ||
getCurrentPostType() === 'wp_template' ),
};
}, [] );

Expand Down

0 comments on commit 923e1d9

Please sign in to comment.