Make WordPress Core

Opened 7 months ago

Closed 6 months ago

Last modified 5 months ago

#63743 closed enhancement (wontfix)

General: Prevent php warning for not readable files

Reported by: ninos-ego's profile Ninos Ego Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Themes Keywords:
Focuses: Cc:

Description

Having unreadable php-files in theme-directory triggers following php-warning:

file_get_contents(/path/to/thememaySubdir/file.php): Failed to open stream: No such file or directory in /wp-includes/class-wp-theme.php#L1333

This PR hardens the get_post_templates() function a bit.

Ref:
https://github.com/WordPress/wordpress-develop/pull/9311

Change History (8)

This ticket was mentioned in PR #9311 on WordPress/wordpress-develop by @Ninos Ego.


7 months ago
#1

Having unreadable php-files in theme-directory triggers following php-warning:

file_get_contents(/path/to/thememaySubdir/file.php): Failed to open stream: No such file or directory in /wp-includes/class-wp-theme.php#L1333

This PR hardens the get_post_templates() function a bit.

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

@mindctrl commented on PR #9311:


7 months ago
#2

How would site admins, or log monitoring tools, know when there's a file read error if we suppress errors?

@Ninos Ego commented on PR #9311:


7 months ago
#3

How would site admins, or log monitoring tools, know when there's a file read error if we suppress errors?

For me such error output only makes sense for files which must be readable. The function parses all php-files in theme's subdirectories, not only template files, also which are not relevant for templating. Would be better to have some predefined folders (theme dir, /templates, ...) for parsing (also for performance reasons), but this would may break compatibility with some themes.

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


7 months ago

#5 @krupajnanda
7 months ago

  • Keywords needs-test-info needs-screenshots added

Hi @ninos-ego

Thanks for the patch!

Could you share how this warning is triggered? What are scenarios/use-cases here? Additionally, if you could share steps along with some visual/screenshot will be helpful to validate the patch and its impact more accurately.

#6 @jorbin
7 months ago

  • Component changed from General to Themes
  • Keywords close added

Having an unreadable file in your theme feels more like a misconfiguration of a site than something that should be blindly ignored.

#7 @mindctrl
6 months ago

  • Keywords has-patch needs-test-info needs-screenshots close removed
  • Resolution set to wontfix
  • Status changed from new to closed

I agree with @jorbin here. I don't think it's wise to hide file read errors. Hiding errors from site admins and monitoring tools makes the problem harder to discover and debug. With that in mind, I'm going to close this ticket to help clean up Trac. Feel free to reopen if you think this is a problem that needs to be solved in a more visible way.

#8 @sabernhardt
5 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.