Search code examples
phpwordpressvalidationif-statementredux-framework

how to validate redux framework variable value


I used Redux Framework in my wordpress theme, now i want to use my global variable in my theme, how to validate my global variable if is ok/validated do my codes...

    array(
        'id'       => 'my_id',
        'type'     => 'switch',
        'title'    => __( 'Display Social Icons' , 'txd' ),
        'default'  => false,
    ),

and how to validate it, if its true, do my codes...

when i use var_dump(); i have this

string(1) "1"

now how to validate my variable?

if ( $my_var ) { do something... }
if ( 1 == $my_var ) { do ... }
if ( '1' == $my_var ) { ... }
if ( ! empty( $my_var ) ) { ... }
if ( ! empty( $my_var ) && '1' == $my_var ) { ... }
if ( '1' === $my_var ) { ... }

i am searching most standard and most safe way for doing my way. tnx


Solution

  • Some of your options are not logically equivalent, for instance if ($my_var) would be asking is $myvar defined and not null, whereas if ('1' === $my_var) means is $my_var equal in value and in type to '1'. If you want to check it is not only a string but is also the string '1' then your last option is best.