<?php $messages = $form_options['messages']; foreach ( $messages as $key => $message ): $elid = str_replace( '-', '_', $key ); $content = apply_filters( 'wpmtst_l10n', $message['text'], wpmtst_get_l10n_context( 'form-messages' ), $key . ' : text' ); ?> <tr> <th scope="row"> <label for="<?php echo $elid; ?>"> <?php _ex( $message['description'], 'description', 'strong-testimonials' ); ?> </label> <input type="hidden" name="wpmtst_form_options[messages][<?php echo $key; ?>][description]" value="<?php esc_attr_e( $message['description'] ); ?>"/> </th> <td> <?php if ( 'submission_success' == $elid ): ?> <?php $settings = array( 'textarea_name' => "wpmtst_form_options[messages][$key][text]", 'textarea_rows' => 10, ); wp_editor( $content, $elid, $settings ); ?> <?php else: ?> <input type="text" id="<?php echo $elid; ?>" name="wpmtst_form_options[messages][<?php echo $key; ?>][text]" value="<?php echo esc_attr( $content ); ?>" required /> <?php endif; ?> </td> <td class="actions"> <input type="button" class="button secondary restore-default-message" value="<?php _ex( 'restore default', 'singular', 'strong-testimonials' ); ?>" data-target-id="<?php echo $elid; ?>"/> </td> </tr> <?php endforeach; ?> 

Help solve the problem. In the beginning there is a foreach loop. And like in the new version of PHP you need to wrap it in if (is_array ($ messages)) {code}. But something does not work. First, for foreach there are no parentheses, there is a colon and I do not understand how to wrap this code.

    2 answers 2

    Just like with foreach, use the alternative syntax if endif, it should end up like this:

      <?php if (is_array($form_options['messages'])): $messages = $form_options['messages']; foreach ( $messages as $key => $message ): $elid = str_replace( '-', '_', $key ); $content = apply_filters( 'wpmtst_l10n', $message['text'], wpmtst_get_l10n_context( 'form-messages' ), $key . ' : text' ); ?> <tr> <th scope="row"> <label for="<?php echo $elid; ?>"> <?php _ex( $message['description'], 'description', 'strong-testimonials' ); ?> </label> <input type="hidden" name="wpmtst_form_options[messages][<?php echo $key; ?>][description]" value="<?php esc_attr_e( $message['description'] ); ?>"/> </th> <td> <?php if ( 'submission_success' == $elid ): ?> <?php $settings = array( 'textarea_name' => "wpmtst_form_options[messages][$key][text]", 'textarea_rows' => 10, ); wp_editor( $content, $elid, $settings ); ?> <?php else: ?> <input type="text" id="<?php echo $elid; ?>" name="wpmtst_form_options[messages][<?php echo $key; ?>][text]" value="<?php echo esc_attr( $content ); ?>" required /> <?php endif; ?> </td> <td class="actions"> <input type="button" class="button secondary restore-default-message" value="<?php _ex( 'restore default', 'singular', 'strong-testimonials' ); ?>" data-target-id="<?php echo $elid; ?>"/> </td> </tr> <?php endforeach; endif; ?> 

    You can also read more about the syntax on the official PHP site.

    • Notice: Undefined index: messages in /sata1/home/users/avtoceh1/www/www.avtoceh.com/wp-content/plugins/strong-testimonials/admin/partials/settings/form.php on line 40. Here is this line: if (is_array ($ form_options ['messages'])): - Artyom Oleynichenko
    • if (isset ($ form_options ['messages']) && is_array ($ form_options ['messages'])): This is how it works. Thank ! - Artyom Oleynichenko

    How is this no braces for foreach ?

     <?php $messages = $form_options['messages']; if ( is_array($messages) ) { foreach ( $messages as $key => $message ) { $elid = str_replace( '-', '_', $key ); $content = apply_filters( 'wpmtst_l10n', $message['text'], wpmtst_get_l10n_context( 'form-messages' ), $key . ' : text' ); ?> <tr> <th scope="row"> <label for="<?php echo $elid; ?>"> <?php _ex( $message['description'], 'description', 'strong-testimonials' ); ?> </label> <input type="hidden" name="wpmtst_form_options[messages][<?php echo $key; ?>][description]" value="<?php esc_attr_e( $message['description'] ); ?>"/> </th> <td> <?php if ( 'submission_success' == $elid ): ?> <?php $settings = array( 'textarea_name' => "wpmtst_form_options[messages][$key][text]", 'textarea_rows' => 10, ); wp_editor( $content, $elid, $settings ); ?> <?php else: ?> <input type="text" id="<?php echo $elid; ?>" name="wpmtst_form_options[messages][<?php echo $key; ?>][text]" value="<?php echo esc_attr( $content ); ?>" required /> <?php endif; ?> </td> <td class="actions"> <input type="button" class="button secondary restore-default-message" value="<?php _ex( 'restore default', 'singular', 'strong-testimonials' ); ?>" data-target-id="<?php echo $elid; ?>"/> </td> </tr> <?php } } ?>