I have php log error like:
2024/06/26 18:26:17 [error] 231349#231349: *424966 FastCGI sent in stderr: "PHP message: PHP Warning: Undefined array key "block" in /var/www/test/wp-content/plugins/javascript-notifier/javascript-notifier.php on line 74" while reading upstream, client: IP, server: test.test, request: "GET /blablabla/ HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php8.3-fpm.sock:", host: "blablabla"
The error message indicates that the array key block
is being accessed in the plugin’s code without first checking if it exists. Maybe to prevent the PHP warning, you can add a check to ensure that the block
key is defined before using it. Here is the modified part of the code in javascript-notifier.php
:
add_action( 'wp_footer',
function() {
$settings = get_option( 'javascript_notifier_settings' );
$block = isset($settings['block']) ? $settings['block'] : '';
$style = 'style="background-color:' . $settings['bg_color'] . ';color:' . $settings['fg_color'] . ';font-size:' . $settings['font_size'] . '%;opacity:' . $settings['opacity'] . ';' . $settings['custom_css'] . '"';
?>
<!-- JavaScript Notifier -->
<?php if( $block ) : ?><div class="javascript_notifier" id="javascript_notifier_block" <?php echo $style; ?>><div id="javascript_notifier_block_2"><div id="javascript_notifier_block_3"><?php else : ?><div class="javascript_notifier" id="javascript_notifier_bar" <?php echo $style; ?>><?php endif; ?><strong><?php echo $settings['message']; ?></strong></div><?php if( $block ) : ?></div></div><?php endif; ?>
<script id="hide-javascript-notifier-js" type="application/javascript">
document.getElementById('javascript_notifier_<?php echo( $block ? 'block' : 'bar' ); ?>').style.setProperty('display', 'none', 'important');
</script>
<!-- End JavaScript Notifier -->
<?php
}, 1 );
By adding isset($settings['block']) ? $settings['block'] : ''
, we can ensure that the $block
variable is set to an empty string if the block
key is not defined in the $settings
array. This will prevent the PHP warning from being triggered. I tested it and it works for me, but maybe review it as I am not a developer and maybe there is other solution for that.