admin
6 days ago
emails
4 months ago
fields
6 days ago
functions
6 days ago
providers
10 months ago
templates
4 months ago
class-db.php
1 year ago
class-fields.php
1 year ago
class-form.php
6 days ago
class-install.php
1 year ago
class-process.php
4 months ago
class-providers.php
1 year ago
class-templates.php
2 years ago
class-widget.php
1 year ago
deprecated.php
8 months ago
functions-list.php
3 years ago
functions.php
11 months ago
integrations.php
4 months ago
integrations.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Register and setup WPForms as a Visual Composer element. |
| 9 | * |
| 10 | * @since 1.3.0 |
| 11 | * |
| 12 | * @noinspection PhpUndefinedFunctionInspection |
| 13 | */ |
| 14 | function wpforms_visual_composer_shortcode() { |
| 15 | |
| 16 | if ( ! is_user_logged_in() ) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | $form_obj = wpforms()->obj( 'form' ); |
| 21 | |
| 22 | if ( ! $form_obj ) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | $wpf = $form_obj->get( |
| 27 | '', |
| 28 | [ |
| 29 | 'orderby' => 'title', |
| 30 | ] |
| 31 | ); |
| 32 | |
| 33 | if ( ! empty( $wpf ) ) { |
| 34 | $forms = [ |
| 35 | esc_html__( 'Select a form to display', 'wpforms-lite' ) => '', |
| 36 | ]; |
| 37 | |
| 38 | foreach ( $wpf as $form ) { |
| 39 | $forms[ $form->post_title ] = $form->ID; |
| 40 | } |
| 41 | } else { |
| 42 | $forms = [ |
| 43 | esc_html__( 'No forms found', 'wpforms-lite' ) => '', |
| 44 | ]; |
| 45 | } |
| 46 | |
| 47 | vc_map( |
| 48 | [ |
| 49 | 'name' => esc_html__( 'WPForms', 'wpforms-lite' ), |
| 50 | 'base' => 'wpforms', |
| 51 | 'icon' => WPFORMS_PLUGIN_URL . 'assets/images/sullie-vc.png', |
| 52 | 'category' => esc_html__( 'Content', 'wpforms-lite' ), |
| 53 | 'description' => esc_html__( 'Add your form', 'wpforms-lite' ), |
| 54 | 'params' => [ |
| 55 | [ |
| 56 | 'type' => 'dropdown', |
| 57 | 'heading' => esc_html__( 'Form', 'wpforms-lite' ), |
| 58 | 'param_name' => 'id', |
| 59 | 'value' => $forms, |
| 60 | 'save_always' => true, |
| 61 | 'description' => esc_html__( 'Select a form to add it to your post or page.', 'wpforms-lite' ), |
| 62 | 'admin_label' => true, |
| 63 | ], |
| 64 | [ |
| 65 | 'type' => 'dropdown', |
| 66 | 'heading' => esc_html__( 'Display Form Name', 'wpforms-lite' ), |
| 67 | 'param_name' => 'title', |
| 68 | 'value' => [ |
| 69 | // phpcs:ignore WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned |
| 70 | esc_html__( 'No', 'wpforms-lite' ) => 'false', |
| 71 | esc_html__( 'Yes', 'wpforms-lite' ) => 'true', |
| 72 | ], |
| 73 | 'save_always' => true, |
| 74 | 'description' => esc_html__( 'Would you like to display the forms name?', 'wpforms-lite' ), |
| 75 | 'dependency' => [ |
| 76 | 'element' => 'id', |
| 77 | 'not_empty' => true, |
| 78 | ], |
| 79 | ], |
| 80 | [ |
| 81 | 'type' => 'dropdown', |
| 82 | 'heading' => esc_html__( 'Display Form Description', 'wpforms-lite' ), |
| 83 | 'param_name' => 'description', |
| 84 | 'value' => [ |
| 85 | // phpcs:ignore WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned |
| 86 | esc_html__( 'No', 'wpforms-lite' ) => 'false', |
| 87 | esc_html__( 'Yes', 'wpforms-lite' ) => 'true', |
| 88 | ], |
| 89 | 'save_always' => true, |
| 90 | 'description' => esc_html__( 'Would you like to display the form description?', 'wpforms-lite' ), |
| 91 | 'dependency' => [ |
| 92 | 'element' => 'id', |
| 93 | 'not_empty' => true, |
| 94 | ], |
| 95 | ], |
| 96 | ], |
| 97 | ] |
| 98 | ); |
| 99 | } |
| 100 | add_action( 'vc_before_init', 'wpforms_visual_composer_shortcode' ); |
| 101 | |
| 102 | /** |
| 103 | * Load our basic CSS when in Visual Composer's frontend editor. |
| 104 | * |
| 105 | * @since 1.3.0 |
| 106 | */ |
| 107 | function wpforms_visual_composer_shortcode_css() { |
| 108 | |
| 109 | $min = wpforms_get_min_suffix(); |
| 110 | |
| 111 | // Load CSS per global setting. |
| 112 | if ( wpforms_setting( 'disable-css', '1' ) === '1' ) { |
| 113 | wp_enqueue_style( |
| 114 | 'wpforms-full', |
| 115 | WPFORMS_PLUGIN_URL . "assets/css/frontend/classic/wpforms-full{$min}.css", |
| 116 | [], |
| 117 | WPFORMS_VERSION |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | if ( wpforms_setting( 'disable-css', '1' ) === '2' ) { |
| 122 | wp_enqueue_style( |
| 123 | 'wpforms-base', |
| 124 | WPFORMS_PLUGIN_URL . "assets/css/frontend/classic/wpforms-base{$min}.css", |
| 125 | [], |
| 126 | WPFORMS_VERSION |
| 127 | ); |
| 128 | } |
| 129 | } |
| 130 | add_action( 'vc_load_iframe_jscss', 'wpforms_visual_composer_shortcode_css' ); |
| 131 |