save_fields.php
| 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 | ?> |