• Resolved Generosus

    (@generosus)


    Help Appreciated!

    I am using a code snippet (PHP code) that adds a checkbox to our WordPress registration form.

    The PHP code is working great, but when I activate Query Monitor (plugin) it is displaying the following PHP Warning (backend): “Undefined Variable $checked

    Details: https://prnt.sc/1ruAIrLHBzvJ

    The affected PHP code is presented below. Any idea how to fix this? (i.e., how should I define the variable “$checked”?)

    Thank you.

    __________________

    // Add the checkbox to registration form
    add_action( 'register_form', 'foo_add_privacy_policy_field' );
    function foo_add_privacy_policy_field() {
      $checked = isset( $_POST['foo_privacy_policy'] ) ? ' checked="checked"' : ''; ?>
      <p>
        <input type="checkbox" name="foo_privacy_policy" id="foo_privacy_policy" class="checkbox" value="1" <?php echo $checked; ?> style="margin-top: .2px; height: 1rem; width: 1rem;" />
        <label for="foo_privacy_policy" style="display: inline!important;"><?php _e( 'I have read and accept your <a href="/privacy/" rel="noopener noreferrer" target="_blank"><u>Privacy Policy</u></a>.', 'foo' ) ?>
        </label>
      </p>
      <?php
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    This isn’t an appropriate forum for asking for coding advice, please use the main support forums or a general PHP support forum.

    Thread Starter Generosus

    (@generosus)

    Hi @johnbillion,

    Respectfully, the intent here is to make sure your plugin is not generating false positives. So, can you look into that?

    Thank you.

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    The error handler in Query Monitor reports errors that PHP itself captures, there’s nothing special about the way that QM identifies errors.

    I recommend that you try inserting that code directly into a plugin or theme file rather than eval()-ing it via a PHP snippet plugin. There might be some oddness with the way the code is handled by the plugin. Check that you’re not missing the closing } on the function too.

    Thread Starter Generosus

    (@generosus)

    Solved:

    Your plugin and advice forced us to re-evaluate our entire PHP code snippet. We identified a code line that was improperly “commented out.” That is, “//” was not used properly.

    Thank you!

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Glad you got it sorted ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to Fix Query Monitor PHP Warning : Undefined Variable $checked’ is closed to new replies.