PluginProbe
Advanced Custom Fields (ACF®) / 3.1.5
Advanced Custom Fields (ACF®) v3.1.5
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / core / actions / save_fields.php
save_fields.php
76 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // strip slashes
4 $_POST = array_map('stripslashes_deep', $_POST);
5
6 // save fields
7 $fields = $_POST['fields'];
8
9 // get all keys to find fields
10 $dont_delete = array();
11
12 if($fields)
13 {
14 $i = -1;
15
16 // remove dummy field
17 unset($fields['999']);
18
19 // loop through and save fields
20 foreach($fields as $field)
21 {
22 $i++;
23
24 // each field has a unique id!
25 if(!isset($field['key'])) $field['key'] = 'field_' . uniqid();
26
27 // add to dont delete array
28 $dont_delete[] = $field['key'];
29
30 // order
31 $field['order_no'] = $i;
32
33 // update field
34 $this->update_field($post_id, $field);
35 }
36 }
37
38 // delete all other field
39 foreach(get_post_custom_keys($post_id) as $key)
40 {
41 if(strpos($key, 'field_') !== false && !in_array($key, $dont_delete))
42 {
43 // this is a field, and it wasn't found in the dont_delete array
44 delete_post_meta($post_id, $key);
45 }
46 }
47
48 // save location
49 $location = $_POST['location'];
50
51 if(!isset($location['allorany'])) { $location['allorany'] = 'all'; }
52 update_post_meta($post_id, 'allorany', $location['allorany']);
53
54 delete_post_meta($post_id, 'rule');
55 if($location['rules'])
56 {
57 foreach($location['rules'] as $k => $rule)
58 {
59
60 $rule['order_no'] = $k;
61 add_post_meta($post_id, 'rule', $rule);
62 }
63 }
64
65 // save options
66 $options = $_POST['options'];
67
68 if(!isset($options['position'])) { $options['position'] = 'normal'; }
69 if(!isset($options['layout'])) { $options['layout'] = 'default'; }
70 if(!isset($options['show_on_page'])) { $options['show_on_page'] = array(); }
71
72 update_post_meta($post_id, 'position', $options['position']);
73 update_post_meta($post_id, 'layout', $options['layout']);
74 update_post_meta($post_id, 'show_on_page', $options['show_on_page']);
75
76 ?>