email.php
| 1 | <?php |
| 2 | |
| 3 | class acf_field_email extends acf_field |
| 4 | { |
| 5 | |
| 6 | /* |
| 7 | * __construct |
| 8 | * |
| 9 | * Set name / label needed for actions / filters |
| 10 | * |
| 11 | * @since 3.6 |
| 12 | * @date 23/01/13 |
| 13 | */ |
| 14 | |
| 15 | function __construct() |
| 16 | { |
| 17 | // vars |
| 18 | $this->name = 'email'; |
| 19 | $this->label = __("Email",'acf'); |
| 20 | $this->defaults = array( |
| 21 | 'default_value' => '', |
| 22 | 'placeholder' => '', |
| 23 | 'prepend' => '', |
| 24 | 'append' => '' |
| 25 | ); |
| 26 | |
| 27 | |
| 28 | // do not delete! |
| 29 | parent::__construct(); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | /* |
| 34 | * create_field() |
| 35 | * |
| 36 | * Create the HTML interface for your field |
| 37 | * |
| 38 | * @param $field - an array holding all the field's data |
| 39 | * |
| 40 | * @type action |
| 41 | * @since 3.6 |
| 42 | * @date 23/01/13 |
| 43 | */ |
| 44 | |
| 45 | function create_field( $field ) |
| 46 | { |
| 47 | // vars |
| 48 | $o = array( 'id', 'class', 'name', 'value', 'placeholder' ); |
| 49 | $e = ''; |
| 50 | |
| 51 | |
| 52 | // prepend |
| 53 | if( $field['prepend'] !== "" ) |
| 54 | { |
| 55 | $field['class'] .= ' acf-is-prepended'; |
| 56 | $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | // append |
| 61 | if( $field['append'] !== "" ) |
| 62 | { |
| 63 | $field['class'] .= ' acf-is-appended'; |
| 64 | $e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | $e .= '<div class="acf-input-wrap">'; |
| 69 | $e .= '<input type="email"'; |
| 70 | |
| 71 | foreach( $o as $k ) |
| 72 | { |
| 73 | $e .= ' ' . $k . '="' . esc_attr( $field[ $k ] ) . '"'; |
| 74 | } |
| 75 | |
| 76 | $e .= ' />'; |
| 77 | $e .= '</div>'; |
| 78 | |
| 79 | |
| 80 | // return |
| 81 | echo $e; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /* |
| 86 | * create_options() |
| 87 | * |
| 88 | * Create extra options for your field. This is rendered when editing a field. |
| 89 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
| 90 | * |
| 91 | * @type action |
| 92 | * @since 3.6 |
| 93 | * @date 23/01/13 |
| 94 | * |
| 95 | * @param $field - an array holding all the field's data |
| 96 | */ |
| 97 | |
| 98 | function create_options( $field ) |
| 99 | { |
| 100 | // vars |
| 101 | $key = $field['name']; |
| 102 | |
| 103 | ?> |
| 104 | <tr class="field_option field_option_<?php echo $this->name; ?>"> |
| 105 | <td class="label"> |
| 106 | <label><?php _e("Default Value",'acf'); ?></label> |
| 107 | <p><?php _e("Appears when creating a new post",'acf') ?></p> |
| 108 | </td> |
| 109 | <td> |
| 110 | <?php |
| 111 | |
| 112 | do_action('acf/create_field', array( |
| 113 | 'type' => 'text', |
| 114 | 'name' => 'fields['.$key.'][default_value]', |
| 115 | 'value' => $field['default_value'], |
| 116 | )); |
| 117 | |
| 118 | ?> |
| 119 | </td> |
| 120 | </tr> |
| 121 | <tr class="field_option field_option_<?php echo $this->name; ?>"> |
| 122 | <td class="label"> |
| 123 | <label><?php _e("Placeholder Text",'acf'); ?></label> |
| 124 | <p><?php _e("Appears within the input",'acf') ?></p> |
| 125 | </td> |
| 126 | <td> |
| 127 | <?php |
| 128 | do_action('acf/create_field', array( |
| 129 | 'type' => 'text', |
| 130 | 'name' => 'fields[' .$key.'][placeholder]', |
| 131 | 'value' => $field['placeholder'], |
| 132 | )); |
| 133 | ?> |
| 134 | </td> |
| 135 | </tr> |
| 136 | <tr class="field_option field_option_<?php echo $this->name; ?>"> |
| 137 | <td class="label"> |
| 138 | <label><?php _e("Prepend",'acf'); ?></label> |
| 139 | <p><?php _e("Appears before the input",'acf') ?></p> |
| 140 | </td> |
| 141 | <td> |
| 142 | <?php |
| 143 | do_action('acf/create_field', array( |
| 144 | 'type' => 'text', |
| 145 | 'name' => 'fields[' .$key.'][prepend]', |
| 146 | 'value' => $field['prepend'], |
| 147 | )); |
| 148 | ?> |
| 149 | </td> |
| 150 | </tr> |
| 151 | <tr class="field_option field_option_<?php echo $this->name; ?>"> |
| 152 | <td class="label"> |
| 153 | <label><?php _e("Append",'acf'); ?></label> |
| 154 | <p><?php _e("Appears after the input",'acf') ?></p> |
| 155 | </td> |
| 156 | <td> |
| 157 | <?php |
| 158 | do_action('acf/create_field', array( |
| 159 | 'type' => 'text', |
| 160 | 'name' => 'fields[' .$key.'][append]', |
| 161 | 'value' => $field['append'], |
| 162 | )); |
| 163 | ?> |
| 164 | </td> |
| 165 | </tr> |
| 166 | <?php |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | |
| 171 | new acf_field_email(); |
| 172 | |
| 173 | ?> |