multilanguage
1 year ago
recommendations
11 months ago
colibri.php
1 year ago
contact-form.php
1 year ago
entity.php
4 years ago
get-body-class.php
1 year ago
get-classic-page-template.php
1 year ago
get-page-query.php
1 year ago
get-page-title.php
1 year ago
get-post-content.php
1 year ago
get-post-styles.php
1 year ago
index.php
11 months ago
kubio-cloud.php
1 year ago
page-templates.php
4 years ago
save-template-parts-filter.php
1 year ago
subscribe-form.php
4 years ago
typekit.php
4 years ago
update-settings-flags.php
1 year ago
contact-form.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | function kubio_wpform_get_forms() { |
| 5 | $wp_forms = wpforms()->form->get( '', array( 'order' => 'DESC' ) ); |
| 6 | $wp_forms = ! empty( $wp_forms ) ? $wp_forms : array(); |
| 7 | $wp_forms = array_map( |
| 8 | function ( $form ) { |
| 9 | return array( |
| 10 | 'label' => htmlspecialchars_decode( $form->post_title, ENT_QUOTES ), |
| 11 | 'value' => $form->ID, |
| 12 | ); |
| 13 | }, |
| 14 | $wp_forms |
| 15 | ); |
| 16 | return $wp_forms; |
| 17 | } |
| 18 | function kubio_contact_forms_by_type( WP_REST_Request $data ) { |
| 19 | |
| 20 | $forms = array(); |
| 21 | if ( class_exists( '\Forminator_GFBlock_Forms' ) ) { |
| 22 | $forminator_forms = Forminator_GFBlock_Forms::get_instance()->get_forms(); |
| 23 | |
| 24 | // remove the empty form |
| 25 | array_shift( $forminator_forms ); |
| 26 | if ( count( $forminator_forms ) === 0 ) { |
| 27 | kubio_forminator_create_sample_form(); |
| 28 | $forminator_forms = Forminator_GFBlock_Forms::get_instance()->get_forms(); |
| 29 | array_shift( $forminator_forms ); |
| 30 | } |
| 31 | if ( count( $forminator_forms ) > 0 ) { |
| 32 | $forms['forminator'] = $forminator_forms; |
| 33 | } |
| 34 | } |
| 35 | if ( class_exists( '\WPCF7' ) ) { |
| 36 | $contact_form7_items = array(); |
| 37 | $args = array( |
| 38 | 'post_type' => 'wpcf7_contact_form', |
| 39 | 'posts_per_page' => - 1, |
| 40 | ); |
| 41 | if ( $data = get_posts( $args ) ) { |
| 42 | foreach ( $data as $key ) { |
| 43 | $contact_form7_items[] = array( |
| 44 | 'label' => $key->post_title, |
| 45 | 'value' => $key->ID, |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | if ( count( $contact_form7_items ) > 0 ) { |
| 50 | $forms['contactForm7'] = $contact_form7_items; |
| 51 | } |
| 52 | } |
| 53 | if ( class_exists( 'WPForms' ) ) { |
| 54 | $wp_forms = kubio_wpform_get_forms(); |
| 55 | if ( count( $wp_forms ) > 0 ) { |
| 56 | |
| 57 | $forms['wpForms'] = $wp_forms; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return $forms; |
| 62 | } |
| 63 | |
| 64 | add_action( |
| 65 | 'rest_api_init', |
| 66 | function () { |
| 67 | $namespace = 'kubio/v1'; |
| 68 | register_rest_route( |
| 69 | $namespace, |
| 70 | '/contact-form/forms_by_type', |
| 71 | array( |
| 72 | 'methods' => 'GET', |
| 73 | 'callback' => 'kubio_contact_forms_by_type', |
| 74 | 'permission_callback' => function () { |
| 75 | return current_user_can( 'edit_posts' ); |
| 76 | }, |
| 77 | |
| 78 | ) |
| 79 | ); |
| 80 | } |
| 81 | ); |
| 82 |