Code Simplification

Support MB Settings Page Code Simplification

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3514
    87Pancakes87Pancakes
    Participant

    Is there a way to simplify this code or is this the correct way to map the data in the frontend?

    <?php
    $field_id = 'hello_bar';
    if ( !empty( $settings[$field_id] ) ) {
    echo '' . $settings[$field_id] . '';
    }
    ?>
    #3516
    Anh TranAnh Tran
    Keymaster

    I think it would be better if you have default values for your settings, and then you don't need to check with if:

    $default = array();
    $settings = get_option( 'setting_id' );
    $settings = wp_parse_args( $settings, $default );
    
    // Then
    echo $settings[$field_id];
    #3535
    87Pancakes87Pancakes
    Participant

    Thank-you 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Code Simplification’ is closed to new replies.