Make WordPress Core

Opened 5 years ago

Closed 13 months ago

Last modified 12 months ago

#54381 closed enhancement (fixed)

Add filter to validate_theme_requirements

Reported by: kraftbj Owned by: kraftbj
Priority: normal Milestone: 6.9
Component: Themes Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

There may be the need to add extra requirements for a theme to validate that site administrators may want to add. The validate_theme_requirements function looks keen for this, but there are currently no hooks in the function.

An example use case: A particular site on a multisite should never have a theme changed via the UI (a mission-critical site). The multisite, generally, has various themes network activated. Such a filter could allow a site administrator to check the blog ID and return a WP_Error if the blog ID is in a "theme_change_disallowed" array.

Proposing a validate_theme_requirement filter that hooks at the end of the current function to allow additional validation requirements. Intentionally not filtering the current failing conditions (incompatible WP or PHP) to prevent poor implementation of the filter to lead to a PHP/WP version-related fatal.

Attachments (1)

54381-validate-theme-requirements-filter.diff​ (792 bytes ) - added by sachinrajcp123 16 months ago.

Download all attachments as: .zip

Change History (13)

This ticket was mentioned in ​PR #1812 on ​WordPress/wordpress-develop by ​kraftbj.


5 years ago
#1

  • Keywords has-patch has-unit-tests added

Adds a filter, validate_theme_requirements, to allow for additional theme validation requirements.

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

#2 @sachinrajcp123
16 months ago

Enhancement: Add filter hook to allow customization of validate_theme_requirements() results.

#3 @kraftbj
16 months ago

  • Milestone Awaiting Review → 6.9
  • Owner set to kraftbj
  • Status new → accepted

Refreshed the patch to see if we can land in 6.9!

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


14 months ago

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


13 months ago

#6 @wildworks
13 months ago

This ticket was featured on today's 6.9 Bug Scrub.

Maybe @jorbin will take a look at this ticket if he has time.

#7 @joedolson
13 months ago

It really seems like we should add the same filtering capabilities in validate_plugin_requirements(), at the same time, which seems to have the same limitations.

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


13 months ago
#8

For API consistency, add a filter to validate_plugin_requirement comparable to validate_theme_requirement

Not sure where tests for this might live, if we need them.

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

​@jorbin commented on ​PR #10361:


13 months ago
#10

@joedolson good catch. I agree.

#11 @jorbin
13 months ago

  • Resolution → fixed
  • Status accepted → closed

In 60995:

Plugins and Themes: Add filters to validation functions.

It is now possible to add additional validation requirements for themes and plugins besides the built in core checks.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/1812 and ​https://github.com/WordPress/wordpress-develop/pull/10361.

Props kraftbj, mukesh27, jorbin, joedolson.
Fixes #54381.

#12 @desrosj
12 months ago

The miscellaneous developer-focused changes developer note mentioned the two new hooks introduced in [60995] but did not cover their usage in depth: ​https://make.wordpress.org/core/2025/11/17/miscellaneous-developer-focused-changes-in-6-9/.

Note: See TracTickets for help on using tickets.