php - How do you fix this notice: Uninitialized string offset: 0 with stripslashes? -


when upload theme wordpress, notice in options page:

uninitialized string offset: 0

this code:

function name_of_function ( $args ) {     extract( $args );     $option_name = 'the_theme_options';     $options = get_option( $option_name );     switch ( $type ) {           case 'text':             $options[$id] = stripslashes( $options[$id] );             $options[$id] = esc_attr( $options[$id] );             echo "<input class='regular-text$class' type='text' id='$id' name='" . $option_name . "[$id]' value='$options[$id]'>";             echo ( $desc != '' ) ? "<br><span class='description'>$desc</span>" : "";         break; 

when save, notice goes away.

i tried adding isset, (i getting notice:undefined index @ first):

$options[$id] = stripslashes( isset( $options[$id] ); 

the errors go away fails save.

then added isset following line:

$options[$id] = esc_attr( isset( $options[$id] ) ); 

still didn't work.

i tried removing line still errors:

$options[$id] = stripslashes( $options[$id] ); 

i tried this:

if ( isset( $options[$id] ) {     $options[$id] = stripslashes( $options[$id] ); } 

i'm aware of things tried don't make sense.

i've been searching hours. read docs. can't seem find solution this.

$options string in context, not array. trying treat array, doesn't work. logic in code never work; it's not clear you're trying $options[$id].

the reason get

uninitialized string offset: 0

is $id not initialized anywhere, php treats 0. saying, "look @ string ($options) , array value @ key 0," , php throws hands because doesn't make sense.

your various solutions won't work several other reasons. stripslashes( isset( $options[$id] ); fails because (1) $options[$id] doesn't exist , (2) stripslashes() takes string parameter, handing boolean value. same problem esc_attr( isset( $options[$id] ) );


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -