get_posted_data(); if ( ! is_array( $posted ) ) { return; } $values = array(); foreach ( $posted as $key => $value ) { if ( 0 === strpos( $key, '_' ) ) { continue; } $values[ $key ] = $value; } AOLI_Form_Processor::process( 'cf7', (string) $contact_form->id(), $values ); } /** * Get available CF7 forms. * * @return array */ public static function get_forms() { if ( ! post_type_exists( 'wpcf7_contact_form' ) ) { return array(); } $posts = get_posts( array( 'post_type' => 'wpcf7_contact_form', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); $forms = array(); foreach ( $posts as $post ) { $forms[ $post->ID ] = $post->post_title; } return $forms; } /** * Field types to exclude from mapping. * * @return array */ private static function excluded_field_types() { return array( 'submit', 'reset', 'button', 'acceptance', 'quiz', 'captcha', 'recaptcha', 'turnstile', 'response', 'count', ); } /** * Get form field names. * * @param int $form_id Form ID. * @return array */ public static function get_form_fields( $form_id ) { $form_id = absint( $form_id ); if ( ! $form_id ) { return array(); } $fields = array(); $contact_form = null; if ( function_exists( 'wpcf7_contact_form' ) ) { $contact_form = wpcf7_contact_form( $form_id ); } elseif ( class_exists( 'WPCF7_ContactForm' ) ) { $contact_form = WPCF7_ContactForm::get_instance( $form_id ); } if ( $contact_form && method_exists( $contact_form, 'scan_form_tags' ) ) { $tags = $contact_form->scan_form_tags(); foreach ( (array) $tags as $tag ) { if ( empty( $tag->name ) ) { continue; } $type = isset( $tag->basetype ) ? $tag->basetype : $tag->type; $type = preg_replace( '/\*+$/', '', (string) $type ); if ( in_array( $type, self::excluded_field_types(), true ) ) { continue; } $fields[ $tag->name ] = sprintf( '%s (%s)', $tag->name, $type ); } } if ( empty( $fields ) && $contact_form && method_exists( $contact_form, 'prop' ) ) { $fields = self::parse_form_template_string( (string) $contact_form->prop( 'form' ) ); } if ( empty( $fields ) ) { $fields = self::parse_form_template( $form_id ); } return $fields; } /** * Parse CF7 form template when scan_form_tags is unavailable. * * @param int $form_id Form ID. * @return array */ private static function parse_form_template( $form_id ) { $post = get_post( $form_id ); if ( ! $post || 'wpcf7_contact_form' !== $post->post_type ) { return array(); } $template = (string) get_post_meta( $form_id, '_form', true ); if ( '' === $template ) { $template = (string) $post->post_content; } return self::parse_form_template_string( $template ); } /** * Extract named fields from a CF7 form template string. * * @param string $template Form template. * @return array */ private static function parse_form_template_string( $template ) { $fields = array(); $pattern = '/\[(?!\/)(?:text|email|url|tel|number|textarea|select|checkbox|radio|date|file|hidden)(?:\*+)?\s+([a-zA-Z0-9_:-]+)/'; if ( preg_match_all( $pattern, $template, $matches ) ) { foreach ( array_unique( $matches[1] ) as $name ) { $fields[ $name ] = $name; } } return $fields; } }