• DJABHipHop

    (@pressthemes1)


    Let’s say Website field is hidden then we remove “, and website “ and make “, Email” say “, and email
    Let’s say Email field is hidden then we remove “, Email
    Let’s say both Email & Website field is hidden then we remove “, Email , and website
    My code not perfect but it works

    public function comment_form_default_fields_filter($fields) {
    // Fetch options from wherever they are defined
    $options = $this->options(); // Assuming $this->options() retrieves the options array

    // Initialize text variables for conditional use
    $url_text = ', and website '; // Default text for URL field
    $email_text = ', email'; // Default text for email field

    // Check if email field should be removed
    if (!empty($options['remove_email'])) {
    unset($fields['email']); // Remove email field from fields array
    $email_text = ''; // Update email text if field is removed
    }

    // Check if URL field should be hidden
    if (!empty($options['hide_url'])) {
    unset($fields['url']); // Remove URL field from fields array
    $url_text = ''; // Update URL text if field is hidden

    // If both remove_email and hide_url are true, reset email_text
    if (!empty($options['remove_email'])) {
    $email_text = '';
    } else {
    $email_text = ', and email';
    }
    }

    // Fetch current commenter's information
    $commenter = wp_get_current_commenter();

    // Check if commenter's email is present to pre-check consent checkbox
    $consent = empty($commenter['comment_author_email']) ? '' : ' checked="checked"';

    // Construct the consent checkbox field with appropriate text
    $fields['cookies'] = '<p class="comment-form-cookies-consent"><label for="wp-comment-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . 'Save my name' . $email_text . $url_text . ' in this browser for the next time I comment.</label></p>';

    // Return modified fields array
    return $fields;
    }
  • You must be logged in to reply to this topic.