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