Make WordPress Core


Ignore:
Timestamp:
10/20/2025 10:29:35 PM (13 months ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme.php

    r60934 r60995  
    15301530                $this->assertSame( $template_path, $new_template_path, 'Switching blogs switches the template path' );
    15311531        }
     1532
     1533        /**
     1534         * Verify the validate_theme_requirements theme responds as expected for twentyten.
     1535         *
     1536         * @ticket 54381
     1537         */
     1538        public function test_validate_theme_requirements_filter_default() {
     1539                // Default expectation since twentyten has the least strict requirements.
     1540                $this->assertTrue( validate_theme_requirements( 'twentyten' ) );
     1541        }
     1542
     1543        /**
     1544         * Verify that a filtered failure of validate_theme_requirements returns WP_Error
     1545         *
     1546         * @ticket 54381
     1547         */
     1548        public function test_validate_theme_requirements_filter_error() {
     1549                // Adds an extra requirement that always fails.
     1550                add_filter(
     1551                        'validate_theme_requirements',
     1552                        function () {
     1553                                return new WP_Error( 'theme_test_failed_requirement' );
     1554                        }
     1555                );
     1556
     1557                $this->assertInstanceOf( 'WP_Error', validate_theme_requirements( 'twentyten' ) );
     1558        }
     1559
     1560        /**
     1561         * Verify that the theme is passed through to the validate_theme_requirements filter by selectively erroring.
     1562         *
     1563         * @ticket 54381
     1564         */
     1565        public function test_validate_theme_requirements_filter_selective_failure() {
     1566                // Adds an extra requirement only for a particular theme.
     1567                add_filter(
     1568                        'validate_theme_requirements',
     1569                        function ( $met_requirements, $stylesheet ) {
     1570                                if ( 'twentytwenty' === $stylesheet ) {
     1571                                        return new WP_Error( 'theme_test_failed_requirement' );
     1572                                }
     1573                                return $met_requirements;
     1574                        },
     1575                        10,
     1576                        2
     1577                );
     1578
     1579                $this->assertTrue( validate_theme_requirements( 'twentyten' ) );
     1580                $this->assertInstanceOf( 'WP_Error', validate_theme_requirements( 'twentytwenty' ) );
     1581        }
    15321582}
Note: See TracChangeset for help on using the changeset viewer.