samikeijonen / checathlon

Business type of theme with pixel perfect design
https://foxland.fi/downloads/checathlon/
8 stars 4 forks source link

Ternary: Returning true/false #8

Closed justintadlock closed 7 years ago

justintadlock commented 7 years ago

In inc/template-tags.php, you have several functions that return true or false like so:

return ( is_page_template( 'templates/pricing-page.php' ) ) ? true : false;

There's really no need for that. is_page_template(), in this example, will return true or false on its own. So, you merely need:

return is_page_template( 'templates/pricing-page.php' );

Your inline doc is already appropriately marked @return bool, so this is even clear to those unfamiliar with the return value of is_page_template().

Even multiple checks like in this example:

return ( is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) || is_active_sidebar( 'sidebar-5' ) ) ? true : false;

Can be:

return is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) || is_active_sidebar( 'sidebar-5' );

It'll save on unnecessary code.

justintadlock commented 7 years ago

Noticed the same thing in your inc/customizer files too, such as this example:

function checathlon_show_featured_title( $control ) {

    if ( 'nothing' != $control->manager->get_setting( 'front_page_featured' )->value() ) {
        return true;
    } else {
        return false;
    }

}

You can simply return:

return 'nothing' != $control->manager->get_setting( 'front_page_featured' )->value();

The return value is the result of the != operation.

samikeijonen commented 7 years ago

That's true!