| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_action( 'init', function() {
|
| if ( ! defined( 'DOING_CRON' ) && ! defined( 'WP_CLI' ) ) {
|
|
|
| if ( isset( $_GET['sync_gravityview'] ) && current_user_can( 'manage_options' ) ) {
|
| add_action( 'admin_init', 'gv_sync_all_views' );
|
| }
|
| }
|
| } );
|
|
|
|
|
| add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
|
| if ( ! current_user_can( 'manage_options' ) ) {
|
| return;
|
| }
|
|
|
| $wp_admin_bar->add_node( [
|
| 'id' => 'sync_gravityview',
|
| 'title' => '🔄 Sync GravityViews',
|
| 'href' => add_query_arg( 'sync_gravityview', '1', admin_url() ),
|
| 'meta' => [
|
| 'title' => 'Sync all GravityView configurations to CPT',
|
| ],
|
| ] );
|
| }, 100 );
|
|
|
|
|
| add_action( 'gravityview_view_saved', 'gv_sync_single_view', 10, 2 );
|
| add_action( 'gravityview/view/updated', 'gv_sync_single_view', 10, 2 );
|
| add_action( 'save_post_gravityview', 'gv_sync_single_view_by_post_id', 10, 1 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_sync_all_views() {
|
| error_log( 'GV_VIEWS_SYNC: Starting full sync' );
|
|
|
|
|
| $args = [
|
| 'post_type' => 'gravityview',
|
| 'posts_per_page' => -1,
|
| 'post_status' => 'any',
|
| 'fields' => 'ids',
|
| ];
|
|
|
| $view_posts = get_posts( $args );
|
|
|
| if ( empty( $view_posts ) ) {
|
| error_log( 'GV_VIEWS_SYNC: No views found' );
|
| return;
|
| }
|
|
|
| $count = 0;
|
| foreach ( $view_posts as $view_id ) {
|
| gv_sync_single_view_by_post_id( $view_id );
|
| $count++;
|
| }
|
|
|
| error_log( "GV_VIEWS_SYNC: Synced {$count} views" );
|
|
|
|
|
| if ( is_admin() ) {
|
| add_action( 'admin_notices', function() use ( $count ) {
|
| echo '<div class="notice notice-success is-dismissible">';
|
| echo '<p>✅ GravityView Sync Complete: ' . $count . ' views synced.</p>';
|
| echo '</div>';
|
| } );
|
| }
|
| }
|
|
|
|
|
|
|
|
|
| function gv_sync_single_view_by_post_id( $view_id ) {
|
| if ( get_post_type( $view_id ) !== 'gravityview' ) {
|
| return;
|
| }
|
|
|
|
|
| $view_post = get_post( $view_id );
|
| if ( ! $view_post ) {
|
| return;
|
| }
|
|
|
| gv_process_view_sync( $view_id, $view_post );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_sync_single_view( $view_id, $view_data = null ) {
|
| gv_sync_single_view_by_post_id( $view_id );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_process_view_sync( $view_id, $view_post ) {
|
| error_log( "GV_VIEWS_SYNC: Processing view ID {$view_id}" );
|
|
|
|
|
| $view_data = gravityview_get_current_view_data( $view_id );
|
|
|
|
|
| $view_settings = get_post_meta( $view_id, '_gravityview_settings', true );
|
| if ( ! is_array( $view_settings ) ) {
|
| $view_settings = [];
|
| }
|
|
|
|
|
| $form_id = get_post_meta( $view_id, '_gravityview_form_id', true );
|
|
|
|
|
| $template = get_post_meta( $view_id, '_gravityview_template', true );
|
| if ( empty( $template ) ) {
|
| $template = 'table';
|
| }
|
|
|
|
|
| $existing_posts = get_posts( [
|
| 'post_type' => 'gv_views_sync',
|
| 'meta_key' => 'view_id',
|
| 'meta_value' => $view_id,
|
| 'numberposts' => 1,
|
| 'post_status' => 'any',
|
| ] );
|
|
|
| $existing_post_id = ! empty( $existing_posts ) ? $existing_posts[0]->ID : null;
|
|
|
|
|
| $post_data = [
|
| 'post_type' => 'gv_views_sync',
|
| 'post_title' => $view_post->post_title,
|
| 'post_content' => $view_post->post_content,
|
| 'post_status' => $view_post->post_status,
|
| ];
|
|
|
|
|
| $meta_data = gv_build_view_meta_data( $view_id, $view_post, $form_id, $template, $view_settings );
|
|
|
|
|
| if ( $existing_post_id ) {
|
| $post_data['ID'] = $existing_post_id;
|
| $post_id = wp_update_post( $post_data );
|
| error_log( "GV_VIEWS_SYNC: Updated view {$view_id} (post {$post_id})" );
|
| } else {
|
| $post_id = wp_insert_post( $post_data );
|
| error_log( "GV_VIEWS_SYNC: Created view {$view_id} (post {$post_id})" );
|
| }
|
|
|
|
|
| if ( $post_id && ! is_wp_error( $post_id ) ) {
|
| foreach ( $meta_data as $key => $value ) {
|
| update_post_meta( $post_id, $key, $value );
|
| }
|
|
|
|
|
| $acf_link_fields = [
|
| 'gv_view_edit_link',
|
| 'gv_multiple_entries_edit_link',
|
| 'gv_single_entry_edit_link',
|
| 'gv_edit_entry_edit_link',
|
| 'gv_view_preview_link',
|
| 'primary_form_edit_link'
|
| ];
|
|
|
| foreach ( $acf_link_fields as $field ) {
|
| if ( isset( $meta_data[ $field ] ) ) {
|
| update_post_meta( $post_id, '_' . $field, 'field_' . $field );
|
| }
|
| }
|
|
|
|
|
| do_action( 'gv_views_sync_complete', $post_id, $view_id );
|
| error_log( "GV_VIEWS_SYNC: Completed sync for view {$view_id}" );
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_build_view_meta_data( $view_id, $view_post, $form_id, $template, $view_settings ) {
|
|
|
|
|
| $entry_count = gv_get_view_entry_count( $view_id, $form_id );
|
|
|
|
|
| $forms_data = gv_get_connected_forms_data( $view_id, $form_id );
|
|
|
|
|
| $fields_data = gv_get_view_fields_data( $view_id );
|
|
|
|
|
| $widgets_data = gv_get_view_widgets_data( $view_id );
|
|
|
|
|
| $custom_code = gv_get_view_custom_code( $view_id );
|
|
|
|
|
| $integrations = gv_get_view_integrations( $view_id, $form_id );
|
|
|
|
|
| $meta_data = [
|
|
|
| 'view_id' => $view_id,
|
| 'view_slug' => $view_post->post_name,
|
| 'view_status' => $view_post->post_status === 'publish' ? 'active' : 'inactive',
|
| 'view_type' => $template,
|
| 'entry_count' => $entry_count,
|
| 'date_created' => $view_post->post_date,
|
| 'date_modified' => $view_post->post_modified,
|
|
|
|
|
| 'gv_view_edit_link' => admin_url( 'post.php?post=' . $view_id . '&action=edit' ),
|
| 'gv_multiple_entries_edit_link' => admin_url( 'post.php?post=' . $view_id . '&action=edit#gravityview_directory_fields' ),
|
| 'gv_single_entry_edit_link' => admin_url( 'post.php?post=' . $view_id . '&action=edit#gravityview_single_fields' ),
|
| 'gv_edit_entry_edit_link' => admin_url( 'post.php?post=' . $view_id . '&action=edit#gravityview_edit_fields' ),
|
| 'gv_view_preview_link' => get_permalink( $view_id ),
|
| 'view_shortcode' => '[gravityview id="' . $view_id . '"]',
|
|
|
|
|
| 'primary_form_id' => $form_id,
|
| 'primary_form_title' => $forms_data['primary_form_title'],
|
| 'primary_form_edit_link' => admin_url( 'admin.php?page=gf_edit_forms&id=' . $form_id ),
|
| 'multiple_forms_enabled' => $forms_data['multiple_forms_enabled'],
|
| 'strict_entry_match' => $forms_data['strict_entry_match'],
|
| 'connected_forms_list' => $forms_data['connected_forms_list'],
|
| 'join_conditions_list' => $forms_data['join_conditions_list'],
|
|
|
|
|
| 'multiple_entries_fields_list' => $fields_data['multiple_entries'],
|
| 'single_entry_fields_list' => $fields_data['single_entry'],
|
| 'edit_entry_fields_list' => $fields_data['edit_entry'],
|
| 'field_mappings_details' => $fields_data['mappings'],
|
| 'custom_content_fields' => $fields_data['custom_content'],
|
| 'total_fields_count' => $fields_data['total_count'],
|
|
|
|
|
| 'widgets_top_list' => $widgets_data['top'],
|
| 'widgets_bottom_list' => $widgets_data['bottom'],
|
|
|
|
|
| 'filter_enabled' => ! empty( $view_settings['filter'] ),
|
| 'advanced_filter_enabled' => ! empty( $view_settings['advanced_filter'] ),
|
| 'advanced_filter_rules_list' => gv_format_filter_rules( $view_settings ),
|
| 'filter_by_user' => ! empty( $view_settings['show_only_user_entries'] ),
|
| 'filter_approval_status' => gv_get_approval_filter( $view_settings ),
|
| 'default_sort_field' => ! empty( $view_settings['sort_field'] ) ? $view_settings['sort_field'] : '',
|
| 'default_sort_direction' => ! empty( $view_settings['sort_direction'] ) ? $view_settings['sort_direction'] : 'desc',
|
| 'search_enabled' => ! empty( $view_settings['search_layout'] ),
|
| 'search_fields_list' => gv_format_search_fields( $view_id ),
|
| 'pagination_enabled' => ! empty( $view_settings['pagination'] ),
|
| 'entries_per_page' => ! empty( $view_settings['page_size'] ) ? $view_settings['page_size'] : 20,
|
|
|
|
|
| 'show_only_approved' => ! empty( $view_settings['show_only_approved'] ),
|
| 'hide_empty_fields' => ! empty( $view_settings['hide_empty'] ),
|
| 'hide_until_searched' => ! empty( $view_settings['hide_until_searched'] ),
|
| 'lightbox_enabled' => ! empty( $view_settings['lightbox'] ),
|
| 'featured_entries_enabled' => $integrations['featured_entries'],
|
| 'ratings_enabled' => $integrations['ratings_reviews'],
|
| 'entry_link_type' => gv_get_entry_link_type( $view_settings ),
|
| 'no_entries_message' => ! empty( $view_settings['no_entries_text'] ) ? $view_settings['no_entries_text'] : '',
|
| 'table_columns_config' => gv_format_table_config( $view_id, $template ),
|
| 'map_settings_details' => gv_format_map_settings( $view_id, $template ),
|
| 'calendar_settings_details' => gv_format_calendar_settings( $view_id, $template ),
|
|
|
|
|
| 'view_permissions' => gv_get_view_permissions( $view_settings ),
|
| 'edit_entry_permission' => gv_get_edit_permission( $view_settings ),
|
| 'delete_entry_permission' => gv_get_delete_permission( $view_settings ),
|
| 'user_edit_enabled' => ! empty( $view_settings['user_edit'] ),
|
| 'user_delete_enabled' => ! empty( $view_settings['user_delete'] ),
|
| 'moderate_entries' => ! empty( $view_settings['admin_approval'] ),
|
| 'magic_links_enabled' => $integrations['magic_links'],
|
| 'magic_links_config' => gv_format_magic_links( $view_id ),
|
| 'allowed_user_roles_list' => gv_format_allowed_roles( $view_settings ),
|
|
|
|
|
| 'csv_export_enabled' => ! empty( $view_settings['csv_enable'] ),
|
| 'csv_export_fields_list' => gv_format_csv_fields( $view_id ),
|
| 'print_enabled' => ! empty( $view_settings['print_enable'] ),
|
| 'print_layout_config' => gv_format_print_config( $view_settings ),
|
| 'pdf_export_enabled' => $integrations['pdf_export'],
|
| 'excel_export_enabled' => ! empty( $view_settings['excel_enable'] ),
|
| 'export_permissions' => gv_get_export_permissions( $view_settings ),
|
|
|
|
|
| 'gravity_flow_enabled' => $integrations['gravity_flow'],
|
| 'gravity_flow_settings' => $integrations['gravity_flow_settings'],
|
| 'gravity_pdf_enabled' => $integrations['gravity_pdf'],
|
| 'gravity_pdf_templates' => $integrations['gravity_pdf_templates'],
|
| 'gravity_calendar_enabled' => $integrations['gravity_calendar'],
|
| 'gravity_calendar_settings' => $integrations['gravity_calendar_settings'],
|
| 'gravity_charts_enabled' => $integrations['gravity_charts'],
|
| 'gravity_charts_config' => $integrations['gravity_charts_config'],
|
| 'gravity_boards_enabled' => $integrations['gravity_boards'],
|
| 'gravity_boards_settings' => $integrations['gravity_boards_settings'],
|
| 'gravity_math_calculations' => $integrations['gravity_math_calculations'],
|
| 'connected_feeds_list' => $integrations['connected_feeds_list'],
|
|
|
|
|
| 'custom_css' => $custom_code['css'],
|
| 'custom_javascript' => $custom_code['javascript'],
|
| 'custom_php_hooks' => $custom_code['php_hooks'],
|
| 'css_classes' => ! empty( $view_settings['class'] ) ? $view_settings['class'] : '',
|
|
|
|
|
| 'rest_api_enabled' => ! empty( $view_settings['rest_enable'] ),
|
| 'api_endpoints_list' => gv_format_api_endpoints( $view_id ),
|
| 'whalesync_status' => 'active',
|
| 'last_sync' => current_time( 'mysql' ),
|
| 'airtable_record_id' => get_post_meta( $view_id, '_airtable_record_id', true ),
|
| 'sync_errors' => '',
|
|
|
|
|
| 'embedded_pages_list' => gv_get_embedded_pages( $view_id ),
|
| 'view_notes' => get_post_meta( $view_id, '_gravityview_notes', true ),
|
| 'cache_enabled' => ! empty( $view_settings['cache_enable'] ),
|
| 'cache_duration' => ! empty( $view_settings['cache_duration'] ) ? $view_settings['cache_duration'] : 3600,
|
| 'view_template' => $template,
|
| ];
|
|
|
| return $meta_data;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_get_connected_forms_data( $view_id, $primary_form_id ) {
|
| $data = [
|
| 'primary_form_title' => '',
|
| 'multiple_forms_enabled'=> false,
|
| 'strict_entry_match' => false,
|
| 'connected_forms_list' => '',
|
| 'join_conditions_list' => '',
|
| ];
|
|
|
|
|
| if ( class_exists( 'GFAPI' ) && $primary_form_id ) {
|
| $form = GFAPI::get_form( $primary_form_id );
|
| if ( $form ) {
|
| $data['primary_form_title'] = $form['title'];
|
| }
|
| }
|
|
|
|
|
| $joined_forms = get_post_meta( $view_id, '_gravityview_joined_forms', true );
|
| if ( ! empty( $joined_forms ) && is_array( $joined_forms ) ) {
|
| $data['multiple_forms_enabled'] = true;
|
|
|
|
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "CONNECTED FORMS";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
| $output[] = "Primary Form: {$data['primary_form_title']} (ID: {$primary_form_id})";
|
| $output[] = "";
|
|
|
| $count = 1;
|
| foreach ( $joined_forms as $joined ) {
|
| if ( ! empty( $joined['form_id'] ) ) {
|
| $joined_form = GFAPI::get_form( $joined['form_id'] );
|
| if ( $joined_form ) {
|
| $output[] = "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
| $output[] = "JOINED FORM #{$count}";
|
| $output[] = "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
| $output[] = "Form: {$joined_form['title']} (ID: {$joined['form_id']})";
|
| $output[] = "Join Type: " . ( ! empty( $joined['join_type'] ) ? $joined['join_type'] : 'left' );
|
| $output[] = "";
|
| $count++;
|
| }
|
| }
|
| }
|
|
|
| $data['connected_forms_list'] = implode( "\n", $output );
|
|
|
|
|
| $conditions_output = [];
|
| $conditions_output[] = "═══════════════════════════════════════════════";
|
| $conditions_output[] = "JOIN CONDITIONS";
|
| $conditions_output[] = "═══════════════════════════════════════════════";
|
| $conditions_output[] = "";
|
|
|
| foreach ( $joined_forms as $joined ) {
|
| if ( ! empty( $joined['join_on'] ) ) {
|
| $conditions_output[] = "Primary Field: {$joined['join_on']['field']}";
|
| $conditions_output[] = "Joined Field: {$joined['join_on']['joined_field']}";
|
| $conditions_output[] = "Condition: {$joined['join_on']['condition']}";
|
| $conditions_output[] = "";
|
| }
|
| }
|
|
|
| $data['join_conditions_list'] = implode( "\n", $conditions_output );
|
|
|
|
|
| $view_settings = get_post_meta( $view_id, '_gravityview_settings', true );
|
| $data['strict_entry_match'] = ! empty( $view_settings['strict_match'] );
|
| } else {
|
| $data['connected_forms_list'] = "Single form view - no additional forms connected";
|
| $data['join_conditions_list'] = "N/A - Single form view";
|
| }
|
|
|
| return $data;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_get_view_fields_data( $view_id ) {
|
| $data = [
|
| 'multiple_entries' => '',
|
| 'single_entry' => '',
|
| 'edit_entry' => '',
|
| 'mappings' => '',
|
| 'custom_content' => '',
|
| 'total_count' => 0,
|
| ];
|
|
|
|
|
| $directory_fields = get_post_meta( $view_id, '_gravityview_directory_fields', true );
|
| $data['multiple_entries'] = gv_format_fields_list( $directory_fields, 'Directory/Multiple Entries' );
|
|
|
|
|
| $single_fields = get_post_meta( $view_id, '_gravityview_single_fields', true );
|
| $data['single_entry'] = gv_format_fields_list( $single_fields, 'Single Entry' );
|
|
|
|
|
| $edit_fields = get_post_meta( $view_id, '_gravityview_edit_fields', true );
|
| $data['edit_entry'] = gv_format_fields_list( $edit_fields, 'Edit Entry' );
|
|
|
|
|
| $total = 0;
|
| if ( is_array( $directory_fields ) ) {
|
| $total += count( $directory_fields, COUNT_RECURSIVE );
|
| }
|
| if ( is_array( $single_fields ) ) {
|
| $total += count( $single_fields, COUNT_RECURSIVE );
|
| }
|
| if ( is_array( $edit_fields ) ) {
|
| $total += count( $edit_fields, COUNT_RECURSIVE );
|
| }
|
| $data['total_count'] = $total;
|
|
|
|
|
| $data['mappings'] = gv_format_field_mappings( $view_id );
|
|
|
|
|
| $data['custom_content'] = gv_extract_custom_content( $directory_fields, $single_fields );
|
|
|
| return $data;
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_fields_list( $fields, $section_name ) {
|
| if ( empty( $fields ) || ! is_array( $fields ) ) {
|
| return "No fields configured for {$section_name}";
|
| }
|
|
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = strtoupper( $section_name ) . " FIELDS";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
| $field_count = 0;
|
| foreach ( $fields as $zone_id => $zone_fields ) {
|
| if ( ! empty( $zone_fields ) && is_array( $zone_fields ) ) {
|
| $output[] = "Zone: " . $zone_id;
|
| $output[] = "";
|
|
|
| foreach ( $zone_fields as $field ) {
|
| $field_count++;
|
| $output[] = "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
| $output[] = "FIELD #{$field_count}";
|
| $output[] = "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
|
|
| if ( ! empty( $field['id'] ) ) {
|
| $output[] = "Field ID: " . $field['id'];
|
| }
|
| if ( ! empty( $field['label'] ) ) {
|
| $output[] = "Label: " . $field['label'];
|
| }
|
| if ( ! empty( $field['custom_label'] ) ) {
|
| $output[] = "Custom Label: " . $field['custom_label'];
|
| }
|
| if ( ! empty( $field['type'] ) ) {
|
| $output[] = "Type: " . $field['type'];
|
| }
|
| if ( ! empty( $field['form_id'] ) ) {
|
| $output[] = "Form ID: " . $field['form_id'];
|
| }
|
| if ( ! empty( $field['custom_class'] ) ) {
|
| $output[] = "CSS Class: " . $field['custom_class'];
|
| }
|
| if ( ! empty( $field['show_label'] ) ) {
|
| $output[] = "Show Label: Yes";
|
| }
|
| if ( ! empty( $field['only_loggedin'] ) ) {
|
| $output[] = "⚠️ Logged-in Users Only";
|
| }
|
| if ( ! empty( $field['only_loggedin_cap'] ) ) {
|
| $output[] = "Required Capability: " . $field['only_loggedin_cap'];
|
| }
|
| $output[] = "";
|
| }
|
| }
|
| }
|
|
|
| $output[] = "Total Fields: " . $field_count;
|
| $output[] = "";
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_get_view_entry_count( $view_id, $form_id ) {
|
| if ( ! class_exists( 'GFAPI' ) || empty( $form_id ) ) {
|
| return 0;
|
| }
|
|
|
| $search_criteria = [
|
| 'status' => 'active',
|
| ];
|
|
|
| try {
|
| return GFAPI::count_entries( $form_id, $search_criteria );
|
| } catch ( Exception $e ) {
|
| error_log( 'GV_VIEWS_SYNC: Error counting entries: ' . $e->getMessage() );
|
| return 0;
|
| }
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_view_widgets_data( $view_id ) {
|
| $data = [
|
| 'top' => '',
|
| 'bottom' => '',
|
| ];
|
|
|
| $widgets = get_post_meta( $view_id, '_gravityview_directory_widgets', true );
|
|
|
| if ( ! empty( $widgets ) && is_array( $widgets ) ) {
|
|
|
| if ( ! empty( $widgets['header_top'] ) ) {
|
| $data['top'] = gv_format_widgets_list( $widgets['header_top'], 'Top' );
|
| } else {
|
| $data['top'] = "No top widgets configured";
|
| }
|
|
|
|
|
| if ( ! empty( $widgets['footer_bottom'] ) ) {
|
| $data['bottom'] = gv_format_widgets_list( $widgets['footer_bottom'], 'Bottom' );
|
| } else {
|
| $data['bottom'] = "No bottom widgets configured";
|
| }
|
| } else {
|
| $data['top'] = "No widgets configured";
|
| $data['bottom'] = "No widgets configured";
|
| }
|
|
|
| return $data;
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_widgets_list( $widgets, $position ) {
|
| if ( empty( $widgets ) || ! is_array( $widgets ) ) {
|
| return "No {$position} widgets configured";
|
| }
|
|
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = strtoupper( $position ) . " WIDGETS";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
| $count = 1;
|
| foreach ( $widgets as $widget ) {
|
| $output[] = "Widget #{$count}:";
|
| if ( ! empty( $widget['id'] ) ) {
|
| $output[] = " Type: " . $widget['id'];
|
| }
|
| if ( ! empty( $widget['label'] ) ) {
|
| $output[] = " Label: " . $widget['label'];
|
| }
|
| $output[] = "";
|
| $count++;
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_get_view_custom_code( $view_id ) {
|
| $data = [
|
| 'css' => '',
|
| 'javascript' => '',
|
| 'php_hooks' => '',
|
| ];
|
|
|
|
|
| $custom_css = get_post_meta( $view_id, '_gravityview_custom_css', true );
|
| if ( ! empty( $custom_css ) ) {
|
| $data['css'] = $custom_css;
|
| } else {
|
| $data['css'] = "/* No custom CSS */";
|
| }
|
|
|
|
|
| $custom_js = get_post_meta( $view_id, '_gravityview_custom_javascript', true );
|
| if ( ! empty( $custom_js ) ) {
|
| $data['javascript'] = $custom_js;
|
| } else {
|
| $data['javascript'] = "// No custom JavaScript";
|
| }
|
|
|
|
|
| $data['php_hooks'] = gv_detect_custom_hooks( $view_id );
|
|
|
| return $data;
|
| }
|
|
|
|
|
|
|
|
|
| function gv_detect_custom_hooks( $view_id ) {
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "DETECTED PHP HOOKS & FILTERS";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
|
|
| $hooks_to_check = [
|
| 'gravityview_fields_' . $view_id,
|
| 'gravityview_query_filter_' . $view_id,
|
| 'gravityview/view/settings/' . $view_id,
|
| 'gravityview_search_criteria_' . $view_id,
|
| ];
|
|
|
| $found = false;
|
| foreach ( $hooks_to_check as $hook ) {
|
| if ( has_filter( $hook ) ) {
|
| $output[] = "✓ Found: " . $hook;
|
| $found = true;
|
| }
|
| }
|
|
|
| if ( ! $found ) {
|
| $output[] = "No custom PHP hooks detected";
|
| }
|
|
|
| $output[] = "";
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_get_view_integrations( $view_id, $form_id ) {
|
| $integrations = [
|
| 'featured_entries' => false,
|
| 'ratings_reviews' => false,
|
| 'magic_links' => false,
|
| 'pdf_export' => false,
|
| 'gravity_flow' => false,
|
| 'gravity_flow_settings' => '',
|
| 'gravity_pdf' => false,
|
| 'gravity_pdf_templates' => '',
|
| 'gravity_calendar' => false,
|
| 'gravity_calendar_settings' => '',
|
| 'gravity_charts' => false,
|
| 'gravity_charts_config' => '',
|
| 'gravity_boards' => false,
|
| 'gravity_boards_settings' => '',
|
| 'gravity_math_calculations' => '',
|
| 'connected_feeds_list' => '',
|
| ];
|
|
|
|
|
| if ( class_exists( 'GravityView_Featured_Entries' ) ) {
|
| $integrations['featured_entries'] = true;
|
| }
|
|
|
|
|
| if ( class_exists( 'GravityView_Ratings_Reviews' ) ) {
|
| $integrations['ratings_reviews'] = true;
|
| }
|
|
|
|
|
| if ( class_exists( 'GravityView_Magic_Links' ) ) {
|
| $integrations['magic_links'] = true;
|
| }
|
|
|
|
|
| if ( class_exists( 'GravityView_PDF' ) || class_exists( 'GPDFAPI' ) ) {
|
| $integrations['pdf_export'] = true;
|
| $integrations['gravity_pdf_templates'] = gv_get_pdf_templates( $view_id, $form_id );
|
| }
|
|
|
|
|
| if ( class_exists( 'Gravity_Flow' ) ) {
|
| $integrations['gravity_flow'] = true;
|
| $integrations['gravity_flow_settings'] = gv_get_flow_settings( $form_id );
|
| }
|
|
|
|
|
| if ( class_exists( 'GravityView_Calendar' ) ) {
|
| $integrations['gravity_calendar'] = true;
|
| $integrations['gravity_calendar_settings'] = gv_get_calendar_settings( $view_id );
|
| }
|
|
|
|
|
| if ( class_exists( 'GravityView_Charts' ) || class_exists( 'GFChart' ) ) {
|
| $integrations['gravity_charts'] = true;
|
| $integrations['gravity_charts_config'] = gv_get_charts_config( $view_id, $form_id );
|
| }
|
|
|
|
|
| if ( class_exists( 'GravityView_Boards' ) ) {
|
| $integrations['gravity_boards'] = true;
|
| $integrations['gravity_boards_settings'] = gv_get_boards_settings( $view_id );
|
| }
|
|
|
|
|
| $integrations['gravity_math_calculations'] = gv_detect_math_calculations( $view_id );
|
|
|
|
|
| $integrations['connected_feeds_list'] = gv_get_connected_feeds( $form_id );
|
|
|
| return $integrations;
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_connected_feeds( $form_id ) {
|
| if ( ! class_exists( 'GFAddOn' ) || empty( $form_id ) ) {
|
| return "No feeds detected";
|
| }
|
|
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "CONNECTED FEEDS & ADD-ONS";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
|
|
| $addons = GFAddOn::get_registered_addons();
|
| $feed_count = 0;
|
|
|
| foreach ( $addons as $addon_class ) {
|
| if ( ! class_exists( $addon_class ) ) {
|
| continue;
|
| }
|
|
|
| try {
|
| $addon = call_user_func( [ $addon_class, 'get_instance' ] );
|
| if ( ! $addon || ! method_exists( $addon, 'get_feeds' ) ) {
|
| continue;
|
| }
|
|
|
| $feeds = $addon->get_feeds( $form_id );
|
|
|
| if ( ! empty( $feeds ) && is_array( $feeds ) ) {
|
| $addon_name = method_exists( $addon, 'get_short_title' ) ? $addon->get_short_title() : 'Unknown';
|
|
|
| foreach ( $feeds as $feed ) {
|
| $feed_count++;
|
| $feed_name = ! empty( $feed['meta']['feed_name'] ) ? $feed['meta']['feed_name'] : 'Unnamed';
|
| $is_active = ! isset( $feed['is_active'] ) || $feed['is_active'] ? 'Active' : 'Inactive';
|
|
|
| $output[] = "Feed #{$feed_count}: {$addon_name} - {$feed_name} ({$is_active})";
|
| }
|
| }
|
| } catch ( Exception $e ) {
|
| continue;
|
| }
|
| }
|
|
|
| if ( $feed_count === 0 ) {
|
| $output[] = "No feeds connected";
|
| }
|
|
|
| $output[] = "";
|
| $output[] = "Total Feeds: " . $feed_count;
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_format_filter_rules( $settings ) {
|
| if ( empty( $settings['search_criteria'] ) ) {
|
| return "No advanced filter rules configured";
|
| }
|
|
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "ADVANCED FILTER RULES";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
| $criteria = $settings['search_criteria'];
|
|
|
| if ( ! empty( $criteria['field_filters'] ) ) {
|
| $count = 1;
|
| foreach ( $criteria['field_filters'] as $filter ) {
|
| if ( is_array( $filter ) && ! empty( $filter['key'] ) ) {
|
| $output[] = "Filter #{$count}:";
|
| $output[] = " Field: " . $filter['key'];
|
| $output[] = " Operator: " . ( ! empty( $filter['operator'] ) ? $filter['operator'] : '=' );
|
| $output[] = " Value: " . ( ! empty( $filter['value'] ) ? $filter['value'] : '' );
|
| $output[] = "";
|
| $count++;
|
| }
|
| }
|
| }
|
|
|
| if ( ! empty( $criteria['mode'] ) ) {
|
| $output[] = "Filter Mode: " . $criteria['mode'];
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_search_fields( $view_id ) {
|
| $search_fields = get_post_meta( $view_id, '_gravityview_search_fields', true );
|
|
|
| if ( empty( $search_fields ) || ! is_array( $search_fields ) ) {
|
| return "Default search configuration";
|
| }
|
|
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "SEARCHABLE FIELDS";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
| foreach ( $search_fields as $field ) {
|
| if ( ! empty( $field['field'] ) ) {
|
| $output[] = "• Field: " . $field['field'];
|
| if ( ! empty( $field['input'] ) ) {
|
| $output[] = " Input Type: " . $field['input'];
|
| }
|
| }
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_approval_filter( $settings ) {
|
| if ( ! empty( $settings['show_only_approved'] ) ) {
|
| return 'approved';
|
| } elseif ( ! empty( $settings['show_all_entries'] ) ) {
|
| return 'all';
|
| }
|
| return 'all';
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_entry_link_type( $settings ) {
|
| if ( ! empty( $settings['single_entry_link'] ) ) {
|
| if ( $settings['single_entry_link'] === 'lightbox' ) {
|
| return 'lightbox';
|
| } elseif ( $settings['single_entry_link'] === 'new_tab' ) {
|
| return 'new_tab';
|
| }
|
| return 'single_entry';
|
| }
|
| return 'none';
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_view_permissions( $settings ) {
|
| if ( ! empty( $settings['restrict_to_logged_in'] ) ) {
|
| if ( ! empty( $settings['restrict_to_roles'] ) ) {
|
| return 'role-based';
|
| }
|
| return 'logged-in';
|
| }
|
| return 'public';
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_edit_permission( $settings ) {
|
| if ( ! empty( $settings['user_edit'] ) ) {
|
| return 'creator';
|
| } elseif ( ! empty( $settings['admin_edit'] ) ) {
|
| return 'admin';
|
| }
|
| return 'none';
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_delete_permission( $settings ) {
|
| if ( ! empty( $settings['user_delete'] ) ) {
|
| return 'creator';
|
| } elseif ( ! empty( $settings['admin_delete'] ) ) {
|
| return 'admin';
|
| }
|
| return 'none';
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_allowed_roles( $settings ) {
|
| if ( empty( $settings['restrict_to_roles'] ) ) {
|
| return "All roles allowed";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Allowed Roles:";
|
|
|
| if ( is_array( $settings['restrict_to_roles'] ) ) {
|
| foreach ( $settings['restrict_to_roles'] as $role ) {
|
| $output[] = "• " . $role;
|
| }
|
| } else {
|
| $output[] = "• " . $settings['restrict_to_roles'];
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_export_permissions( $settings ) {
|
| if ( ! empty( $settings['csv_restrict'] ) || ! empty( $settings['print_restrict'] ) ) {
|
| if ( ! empty( $settings['csv_restrict_roles'] ) ) {
|
| return 'role-based';
|
| }
|
| return 'logged-in';
|
| }
|
| return 'public';
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_csv_fields( $view_id ) {
|
| $csv_fields = get_post_meta( $view_id, '_gravityview_csv_fields', true );
|
|
|
| if ( empty( $csv_fields ) ) {
|
| return "All visible fields included in CSV export";
|
| }
|
|
|
| $output = [];
|
| $output[] = "CSV Export Fields:";
|
|
|
| if ( is_array( $csv_fields ) ) {
|
| foreach ( $csv_fields as $field ) {
|
| $output[] = "• " . $field;
|
| }
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_print_config( $settings ) {
|
| $output = [];
|
| $output[] = "Print Configuration:";
|
|
|
| if ( ! empty( $settings['print_title'] ) ) {
|
| $output[] = "• Include Title: Yes";
|
| }
|
| if ( ! empty( $settings['print_description'] ) ) {
|
| $output[] = "• Include Description: Yes";
|
| }
|
| if ( ! empty( $settings['print_pagebreak'] ) ) {
|
| $output[] = "• Page Break Between Entries: Yes";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_api_endpoints( $view_id ) {
|
| $output = [];
|
| $output[] = "REST API Endpoints:";
|
| $output[] = "• Views: /wp-json/gravityview/v1/views/" . $view_id;
|
| $output[] = "• Entries: /wp-json/gravityview/v1/views/" . $view_id . "/entries.json";
|
| $output[] = "• Single Entry: /wp-json/gravityview/v1/views/" . $view_id . "/entries/{entry_id}.json";
|
| $output[] = "• HTML Format: /wp-json/gravityview/v1/views/" . $view_id . "/entries.html";
|
| $output[] = "• CSV Format: /wp-json/gravityview/v1/views/" . $view_id . "/entries.csv";
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_embedded_pages( $view_id ) {
|
| global $wpdb;
|
|
|
|
|
| $shortcode = '[gravityview id="' . $view_id . '"';
|
| $posts = $wpdb->get_results(
|
| $wpdb->prepare(
|
| "SELECT ID, post_title, post_type FROM {$wpdb->posts}
|
| WHERE post_content LIKE %s
|
| AND post_status = 'publish'",
|
| '%' . $wpdb->esc_like( $shortcode ) . '%'
|
| )
|
| );
|
|
|
| if ( empty( $posts ) ) {
|
| return "View not currently embedded in any pages/posts";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Embedded in:";
|
|
|
| foreach ( $posts as $post ) {
|
| $output[] = "• {$post->post_title} ({$post->post_type} ID: {$post->ID})";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_format_table_config( $view_id, $template ) {
|
| if ( $template !== 'table' && $template !== 'datatables' ) {
|
| return "N/A - Not a table view";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Table Configuration:";
|
|
|
| $settings = get_post_meta( $view_id, '_gravityview_settings', true );
|
|
|
| if ( $template === 'datatables' ) {
|
| $output[] = "• Type: DataTables";
|
| if ( ! empty( $settings['datatables_responsive'] ) ) {
|
| $output[] = "• Responsive: Yes";
|
| }
|
| if ( ! empty( $settings['datatables_scrollx'] ) ) {
|
| $output[] = "• Horizontal Scroll: Yes";
|
| }
|
| } else {
|
| $output[] = "• Type: Standard Table";
|
| }
|
|
|
| if ( ! empty( $settings['sort_columns'] ) ) {
|
| $output[] = "• Sortable Columns: Yes";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_map_settings( $view_id, $template ) {
|
| if ( $template !== 'map' ) {
|
| return "N/A - Not a map view";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Map Configuration:";
|
|
|
| $map_settings = get_post_meta( $view_id, '_gravityview_maps_settings', true );
|
|
|
| if ( ! empty( $map_settings['map_center'] ) ) {
|
| $output[] = "• Center: " . $map_settings['map_center'];
|
| }
|
| if ( ! empty( $map_settings['map_zoom'] ) ) {
|
| $output[] = "• Zoom Level: " . $map_settings['map_zoom'];
|
| }
|
| if ( ! empty( $map_settings['map_marker_field'] ) ) {
|
| $output[] = "• Marker Field: " . $map_settings['map_marker_field'];
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_calendar_settings( $view_id, $template ) {
|
| if ( $template !== 'calendar' ) {
|
| return "N/A - Not a calendar view";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Calendar Configuration:";
|
|
|
| $cal_settings = get_post_meta( $view_id, '_gravityview_calendar_settings', true );
|
|
|
| if ( ! empty( $cal_settings['calendar_start_field'] ) ) {
|
| $output[] = "• Start Date Field: " . $cal_settings['calendar_start_field'];
|
| }
|
| if ( ! empty( $cal_settings['calendar_end_field'] ) ) {
|
| $output[] = "• End Date Field: " . $cal_settings['calendar_end_field'];
|
| }
|
| if ( ! empty( $cal_settings['calendar_view'] ) ) {
|
| $output[] = "• Default View: " . $cal_settings['calendar_view'];
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_get_pdf_templates( $view_id, $form_id ) {
|
| if ( ! class_exists( 'GPDFAPI' ) ) {
|
| return "Gravity PDF not active";
|
| }
|
|
|
| $output = [];
|
| $output[] = "PDF Templates:";
|
|
|
| try {
|
| $pdfs = GPDFAPI::get_form_pdfs( $form_id );
|
| if ( ! empty( $pdfs ) ) {
|
| foreach ( $pdfs as $pdf ) {
|
| $output[] = "• " . $pdf['name'] . " (ID: " . $pdf['id'] . ")";
|
| }
|
| } else {
|
| $output[] = "No PDF templates configured";
|
| }
|
| } catch ( Exception $e ) {
|
| $output[] = "Error loading PDF templates";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_flow_settings( $form_id ) {
|
| if ( ! class_exists( 'Gravity_Flow' ) ) {
|
| return "Gravity Flow not active";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Gravity Flow Configuration:";
|
|
|
| $flow = gravity_flow();
|
| $steps = $flow->get_steps( $form_id );
|
|
|
| if ( ! empty( $steps ) ) {
|
| foreach ( $steps as $step ) {
|
| $output[] = "• Step: " . $step->get_name() . " (Type: " . $step->get_type() . ")";
|
| }
|
| } else {
|
| $output[] = "No workflow steps configured";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_calendar_settings( $view_id ) {
|
| $cal_config = get_post_meta( $view_id, '_gravityview_calendar_config', true );
|
|
|
| if ( empty( $cal_config ) ) {
|
| return "Default calendar configuration";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Calendar Settings:";
|
|
|
| if ( ! empty( $cal_config['title_field'] ) ) {
|
| $output[] = "• Title Field: " . $cal_config['title_field'];
|
| }
|
| if ( ! empty( $cal_config['date_field'] ) ) {
|
| $output[] = "• Date Field: " . $cal_config['date_field'];
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_charts_config( $view_id, $form_id ) {
|
| $output = [];
|
| $output[] = "Charts Configuration:";
|
|
|
| $charts = get_post_meta( $view_id, '_gravityview_charts', true );
|
|
|
| if ( ! empty( $charts ) && is_array( $charts ) ) {
|
| foreach ( $charts as $chart ) {
|
| if ( ! empty( $chart['type'] ) ) {
|
| $output[] = "• Chart Type: " . $chart['type'];
|
| if ( ! empty( $chart['field'] ) ) {
|
| $output[] = " Data Field: " . $chart['field'];
|
| }
|
| }
|
| }
|
| } else {
|
| $output[] = "No charts configured";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_get_boards_settings( $view_id ) {
|
| $boards_config = get_post_meta( $view_id, '_gravityview_boards_config', true );
|
|
|
| if ( empty( $boards_config ) ) {
|
| return "Default boards configuration";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Kanban Boards Settings:";
|
|
|
| if ( ! empty( $boards_config['status_field'] ) ) {
|
| $output[] = "• Status Field: " . $boards_config['status_field'];
|
| }
|
| if ( ! empty( $boards_config['columns'] ) ) {
|
| $output[] = "• Columns: " . implode( ', ', $boards_config['columns'] );
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_detect_math_calculations( $view_id ) {
|
| $view_post = get_post( $view_id );
|
|
|
| if ( ! $view_post ) {
|
| return "No Math calculations detected";
|
| }
|
|
|
|
|
| if ( strpos( $view_post->post_content, '[gv_math' ) !== false ) {
|
| preg_match_all( '/\[gv_math[^\]]*\]/', $view_post->post_content, $matches );
|
|
|
| if ( ! empty( $matches[0] ) ) {
|
| $output = [];
|
| $output[] = "Math Calculations Found:";
|
| foreach ( $matches[0] as $match ) {
|
| $output[] = "• " . $match;
|
| }
|
| return implode( "\n", $output );
|
| }
|
| }
|
|
|
| return "No Math calculations detected";
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_magic_links( $view_id ) {
|
| if ( ! class_exists( 'GravityView_Magic_Links' ) ) {
|
| return "Magic Links not active";
|
| }
|
|
|
| $magic_config = get_post_meta( $view_id, '_gravityview_magic_links', true );
|
|
|
| if ( empty( $magic_config ) ) {
|
| return "Default Magic Links configuration";
|
| }
|
|
|
| $output = [];
|
| $output[] = "Magic Links Configuration:";
|
|
|
| if ( ! empty( $magic_config['expiry'] ) ) {
|
| $output[] = "• Link Expiry: " . $magic_config['expiry'] . " hours";
|
| }
|
| if ( ! empty( $magic_config['usage_limit'] ) ) {
|
| $output[] = "• Usage Limit: " . $magic_config['usage_limit'];
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_extract_custom_content( $directory_fields, $single_fields ) {
|
| $output = [];
|
| $output[] = "Custom Content Fields:";
|
| $found = false;
|
|
|
|
|
| if ( is_array( $directory_fields ) ) {
|
| foreach ( $directory_fields as $zone => $fields ) {
|
| if ( is_array( $fields ) ) {
|
| foreach ( $fields as $field ) {
|
| if ( ! empty( $field['id'] ) && $field['id'] === 'custom' ) {
|
| $output[] = "• Directory: " . ( ! empty( $field['content'] ) ? substr( $field['content'], 0, 50 ) . '...' : 'Custom content' );
|
| $found = true;
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
|
|
| if ( is_array( $single_fields ) ) {
|
| foreach ( $single_fields as $zone => $fields ) {
|
| if ( is_array( $fields ) ) {
|
| foreach ( $fields as $field ) {
|
| if ( ! empty( $field['id'] ) && $field['id'] === 'custom' ) {
|
| $output[] = "• Single: " . ( ! empty( $field['content'] ) ? substr( $field['content'], 0, 50 ) . '...' : 'Custom content' );
|
| $found = true;
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| if ( ! $found ) {
|
| $output[] = "No custom content fields";
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
|
|
|
|
| function gv_format_field_mappings( $view_id ) {
|
| $output = [];
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "FIELD MAPPINGS & CONFIGURATION";
|
| $output[] = "═══════════════════════════════════════════════";
|
| $output[] = "";
|
|
|
|
|
| $zones = [
|
| 'directory' => get_post_meta( $view_id, '_gravityview_directory_fields', true ),
|
| 'single' => get_post_meta( $view_id, '_gravityview_single_fields', true ),
|
| 'edit' => get_post_meta( $view_id, '_gravityview_edit_fields', true ),
|
| ];
|
|
|
| foreach ( $zones as $zone_name => $zone_fields ) {
|
| if ( ! empty( $zone_fields ) && is_array( $zone_fields ) ) {
|
| $output[] = ucfirst( $zone_name ) . " Zone Mappings:";
|
|
|
| foreach ( $zone_fields as $position => $fields ) {
|
| if ( ! empty( $fields ) && is_array( $fields ) ) {
|
| $output[] = " Position: " . $position;
|
| $output[] = " Field Count: " . count( $fields );
|
| }
|
| }
|
|
|
| $output[] = "";
|
| }
|
| }
|
|
|
| return implode( "\n", $output );
|
| }
|
|
|
|
|
| add_action( 'init', function() {
|
| if ( ! wp_next_scheduled( 'gv_views_sync_cron' ) ) {
|
| wp_schedule_event( time(), 'daily', 'gv_views_sync_cron' );
|
| }
|
| } );
|
|
|
| add_action( 'gv_views_sync_cron', 'gv_sync_all_views' );
|
|
|
|
|
| register_deactivation_hook( __FILE__, function() {
|
| wp_clear_scheduled_hook( 'gv_views_sync_cron' );
|
| } );
|
| |
| |
Comments