Skip to content

Commit 639bd9d

Browse files
committed
Remove unnecessary variables and consolidate changes
1 parent 823018e commit 639bd9d

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

plugins/speculation-rules/settings.php

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,7 @@ function plsr_render_settings_field( array $args ): void {
284284
return; // @codeCoverageIgnore
285285
}
286286

287-
$value = $option[ $args['field'] ];
288-
$show_notice = 'authentication' === $args['field'] && ! wp_using_ext_object_cache();
289-
$show_warning = $show_notice && 'logged_out' !== $value;
287+
$value = $option[ $args['field'] ];
290288
?>
291289
<fieldset id="<?php echo esc_attr( 'plsr-' . $args['field'] . '-setting' ); ?>">
292290
<legend class="screen-reader-text"><?php echo esc_html( $args['title'] ); ?></legend>
@@ -304,8 +302,8 @@ function plsr_render_settings_field( array $args ): void {
304302
</p>
305303
<?php endforeach; ?>
306304

307-
<?php if ( $show_notice ) : ?>
308-
<div id="plsr-auth-notice" class="notice <?php echo esc_attr( $show_warning ? 'notice-warning' : 'notice-info' ); ?> inline">
305+
<?php if ( 'authentication' === $args['field'] && ! wp_using_ext_object_cache() ) : ?>
306+
<div id="plsr-auth-notice" class="notice <?php echo esc_attr( 'logged_out' !== $value ? 'notice-warning' : 'notice-info' ); ?> inline">
309307
<p>
310308
<?php
311309
echo wp_kses(
@@ -324,6 +322,26 @@ function plsr_render_settings_field( array $args ): void {
324322
?>
325323
</p>
326324
</div>
325+
<?php
326+
// phpcs:ignore Squiz.PHP.Heredoc.NotAllowed -- Part of the PCP ruleset. Appealed in <https://github.com/WordPress/plugin-check/issues/792#issuecomment-3214985527>.
327+
$js = <<<'JS'
328+
const authOptions = document.getElementById( 'plsr-authentication-setting' );
329+
const noticeDiv = document.getElementById( 'plsr-auth-notice' );
330+
if ( authOptions && noticeDiv ) {
331+
authOptions.addEventListener( 'change', ( /** @type {Event} */ event ) => {
332+
const target = event.target;
333+
if ( ! ( target instanceof HTMLInputElement && 'radio' === target.type ) ) {
334+
return;
335+
}
336+
const isLoggedOut = ( target.value === 'logged_out' );
337+
noticeDiv.classList.toggle( 'notice-info', isLoggedOut );
338+
noticeDiv.classList.toggle( 'notice-warning', ! isLoggedOut );
339+
} );
340+
}
341+
JS;
342+
// 👆 This 'JS;' line can only be indented two tabs when minimum PHP version is increased to 7.3+.
343+
wp_print_inline_script_tag( $js, array( 'type' => 'module' ) );
344+
?>
327345
<?php endif; ?>
328346

329347
<p class="description" style="max-width: 800px;">
@@ -341,28 +359,7 @@ function plsr_render_settings_field( array $args ): void {
341359
?>
342360
</p>
343361
</fieldset>
344-
345362
<?php
346-
if ( $show_notice ) {
347-
// phpcs:ignore Squiz.PHP.Heredoc.NotAllowed -- Part of the PCP ruleset. Appealed in <https://github.com/WordPress/plugin-check/issues/792#issuecomment-3214985527>.
348-
$js = <<<'JS'
349-
const authOptions = document.getElementById( 'plsr-authentication-setting' );
350-
const noticeDiv = document.getElementById( 'plsr-auth-notice' );
351-
if ( authOptions && noticeDiv ) {
352-
authOptions.addEventListener( 'change', ( /** @type {Event} */ event ) => {
353-
const target = event.target;
354-
if ( ! ( target instanceof HTMLInputElement && 'radio' === target.type ) ) {
355-
return;
356-
}
357-
const isLoggedOut = ( target.value === 'logged_out' );
358-
noticeDiv.classList.toggle( 'notice-info', isLoggedOut );
359-
noticeDiv.classList.toggle( 'notice-warning', ! isLoggedOut );
360-
} );
361-
}
362-
JS;
363-
// 👆 This 'JS;' line can only be indented two tabs when minimum PHP version is increased to 7.3+.
364-
wp_print_inline_script_tag( $js, array( 'type' => 'module' ) );
365-
}
366363
}
367364

368365
/**

0 commit comments

Comments
 (0)