Givewp: Country with no base state defined returns false instead of array()

Created on 14 Dec 2017  Β·  6Comments  Β·  Source: impress-org/givewp

Issue Overview

give_get_state() returns false if no base state is selected. Should return empty array. When the default state is retrieved 'false' is converted to a string and is set as the default state.

Expected Behavior

Selecting a country with no states and no default state selected should have an empty input for county or state.

Current Behavior

Input field for country or state is autopopulated with "false"

Possible Solution

in Give/1.8.18
/includes/country-functions.php:38
replace with
$state = isset( $give_options['base_state'] ) ? $give_options['base_state'] : array();

Temporary Workaround

Add this snippet to the theme functions.php

add_filter(
    'give_give_states',
    function($state)
    {
        return ($state === false ? [] : $state);
    }
);

Steps to Reproduce (for bugs)

  1. In Give Settings, set Base Country to "United Kingdom"
  2. Do not set a base county/province
  3. In a donation form's billing details, select "United Kingdom"
  4. Note that the county input is defaulted to "false"

Related Issues and/or PRs

N/A

Todos

  • [ ] Tests
  • [ ] Documentation

WordPress Environment

wpgive-form-screenshot

WordPress Environment

Home URL: https://www.childrenincrossfire.org
Site URL: https://www.childrenincrossfire.org
WP Version: 4.9.1
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: βœ”
WP Cron: βœ”
Language: en_US
Permalink Structure: /%postname%/
Show on Front: page
Page on Front: Home (#27)
Page for Posts: Unset
Table Prefix Length: 6
Table Prefix Status: Acceptable
Admin AJAX: Inaccessible
Registered Post Statuses: publish, future, draft, pending, private, trash, auto-draft, inherit, wc-pending, wc-processing, wc-on-hold, wc-completed, wc-cancelled, wc-refunded, wc-failed, refunded, failed, revoked, cancelled, abandoned, processing, preapproval, give_subscription

Server Environment

Hosting Provider: DBH: localhost, SRV: www.childrenincrossfire.org
TLS Connection: Connection uses TLS 1.2
TLS Connection: Bad
Server Info: LiteSpeed
PHP Version: ❌ 5.5.38 - We recommend a minimum PHP version of 5.6. See: PHP Requirements in Give
PHP Post Max Size: 100 MB
PHP Time Limit: 60
PHP Max Input Vars: 5000
PHP Max Upload Size: 100 MB
cURL Version: 7.54.0, OpenSSL/1.0.2k
SUHOSIN Installed: –
Default Timezone is UTC: βœ”
fsockopen/cURL: βœ”
SoapClient: ❌ Your server does not have the SoapClient class enabled - some gateway plugins which use SOAP may not work as expected.
DOMDocument: βœ”
gzip: βœ”
GD Graphics Library: βœ”
Multibyte String: βœ”
Remote Post: βœ”
Remote Get: βœ”

Give Configuration

Give Version: 1.8.17
Upgraded From: –
Test Mode: Disabled
Currency Code: GBP
Currency Position: Before
Decimal Separator: .
Thousands Separator: ,
Success Page: https://www.childrenincrossfire.org/donation-confirmation/
Failure Page: https://www.childrenincrossfire.org/donation-failed/
Donation History Page: https://www.childrenincrossfire.org/donation-history/
Give Forms Slug: /donations/
Enabled Payment Gateways: Stripe - Credit Card
Default Payment Gateway: Stripe - Credit Card
PayPal IPN Verification: Enabled
PayPal IPN Notifications: N/A
Admin Email Notifications: Enabled
Donor Email Access: Enabled

Session Configuration

Give Use Sessions: Enabled
Session: Enabled
Session Name: PHPSESSID
Cookie Path: /
Save Path: /tmp
Use Cookies: Enabled
Use Only Cookies: Enabled

Active Give Add-ons

Give - Form Field Manager: βœ” Licensed – by WordImpress – 1.2.4
Give - Recurring Donations: βœ” Licensed – by WordImpress – 1.4.2
Give - Stripe Gateway: βœ” Licensed – by WordImpress – 1.5.1

Other Active Plugins

Akismet Anti-Spam: by Automattic – 4.0.1
Bootstrap 3 Shortcodes: by Michael W. Delaney, Filip Stefansson, and Simon Yeldon – 3.3.10
Duplicate Post: by Enrico Battocchi – 3.2.1
Envira Gallery: by Envira Gallery Team – 1.7.1
Gravity Forms: by rocketgenius – 1.9.13.7
iThemes Security: by iThemes – 6.6.1
MetaSlider: by Team Updraft – 3.6.6
Postman SMTP: by Jason Hendriks – 1.7.2
Redirection: by John Godley – 2.10.1
Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 2.3.1
Seriously Simple Podcasting: by Castos – 1.19.3
TablePress: by Tobias BΓ€thge – 1.9
Thumbnail Upscale: by Stanislav Khromov – 1.1
UpdraftPlus - Backup/Restore: by UpdraftPlus.Com, DavidAnderson – 1.13.16
WooCommerce: by Automattic – 3.2.5
Wordfence Security: by Wordfence – 6.3.22
WP-Optimize: by David Anderson, Ruhani Rabin, Team Updraft – 2.1.1
WP Fastest Cache: by Emre Vona – 0.8.7.5
WP Fastest Cache Premium: by Emre Vona – 1.4.2
WP Maintenance Mode: by Designmodo – 2.0.9
WP Quiz: by MyThemeShop – 1.1.0
Yoast SEO: by Team Yoast – 5.8

Inactive Plugins

Advanced Sidebar Menu: by Mat Lipe – 7.0.1
Compress JPEG & PNG images: by TinyPNG – 2.2.6
Contact Form 7: by Takayuki Miyoshi – 4.9.2
Google XML Sitemaps: by Arne Brachhold – 4.0.9

Theme

Name: Children in Crossfire
Version: 1.1
Author URL:
Child Theme: Yes
Parent Theme Name: White Whale Framework
Parent Theme Version: 1.0.0
Parent Theme Author URL: http://whitewhaleweb.com

Most helpful comment

Thanks for reporting. @raftaar1191 is looking into it asap.

All 6 comments

Thanks for reporting. @raftaar1191 is looking into it asap.

@hahn208 @DevinWalker I have tried to reproduce this issue with the latest code of Give 1.8.18 branch and the current version of Give 1.8.17, but I couldn't reproduce this issue.

ezgif com-video-to-gif

@emgk It looks like you used his reproduce steps... but on 1.8.18 - can you verify the bug in the current release version of 1.8.17?

Yes @DevinWalker, I have tested it with Give version 1.8.17 but couldn't able to reproduce it.

It looks like the issue stemmed from a line of JS that I added on DOM loaded document.querySelector('#billing_country').selectedIndex=0; which sets the country to none by default. I added a trigger to fire the onchange event on that element, which has fixed the problem.

Thanks for following up!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

henryholtgeerts picture henryholtgeerts  Β·  3Comments

mathetos picture mathetos  Β·  3Comments

Benunc picture Benunc  Β·  3Comments

vukvukovich picture vukvukovich  Β·  4Comments

mathetos picture mathetos  Β·  4Comments