rep__get_sync_fields( $field_group_name, $post_id )

This function retrieves the list of fields that are marked for synchronization in a given field group for a specific post. It returns an array containing three subarrays: ‘forced’, ‘conditional’, and ‘for_sync’. ‘forced’ contains the keys of fields that must be synchronized regardless. ‘conditional’ contains the keys of fields that should be synchronized if certain conditions are met. ‘for_sync’ is a combination of ‘forced’ and ‘conditional’ keys that have met the set condition.

Namespace

REP_Malcolm

Parameters

$field_group_name

string

Details to get.

$post_id

string

The post ID to check for conditional sync fields.

Return

array

An array containing forced, conditional, and for_sync fields..

Source

File: \includes\rep-helper-functions.php

function rep__get_sync_fields( $field_group_name, $post_id, $api_data ){

    $forced = array_column( lp__fields_query( array(
        'parent' => $field_group_name,
        'sync_data' => array( 
            'operator' => '===',
            'value' => 1,
        ),
    ) ), 'key' );

    $conditional = array_column( lp__fields_query( array(
        'parent' => $field_group_name,
        'sync_data' => array( 
            'operator' => '!==',
            'value' => 0,
        ),
        'sync_data' => array( 
            'operator' => '!==',
            'value' => 1,
        ),
    ) ), 'key' );

    $passed_conditional = array_column( lp__fields_query( array(
        'parent' => $field_group_name,
        'sync_data' => array( $post_id, $api_data ),
    ) ), 'key' );

    $for_sync = array_merge( $forced, 
        array_filter( $conditional, function ($field) use ($passed_conditional) {
            return in_array($field, $passed_conditional);
        })
    );

    return array( 
        'forced' => $forced,
        'conditional' => $conditional,
        'for_sync' => $for_sync
    );

}