Divi_Helpers::extract_forms()
Extract form info from the Divi shortcode
Return Return
(array)
Source Source
File: src/integrations/divi/helpers/divi-helpers.php
public static function extract_forms() { global $wpdb; $form_posts = $wpdb->get_results( $wpdb->prepare( "SELECT `ID`, `post_content`, `post_title` FROM $wpdb->posts WHERE post_status NOT IN('trash', 'inherit', 'auto-draft') AND post_type IS NOT NULL AND post_type NOT LIKE %s AND post_content LIKE %s", 'revision', '%%et_pb_contact_form%%' ) ); $data = array(); if ( empty( $form_posts ) ) { return $data; } foreach ( $form_posts as $form_post ) { // Get forms $pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/'; preg_match_all( $pattern_regex, $form_post->post_content, $forms, PREG_SET_ORDER ); if ( empty( $forms ) ) { continue; } $jjj = 0; foreach ( $forms as $form ) { $pattern_form = get_shortcode_regex( array( 'et_pb_contact_form' ) ); preg_match_all( "/$pattern_form/", $form[0], $forms_extracted, PREG_SET_ORDER ); if ( empty( $forms_extracted ) ) { continue; } foreach ( $forms_extracted as $form_extracted ) { $form_attrs = shortcode_parse_atts( $form_extracted[3] ); $form_id = isset( $form_attrs['_unique_id'] ) ? $form_attrs['_unique_id'] : ''; if ( empty( $form_id ) ) { continue; } $form_id = sprintf( '%d-%s', $form_post->ID, $form_id ); $form_title = isset( $form_attrs['title'] ) ? $form_attrs['title'] : __( 'No form title', 'uncanny-automator' ); $form_title = sprintf( '%s - %s', $form_post->post_title, $form_title ); $fields = self::extract_fields( $form[0] ); $data[ $form_id ]['title'] = $form_title; $data[ $form_id ]['fields'] = $fields; } $jjj ++; } } return $data; }
Expand full source code Collapse full source code View on Github