-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgutenberg-gravityforms.php
More file actions
132 lines (96 loc) · 2.76 KB
/
Copy pathgutenberg-gravityforms.php
File metadata and controls
132 lines (96 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Plugin Name: Gutenberg Gravity Form Selector
* Plugin URI: https://github.com/lucasstark/gutenberg-gravityforms
* Description: Shows how to build a Editor Block which represents a shortcode, specific example shown here is to render a Gravity Form
* Author: lucasstark
* Author URI: https://elementstark.com/
* Version: 1.0.0
* License: GPL2+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* @package GB
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class GB_Gravity_Forms {
/**
* @var GB_Gravity_Forms
*/
private static $instance;
/**
* Registers the plugin.
*/
public static function register() {
if ( self::$instance == null ) {
self::$instance = new GB_Gravity_Forms();
}
}
/**
* @var string The plugin base directory path ( without trailing slash )
*/
private $_dir;
/**
* @var string The plugin base URL path ( without trailing slash )
*/
private $_url;
/**
* @var string Asset version string
*/
private $_assets_version;
/**
* @var GB_Gravity_Forms_Form_Block
*/
private $_form_block_output;
private function __construct() {
$this->_dir = untrailingslashit( plugin_dir_path( __FILE__ ) );
$this->_url = untrailingslashit( plugins_url( '/', __FILE__ ) );
$this->assets_version = '1.0.0';
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) );
}
public function on_plugins_loaded() {
if ( class_exists( 'GFAPI' ) ) {
add_action( 'enqueue_block_editor_assets', array( $this, 'on_enqueue_block_editor_assets' ) );
require $this->_dir . '/inc/blocks/class-gb-gravityforms-form-block.php';
$this->_form_block_output = new GB_Gravity_Forms_Form_Block();
}
}
public function on_enqueue_block_editor_assets() {
// Scripts.
wp_enqueue_script(
'gb-gravityforms-block', // Handle.
$this->_url . '/assets/js/block.js',
array( 'wp-blocks', 'wp-i18n', 'wp-element' ), // Dependencies, defined above.
$this->assets_version
);
// Styles.
wp_enqueue_style(
'gb-gravityforms-block', // Handle.
$this->_url . '/assets/css/editor.css',
array( 'wp-blocks', 'wp-i18n', 'wp-element' ), // Dependencies, defined above.
$this->assets_version );
$forms = array(
0 => array(
'value' => 0,
'label' => __( 'Choose Your Form', 'gutenberg-gravityforms' )
)
);
$formmeta = array(
0 => __( 'Choose Your Form', 'gutenberg-gravityforms' )
);
foreach ( GFAPI::get_forms() as $form ) {
$forms[] = array(
'value' => $form['id'],
'label' => $form['title']
);
$formmeta[ $form['id'] ] = array( 'title' => $form['title'] );
}
wp_localize_script( 'gb-gravityforms-block', 'gb_gravityforms_block_params', array(
'forms' => $forms,
'formMeta' => $formmeta
) );
}
}
GB_Gravity_Forms::register();