Home / Admin / GravityView_DIR_AD_FPOPULATION – Auto-Populate GravityView Field Details on CPT Sync
Duplicate Snippet

Embed Snippet on Your Site

GravityView_DIR_AD_FPOPULATION – Auto-Populate GravityView Field Details on CPT Sync

* Location: Run Everywhere
* Priority: 30
* Description: Hooks into GravityView sync to populate detailed field information

ismail daugherty PRO
<10
Code Preview
php
<?php
/**
 * WPCode Snippet: Auto-Populate GravityView Field Details on CPT Sync
 * Location: Run Everywhere
 * Priority: 30
 * Description: Hooks into GravityView sync to populate detailed field information
 */
defined( 'ABSPATH' ) || exit;
/**
 * Hook into GravityView CPT sync completion
 */
add_action( 'gv_views_sync_complete', 'populate_gv_field_details_data', 10, 2 );
/**
 * Main function to populate GravityView field details
 */
function populate_gv_field_details_data( $post_id, $view_id ) {
    
    error_log( "GV_FIELD_DETAILS_SYNC: Processing view {$view_id} for post {$post_id}" );
    
    // Get the view configuration
    $view_post = get_post( $view_id );
    if ( ! $view_post ) {
        error_log( "GV_FIELD_DETAILS_SYNC: Failed to get view post {$view_id}" );
        return false;
    }
    
    // Get connected form(s) for field information
    $form_id = get_post_meta( $view_id, '_gravityview_form_id', true );
    $form = null;
    
    if ( class_exists( 'GFAPI' ) && $form_id ) {
        $form = GFAPI::get_form( $form_id );
    }
    
    // Build comprehensive field details list
    $field_details = generate_gv_field_details_list( $view_id, $form );
    
    // Update post meta with detailed field information
    update_post_meta( $post_id, 'field_details_comprehensive', $field_details );
    update_post_meta( $post_id, 'field_details_sync_timestamp', current_time( 'Y-m-d H:i:s' ) );
    
    // Add direct edit links for each layout section
    $base_edit_url = admin_url( 'post.php?post=' . $view_id . '&action=edit' );
    update_post_meta( $post_id, 'gv_layout_builder_link', $base_edit_url . '#gravityview-view-configuration' );
    update_post_meta( $post_id, 'gv_settings_link', $base_edit_url . '#gravityview-settings' );
    
    // Add view statistics
    $stats = generate_view_statistics( $view_id, $form );
    update_post_meta( $post_id, 'view_statistics', $stats );
    
    error_log( "GV_FIELD_DETAILS_SYNC: Completed view {$view_id} - " . strlen( $field_details ) . " characters" );
    
    return true;
}
/**
 * Generate comprehensive GravityView field details
 */
function generate_gv_field_details_list( $view_id, $form ) {
    
    $output = '';
    
    // Get view title and basic info
    $view_post = get_post( $view_id );
    $template = get_post_meta( $view_id, '_gravityview_template', true );
    
    $output .= "═══════════════════════════════════════════════════════════════════\n";
    $output .= "GRAVITYVIEW: {$view_post->post_title} (ID: {$view_id})\n";
    $output .= "TEMPLATE: " . strtoupper( $template ?: 'table' ) . "\n";
    
    if ( $form ) {
        $output .= "CONNECTED FORM: {$form['title']} (ID: {$form['id']})\n";
    }
    
    $output .= "CREATED: " . $view_post->post_date . "\n";
    $output .= "MODIFIED: " . $view_post->post_modified . "\n";
    $output .= "═══════════════════════════════════════════════════════════════════\n\n";
    
    // Process Directory/Multiple Entries Fields
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    $output .= "DIRECTORY/MULTIPLE ENTRIES LAYOUT\n";
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
    
    $directory_fields = get_post_meta( $view_id, '_gravityview_directory_fields', true );
    $output .= process_gv_layout_fields( $directory_fields, $form, 'Directory' );
    
    // Process Single Entry Fields
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    $output .= "SINGLE ENTRY LAYOUT\n";
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
    
    $single_fields = get_post_meta( $view_id, '_gravityview_single_fields', true );
    $output .= process_gv_layout_fields( $single_fields, $form, 'Single Entry' );
    
    // Process Edit Entry Fields
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    $output .= "EDIT ENTRY LAYOUT\n";
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
    
    $edit_fields = get_post_meta( $view_id, '_gravityview_edit_fields', true );
    $output .= process_gv_layout_fields( $edit_fields, $form, 'Edit Entry' );
    
    // Process Widgets
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    $output .= "WIDGETS CONFIGURATION\n";
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
    
    $widgets = get_post_meta( $view_id, '_gravityview_directory_widgets', true );
    $output .= process_gv_widgets( $widgets );
    
    // Process View Settings
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    $output .= "VIEW SETTINGS & CONFIGURATION\n";
    $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
    
    $settings = get_post_meta( $view_id, '_gravityview_settings', true );
    $output .= process_gv_settings( $settings );
    
    // Process Multiple Forms if enabled
    $joined_forms = get_post_meta( $view_id, '_gravityview_joined_forms', true );
    if ( ! empty( $joined_forms ) ) {
        $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
        $output .= "MULTIPLE FORMS CONFIGURATION\n";
        $output .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
        $output .= process_multiple_forms( $joined_forms );
    }
    
    $output .= "═══════════════════════════════════════════════════════════════════\n";
    $output .= "END OF VIEW FIELD DETAILS\n";
    $output .= "═══════════════════════════════════════════════════════════════════\n";
    
    return $output;
}
/**
 * Process fields for a specific layout
 */
function process_gv_layout_fields( $fields, $form, $layout_name ) {
    
    $output = '';
    
    if ( empty( $fields ) || ! is_array( $fields ) ) {
        return "No fields configured for {$layout_name}\n\n";
    }
    
    $field_count = 0;
    $form_fields = [];
    
    // Build form fields lookup array
    if ( $form && isset( $form['fields'] ) ) {
        foreach ( $form['fields'] as $gf_field ) {
            $form_fields[ $gf_field->id ] = $gf_field;
        }
    }
    
    foreach ( $fields as $zone_id => $zone_fields ) {
        if ( ! empty( $zone_fields ) && is_array( $zone_fields ) ) {
            
            $output .= "ZONE: " . strtoupper( str_replace( '_', ' ', $zone_id ) ) . "\n";
            $output .= "-------------------------------------------\n\n";
            
            foreach ( $zone_fields as $field ) {
                $field_count++;
                
                $output .= "Field #{$field_count}:\n";
                
                // Field ID and Type
                if ( ! empty( $field['id'] ) ) {
                    $output .= "  GV Field ID: {$field['id']}\n";
                    
                    // If it's a form field, get additional details
                    if ( is_numeric( $field['id'] ) && isset( $form_fields[ $field['id'] ] ) ) {
                        $gf_field = $form_fields[ $field['id'] ];
                        $output .= "  Form Field Type: {$gf_field->type}\n";
                        $output .= "  Form Field Label: " . ( $gf_field->label ?: '(No Label)' ) . "\n";
                        
                        // Check for GPPA settings
                        $gppa_settings = extract_gv_gppa_settings( $gf_field );
                        if ( ! empty( $gppa_settings ) ) {
                            $output .= "  Populate Anything Settings:\n";
                            $output .= $gppa_settings;
                        }
                    } else {
                        // It's a GravityView-specific field
                        $output .= "  Field Type: " . get_gv_field_type_name( $field['id'] ) . "\n";
                    }
                }
                
                // Custom Label
                if ( ! empty( $field['custom_label'] ) ) {
                    $output .= "  Custom Label: {$field['custom_label']}\n";
                } elseif ( ! empty( $field['label'] ) ) {
                    $output .= "  Label: {$field['label']}\n";
                }
                
                // Custom CSS Class
                if ( ! empty( $field['custom_class'] ) ) {
                    $output .= "  CSS Class: {$field['custom_class']}\n";
                }
                
                // Visibility Settings
                if ( ! empty( $field['show_label'] ) ) {
                    $output .= "  Show Label: " . ( $field['show_label'] == '1' ? 'Yes' : 'No' ) . "\n";
                }
                
                if ( ! empty( $field['only_loggedin'] ) ) {
                    $output .= "  Visibility: Logged-in Users Only\n";
                    if ( ! empty( $field['only_loggedin_cap'] ) ) {
                        $output .= "  Required Capability: {$field['only_loggedin_cap']}\n";
                    }
                }
                
                // Custom Content
                if ( $field['id'] === 'custom' && ! empty( $field['content'] ) ) {
                    $content_preview = substr( strip_tags( $field['content'] ), 0, 100 );
                    $output .= "  Custom Content: {$content_preview}...\n";
                }
                
                // Search Settings (if in search widget)
                if ( ! empty( $field['search_fields'] ) ) {
                    $output .= "  Search Fields: " . implode( ', ', $field['search_fields'] ) . "\n";
                }
                
                // Additional field-specific settings
                $additional = extract_gv_field_settings( $field );
                if ( ! empty( $additional ) ) {
                    $output .= $additional;
                }
                
                $output .= "\n";
            }
        }
    }
    
    $output .= "Total {$layout_name} Fields: {$field_count}\n\n";
    
    return $output;
}
/**
 * Process widgets configuration
 */
function process_gv_widgets( $widgets ) {
    
    $output = '';
    
    if ( empty( $widgets ) || ! is_array( $widgets ) ) {
        return "No widgets configured\n\n";
    }
    
    $widget_areas = [
        'header_top'    => 'Header Top',
        'header_left'   => 'Header Left',
        'header_right'  => 'Header Right',
        'footer_top'    => 'Footer Top',
        'footer_left'   => 'Footer Left',
        'footer_right'  => 'Footer Right',
        'footer_bottom' => 'Footer Bottom',
    ];
    
    foreach ( $widget_areas as $area_key => $area_name ) {
        if ( ! empty( $widgets[ $area_key ] ) && is_array( $widgets[ $area_key ] ) ) {
            $output .= "{$area_name} Widgets:\n";
            
            foreach ( $widgets[ $area_key ] as $index => $widget ) {
                $widget_num = $index + 1;
                $output .= "  Widget #{$widget_num}:\n";
                
                if ( ! empty( $widget['id'] ) ) {
                    $output .= "    Type: " . get_gv_widget_type_name( $widget['id'] ) . "\n";
                }
                
                if ( ! empty( $widget['label'] ) ) {
                    $output .= "    Label: {$widget['label']}\n";
                }
                
                // Widget-specific settings
                $widget_settings = extract_gv_widget_settings( $widget );
                if ( ! empty( $widget_settings ) ) {
                    $output .= $widget_settings;
                }
            }
            
            $output .= "\n";
        }
    }
    
    return $output;
}
/**
 * Process view settings
 */
function process_gv_settings( $settings ) {
    
    $output = '';
    
    if ( empty( $settings ) || ! is_array( $settings ) ) {
        return "Default view settings\n\n";
    }
    
    // Categorize settings
    $setting_categories = [
        'Display' => [
            'page_size'           => 'Entries Per Page',
            'pagination'          => 'Pagination',
            'hide_empty'          => 'Hide Empty Fields',
            'hide_until_searched' => 'Hide Until Searched',
            'no_entries_text'     => 'No Entries Message',
        ],
        'Permissions' => [
            'show_only_user_entries' => 'Show Only User Entries',
            'user_edit'              => 'User Can Edit',
            'user_delete'            => 'User Can Delete',
            'admin_approval'         => 'Require Admin Approval',
        ],
        'Filtering' => [
            'show_only_approved' => 'Show Only Approved',
            'sort_field'         => 'Default Sort Field',
            'sort_direction'     => 'Sort Direction',
            'search_layout'      => 'Search Layout',
        ],
        'Advanced' => [
            'class'           => 'CSS Classes',
            'cache_enable'    => 'Cache Enabled',
            'cache_duration'  => 'Cache Duration',
            'rest_enable'     => 'REST API Enabled',
        ],
    ];
    
    foreach ( $setting_categories as $category => $category_settings ) {
        $category_output = '';
        
        foreach ( $category_settings as $key => $label ) {
            if ( isset( $settings[ $key ] ) && $settings[ $key ] !== '' ) {
                $value = $settings[ $key ];
                
                if ( is_bool( $value ) || $value === '0' || $value === '1' ) {
                    $value = ( $value == '1' || $value === true ) ? 'Yes' : 'No';
                } elseif ( is_array( $value ) ) {
                    $value = json_encode( $value, JSON_PRETTY_PRINT );
                }
                
                $category_output .= "  {$label}: {$value}\n";
            }
        }
        
        if ( ! empty( $category_output ) ) {
            $output .= "{$category} Settings:\n";
            $output .= $category_output;
            $output .= "\n";
        }
    }
    
    // Advanced Filter Rules
    if ( ! empty( $settings['search_criteria'] ) ) {
        $output .= "Advanced Filter Criteria:\n";
        $output .= process_filter_criteria( $settings['search_criteria'] );
        $output .= "\n";
    }
    
    return $output;
}
/**
 * Process Multiple Forms configuration
 */
function process_multiple_forms( $joined_forms ) {
    
    $output = '';
    
    if ( empty( $joined_forms ) || ! is_array( $joined_forms ) ) {
        return "No joined forms configured\n\n";
    }
    
    $form_count = 1;
    foreach ( $joined_forms as $joined ) {
        $output .= "Joined Form #{$form_count}:\n";
        
        if ( ! empty( $joined['form_id'] ) ) {
            $output .= "  Form ID: {$joined['form_id']}\n";
            
            // Get form title if possible
            if ( class_exists( 'GFAPI' ) ) {
                $joined_form = GFAPI::get_form( $joined['form_id'] );
                if ( $joined_form ) {
                    $output .= "  Form Title: {$joined_form['title']}\n";
                }
            }
        }
        
        if ( ! empty( $joined['join_type'] ) ) {
            $output .= "  Join Type: " . ucfirst( $joined['join_type'] ) . "\n";
        }
        
        if ( ! empty( $joined['join_on'] ) ) {
            $output .= "  Join Conditions:\n";
            
            if ( ! empty( $joined['join_on']['field'] ) ) {
                $output .= "    Primary Field: {$joined['join_on']['field']}\n";
            }
            if ( ! empty( $joined['join_on']['joined_field'] ) ) {
                $output .= "    Joined Field: {$joined['join_on']['joined_field']}\n";
            }
            if ( ! empty( $joined['join_on']['condition'] ) ) {
                $output .= "    Condition: {$joined['join_on']['condition']}\n";
            }
        }
        
        $output .= "\n";
        $form_count++;
    }
    
    return $output;
}
/**
 * Extract GPPA settings for GravityView field
 */
function extract_gv_gppa_settings( $field ) {
    
    $output = '';
    
    // Check for GPPA-enabled fields
    if ( ! empty( $field->{'gppa-choices-enabled'} ) || ! empty( $field->{'gppa-values-enabled'} ) ) {
        
        if ( ! empty( $field->{'gppa-choices-enabled'} ) ) {
            $output .= "    GPPA Choices: Enabled\n";
            
            if ( ! empty( $field->{'gppa-choices-object-type'} ) ) {
                $output .= "      Object Type: {$field->{'gppa-choices-object-type'}}\n";
            }
            if ( ! empty( $field->{'gppa-choices-filter'} ) ) {
                $filters = is_array( $field->{'gppa-choices-filter'} ) 
                    ? json_encode( $field->{'gppa-choices-filter'} ) 
                    : $field->{'gppa-choices-filter'};
                $output .= "      Filters: {$filters}\n";
            }
        }
        
        if ( ! empty( $field->{'gppa-values-enabled'} ) ) {
            $output .= "    GPPA Values: Enabled\n";
            
            if ( ! empty( $field->{'gppa-values-object-type'} ) ) {
                $output .= "      Object Type: {$field->{'gppa-values-object-type'}}\n";
            }
        }
    }
    
    // Check for GPPA Live Merge Tags
    if ( ! empty( $field->{'gppa-live-merge-tags'} ) ) {
        $output .= "    GPPA Live Merge Tags: Enabled\n";
    }
    
    return $output;
}
/**
 * Extract additional GravityView field settings
 */
function extract_gv_field_settings( $field ) {
    
    $output = '';
    
    // Check for sorting options
    if ( ! empty( $field['sort'] ) ) {
        $output .= "  Sortable: Yes\n";
    }
    
    // Check for link settings
    if ( ! empty( $field['link_to_entry'] ) ) {
        $output .= "  Links to Entry: Yes\n";
    }
    
    if ( ! empty( $field['link_to_post'] ) ) {
        $output .= "  Links to Post: Yes\n";
    }
    
    // Check for date format
    if ( ! empty( $field['date_format'] ) ) {
        $output .= "  Date Format: {$field['date_format']}\n";
    }
    
    // Check for truncate settings
    if ( ! empty( $field['truncate_length'] ) ) {
        $output .= "  Truncate Length: {$field['truncate_length']} characters\n";
    }
    
    // Check for new window setting
    if ( ! empty( $field['new_window'] ) ) {
        $output .= "  Opens in New Window: Yes\n";
    }
    
    return $output;
}
/**
 * Extract widget-specific settings
 */
function extract_gv_widget_settings( $widget ) {
    
    $output = '';
    
    // Search widget settings
    if ( $widget['id'] === 'search_bar' ) {
        if ( ! empty( $widget['search_fields'] ) ) {
            $output .= "      Search Fields: " . count( $widget['search_fields'] ) . " fields\n";
        }
        if ( ! empty( $widget['search_clear'] ) ) {
            $output .= "      Show Clear Button: Yes\n";
        }
    }
    
    // Pagination widget settings
    if ( $widget['id'] === 'page_info' || $widget['id'] === 'pagination' ) {
        if ( ! empty( $widget['show_all'] ) ) {
            $output .= "      Show All Option: Yes\n";
        }
    }
    
    // Export widget settings
    if ( $widget['id'] === 'export_link' ) {
        if ( ! empty( $widget['export_type'] ) ) {
            $output .= "      Export Type: {$widget['export_type']}\n";
        }
    }
    
    return $output;
}
/**
 * Process filter criteria
 */
function process_filter_criteria( $criteria ) {
    
    $output = '';
    
    if ( ! empty( $criteria['field_filters'] ) && is_array( $criteria['field_filters'] ) ) {
        $filter_count = 1;
        
        foreach ( $criteria['field_filters'] as $filter ) {
            if ( is_array( $filter ) && ! empty( $filter['key'] ) ) {
                $output .= "  Filter #{$filter_count}:\n";
                $output .= "    Field: {$filter['key']}\n";
                
                if ( ! empty( $filter['operator'] ) ) {
                    $output .= "    Operator: {$filter['operator']}\n";
                }
                if ( isset( $filter['value'] ) ) {
                    $value = is_array( $filter['value'] ) 
                        ? json_encode( $filter['value'] ) 
                        : $filter['value'];
                    $output .= "    Value: {$value}\n";
                }
                
                $filter_count++;
            }
        }
    }
    
    if ( ! empty( $criteria['mode'] ) ) {
        $output .= "  Filter Logic: {$criteria['mode']}\n";
    }
    
    if ( ! empty( $criteria['status'] ) ) {
        $output .= "  Entry Status: {$criteria['status']}\n";
    }
    
    return $output;
}
/**
 * Get human-readable GravityView field type name
 */
function get_gv_field_type_name( $field_id ) {
    
    $field_types = [
        'entry_id'        => 'Entry ID',
        'entry_date'      => 'Entry Date',
        'source_url'      => 'Source URL',
        'ip'              => 'IP Address',
        'created_by'      => 'Created By',
        'user_name'       => 'User Name',
        'custom'          => 'Custom Content',
        'edit_link'       => 'Edit Entry Link',
        'delete_link'     => 'Delete Entry Link',
        'approval_status' => 'Approval Status',
        'other_entries'   => 'Other Entries',
    ];
    
    return isset( $field_types[ $field_id ] ) ? $field_types[ $field_id ] : ucwords( str_replace( '_', ' ', $field_id ) );
}
/**
 * Get human-readable widget type name
 */
function get_gv_widget_type_name( $widget_id ) {
    
    $widget_types = [
        'search_bar'    => 'Search Bar',
        'page_info'     => 'Page Information',
        'pagination'    => 'Pagination Links',
        'export_link'   => 'Export Links',
        'total_entries' => 'Total Entries',
    ];
    
    return isset( $widget_types[ $widget_id ] ) ? $widget_types[ $widget_id ] : ucwords( str_replace( '_', ' ', $widget_id ) );
}
/**
 * Generate view statistics
 */
function generate_view_statistics( $view_id, $form ) {
    
    $output = '';
    
    $output .= "═══════════════════════════════════════════════════════════════════\n";
    $output .= "VIEW STATISTICS\n";
    $output .= "═══════════════════════════════════════════════════════════════════\n\n";
    
    // Count fields in each layout
    $directory_fields = get_post_meta( $view_id, '_gravityview_directory_fields', true );
    $single_fields = get_post_meta( $view_id, '_gravityview_single_fields', true );
    $edit_fields = get_post_meta( $view_id, '_gravityview_edit_fields', true );
    
    $dir_count = count_fields_recursive( $directory_fields );
    $single_count = count_fields_recursive( $single_fields );
    $edit_count = count_fields_recursive( $edit_fields );
    
    $output .= "Field Counts:\n";
    $output .= "  Directory Layout: {$dir_count} fields\n";
    $output .= "  Single Entry Layout: {$single_count} fields\n";
    $output .= "  Edit Entry Layout: {$edit_count} fields\n";
    $output .= "  Total Fields: " . ( $dir_count + $single_count + $edit_count ) . "\n\n";
    
    // Count widgets
    $widgets = get_post_meta( $view_id, '_gravityview_directory_widgets', true );
    $widget_count = count_fields_recursive( $widgets );
    $output .= "Total Widgets: {$widget_count}\n\n";
    
    // Entry statistics (if form is connected)
    if ( $form && class_exists( 'GFAPI' ) ) {
        $entry_count = GFAPI::count_entries( $form['id'] );
        $output .= "Connected Entries: {$entry_count}\n";
        
        // Count active vs inactive
        $active_count = GFAPI::count_entries( $form['id'], ['status' => 'active'] );
        $trash_count = GFAPI::count_entries( $form['id'], ['status' => 'trash'] );
        
        $output .= "  Active: {$active_count}\n";
        $output .= "  Trash: {$trash_count}\n";
    }
    
    $output .= "\n";
    
    // Check for active extensions
    $output .= "Active Extensions:\n";
    
    $extensions = [
        'GravityView_Featured_Entries' => 'Featured Entries',
        'GravityView_Ratings_Reviews'  => 'Ratings & Reviews',
        'GravityView_Magic_Links'      => 'Magic Links',
        'GravityView_Calendar'         => 'Calendar',
        'GravityView_Charts'           => 'Charts',
        'GravityView_Maps'             => 'Maps',
        'GravityView_DataTables'       => 'DataTables',
        'GravityView_PDF'              => 'PDF Export',
        'GravityView_Import_Entries'   => 'Import Entries',
    ];
    
    $active_extensions = 0;
    foreach ( $extensions as $class => $name ) {
        if ( class_exists( $class ) ) {
            $output .= "  ✓ {$name}\n";
            $active_extensions++;
        }
    }
    
    if ( $active_extensions === 0 ) {
        $output .= "  No extensions detected\n";
    }
    
    $output .= "\n═══════════════════════════════════════════════════════════════════\n";
    
    return $output;
}
/**
 * Count fields recursively
 */
function count_fields_recursive( $array ) {
    if ( ! is_array( $array ) ) {
        return 0;
    }
    
    $count = 0;
    foreach ( $array as $value ) {
        if ( is_array( $value ) ) {
            $count += count_fields_recursive( $value );
        } else {
            $count++;
        }
    }
    
    return $count;
}
/**
 * Manual trigger for testing
 */
add_action( 'admin_init', function() {
    if ( isset( $_GET['sync_gv_field_details'] ) && current_user_can( 'manage_options' ) ) {
        $view_id = intval( $_GET['view_id'] );
        
        if ( $view_id ) {
            // Find the sync post
            $sync_posts = get_posts( [
                'post_type'   => 'gv_views_sync',
                'meta_key'    => 'view_id',
                'meta_value'  => $view_id,
                'numberposts' => 1,
            ] );
            
            if ( ! empty( $sync_posts ) ) {
                populate_gv_field_details_data( $sync_posts[0]->ID, $view_id );
                wp_die( 'Field details synced for view ' . $view_id );
            }
        }
    }
} );

Comments

Add a Comment