|
| 1 | +/** |
| 2 | + * Gravity Perks // Copy Cat // Show Source and Target Field Indicators in Form Editor |
| 3 | + * https://gravitywiz.com/documentation/gravity-forms-copy-cat/ |
| 4 | + * |
| 5 | + * Display visual source and target field indicators next to field labels in the form editor. |
| 6 | + */ |
| 7 | +add_filter( 'gform_admin_pre_render', function( $form ) { |
| 8 | + |
| 9 | + if ( ! class_exists( 'GP_Copy_Cat' ) ) { |
| 10 | + return $form; |
| 11 | + } |
| 12 | + |
| 13 | + $gpcc = new GP_Copy_Cat(); |
| 14 | + $gpcc_fields = $gpcc->get_copy_cat_fields( $form ); |
| 15 | + if ( empty( $gpcc_fields ) ) { |
| 16 | + return $form; |
| 17 | + } |
| 18 | + |
| 19 | + add_filter( 'admin_footer', function() { |
| 20 | + ?> |
| 21 | + <style> |
| 22 | + .gpcc-source .gform-field-label:after { |
| 23 | + content: 'GPCC: Source'; |
| 24 | + color: #274524; |
| 25 | + margin: 0 0.5rem; |
| 26 | + background-color: #edf8ec; |
| 27 | + border: 1px solid #d7e8d5; |
| 28 | + border-radius: 40px; |
| 29 | + float: right; |
| 30 | + font-size: 0.6875rem; |
| 31 | + font-weight: 600; |
| 32 | + padding: 0.1125rem 0.4625rem; |
| 33 | + } |
| 34 | + |
| 35 | + .gpcc-target .gform-field-label:after { |
| 36 | + content: 'GPCC: Target'; |
| 37 | + color: #274524; |
| 38 | + margin: 0 0.5rem; |
| 39 | + background-color: #edf8ec; |
| 40 | + border: 1px solid #d7e8d5; |
| 41 | + border-radius: 40px; |
| 42 | + float: right; |
| 43 | + font-size: 0.6875rem; |
| 44 | + font-weight: 600; |
| 45 | + padding: 0.1125rem 0.4625rem; |
| 46 | + } |
| 47 | + </style> |
| 48 | + <?php |
| 49 | + } ); |
| 50 | + |
| 51 | + $mappings = array(); |
| 52 | + foreach ( $gpcc_fields as $_mappings ) { |
| 53 | + $mappings = array_merge( $_mappings ); |
| 54 | + } |
| 55 | + |
| 56 | + foreach( $form['fields'] as &$field ) { |
| 57 | + foreach( $mappings as $mapping ) { |
| 58 | + if ( $field->id == $mapping['source'] ) { |
| 59 | + $field->cssClass .= ' gpcc-source'; |
| 60 | + } |
| 61 | + if ( $field->id == $mapping['target'] ) { |
| 62 | + $field->cssClass .= ' gpcc-target'; |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return $form; |
| 68 | +} ); |
0 commit comments