function setup_meta()

in web/wp-content/plugins/acf-extended/includes/modules/dev/module-dev.php [598:736]


    function setup_meta($post_id = 0){
        
        // validate
        $post_id = acf_get_valid_post_id($post_id);
        
        // bail early
        if(empty($post_id)){
            return;
        }
        
        // extract decoded post_id
        // $id
        // $type
        extract(acf_decode_post_id($post_id));
        
        // set global type
        $this->type = $type;
        
        // get meta
        $all_meta = $this->get_meta($id, $type);
        $wp_meta = $this->sort_meta($all_meta, $type);
        
        // bail early
        if(empty($wp_meta)){
            return;
        }
    
        // vars
        $acf_meta = array();
        
        // loop to prepare acf_meta
        foreach($wp_meta as $key => $meta){
            
            $ref = false;
            $ref_found = false;
            
            // no prefix, so not acf meta
            if(isset($wp_meta["_$key"])){
                $ref = $wp_meta["_$key"];
                $ref_found = true;
            }
            
            // filters
            $ref = apply_filters('acfe/dev/meta_ref', $ref, $wp_meta, $type, $key, $id, $post_id);
            
            if(!$ref){
                continue;
            }
            
            // check if key is field_abcde123456
            if(!acf_is_field_key($ref['value'])){
                continue;
            }
            
            // vars
            $field_key = $ref['value'];
            $field_type = '<em>' . __('Undefined', 'acfe') . '</em>';
            $field_group_title = '<em>' . __('Undefined', 'acfe') . '</em>';
            
            // get field
            $field = acf_get_field($field_key);
    
            // check clone in sub field: field_123456abcdef_field_123456abcfed
            if(!$field && substr_count($field_key, 'field_') > 1){
                
                // get field key (last key)
                $_field_key = substr($field_key, strrpos($field_key, 'field_'));
                
                // get field
                $field = acf_get_field($_field_key);
                
            }
            
            // found field
            if($field){
                
                // Field type
                $field_type = acf_get_field_type($field['type']);
                $field_type = acfe_maybe_get($field_type, 'label', '<em>Undefined</em>');
                
                // Field Group
                $field_group = acfe_get_field_group_from_field($field);
                
                if($field_group){
    
                    $field_group_title = $field_group['title'];
                    
                    // no id setting, try to get raw field group from db
                    if(!$field_group['ID']){
                        $field_group = acf_get_raw_field_group($field_group['key']);
                    }
                    
                    // found db field group
                    if($field_group && $field_group['ID']){
                        
                        $post_status = get_post_status($field_group['ID']);
    
                        if($post_status === 'publish' || $post_status === 'acf-disabled'){
    
                            $field_group_title = '<a href="' . admin_url('post.php?post=' . $field_group['ID'] . '&action=edit') . '">' . $field_group['title'] . '</a>';
        
                        }
    
                    }

                }
                
            }
            
            // assign acf meta: prefix
            if($ref_found){
    
                unset($wp_meta["_$key"]);
    
                $_meta = $ref;
                $_meta['field_type'] = $field_type;
                $_meta['field_group'] = $field_group_title;
    
                $acf_meta[] = $_meta;
                
            }
            
            // assign acf meta: normal
            $_meta = $wp_meta[ $key ];
            $_meta['field_type'] = $field_type;
            $_meta['field_group'] = $field_group_title;
            
            $acf_meta[] = $_meta;

            // unset wp meta
            unset($wp_meta[ $key ]);
            
        }
        
        // assign global
        $this->wp_meta = $wp_meta;
        $this->acf_meta = $acf_meta;
        
    }