/** * get fields from wp-options */ function jcf_field_settings_get($id = '', $select_from_db = false) { $option_name = jcf_fields_get_option_name(); $jcf_read_settings = jcf_get_read_settings(); if (empty($select_from_db) && $jcf_read_settings != JCF_CONF_SOURCE_DB) { $jcf_settings = jcf_get_all_settings_from_file(); $post_type = str_replace('jcf_fields-', '', $option_name); $field_settings = $jcf_settings['field_settings'][$post_type]; } else { $field_settings = jcf_get_options($option_name); } if (!empty($id)) { return @$field_settings[$id]; } return $field_settings; }
/** * update order fieldsets * @param array $keys Fieldsets keys */ function jcf_fieldsets_order($keys = array()) { $option_name = jcf_fieldsets_get_option_name(); $new_fieldsets = array(); $jcf_read_settings = jcf_get_read_settings(); if ($jcf_read_settings != JCF_CONF_SOURCE_DB) { $jcf_settings = jcf_get_all_settings_from_file(); $post_type = jcf_get_post_type(); foreach ($keys as $key) { $new_fieldsets[$key] = $jcf_settings['fieldsets'][$post_type][$key]; unset($jcf_settings['fieldsets'][$post_type][$key]); } $jcf_settings['fieldsets'][$post_type] = $new_fieldsets; jcf_save_all_settings_in_file($jcf_settings); } else { $fieldsets = jcf_get_options($option_name); foreach ($keys as $key) { $new_fieldsets[$key] = $fieldsets[$key]; unset($fieldsets[$key]); } jcf_update_options($option_name, $new_fieldsets); } }
/** * delete field from collection */ public function delete_field($field_id) { $option_name = jcf_fields_get_option_name(); $jcf_read_settings = jcf_get_read_settings(); if ($jcf_read_settings != JCF_CONF_SOURCE_DB) { $jcf_settings = jcf_get_all_settings_from_file(); $post_type = jcf_get_post_type(); $fieldset = $jcf_settings['fieldsets'][$post_type][$this->fieldset_id]; $field_settings = $jcf_settings['field_settings'][$post_type]; if (isset($field_settings[$this->id]['fields'][$field_id])) { unset($field_settings[$this->id]['fields'][$field_id]); } $jcf_settings['fieldsets'][$post_type][$this->fieldset_id] = $fieldset; $jcf_settings['field_settings'][$post_type] = $field_settings; jcf_save_all_settings_in_file($jcf_settings); } else { $field_settings = jcf_get_options($option_name); if (isset($field_settings[$this->id]['fields'][$field_id])) { unset($field_settings[$this->id]['fields'][$field_id]); } jcf_update_options($option_name, $field_settings); } }