PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.0
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / admin / class-gutenblock.php

class-gutenblock.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.4.0, at includes/admin/class-gutenblock.php

113 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
2 /**
3 * Adds weForms block
4 */
5 class weForms_FormBlock {
6 /**
7 * Register widget with WordPress.
8 */
9 public function __construct() {
10 //add_action( 'weforms_loaded', array($this, 'weforms_block_load' ) );
11 // wait for Gutenberg to enqueue it's block assets
12 add_action( 'enqueue_block_editor_assets', array ( $this, 'weforms_form_block' ) );
13 // load the preview information and form
14 add_action( 'wp_head', array( $this, 'load_preview_data' ) );
15 }
16
17 function weforms_form_block() {
18 $js_dir = WEFORMS_ASSET_URI . '/js/';
19 $css_dir = WEFORMS_ASSET_URI . '/css/';
20
21 // Once we have Gutenberg block javascript, we can enqueue our assets
22 wp_register_script(
23 'weforms-forms-block',
24 $js_dir . 'gutenblock.js',
25 array( 'wp-blocks', 'wp-editor', 'wp-components', 'wp-i18n', 'wp-element', 'underscore' )
26 );
27
28 wp_register_style(
29 'weforms-forms-block-style',
30 $css_dir . 'gutenblock.css',
31 array( 'wp-edit-blocks' )
32 );
33 wp_register_style(
34 'weforms-forms-block-editor',
35 $css_dir . 'gutenblock-editor.css',
36 array( 'wp-edit-blocks', 'form-blocks-style' )
37 );
38
39 /**
40 * we need to get our forms so that the block can build a dropdown
41 * with the forms
42 * */
43 wp_enqueue_script( 'weforms-forms-block' );
44
45 $forms = array();
46 $all_forms = weforms()->form->all();
47
48 foreach( $all_forms['forms'] as $form ){
49 $forms[] = array (
50 'value' => $form->id,
51 'label' => $form->name,
52 );
53 }
54
55 $block_logo = WEFORMS_ASSET_URI . '/images/icon-weforms.png';
56 $thumbnail_logo = WEFORMS_ASSET_URI . '/images/icon-weforms.png';
57
58 wp_localize_script( 'weforms-forms-block', 'weFormsBlock', array(
59 'forms' => $forms,
60 'siteUrl' => get_site_url(),
61 'block_logo' => $block_logo,
62 'thumbnail_logo' => $thumbnail_logo
63 ) );
64 wp_enqueue_style( 'weforms-forms-block-style' );
65 wp_enqueue_style( 'weforms-forms-block-editor' );
66 }
67
68 public function load_preview_data() {
69 $js_dir = WEFORMS_ASSET_URI . '/js/';
70
71 // check for preview and iframe get parameters
72 if( isset( $_GET[ 'weforms_preview' ] ) && isset( $_GET[ 'weforms_iframe' ] ) ){
73 $form_id = intval( $_GET[ 'weforms_preview' ] );
74 // Style below: update width and height for particular form
75 ?>
76 <style media="screen">
77 #wpadminbar {
78 display: none;
79 }
80 header,
81 footer{
82 display: none;
83 }
84
85 .wpuf-form-add {
86 z-index: 9001;
87 position: fixed;
88 top: 0;
89 left: 0;
90 width: 100vw;
91 height: 100vh;
92 background-color: white;
93 display: block !important;
94 }
95
96 </style>
97 <?php
98
99 // register our script to target the form iFrame in page builder
100 wp_register_script(
101 'weforms-block-setup',
102 $js_dir . 'blockFrameSetup.js',
103 array( 'underscore', 'jquery' )
104 );
105
106 wp_localize_script( 'weforms-block-setup', 'weFormsBlockSetup', array(
107 'form_id' => $form_id
108 ) );
109
110 wp_enqueue_script( 'weforms-block-setup' );
111 }
112 }
113 }