WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#28170 closed enhancement (fixed)

Add utility method for casting a var to boolean

Reported by: wonderboymusic Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 4.0
Component: General Keywords: has-patch
Focuses: Cc:

Description

Because PHP can be configured without --filter, it is not 100% safe to use filter_var(). This is problematic for casting "false" to false, as PHP always casts it to true. FILTER_VALIDATE_BOOLEAN fixes this, but it may not be available.

Proposed new function: wp_validate_boolean().

Attachments (1)

28170.diff (645 bytes) - added by wonderboymusic 6 years ago.

Download all attachments as: .zip

Change History (4)

@wonderboymusic
6 years ago

This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.


6 years ago

#2 @wonderboymusic
6 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28542:

Because PHP can be configured without --filter, it is not 100% safe to use filter_var(). This is problematic for casting "false" to false, as PHP always casts it to true. FILTER_VALIDATE_BOOLEAN fixes this, but it may not be available.

Add a new function, wp_validate_boolean(), to replace filter_var( $var, FILTER_VALIDATE_BOOLEAN ).

Fixes #28170.

This ticket was mentioned in Slack in #core-restapi by ocean90. View the logs.


4 years ago

Note: See TracTickets for help on using tickets.