Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#50030 closed defect (bug) (wontfix)

Post Attributes default template's value is empty

Reported by: sandesh055's profile sandesh055 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.5
Component: Editor Keywords: has-patch reporter-feedback
Focuses: Cc:

Description

Default template value is empty in gutenberg.

File : wp-admin\edit-form-blocks.php
Line number : 162

Before the value was "default"

File : wp-admin\includes\meta-boxes.php
Line number : 988

Attachments (1)

edit-form-blocks.diff (844 bytes) - added by sandesh055 5 years ago.
Fix of the default template value bug

Download all attachments as: .zip

Change History (14)

@sandesh055
5 years ago

Fix of the default template value bug

#1 @sandesh055
5 years ago

  • Keywords has-patch added; needs-patch removed

This ticket was mentioned in PR #312 on WordPress/wordpress-develop by sandeshjangam.


5 years ago
#2

Default template value is empty in gutenberg.
File : wp-admin\edit-form-blocks.php
Line number : 162

Before the value was "default"
File : wp-admin\includes\meta-boxes.php
Line number : 988

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

#3 @sandesh055
5 years ago

  • Keywords 2nd-opinion dev-feedback needs-testing added

#4 @noisysocks
4 years ago

  • Keywords 2nd-opinion removed

Hi @sandesh055. Not sure what you mean here. The code you linked to in your "before" example doesn't have an associative array at all.

Is there a bug that this fixes? How do I spot it?

#5 @sandesh055
4 years ago

@noisysocks Seems like the "Before" code is updated in the latest version

Now the line number is 1001. Check this below code,

File : wp-admin\includes\meta-boxes.php
Line number: 1001

Reference code -

<select name="page_template" id="page_template">
	
<option value="default"><?php echo esc_html( $default_title ); ?></option>

--- Gutenberg Editor ---

After the WordPress Gutenberg update, the value of the "Default template" is "empty" in "Post attributes"
Here is a screenshot - https://a.cl.ly/Jruql5AL

--- Classic Editor ---

If you enable the classic editor, then you will see the value of the "Default template" is "default" in "Post attributes"
Here is a screenshot - https://a.cl.ly/7KubJnyz

------ Solution -----

I have created a fix in the diff file.

File : wp-admin\edit-form-blocks.php
Line number: 162

Reference code -

$available_templates = ! empty( $available_templates ) ? array_merge(
	array(
		/** This filter is documented in wp-admin/includes/meta-boxes.php */
		'' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ),
	),
	$available_templates
) : $available_templates;

You can see that the key of "Default template" is empty instead of "default"

I hope it clears the confusion.

#6 @noisysocks
4 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 5.7

Thanks for clearing that up :)

#7 follow-up: @noisysocks
4 years ago

  • Keywords reporter-feedback added; needs-testing removed

I tested PR #312 locally and noticed that it introduces a "Updating failed. Invalid parameter(s): template" error when you change the template to Default template and save the post.

This is because the posts REST endpoint requires template to be '' or a valid template file. It does not allow 'default'.

@sandesh055: Does having the option's value set to "" cause a user-facing bug somewhere?

#8 in reply to: ↑ 7 @sandesh055
4 years ago

Ohh, Users are not facing a bug directly but conditions based on the "default" key causing an issue sometimes.

As a developer needs to keep both the condition old one and new i.e. compare with 'default' and 'empty' to maintain compatibility.

Replying to noisysocks:

I tested PR #312 locally and noticed that it introduces a "Updating failed. Invalid parameter(s): template" error when you change the template to Default template and save the post.

This is because the posts REST endpoint requires template to be '' or a valid template file. It does not allow 'default'.

@sandesh055: Does having the option's value set to "" cause a user-facing bug somewhere?

#9 @noisysocks
4 years ago

@sandesh055: Which code needs to check both conditions? A hook? (Which hook?) Or code that looks at the editor DOM?

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


4 years ago

#11 follow-up: @johnbillion
4 years ago

  • Milestone changed from 5.7 to Awaiting Review

@sandesh055 Do you have some more info about this issue as above please? Thanks!

#12 in reply to: ↑ 11 @sandesh055
4 years ago

Sorry, somehow I missed the last notification.

I was working on the overriding template based on selected post attributes. At that time, I was checking 'default' value. Somehow, I have managed backward compatibility by changing conditions in plugin.

As @noisysocks said, the pr is causing some other issue and that is directly breaking.

I think, we should close this ticket.
It seems like not a major issue and not affecting many sites directly.

Your thoughts please?

Replying to johnbillion:

@sandesh055 Do you have some more info about this issue as above please? Thanks!

#13 @johnbillion
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for the follow-up @sandesh055, much appreciated! I'll close this off in that case.

Note: See TracTickets for help on using tickets.