Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/wp-admin/class-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static function render_approve_domains_field() {
public static function render_comment_settings_field() {
?>
<fieldset>
<?php if ( ! function_exists( 'wp_is_block_theme' ) || ! \wp_is_block_theme() ) : ?>
<?php if ( ! \webmention_use_block_hooks() ) : ?>
<p>
<label for="webmention_show_comment_form">
<input type="checkbox" name="webmention_show_comment_form" id="webmention_show_comment_form" value="1" <?php \checked( true, \get_option( 'webmention_show_comment_form' ) ); ?> />
Expand Down
30 changes: 30 additions & 0 deletions tests/phpunit/tests/class-test-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function test_block_theme_falls_back_when_form_block_is_missing() {
$registry->unregister( 'webmention/form' );
$this->assertFalse( webmention_use_block_hooks() );

ob_start();
\Webmention\WP_Admin\Settings_Fields::render_comment_settings_field();
$this->assertStringContainsString( 'name="webmention_show_comment_form"', ob_get_clean() );

$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );
the_post();
Expand All @@ -43,6 +47,32 @@ public function test_block_theme_falls_back_when_form_block_is_missing() {
}
}

/**
* Test that disabling Block Hooks preserves the classic form setting in block themes.
*/
public function test_block_theme_shows_form_setting_when_hooks_are_disabled() {
if ( ! site_supports_blocks() ) {
$this->markTestSkipped( 'Block themes are not supported.' );
}

$stylesheet = get_stylesheet();
register_theme_directory( DIR_TESTDATA . '/themedir1' );
switch_theme( 'block-theme' );
add_filter( 'webmention_use_block_hooks', '__return_false' );

try {
$this->assertFalse( webmention_use_block_hooks() );
ob_start();
\Webmention\WP_Admin\Settings_Fields::render_comment_settings_field();
$settings = ob_get_clean();
$this->assertStringContainsString( 'name="webmention_show_comment_form"', $settings );
$this->assertStringContainsString( 'name="webmention_comment_form_text"', $settings );
} finally {
remove_filter( 'webmention_use_block_hooks', '__return_false' );
switch_theme( $stylesheet );
}
}

/**
* Test actual hook insertion and rendering with a block theme and a disabled legacy option.
*/
Expand Down
Loading