$contents['fields'][$data]['label']]; } } } if ( ! empty( $final_data ) ) { $final_data = array_merge( ...$final_data ); } return $final_data; } public static function get_custom_fields( $directory_type ) { $contents = get_term_meta( $directory_type, 'submission_form_fields', true ); // Validate and unserialize if needed if ( is_string( $contents ) ) { $contents = maybe_unserialize( $contents ); } // Return empty array if contents is invalid or empty if ( empty( $contents ) || ! is_array( $contents ) || empty( $contents['groups'] ) || ! is_array( $contents['groups'] ) ) { return []; } $data = []; foreach ( $contents['groups'] as $content ) { if ( ! empty( $content['fields'] ) && is_array( $content['fields'] ) ) { $data[] = $content['fields']; } } // Return empty array if no valid data found if ( empty( $data ) ) { return []; } $all_data = array_merge( ...$data ); $except_data = [ 'file', 'url', 'video', 'phone', 'website', ]; // Create a regex pattern to match any key that starts with the except_data keys $pattern = '/^(' . implode('|', array_map('preg_quote', $except_data)) . ')/'; // Filter the all_data array $filteredArray = array_filter($all_data, function($item) use ($pattern) { return preg_match($pattern, $item); }); $final_data = []; if ( ! empty( $contents['fields'] ) && is_array( $contents['fields'] ) ) { foreach ( $filteredArray as $data ) { if ( isset( $contents['fields'][$data]['label'] ) ) { $final_data[] = [$data => $contents['fields'][$data]['label']]; } } } if ( ! empty( $final_data ) ) { $final_data = array_merge( ...$final_data ); } return $final_data; } public static function get_custom_color_field( $directory_type ) { $contents = get_term_meta( $directory_type, 'submission_form_fields', true ); // Validate and unserialize if needed if ( is_string( $contents ) ) { $contents = maybe_unserialize( $contents ); } // Return empty array if contents is invalid or empty if ( empty( $contents ) || ! is_array( $contents ) || empty( $contents['groups'] ) || ! is_array( $contents['groups'] ) ) { return []; } $data = []; foreach ( $contents['groups'] as $content ) { if ( ! empty( $content['fields'] ) && is_array( $content['fields'] ) ) { $data[] = $content['fields']; } } // Return empty array if no valid data found if ( empty( $data ) ) { return []; } $all_data = array_merge( ...$data ); $except_data = [ 'color_picker', ]; // Create a regex pattern to match any key that starts with the except_data keys $pattern = '/^(' . implode('|', array_map('preg_quote', $except_data)) . ')/'; // Filter the all_data array $filteredArray = array_filter($all_data, function($item) use ($pattern) { return preg_match($pattern, $item); }); // $filteredArray = array_intersect( $all_data, $except_data ); $final_data = []; if ( ! empty( $contents['fields'] ) && is_array( $contents['fields'] ) ) { foreach ( $filteredArray as $data ) { if ( isset( $contents['fields'][$data]['label'] ) ) { $final_data[] = [$data => $contents['fields'][$data]['label']]; } } } if ( ! empty( $final_data ) ) { $final_data = array_merge( ...$final_data ); } return $final_data; } public static function get_group_fields() { $fieldGroups = []; if ( directorist_is_multi_directory_enabled() ) { $directoryTypes = directory_types(); foreach ( $directoryTypes as $directoryType ) { $id = $directoryType->term_id; $name = $directoryType->name; $fieldGroups[] = [ 'label' => $name, 'options' => self::get_preset_fields( $id ), ]; } } else { $fieldGroups = self::get_preset_fields( default_directory_type() ); } return $fieldGroups; } public static function get_custom_group_fields() { $fieldGroups = []; if ( directorist_is_multi_directory_enabled() ) { $directoryTypes = directory_types(); foreach ( $directoryTypes as $directoryType ) { $id = $directoryType->term_id; $name = $directoryType->name; $fieldGroups[] = [ 'label' => $name, 'options' => self::get_custom_fields( $id ), ]; } } else { $fieldGroups = self::get_custom_fields( default_directory_type() ); } return $fieldGroups; } public static function get_custom_color_group_fields() { $fieldGroups = []; if ( directorist_is_multi_directory_enabled() ) { $directoryTypes = directory_types(); foreach ( $directoryTypes as $directoryType ) { $id = $directoryType->term_id; $name = $directoryType->name; $fieldGroups[] = [ 'label' => $name, 'options' => self::get_custom_color_field( $id ), ]; } } else { $fieldGroups = self::get_custom_color_field( default_directory_type() ); } return $fieldGroups; } public static function get_builder_data() { $builder = new Builder_Data; return $builder->get_fields(); } public static function get_single_listing_fields( $widget_name = '' ) { if ( empty( $widget_name ) ) { return; } $contents = get_term_meta( default_directory_type(), 'submission_form_fields', true ); // Validate and unserialize if needed if ( is_string( $contents ) ) { $contents = maybe_unserialize( $contents ); } if ( empty( $contents ) || ! is_array( $contents ) || ! isset( $contents['fields'][$widget_name] ) ) { return; } $single = Directorist_Single_Listing::instance( get_the_ID() ); $data = $contents['fields'][$widget_name]; switch ( $data['widget_key'] ) { case 'map': $single->field_template( $data ); break; case 'social_info': $data['label'] = ''; $single->field_template( $data ); break; case 'pricing': CoreHelper::listing_price( $single->id ); break; case 'checkbox': self::get_listing_checked_items( $data ); break; default: echo wp_kses_post($single->get_field_value( $data )); break; } } public static function get_single_listing_other_fields( $args = '' ) { if ( empty( $args ) ) { return; } echo wp_kses_post('