AdvancedCustomFields / AdvancedCustomFields/acf

Groups are duplicated automatically and somes groups are converteds to posts.

Open
#400 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Hey everyone,

Did anyone have problems with automatic duplication of groups?
I noticed that some groups started to appear as posts. Did this happen to any of you?

I`m using a external script (by @jessepearson) to sync modified groups automatically. Do you think it can be causing this error?

function lgr_sync_acf_fields() {
			
					// vars
					$groups = acf_get_field_groups();
					$sync 	= array();
				
					// bail early if no field groups
					if( empty( $groups ) )
						return;
				
					// find JSON field groups which have not yet been imported
					foreach( $groups as $group ) {
						
						// vars
						$local 		= acf_maybe_get( $group, 'local', false );
						$modified 	= acf_maybe_get( $group, 'modified', 0 );
						$private 	= acf_maybe_get( $group, 'private', false );
						
						// ignore DB / PHP / private field groups
						if( $local !== 'json' || $private ) {
							
							// do nothing
							
						} elseif( ! $group[ 'ID' ] ) {
							
							$sync[ $group[ 'key' ] ] = $group;
							
						} elseif( $modified && $modified > get_post_modified_time( 'U', true, $group[ 'ID' ], true ) ) {
							
							$sync[ $group[ 'key' ] ]  = $group;
						}
					}
				
					// bail if no sync needed
					if( empty( $sync ) )
						return;
				
					if( ! empty( $sync ) ) { //if( ! empty( $keys ) ) {
						
						// vars
						$new_ids = array();
						
						foreach( $sync as $key => $v ) { //foreach( $keys as $key ) {
							
							// append fields
							if( acf_have_local_fields( $key ) ) {
								
								$sync[ $key ][ 'fields' ] = acf_get_fields( $key );
								
							}
							// import
							$field_group = acf_import_field_group( $sync[ $key ] );
						}
					}
				}
				add_action( 'admin_init', 'lgr_sync_acf_fields' );

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported lgr_sync_acf_fields function, its admin_init hook, and the acf_import_field_group call. Reproduce the behavior with the external synchronization script and inspect whether it duplicates groups or converts them into posts. Done means the cause is identified and the affected behavior can be verified as fixed or ruled out.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.