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