| @@ -34,17 +34,36 @@ | ||
| 34 | 34 | ?> |
| 35 | 35 | |
| 36 | 36 | <optgroup label="<?php esc_attr_e( 'Forms', 'convertkit' ); ?>" id="convertkit-forms" data-option-value-prefix="form:"> |
| 37 | 37 | <?php |
| 38 | - if ( $forms->exist() ) { | |
| 39 | - foreach ( $forms->get() as $form ) { | |
| 38 | + $non_legacy_forms = $forms->get_non_legacy(); | |
| 39 | + if ( is_array( $non_legacy_forms ) ) { | |
| 40 | + foreach ( $non_legacy_forms as $form ) { | |
| 40 | 41 | printf( |
| 41 | 42 | '<option value="%s"%s>%s [%s]</option>', |
| 42 | 43 | esc_attr( 'form:' . $form['id'] ), |
| 43 | 44 | selected( 'form:' . $form['id'], $value, false ), |
| 44 | 45 | esc_attr( $form['name'] ), |
| 45 | - ( ! empty( $form['format'] ) ? esc_attr( $form['format'] ) : 'inline' ) | |
| 46 | + esc_attr( $form['format'] ) | |
| 46 | 47 | ); |
| 48 | + } | |
| 49 | + } | |
| 50 | + | |
| 51 | + // If the currently-selected value references a legacy form (which is | |
| 52 | + // no longer exposed as a new selection option), append it here so a | |
| 53 | + // previously-saved mapping continues to render as selected. | |
| 54 | + if ( is_string( $value ) && strpos( $value, 'form:' ) === 0 ) { | |
| 55 | + $selected_form_id = (int) substr( $value, 5 ); | |
| 56 | + if ( $selected_form_id && $forms->is_legacy( $selected_form_id ) ) { | |
| 57 | + $legacy_form = $forms->get_by_id( $selected_form_id ); | |
| 58 | + if ( $legacy_form ) { | |
| 59 | + printf( | |
| 60 | + '<option value="%s" selected>%s [%s]</option>', | |
| 61 | + esc_attr( 'form:' . $legacy_form['id'] ), | |
| 62 | + esc_attr( $legacy_form['name'] ), | |
| 63 | + 'inline' | |
| 64 | + ); | |
| 65 | + } | |
| 47 | 66 | } |
| 48 | 67 | } |
| 49 | 68 | ?> |
| 50 | 69 | </optgroup> |