├── .gitignore
├── README.md
├── acf-auto_generated_value-v4.php
├── acf-auto_generated_value-v5.php
├── acf-auto_generated_value.php
├── css
├── README.md
└── input.css
├── images
└── README.md
├── js
├── README.md
└── input.js
├── lang
└── README.md
└── readme.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # OS generated files #
2 | ######################
3 | .DS_Store
4 | .DS_Store?
5 | ._*
6 | .Spotlight-V100
7 | .Trashes
8 | ehthumbs.db
9 | Thumbs.db
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ACF Auto-generated value Field
2 |
3 | -----------------------
4 |
5 | ### Creates a hidden/readonly field in a repeater that gets a unique key, that won't change once it is saved. Ideal for user-generated forms. Includes option to hide the field from the user
6 |
7 |
8 | ### Compatibility
9 |
10 | This ACF field type is compatible with:
11 | * ACF 5
12 |
13 | ### Installation
14 |
15 | 1. Copy the `acf-auto_generated_value` folder into your `wp-content/plugins` folder
16 | 2. Activate the Auto-generated value plugin via the plugins admin page
17 | 3. Create a new field via ACF and select the Auto-generated value type
18 | 4. Please refer to the Creates a hidden/readonly field in a repeater that gets a unique key, that won't change once it is saved. Ideal for user-generated forms. for more info regarding the field type settings
19 |
20 | ### Changelog
21 | Please see `readme.txt` for changelog
22 |
--------------------------------------------------------------------------------
/acf-auto_generated_value-v4.php:
--------------------------------------------------------------------------------
1 | name = 'auto_generated_value';
23 | $this->label = __('Auto-generated value');
24 | $this->category = __("Basic",'acf'); // Basic, Content, Choice, etc
25 | $this->defaults = array(
26 | // add default here to merge into your field.
27 | // This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
28 | //'preview_size' => 'thumbnail'
29 | );
30 |
31 |
32 | // do not delete!
33 | parent::__construct();
34 |
35 |
36 | // settings
37 | $this->settings = array(
38 | 'path' => apply_filters('acf/helpers/get_path', __FILE__),
39 | 'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
40 | 'version' => '1.0.0'
41 | );
42 |
43 | }
44 |
45 |
46 | /*
47 | * create_options()
48 | *
49 | * Create extra options for your field. This is rendered when editing a field.
50 | * The value of $field['name'] can be used (like below) to save extra data to the $field
51 | *
52 | * @type action
53 | * @since 3.6
54 | * @date 23/01/13
55 | *
56 | * @param $field - an array holding all the field's data
57 | */
58 |
59 | function create_options( $field )
60 | {
61 | // defaults?
62 | /*
63 | $field = array_merge($this->defaults, $field);
64 | */
65 |
66 | // key is needed in the field names to correctly save the data
67 | $key = $field['name'];
68 |
69 |
70 | // Create Field Options HTML
71 | ?>
72 |
94 | defaults, $field);
116 | */
117 |
118 | // perhaps use $field['preview_size'] to alter the markup?
119 |
120 |
121 | // create Field HTML
122 | ?>
123 |
124 |
125 |
126 | settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] );
149 | wp_register_style( 'acf-input-auto_generated_value', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] );
150 |
151 |
152 | // scripts
153 | wp_enqueue_script(array(
154 | 'acf-input-auto_generated_value',
155 | ));
156 |
157 | // styles
158 | wp_enqueue_style(array(
159 | 'acf-input-auto_generated_value',
160 | ));
161 |
162 |
163 | }
164 |
165 |
166 | /*
167 | * input_admin_head()
168 | *
169 | * This action is called in the admin_head action on the edit screen where your field is created.
170 | * Use this action to add CSS and JavaScript to assist your create_field() action.
171 | *
172 | * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
173 | * @type action
174 | * @since 3.6
175 | * @date 23/01/13
176 | */
177 |
178 | function input_admin_head()
179 | {
180 | // Note: This function can be removed if not used
181 | }
182 |
183 |
184 | /*
185 | * field_group_admin_enqueue_scripts()
186 | *
187 | * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited.
188 | * Use this action to add CSS + JavaScript to assist your create_field_options() action.
189 | *
190 | * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
191 | * @type action
192 | * @since 3.6
193 | * @date 23/01/13
194 | */
195 |
196 | function field_group_admin_enqueue_scripts()
197 | {
198 | // Note: This function can be removed if not used
199 | }
200 |
201 |
202 | /*
203 | * field_group_admin_head()
204 | *
205 | * This action is called in the admin_head action on the edit screen where your field is edited.
206 | * Use this action to add CSS and JavaScript to assist your create_field_options() action.
207 | *
208 | * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
209 | * @type action
210 | * @since 3.6
211 | * @date 23/01/13
212 | */
213 |
214 | function field_group_admin_head()
215 | {
216 | // Note: This function can be removed if not used
217 | }
218 |
219 |
220 | /*
221 | * load_value()
222 | *
223 | * This filter is applied to the $value after it is loaded from the db
224 | *
225 | * @type filter
226 | * @since 3.6
227 | * @date 23/01/13
228 | *
229 | * @param $value - the value found in the database
230 | * @param $post_id - the $post_id from which the value was loaded
231 | * @param $field - the field array holding all the field options
232 | *
233 | * @return $value - the value to be saved in the database
234 | */
235 |
236 | function load_value( $value, $post_id, $field )
237 | {
238 | // Note: This function can be removed if not used
239 | return $value;
240 | }
241 |
242 |
243 | /*
244 | * update_value()
245 | *
246 | * This filter is applied to the $value before it is updated in the db
247 | *
248 | * @type filter
249 | * @since 3.6
250 | * @date 23/01/13
251 | *
252 | * @param $value - the value which will be saved in the database
253 | * @param $post_id - the $post_id of which the value will be saved
254 | * @param $field - the field array holding all the field options
255 | *
256 | * @return $value - the modified value
257 | */
258 |
259 | function update_value( $value, $post_id, $field )
260 | {
261 | // Note: This function can be removed if not used
262 | return $value;
263 | }
264 |
265 |
266 | /*
267 | * format_value()
268 | *
269 | * This filter is applied to the $value after it is loaded from the db and before it is passed to the create_field action
270 | *
271 | * @type filter
272 | * @since 3.6
273 | * @date 23/01/13
274 | *
275 | * @param $value - the value which was loaded from the database
276 | * @param $post_id - the $post_id from which the value was loaded
277 | * @param $field - the field array holding all the field options
278 | *
279 | * @return $value - the modified value
280 | */
281 |
282 | function format_value( $value, $post_id, $field )
283 | {
284 | // defaults?
285 | /*
286 | $field = array_merge($this->defaults, $field);
287 | */
288 |
289 | // perhaps use $field['preview_size'] to alter the $value?
290 |
291 |
292 | // Note: This function can be removed if not used
293 | return $value;
294 | }
295 |
296 |
297 | /*
298 | * format_value_for_api()
299 | *
300 | * This filter is applied to the $value after it is loaded from the db and before it is passed back to the API functions such as the_field
301 | *
302 | * @type filter
303 | * @since 3.6
304 | * @date 23/01/13
305 | *
306 | * @param $value - the value which was loaded from the database
307 | * @param $post_id - the $post_id from which the value was loaded
308 | * @param $field - the field array holding all the field options
309 | *
310 | * @return $value - the modified value
311 | */
312 |
313 | function format_value_for_api( $value, $post_id, $field )
314 | {
315 | // defaults?
316 | /*
317 | $field = array_merge($this->defaults, $field);
318 | */
319 |
320 | // perhaps use $field['preview_size'] to alter the $value?
321 |
322 |
323 | // Note: This function can be removed if not used
324 | return $value;
325 | }
326 |
327 |
328 | /*
329 | * load_field()
330 | *
331 | * This filter is applied to the $field after it is loaded from the database
332 | *
333 | * @type filter
334 | * @since 3.6
335 | * @date 23/01/13
336 | *
337 | * @param $field - the field array holding all the field options
338 | *
339 | * @return $field - the field array holding all the field options
340 | */
341 |
342 | function load_field( $field )
343 | {
344 | // Note: This function can be removed if not used
345 | return $field;
346 | }
347 |
348 |
349 | /*
350 | * update_field()
351 | *
352 | * This filter is applied to the $field before it is saved to the database
353 | *
354 | * @type filter
355 | * @since 3.6
356 | * @date 23/01/13
357 | *
358 | * @param $field - the field array holding all the field options
359 | * @param $post_id - the field group ID (post_type = acf)
360 | *
361 | * @return $field - the modified field
362 | */
363 |
364 | function update_field( $field, $post_id )
365 | {
366 | // Note: This function can be removed if not used
367 | return $field;
368 | }
369 |
370 |
371 | }
372 |
373 |
374 | // create field
375 | new acf_field_auto_generated_value();
376 |
377 | ?>
378 |
--------------------------------------------------------------------------------
/acf-auto_generated_value-v5.php:
--------------------------------------------------------------------------------
1 | name = 'auto_generated_value';
26 |
27 |
28 | /*
29 | * label (string) Multiple words, can include spaces, visible when selecting a field type
30 | */
31 |
32 | $this->label = __('Auto-generated value', 'acf-auto_generated_value');
33 |
34 |
35 | /*
36 | * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME
37 | */
38 |
39 | $this->category = 'basic';
40 |
41 |
42 | /*
43 | * defaults (array) Array of default settings which are merged into the field object. These are used later in settings
44 | */
45 |
46 | $this->defaults = array(
47 | 'value_prefix' => 'my_key_',
48 | );
49 |
50 |
51 | /*
52 | * l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via:
53 | * var message = acf._e('auto_generated_value', 'error');
54 | */
55 |
56 | $this->l10n = array(
57 | 'error' => __('Error! Please enter a higher value', 'acf-auto_generated_value'),
58 | );
59 |
60 |
61 | // do not delete!
62 | parent::__construct();
63 |
64 | }
65 |
66 |
67 | /*
68 | * render_field_settings()
69 | *
70 | * Create extra settings for your field. These are visible when editing a field
71 | *
72 | * @type action
73 | * @since 3.6
74 | * @date 23/01/13
75 | *
76 | * @param $field (array) the $field being edited
77 | * @return n/a
78 | */
79 |
80 | function render_field_settings( $field ) {
81 |
82 | /*
83 | * acf_render_field_setting
84 | *
85 | * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings.
86 | * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array.
87 | *
88 | * More than one setting can be added by copy/paste the above code.
89 | * Please note that you must also have a matching $defaults value for the field name (font_size)
90 | */
91 |
92 | acf_render_field_setting( $field, array(
93 | 'label' => __('Prefix','acf-auto_generated_value'),
94 | 'instructions' => __('Set the prefix of the generated key','acf-auto_generated_value'),
95 | 'type' => 'text',
96 | 'name' => 'value_prefix',
97 | ));
98 |
99 | acf_render_field_setting( $field, array(
100 | 'label' => __('Hide','acf-auto_generated_value'),
101 | 'instructions' => __('Hide the field from the user','acf-auto_generated_value'),
102 | 'type' => 'radio',
103 | 'layout' => 'horizontal',
104 | 'name' => 'hide',
105 | 'choices' => array('yes' => 'Yes', 'no' => 'No'),
106 | ));
107 |
108 | }
109 |
110 |
111 |
112 | /*
113 | * render_field()
114 | *
115 | * Create the HTML interface for your field
116 | *
117 | * @param $field (array) the $field being rendered
118 | *
119 | * @type action
120 | * @since 3.6
121 | * @date 23/01/13
122 | *
123 | * @param $field (array) the $field being edited
124 | * @return n/a
125 | */
126 |
127 | function render_field( $field ) {
128 |
129 |
130 | /*
131 | * Review the data of $field.
132 | * This will show what data is available
133 | */
134 |
135 | /*
136 | * Create a simple text input using the 'font_size' setting.
137 | */
138 | ?>
139 |