'picture_layout', 'type' => 'select', 'label' => __( 'Layout', '2ranq-forms' ), 'options' => array( 'grid' => __( 'Cards side by side', '2ranq-forms' ), 'list' => __( 'One under another', '2ranq-forms' ), ), 'default' => 'grid', ); $settings['advanced'][] = array( 'key' => 'picture_meta_label', 'type' => 'text', 'label' => __( 'Word for the small line', '2ranq-forms' ), 'help' => __( 'Only used in the email, before the small line. For example: Seats.', '2ranq-forms' ), ); return $settings; } /** * The options, with an image and a small line. * * The base class cleans the label and the value. What only this field has is * added here. * * @param array $field The field settings. * * @return array */ protected function get_choices( $field ) { $clean = parent::get_choices( $field ); $raw = isset( $field['choices'] ) && is_array( $field['choices'] ) ? array_values( $field['choices'] ) : array(); foreach ( $clean as $index => $choice ) { $extra = isset( $raw[ $index ] ) && is_array( $raw[ $index ] ) ? $raw[ $index ] : array(); $clean[ $index ]['image'] = isset( $extra['image'] ) ? esc_url_raw( (string) $extra['image'] ) : ''; $clean[ $index ]['meta'] = isset( $extra['meta'] ) ? sanitize_text_field( (string) $extra['meta'] ) : ''; $clean[ $index ]['disabled'] = ! empty( $extra['disabled'] ); } return $clean; } /** * The list of allowed values. * * An option that is unavailable does NOT count. Without this anyone could * send its value by hand, because the whole list is visible in the HTML. * * @param array $field The field settings. * * @return array */ protected function allowed_values( $field ) { $values = array(); foreach ( $this->get_choices( $field ) as $choice ) { if ( $choice['disabled'] ) { continue; } $values[] = $choice['value']; } return $values; } /** * Prints the field. * * @param array $field The field settings. * @param int $form_id The form id. * * @return void */ public function render( $field, $form_id ) { $describedby = $this->describedby( $field, $form_id ); $choices = $this->get_choices( $field ); $base_id = $this->input_id( $field, $form_id ); $layout = isset( $field['picture_layout'] ) && 'list' === $field['picture_layout'] ? 'list' : 'grid'; // After a failed send the visitor's pick comes back instead of the default. $sticky = $this->sticky_value( $field, $form_id ); ?>