function acf_delete_field($selector = 0) { // disable filters to ensure ACF loads raw data from DB acf_disable_filters(); // load the origional field gorup $field = acf_get_field($selector); // bail early if field did not load correctly if (empty($field)) { return false; } // delete field wp_delete_post($field['ID'], true); // action for 3rd party customisation do_action("acf/delete_field", $field); do_action("acf/delete_field/type={$field['type']}", $field); // clear cache acf_delete_cache("get_field/key={$field['key']}"); // return return true; }
function acf_delete_value($post_id = 0, $field) { // action for 3rd party customization do_action("acf/delete_value", $post_id, $field['name'], $field); do_action("acf/delete_value/type={$field['type']}", $post_id, $field['name'], $field); do_action("acf/delete_value/name={$field['_name']}", $post_id, $field['name'], $field); do_action("acf/delete_value/key={$field['key']}", $post_id, $field['name'], $field); // delete value $return = acf_delete_metadata($post_id, $field['name']); // delete reference acf_delete_metadata($post_id, $field['name'], true); // clear cache acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}"); acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}"); // return return $return; }
protected function get_field_objects($post_id, $fields = array()) { $field_groups = array(); acf_delete_cache('get_field_groups'); if (is_numeric($post_id)) { $field_groups = acf_get_field_groups(array('post_id' => $post_id)); } elseif ($post_id == 'options') { $keys = array_keys(wpsw_get_config('register.options_page')); foreach ($keys as $key) { $field_groups = array_merge($field_groups, acf_get_field_groups(array('options_page' => $key))); } } foreach ($field_groups as $field_group) { acf_delete_cache("get_fields/ID={$field_group['ID']}"); $acf_fields = acf_get_fields($field_group); if (is_array($acf_fields)) { $fields = array_merge($fields, $acf_fields); } } $field_objects = array(); foreach ($fields as $key => $field) { $field_objects[$field['name']] = $field; } return $field_objects; }
function acf_update_field_group($field_group = array()) { // validate $field_group = acf_get_valid_field_group($field_group); // may have been posted. Remove slashes $field_group = wp_unslash($field_group); // parse types (converts string '0' to int 0) $field_group = acf_parse_types($field_group); // locations may contain 'uniquid' array keys $field_group['location'] = array_values($field_group['location']); foreach ($field_group['location'] as $k => $v) { $field_group['location'][$k] = array_values($v); } // store origional field group for return $data = $field_group; // extract some args $extract = acf_extract_vars($data, array('ID', 'key', 'title', 'menu_order', 'fields', 'active')); // vars $data = maybe_serialize($data); $post_status = $extract['active'] ? 'publish' : 'acf-disabled'; // save $save = array('ID' => $extract['ID'], 'post_status' => $post_status, 'post_type' => 'acf-field-group', 'post_title' => $extract['title'], 'post_name' => $extract['key'], 'post_excerpt' => sanitize_title($extract['title']), 'post_content' => $data, 'menu_order' => $extract['menu_order']); // allow field groups to contain the same name add_filter('wp_unique_post_slug', 'acf_update_field_group_wp_unique_post_slug', 100, 6); // update the field group and update the ID if ($field_group['ID']) { wp_update_post($save); } else { $field_group['ID'] = wp_insert_post($save); } // action for 3rd party customization do_action('acf/update_field_group', $field_group); // clear cache acf_delete_cache("get_field_group/key={$field_group['key']}"); // return return $field_group; }
function clear_acf_cache($fields = false) { global $wp_object_cache; $group = 'acf'; if (isset($wp_object_cache->cache[$group])) { $cache = $wp_object_cache->cache[$group]; //echo '<pre>'; print_r($cache); die; foreach ($cache as $key => $value) { wp_cache_delete($key, $group); } } if (class_exists('acf_cache') && function_exists('acf_delete_cache')) { acf_delete_cache(); } }