Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify template parts in error messages #28398

Merged

Conversation

carolinan
Copy link
Contributor

@carolinan carolinan commented Jan 21, 2021

Description

Fixes #28056

This PR adds the template part slug to the error messages when a template part can not be found.
The error message on the front is only visible to logged in users and is now translatable.

How has this been tested?

To confirm the issue in #28056 you first need a full site editing theme where a template part is missing.
You can install TT1 Blocks and rename either the header or footer template part files inside
the block-template-parts folder, and view the site editor and the front.

In the site editor, you should see the message: Template part has been deleted or is unavailable.
On the front, you should see: Template Part Not Found.
If you log out, you should see that the error message is visible to all visitors.

Apply the PR.
View the front while logged out. The error message should not be visible.
Login. The error message should now say: Template part has been deleted or is unavailable: (template part slug)
Open the site editor. The error message should now say: Template part has been deleted or is unavailable: (template part slug)

Screenshots

template part error message with slug to identify which template part that is missing.

Types of changes

Enhancement, bug fix.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

Adding the template part slug to the error messages helps developers identify the missing template part.
@carolinan carolinan requested a review from ajitbohra as a code owner January 21, 2021 16:23
@carolinan carolinan added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label Jan 21, 2021
@gziolo gziolo added the Internationalization (i18n) Issues or PRs related to internationalization efforts label Jan 21, 2021
Base automatically changed from master to trunk March 1, 2021 15:45
@carolinan carolinan requested a review from aristath March 4, 2021 06:19
Copy link
Member

@aristath aristath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -65,8 +65,12 @@ function render_block_core_template_part( $attributes ) {
}
}

if ( ! $template_part_id || is_null( $content ) ) {
return __( 'Template Part not found.' );
if ( is_null( $content ) && is_user_logged_in() ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check for a user role and not only logged in users?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that too... Maybe current_user_can( edit_themes ); 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps leave it as is until #27597

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ That's why I approved the PR 😆

@carolinan carolinan merged commit 73b2d92 into WordPress:trunk Mar 23, 2021
@github-actions github-actions bot added this to the Gutenberg 10.3 milestone Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code Internationalization (i18n) Issues or PRs related to internationalization efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the "Template Part Not Found" error message
3 participants