bidirectional.php
3 months ago
choices-label.php
3 months ago
data.php
3 months ago
instructions.php
3 months ago
permissions.php
3 months ago
settings.php
3 months ago
validation.php
3 months ago
instructions.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_instructions')): |
| 8 | |
| 9 | class acfe_instructions{ |
| 10 | |
| 11 | function __construct(){ |
| 12 | |
| 13 | add_action('acfe/pre_render_field_group', array($this, 'pre_render_field_group'), 10, 3); |
| 14 | add_filter('acf/field_wrapper_attributes', array($this, 'field_wrapper_attributes'), 10, 2); |
| 15 | |
| 16 | } |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * pre_render_field_group |
| 21 | * |
| 22 | * @param $field_group |
| 23 | * @param $fields |
| 24 | * @param $post_id |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | function pre_render_field_group($field_group, $fields, $post_id){ |
| 29 | |
| 30 | // bail early on override (acfe_form) |
| 31 | if(acf_is_filter_enabled('acfe/override_instruction')){ |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | acf_disable_filter('acfe/instruction_tooltip'); |
| 36 | acf_disable_filter('acfe/instruction_above_field'); |
| 37 | |
| 38 | if(acfe_get($field_group, 'instruction_placement') === 'tooltip'){ |
| 39 | |
| 40 | acf_enable_filter('acfe/instruction_tooltip'); |
| 41 | |
| 42 | }elseif(acfe_get($field_group, 'instruction_placement') === 'above_field'){ |
| 43 | |
| 44 | acf_enable_filter('acfe/instruction_above_field'); |
| 45 | |
| 46 | } |
| 47 | |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * field_wrapper_attributes |
| 53 | * |
| 54 | * @param $wrapper |
| 55 | * @param $field |
| 56 | * |
| 57 | * @return mixed |
| 58 | */ |
| 59 | function field_wrapper_attributes($wrapper, $field){ |
| 60 | |
| 61 | if(!acfe_get($field, 'label')){ |
| 62 | $wrapper['class'] .= ' acfe-no-label'; |
| 63 | } |
| 64 | |
| 65 | if(acfe_get($field, 'instructions')){ |
| 66 | |
| 67 | if(acf_is_filter_enabled('acfe/instruction_tooltip')){ |
| 68 | $wrapper['data-instruction-tooltip'] = acf_esc_html($field['instructions']); |
| 69 | |
| 70 | }elseif(acf_is_filter_enabled('acfe/instruction_above_field')){ |
| 71 | $wrapper['data-instruction-above-field'] = acf_esc_html($field['instructions']); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | return $wrapper; |
| 77 | |
| 78 | } |
| 79 | |
| 80 | } |
| 81 | |
| 82 | new acfe_instructions(); |
| 83 | |
| 84 | endif; |