• 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
    • This topic was modified 2 years, 3 months ago by t-p. Reason: Moved to Fixing WordPress from Everything else WordPress
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Fix Query Monitor PHP Warning : Undefined Variable $checked’ is closed to new replies.