Support » Plugins » Hacks » how to fix this format of php?

  • <?php
       my_own_field 'my_field_name', array(
          'field1'         => __( '<?php echo esc_attr( $snt['field1'] ); ?>'),
            'field2'       => __( '<?php echo esc_attr( $snt['field2'] ); ?>')
            ), $string->get_value( 'my_field_name' ));
    ?>

    this is just part of the code for creating a new field. The formatting is wrong, because of the t_string, the quotes….I cannot have
    ( ‘<?php echo esc_attr( $snt[‘field1′] ); ?>’),

    four single quotes in one line, so what can i do to fix this? can anyone help please

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter clickmac

    (@clickmac)

    If i use
    ‘<?php echo esc_attr( $snt[“field1”] ); ?>’)

    I won’t get the value i want from the database

    The first line syntax is incorrect

    my_own_field 'my_field_name', array(

    the array should be assigned to a variable

    $array = array(.....);

    Thread Starter clickmac

    (@clickmac)

    Thanks for your reply! This is my solution but i would like to know, how to use add_option in a multi dimentional array?

    add_option ('option1', $snt['field1'] );
    add_option ('option1', $snt['field2'] );
    <?php
       my_own_field ( 'my_field_name', array(
          'field1'         => __( ''.get_option( 'option1' ).''),
            'field2'       => __( ''.get_option( 'option2' ).'')
            ), $string->get_value( 'my_field_name' ));
    ?>
    Thread Starter clickmac

    (@clickmac)

    example:
    if i have three fields

    1 -> field one
    2 -> field two
    3 -> field three

    so the fields are not pre made, when someone clicks a button, a new field appears, and for each field that appears, it can be used with get_option, what and how to assign to each field so that get_option can be used anywhere to call back any one of those values?

    You mean 2 dimensional array?

    $my_own_field = array(
                        'my_field_name1' => array(
                                            'field1' => __( get_option( 'option1' ) ),
                                            'field2' => __( get_option( 'option2' ) ),
                        ),
                        'my_field_name2' => array(
                                            'field1' => __( get_option( 'option1' ) ),
                                            'field2' => __( get_option( 'option2' ) ),
                        ),
                    );
    Thread Starter clickmac

    (@clickmac)

    ok thank you for that ….. not quite what i wanted though … but how do i write,

    if any field from the array is left empty don’t print that field alone but allow the rest to be printed?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to fix this format of php?’ is closed to new replies.