Skip to content

No need for ternary when returning true/false #32

@justintadlock

Description

@justintadlock

In inc/functions.php, there's no need for the ternary:

function mesmerize_sanitize_checkbox($val)
{
    return (isset($val) && $val == true ? true : false);
}

That can simply be written as:

function mesmerize_sanitize_checkbox( $val ) {

	return isset( $val ) && $val;
}

Or:

function mesmerize_sanitize_checkbox( $val ) {

	return ! empty( $val );
}

The return value of the expression in either case will be true or false.

Just keep this in mind anytime you're returning true or false with a ternary. You almost never need it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions