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