| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
| defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
|
| add_action( 'gf_form_feeds_sync_complete', 'populate_gf_field_details_data', 10, 2 );
|
|
|
|
|
|
|
|
|
| function populate_gf_field_details_data( $post_id, $form_id ) {
|
|
|
|
|
| $form = GFAPI::get_form( $form_id );
|
|
|
| if ( ! $form || is_wp_error( $form ) ) {
|
| error_log( "FIELD_DETAILS_SYNC: Failed to get form {$form_id}" );
|
| return false;
|
| }
|
|
|
| error_log( "FIELD_DETAILS_SYNC: Processing form {$form_id} for post {$post_id}" );
|
|
|
|
|
| $field_details = generate_field_details_list( $form );
|
|
|
|
|
| update_post_meta( $post_id, 'field_details_list', $field_details );
|
| update_post_meta( $post_id, 'field_details_last_sync', current_time( 'Y-m-d H:i:s' ) );
|
|
|
|
|
| update_post_meta( $post_id, 'gf_form_edit_link', admin_url( 'admin.php?page=gf_edit_forms&id=' . $form_id ) );
|
| update_post_meta( $post_id, 'gf_form_entries_link', admin_url( 'admin.php?page=gf_entries&id=' . $form_id ) );
|
|
|
| error_log( "FIELD_DETAILS_SYNC: Completed form {$form_id} - " . strlen( $field_details ) . " characters" );
|
|
|
| return true;
|
| }
|
|
|
|
|
|
|
|
|
| function generate_field_details_list( $form ) {
|
|
|
| $output = '';
|
| $fields = $form['fields'] ?? [];
|
|
|
| if ( empty( $fields ) ) {
|
| return 'No fields found in this form.';
|
| }
|
|
|
| $output .= "FORM: {$form['title']} (ID: {$form['id']})\n";
|
| $output .= "TOTAL FIELDS: " . count( $fields ) . "\n";
|
| $output .= "==============================================\n\n";
|
|
|
| foreach ( $fields as $field ) {
|
|
|
| $output .= "Field ID: {$field->id}\n";
|
| $output .= "Label: " . ( $field->label ?: '(No Label)' ) . "\n";
|
| $output .= "Type: {$field->type}\n";
|
|
|
|
|
| if ( ! empty( $field->description ) ) {
|
| $output .= "Description: {$field->description}\n";
|
| }
|
|
|
|
|
| $output .= "Required: " . ( $field->isRequired ? 'Yes' : 'No' ) . "\n";
|
|
|
|
|
| $visibility = 'Visible';
|
| if ( isset( $field->visibility ) && $field->visibility === 'hidden' ) {
|
| $visibility = 'Hidden';
|
| } elseif ( isset( $field->visibility ) && $field->visibility === 'administrative' ) {
|
| $visibility = 'Administrative Only';
|
| }
|
| $output .= "Visibility: {$visibility}\n";
|
|
|
|
|
| if ( ! empty( $field->allowsPrepopulate ) ) {
|
| $output .= "Dynamic Population: Yes\n";
|
| if ( ! empty( $field->inputName ) ) {
|
| $output .= " Parameter Name: {$field->inputName}\n";
|
| }
|
| } else {
|
| $output .= "Dynamic Population: No\n";
|
| }
|
|
|
|
|
| $gppa_settings = extract_gppa_settings( $field );
|
| if ( ! empty( $gppa_settings ) ) {
|
| $output .= "Gravity Perks Populate Anything:\n";
|
| $output .= $gppa_settings;
|
| }
|
|
|
|
|
| $additional = extract_additional_properties( $field );
|
| if ( ! empty( $additional ) ) {
|
| $output .= "Additional Properties:\n";
|
| $output .= $additional;
|
| }
|
|
|
| $output .= "---\n\n";
|
| }
|
|
|
| $output .= "==============================================\n";
|
| $output .= "END OF FIELD LIST\n";
|
|
|
| return $output;
|
| }
|
|
|
|
|
|
|
|
|
| function extract_gppa_settings( $field ) {
|
|
|
| $output = '';
|
|
|
| $gppa_props = [
|
| 'gppa-choices-enabled',
|
| 'gppa-choices-object-type',
|
| 'gppa-choices-filter',
|
| 'gppa-choices-filter-value',
|
| 'gppa-choices-filter-group',
|
| 'gppa-choices-template',
|
| 'gppa-choices-ordering',
|
| 'gppa-values-enabled',
|
| 'gppa-values-object-type',
|
| 'gppa-values-filter',
|
| 'gppa-values-filter-value',
|
| 'gppa-values-filter-group',
|
| 'gppa-live-merge-tags',
|
| ];
|
|
|
| $has_gppa = false;
|
|
|
| foreach ( $gppa_props as $prop ) {
|
| if ( isset( $field->{$prop} ) && ! empty( $field->{$prop} ) ) {
|
| $has_gppa = true;
|
| $readable_name = str_replace( 'gppa-', '', $prop );
|
| $readable_name = str_replace( '-', ' ', $readable_name );
|
| $readable_name = ucwords( $readable_name );
|
|
|
| $value = $field->{$prop};
|
|
|
| if ( is_array( $value ) || is_object( $value ) ) {
|
| $value = json_encode( $value, JSON_PRETTY_PRINT );
|
| }
|
|
|
| if ( is_bool( $value ) ) {
|
| $value = $value ? 'Yes' : 'No';
|
| }
|
|
|
| $output .= " {$readable_name}: {$value}\n";
|
| }
|
| }
|
|
|
|
|
| if ( isset( $field->choices ) && is_array( $field->choices ) ) {
|
| foreach ( $field->choices as $index => $choice ) {
|
| if ( isset( $choice['gppa-filter'] ) ) {
|
| $has_gppa = true;
|
| $output .= " Choice #{$index} Filter: {$choice['gppa-filter']}\n";
|
| if ( isset( $choice['gppa-filter-value'] ) ) {
|
| $output .= " Choice #{$index} Filter Value: {$choice['gppa-filter-value']}\n";
|
| }
|
| }
|
| }
|
| }
|
|
|
| return $has_gppa ? $output : '';
|
| }
|
|
|
|
|
|
|
|
|
| function extract_additional_properties( $field ) {
|
|
|
| $output = '';
|
|
|
| if ( ! empty( $field->cssClass ) ) {
|
| $output .= " CSS Classes: {$field->cssClass}\n";
|
| }
|
|
|
| if ( ! empty( $field->placeholder ) ) {
|
| $output .= " Placeholder: {$field->placeholder}\n";
|
| }
|
|
|
| if ( isset( $field->defaultValue ) && $field->defaultValue !== '' ) {
|
| $default = is_array( $field->defaultValue )
|
| ? json_encode( $field->defaultValue )
|
| : $field->defaultValue;
|
| $output .= " Default Value: {$default}\n";
|
| }
|
|
|
| if ( ! empty( $field->size ) ) {
|
| $output .= " Size: {$field->size}\n";
|
| }
|
|
|
| if ( isset( $field->layoutGridColumnSpan ) ) {
|
| $output .= " Column Span: {$field->layoutGridColumnSpan}/12\n";
|
| }
|
|
|
| if ( ! empty( $field->adminLabel ) ) {
|
| $output .= " Admin Label: {$field->adminLabel}\n";
|
| }
|
|
|
| if ( ! empty( $field->conditionalLogic ) ) {
|
| $output .= " Conditional Logic: Enabled\n";
|
| if ( isset( $field->conditionalLogic['rules'] ) ) {
|
| $rule_count = count( $field->conditionalLogic['rules'] );
|
| $output .= " Conditional Rules: {$rule_count} rule(s)\n";
|
| }
|
| }
|
|
|
| if ( ! empty( $field->choices ) && is_array( $field->choices ) ) {
|
| $choice_count = count( $field->choices );
|
| $output .= " Choices: {$choice_count} option(s)\n";
|
|
|
| $choices_preview = array_slice( $field->choices, 0, 5 );
|
| foreach ( $choices_preview as $choice ) {
|
| $text = isset( $choice['text'] ) ? $choice['text'] : $choice;
|
| $value = isset( $choice['value'] ) ? $choice['value'] : $text;
|
| $output .= " - {$text} (value: {$value})\n";
|
| }
|
|
|
| if ( $choice_count > 5 ) {
|
| $remaining = $choice_count - 5;
|
| $output .= " ... and {$remaining} more\n";
|
| }
|
| }
|
|
|
| if ( ! empty( $field->inputs ) && is_array( $field->inputs ) ) {
|
| $output .= " Sub-fields:\n";
|
| foreach ( $field->inputs as $input ) {
|
| $label = isset( $input['label'] ) ? $input['label'] : 'Unlabeled';
|
| $id = isset( $input['id'] ) ? $input['id'] : 'No ID';
|
| $output .= " - {$label} (ID: {$id})\n";
|
| }
|
| }
|
|
|
| if ( isset( $field->maxFiles ) && $field->maxFiles > 0 ) {
|
| $output .= " Max Files: {$field->maxFiles}\n";
|
| }
|
|
|
| if ( ! empty( $field->allowedExtensions ) ) {
|
| $output .= " Allowed Extensions: {$field->allowedExtensions}\n";
|
| }
|
|
|
| if ( isset( $field->maxFileSize ) && $field->maxFileSize > 0 ) {
|
| $output .= " Max File Size: {$field->maxFileSize} MB\n";
|
| }
|
|
|
| if ( ! empty( $field->enableCalculation ) ) {
|
| $output .= " Calculation: Enabled\n";
|
| if ( ! empty( $field->calculationFormula ) ) {
|
| $output .= " Formula: {$field->calculationFormula}\n";
|
| }
|
| }
|
|
|
| return $output;
|
| }
|
| |
| |
Comments