Пример #1
0
 function remove_field($key)
 {
     // get field
     $field = acf_get_field($key);
     // remove parent reference
     $this->remove_parent_reference($field['parent'], $field['key']);
     // remove field
     unset($this->fields[$key]);
     // remove children
     if (acf_have_local_fields($key)) {
         acf_remove_local_fields($key);
     }
 }
 function rebuild_group($group_key)
 {
     // check for group in cache
     $found = false;
     $cache = wp_cache_get('acf_reusable/rebuilt_group_' . $group_key, 'acf_resuable', false, $found);
     if ($found) {
         $group = $cache;
     }
     // check for json field
     $json_found = false;
     /*
     // no need to check local groups because 
     // if they existed they would have been loaded by maybe_load_local
     // and we would not be here
     // will remove this code if the early loading of local json files works
     if (!$found) {
     	$json_path = plugin_dir_path(__FILE__).'acf-json';
     	if (!is_dir($json_path)) {
     		@mkdir($json_path);
     	}
     	if (is_multisite()) {
     		$json_path .= '/'.get_current_blog_id();
     		if (!is_dir($json_path)) {
     			@mkdir($json_path);
     		}
     	}
     	if (is_dir($json_path) && 
     			($files = scandir($json_path)) !== false &&
     			count($files)) {
     		foreach ($files as $file) {
     			$file_path = $json_path.'/'.$file;
     			if (!is_dir($file_path) && preg_match('/\.json$/', $file)) {
     				$file_group_key = preg_replace('/\.json$/', '', $file);
     				if ($file_group_key == $group_key) {
     					if (($json = file_get_contents($file_path)) !== false &&
     							($group = json_decode($json, true)) !== NULL) {
     						$json_found = true;
     						$found = true;
     					}
     				} // end if match
     			} // end if json file
     		} // end foreach file
     	} // end if is_dir etc
     } // end if !found
     */
     // neither found the rebuild group
     if (!$found) {
         $group = $this->field_groups[$group_key];
         $group['fields'] = $this->rebuild_fields($group_key, $group['fields']);
         $group['fields'] = $this->replace_keys($group['fields']);
         $group['fields'] = $this->correct_keys($group['fields']);
         //echo preg_replace('/\_\[[0-9]+\]\_/', '', 'field_566f61991b2c4_566f60e177211_[1]_');die;
         //echo '<pre>'; print_r($group['fields']); die;
         $this->replaced_keys = array();
         unset($group['ID']);
     }
     // make sure json path exists
     $json_path = plugin_dir_path(__FILE__) . 'acf-json';
     if (!is_dir($json_path)) {
         @mkdir($json_path);
     }
     if (is_multisite()) {
         $json_path .= '/' . get_current_blog_id();
         if (!is_dir($json_path)) {
             @mkdir($json_path);
         }
     }
     // if json files was not found then save json file
     // attempt to save file/ silently fail if folder is not writable
     if (!$json_found && is_dir($json_path)) {
         if (($handle = @fopen($json_path . '/' . $group_key . '.json', 'w')) !== false) {
             $json = acf_json_encode($group);
             fwrite($handle, $json, strlen($json));
             fclose($handle);
         }
     }
     // end if !json found
     // save in cache
     wp_cache_set('acf_reusable/rebuilt_group_' . $group_key, $group, 'acf_resuable');
     $this->field_groups[$group_key] = $group;
     $this->new_field_groups[] = $group;
     if (acf_is_local_field_group($group_key)) {
         // this is already a local field group
         // remove the existing version before replacing
         acf_remove_local_fields($group_key);
         // there currently isn't a remove group function in acf_local
         //echo $group_key,'<br>';
         $this->clear_acf_cache();
         $acf_local = acf_local();
         unset($acf_local->groups[$group_key]);
         //echo '<pre>'; print_r($acf_local->groups); die;
         //unset(acf_local()->groups[$group_key]);
     }
     //echo '<pre>'; print_r($group); die;
     // add or replace the field group to local groups
     acf_add_local_field_group($group);
     //echo $group_key,'<br><pre>'; print_r(acf_get_field_groups()); die;
 }
Пример #3
0
 function remove_field($key = '')
 {
     // get field
     $field = $this->get_field($key);
     // bail early if no field
     if (!$field) {
         return false;
     }
     // remove parent reference
     $this->remove_parent_reference($field['parent'], $field['key']);
     // remove field
     unset($this->fields[$key]);
     // remove children
     if (acf_have_local_fields($key)) {
         acf_remove_local_fields($key);
     }
 }
 function rebuild_group($group_key)
 {
     $group = $this->field_groups[$group_key];
     $group['fields'] = $this->rebuild_fields($group_key, $group['fields']);
     $group['fields'] = $this->replace_keys($group['fields']);
     unset($group['ID']);
     $this->new_field_groups[] = $group;
     if (acf_is_local_field_group($group_key)) {
         // this is already a local field group
         // remove the existing version before replacing
         acf_remove_local_fields($group_key);
         // there currently isn't a remove group function in acf_local
         unset(acf_local()->groups[$group_key]);
     }
     // add or replace the field group to local groups
     acf_add_local_field_group($group);
 }
 function rebuild_group($group_key)
 {
     // check for group in cache
     $found = false;
     $cache = wp_cache_get('acf_reusable/rebuilt_group_' . $group_key, 'acf_resuable', false, $found);
     if ($found) {
         $group = $cache;
     }
     // check for json field
     $json_found = false;
     // neither found the rebuild group
     if (!$found) {
         $group = $this->field_groups[$group_key];
         $group['fields'] = $this->rebuild_fields($group_key, $group['fields']);
         $group['fields'] = $this->replace_keys($group['fields']);
         $group['fields'] = $this->correct_keys($group['fields']);
         //echo preg_replace('/\_\[[0-9]+\]\_/', '', 'field_566f61991b2c4_566f60e177211_[1]_');die;
         //echo '<pre>'; print_r($group['fields']); die;
         $this->replaced_keys = array();
         unset($group['ID']);
     }
     if (!defined('ACF_REUSABLE_DISABLE_JSON') || !ACF_REUSABLE_DISABLE_JSON) {
         // make sure json path exists
         $json_path = plugin_dir_path(__FILE__) . 'acf-json';
         if (!is_dir($json_path)) {
             @mkdir($json_path);
         }
         if (is_multisite()) {
             $json_path .= '/' . get_current_blog_id();
             if (!is_dir($json_path)) {
                 @mkdir($json_path);
             }
         }
         // if json files was not found then save json file
         // attempt to save file/ silently fail if folder is not writable
         if (!$json_found && is_dir($json_path)) {
             if (($handle = @fopen($json_path . '/' . $group_key . '.json', 'w')) !== false) {
                 $json = acf_json_encode($group);
                 fwrite($handle, $json, strlen($json));
                 fclose($handle);
             }
         }
         // end if !json found
     }
     // save in cache
     wp_cache_set('acf_reusable/rebuilt_group_' . $group_key, $group, 'acf_resuable');
     $this->field_groups[$group_key] = $group;
     $this->new_field_groups[] = $group;
     if (acf_is_local_field_group($group_key)) {
         // this is already a local field group
         // remove the existing version before replacing
         acf_remove_local_fields($group_key);
         // there currently isn't a remove group function in acf_local
         //echo $group_key,'<br>';
         $this->clear_acf_cache();
         $acf_local = acf_local();
         unset($acf_local->groups[$group_key]);
         //echo '<pre>'; print_r($acf_local->groups); die;
         //unset(acf_local()->groups[$group_key]);
     }
     //echo '<pre>'; print_r($group); die;
     // add or replace the field group to local groups
     acf_add_local_field_group($group);
     //echo $group_key,'<br><pre>'; print_r(acf_get_field_groups()); die;
 }
 function rebuild_group($group_key)
 {
     // check for group in cache
     $found = false;
     $cache = wp_cache_get('acf_reusable/rebuilt_group_' . $group_key, 'acf_resuable', false, $found);
     if ($found) {
         $group = $cache;
     }
     // check for json field
     $json_found = false;
     if (!$found) {
         $json_path = plugin_dir_path(__FILE__) . 'acf-json';
         if (is_dir($json_path) && ($files = scandir($json_path)) !== false && count($files)) {
             foreach ($files as $file) {
                 $file_path = $json_path . '/' . $file;
                 if (!is_dir($file_path) && preg_match('/\\.json$/', $file)) {
                     $file_group_key = preg_replace('/\\.json$/', '', $file);
                     if ($file_group_key == $group_key) {
                         if (($json = file_get_contents($file_path)) !== false && ($group = json_decode($json, true)) !== NULL) {
                             $json_found = true;
                             $found = true;
                         }
                     }
                     // end if match
                 }
                 // end if json file
             }
             // end foreach file
         }
         // end if is_dir etc
     }
     // end if !found
     // neither found the rebuild group
     if (!$found) {
         $group = $this->field_groups[$group_key];
         $group['fields'] = $this->rebuild_fields($group_key, $group['fields']);
         $group['fields'] = $this->replace_keys($group['fields']);
         $group['fields'] = $this->correct_keys($group['fields']);
         //echo preg_replace('/\_\[[0-9]+\]\_/', '', 'field_566f61991b2c4_566f60e177211_[1]_');die;
         //echo '<pre>'; print_r($group['fields']); die;
         $this->replaced_keys = array();
         unset($group['ID']);
     }
     // if json files was not found then save json file
     // attempt to save file
     if (!$json_found && is_dir($json_path)) {
         if (($handle = @fopen($json_path . '/' . $group_key . '.json', 'w')) !== false) {
             $json = acf_json_encode($group);
             fwrite($handle, $json, strlen($json));
             fclose($handle);
         }
     }
     // end if !json found
     // save in cache
     wp_cache_set('acf_reusable/rebuilt_group_' . $group_key, $group, 'acf_resuable');
     $this->field_groups[$group_key] = $group;
     $this->new_field_groups[] = $group;
     if (acf_is_local_field_group($group_key)) {
         // this is already a local field group
         // remove the existing version before replacing
         acf_remove_local_fields($group_key);
         // there currently isn't a remove group function in acf_local
         unset(acf_local()->groups[$group_key]);
     }
     // add or replace the field group to local groups
     acf_add_local_field_group($group);
 }