Make WordPress Core

Opened 2 years ago

Closed 20 months ago

Last modified 20 months ago

#61811 closed enhancement (fixed)

Set editor rendering mode by post type

Reported by: TyB Owned by: Mamaduka
Priority: normal Milestone: 6.8
Component: Editor Version:
Severity: normal Keywords: gutenberg-merge has-patch
Cc: Focuses:

Description

Sync ticket for ​https://github.com/WordPress/gutenberg/pull/62304

Allow extenders to set the default rendering mode for a specific post type. It seems logical to default the page post type to the template editor, and the post post type to the block editor. Editors should retain the ability to swap between them while in the editor, this setting should only apply to what the editor sees by default.

Extenders should have the ability to define the rendering mode for a post type on registration, and change the rendering mode of an existing post type through a filter.

Change History (29)

This ticket was mentioned in ​PR #7129 on ​WordPress/wordpress-develop by ​@TyB.


2 years ago
#1

  • Keywords has-patch added

# Trac ticket: https://core.trac.wordpress.org/ticket/61811

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

This ticket was mentioned in ​PR #8123 on ​WordPress/wordpress-develop by ​@Mamaduka.


22 months ago
#2

Supersedes: ​https://github.com/WordPress/wordpress-develop/pull/7129
Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/68549

This update updates the page post-type definition and sets template-locked as the new default rendering mode for the block editor.

Trac ticket: https://core.trac.wordpress.org/ticket/61811

#3 @Mamaduka
22 months ago

  • Milestone Awaiting Review → 6.8
  • Owner set to Mamaduka
  • Status new → assigned

​@Mamaduka commented on ​PR #7129:


22 months ago
#4

Closing in favor of #8123.

@TylerB24890, do you mind commenting on a new PR so I can give the props when the the feature is merged into the core?

#5 @Mamaduka
22 months ago

  • Keywords gutenberg-merge added

​@TyB commented on ​PR #8123:


22 months ago
#6

Thanks for the fixes! 😃

​@Mamaduka commented on ​PR #8123:


21 months ago
#7

I'm considering making the new default mode for Pages conditional and only setting it when wp_is_block_theme is true. Why?

Is the create_initial_post_types (still) the best place to enable the new default mode for Pages based on conditions? cc @swissspidy, @peterwilsoncc

​@swissspidy commented on ​PR #8123:


21 months ago
#8

Yes, I don't see why not. Given that create_initial_post_types runs on init, it should be safe to use wp_is_block_theme() at that point.

​@audrasjb commented on ​PR #8123:


21 months ago
#9

I'm considering making the new default mode for Pages conditional and only setting it when wp_is_block_theme is true.

Anyway, I think it would be safer to implement this step by step, and perhaps not making it the default behavior for page-like post types for now, at least in hybrid/classic themes.

​@Mamaduka commented on ​PR #8123:


21 months ago
#10

Synced the latest changes from ​https://github.com/WordPress/gutenberg/pull/69160. This is ready for testing and approval.

​@Mamaduka commented on ​PR #8123:


21 months ago
#11

Thanks. Option persistence is being tracked separately: ​https://github.com/WordPress/gutenberg/issues/68250. I'll try to push an alternative PR for it before beta.

However, that compromise seems to fall into the grey area of the "decisions, not options" philosophy. Let's continue the discussion on the issue.

​@joemcgill commented on ​PR #8123:


21 months ago
#12

@Mamaduka One other observation about this PR is that it doesn't include the same post_type_default_rendering_mode filter for controlling this behavior that #7219 included. Given that we don't tend to offer filters for post type supports, this is probably ok, but we will want to consider the ways developers can easily customize these settings, given that they are registered after the post type, so hooking to registered_post_type will be too late for someone to change this value. Instead they'll need to do something like:

add_action(
        'init',
        function() {
                // Overwrite the editor support to remove default-mode.
                add_post_type_support( 'page', 'editor' );
        },
        99 // Fire after post types are registered.
);

​@Mamaduka commented on ​PR #8123:


21 months ago
#13

Yes, that’s correct way to override it. I was planning including similar snippet in dev note.

​@peterwilsoncc commented on ​PR #8123:


21 months ago
#14

@Mamaduka I took the liberty of merging in trunk to allow for dev environments that have upgraded to bcrypt hashing to log in.

​@peterwilsoncc commented on ​PR #8123:


21 months ago
#15

While the page template is locked in the new render mode, the edit links remain for template parts. Is this intended?

https://github.com/user-attachments/assets/85d4ae6d-75af-4ce8-967f-0e833f0b8ffa

​@peterwilsoncc commented on ​PR #8123:


21 months ago
#16

I figured out the failing tests:

The is_block_theme() call added to this function populates the options cache for the stylesheet and template. In the test suite's default set_up() function, this adds data to the cache after the global scope has been cleaned, including the cache.

​https://github.com/WordPress/wordpress-develop/blob/9acdbb9d8db4eba90d623eefd5ad312cde140593/tests/phpunit/includes/abstract-testcase.php#L117-L134

Reflushing the cache after setting the post types up causes additional failures so I am not sure what the most straight forward approach is for ensuring the test suite is in an expected state.

​@Mamaduka commented on ​PR #8123:


21 months ago
#17

Thanks, @peterwilsoncc!

While the page template is locked in the new render mode, the edit links remain for template parts. Is this intended?

IIRC, the edit link should only be available for users with the correct capabilities. They're also displayed in WP 6.7, if you enable show template from the sidebar.

Is the failing tests something we can resolve in test suite or do we need to change how new default is setup for Pages?

## Screenshot
https://github.com/user-attachments/assets/a1e1dd9f-3fd5-458c-9a55-bac108dffc59

​@joemcgill commented on ​PR #8123:


21 months ago
#18

Is the failing tests something we can resolve in test suite or do we need to change how new default is setup for Pages?

It looks like we just need to fix the tests. Probably calling the cleanup process again in the tear_down_after_class() method would be plenty.

​@Mamaduka commented on ​PR #8123:


21 months ago
#19

It looks like we just need to fix the tests. Probably calling the cleanup process again in the tear_down_after_class() method would be plenty.

@joemcgill, @peterwilsoncc, I would appreciate some guidance on that.

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


21 months ago

#21 @peterwilsoncc
21 months ago

  • Resolution → fixed
  • Status assigned → closed

In 59885:

Editor: Set new default rendering mode for Pages.

This update updates the page post-type definition and sets template-locked as the new default rendering mode for the block editor.

Props mamaduka, wildworks, joemcgill, tyb, swissspidy, audrasjb.
Fixes #61811.

​@huubl commented on ​PR #8123:


21 months ago
#22

Yes, that’s correct way to override it. I was planning including similar snippet in dev note.

Is there a way to force the the rendering mode to 'post-only' and have the 'Show template' button removed?

​@Mamaduka commented on ​PR #8123:


21 months ago
#23

Is there a way to force the the rendering mode to 'post-only'.

See code examples from Gutenberg PR - ​https://github.com/WordPress/gutenberg/pull/68549.

have the 'Show template' button removed?

This is part of general UI. There's no separate setting for it.

​@huubl commented on ​PR #8123:


21 months ago
#24

Is there a way to force the the rendering mode to 'post-only'.

See code examples from Gutenberg PR - ​WordPress/gutenberg#68549.

have the 'Show template' button removed?

This is part of general UI. There's no separate setting for it.

@Mamaduka thank you for your response. From what I understand, this code only sets the default rendering mode but doesn’t enforce it and still allows switching (and keep that as default).

add_action( 'init', function() {
	add_post_type_support( 'page', 'editor' );
} );

Please consider a way to disable 'Show template' and force 'post-only' as rendering mode. For clients, the fewer options, the better.

#25 @Mamaduka
20 months ago

This regressed after r59968. See ​https://github.com/WordPress/gutenberg/issues/69543.

The wp_set_editor_default_mode should use init hook and run after create_initial_post_types.

I'll create PR shortly. cc @joemcgill

#26 @Mamaduka
20 months ago

  • Resolution fixed
  • Status closed → reopened

This ticket was mentioned in ​PR #8499 on ​WordPress/wordpress-develop by ​@Mamaduka.


20 months ago
#27

## Testing Instructions

  1. Create a new editor or admin user.
  2. Switch to this user.
  3. Create a page.
  4. Confirm that it loads with template-locked as the default rendering mode.

Trac ticket: https://core.trac.wordpress.org/ticket/61811#comment:25

#28 @joemcgill
20 months ago

  • Resolution → fixed
  • Status reopened → closed

In 60033:

Editor: Change hook for 'wp_set_editor_default_mode'.

This is a follow up to [59968], which moves the wp_set_editor_default_mode() callback to init to make sure the subsequent call to create_initial_post_types() doesn't overwrite the post type support settings.

Props mamaduka, psykro.
Fixes #61811.

​@Mamaduka commented on ​PR #8499:


20 months ago
#29

Thanks for commiting this, @joemcgill!

Note: See TracTickets for help on using tickets.