Make WordPress Core

Changeset 59564


Ignore:
Timestamp:
12/28/2024 10:08:19 PM (12 months ago)
Author:
SergeyBiryukov
Message:

Options, Meta APIs: Ensure after_section is printed for sections without any fields.

This brings consistency with the before_section HTML content, which did get printed in do_settings_sections() regardless of whether the settings section has any fields attached.

Follow-up to [8855], [21742], [54247].

Props alpipego, SergeyBiryukov.
Fixes #62746.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template.php

    r59224 r59564  
    17851785        }
    17861786
    1787         if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
    1788             continue;
    1789         }
    1790         echo '<table class="form-table" role="presentation">';
    1791         do_settings_fields( $page, $section['id'] );
    1792         echo '</table>';
     1787        if ( isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
     1788            echo '<table class="form-table" role="presentation">';
     1789            do_settings_fields( $page, $section['id'] );
     1790            echo '</table>';
     1791        }
    17931792
    17941793        if ( '' !== $section['after_section'] ) {
  • trunk/tests/phpunit/tests/admin/includesTemplate.php

    r58136 r59564  
    242242
    243243    /**
     244     * @ticket 62746
     245     *
     246     * @param array  $extra_args                   Extra arguments to pass to function `add_settings_section()`.
     247     * @param array  $expected_section_data        Expected set of section data.
     248     * @param string $expected_before_section_html Expected HTML markup to be rendered before the settings section.
     249     * @param string $expected_after_section_html  Expected HTML markup to be rendered after the settings section.
     250     *
     251     * @covers ::add_settings_section
     252     * @covers ::do_settings_sections
     253     *
     254     * @dataProvider data_extra_args_for_add_settings_section
     255     */
     256    public function test_add_settings_section_without_any_fields( $extra_args, $expected_section_data, $expected_before_section_html, $expected_after_section_html ) {
     257        add_settings_section( 'test-section', 'Section title', '__return_false', 'test-page', $extra_args );
     258
     259        ob_start();
     260        do_settings_sections( 'test-page' );
     261        $output = ob_get_clean();
     262
     263        $this->assertStringContainsString( $expected_before_section_html, $output, 'Test page output does not contain the custom markup to be placed before the section.' );
     264        $this->assertStringContainsString( $expected_after_section_html, $output, 'Test page output does not contain the custom markup to be placed after the section.' );
     265    }
     266
     267    /**
    244268     * Data provider for `test_add_settings_section_with_extra_args()`.
    245269     *
Note: See TracChangeset for help on using the changeset viewer.