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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
<?php
/** * Functionality related to the admin TinyMCE editor. * * @since 1.0.0 */ class WPForms_Admin_Editor {
/** * Primary class constructor. * * @since 1.0.0 */ public function __construct() { add_action( 'media_buttons', array( $this, 'media_button' ), 15 ); }
/** * Allow easy shortcode insertion via a custom media button. * * @since 1.0.0 * * @param string $editor_id */ public function media_button( $editor_id ) {
if ( ! \wpforms_current_user_can( 'view_forms' ) ) { return; }
// Provide the ability to conditionally disable the button, so it can be // disabled for custom fields or front-end use such as bbPress. We default // to only showing within the post editor page. if ( ! apply_filters( 'wpforms_display_media_button', $this->is_post_editor_page(), $editor_id ) ) { return; }
// Setup the icon - currently using a dashicon. $icon = '<span class="wp-media-buttons-icon wpforms-menu-icon" style="font-size:16px;margin-top:-2px;"><svg width="18" height="18" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M643 911v128h-252v-128h252zm0-255v127h-252v-127h252zm758 511v128h-341v-128h341zm0-256v128h-672v-128h672zm0-255v127h-672v-127h672zm135 860v-1240q0-8-6-14t-14-6h-32l-378 256-210-171-210 171-378-256h-32q-8 0-14 6t-6 14v1240q0 8 6 14t14 6h1240q8 0 14-6t6-14zm-855-1110l185-150h-406zm430 0l221-150h-406zm553-130v1240q0 62-43 105t-105 43h-1240q-62 0-105-43t-43-105v-1240q0-62 43-105t105-43h1240q62 0 105 43t43 105z" fill="#82878c"/></svg></span>';
printf( '<a href="#" class="button wpforms-insert-form-button" data-editor="%s" title="%s">%s %s</a>', esc_attr( $editor_id ), esc_attr__( 'Add Form', 'wpforms-lite' ), $icon, esc_html__( 'Add Form', 'wpforms-lite' ) );
// If we have made it this far then load the JS. wp_enqueue_script( 'wpforms-editor', WPFORMS_PLUGIN_URL . 'assets/js/admin-editor.js', array( 'jquery' ), WPFORMS_VERSION, true );
add_action( 'admin_footer', array( $this, 'shortcode_modal' ) ); }
/** * Check if we are on the post editor admin page. * * @since 1.6.2 * * @returns boolean True if it is post editor admin page. */ public function is_post_editor_page() {
if ( ! is_admin() ) { return false; }
// get_current_screen() is loaded after 'admin_init' hook and may not exist yet. if ( ! function_exists( 'get_current_screen' ) ) { return false; }
$screen = get_current_screen();
return $screen !== null && $screen->parent_base === 'edit'; }
/** * Modal window for inserting the form shortcode into TinyMCE. * * Thickbox is old and busted so we don't use that. Creating a custom view in * Backbone would make me pull my hair out. So instead we offer a small clean * modal that is based off of the WordPress insert link modal. * * @since 1.0.0 */ public function shortcode_modal() { ?> <div id="wpforms-modal-backdrop" style="display: none"></div> <div id="wpforms-modal-wrap" style="display: none"> <form id="wpforms-modal" tabindex="-1"> <div id="wpforms-modal-title"> <?php esc_html_e( 'Insert Form', 'wpforms-lite' ); ?> <button type="button" id="wpforms-modal-close"><span class="screen-reader-text"><?php esc_html_e( 'Close', 'wpforms-lite' ); ?></span></button> </div> <div id="wpforms-modal-inner">
<div id="wpforms-modal-options"> <?php echo '<p id="wpforms-modal-notice">'; printf( wp_kses( /* translators: %s - WPForms documentation URL. */ __( 'Heads up! Don\'t forget to test your form. <a href="%s" target="_blank" rel="noopener noreferrer">Check out our complete guide</a>!', 'wpforms-lite' ), array( 'a' => array( 'href' => array(), 'rel' => array(), 'target' => array(), ), ) ), 'https://wpforms.com/docs/how-to-properly-test-your-wordpress-forms-before-launching-checklist/' ); echo '</p>'; $args = apply_filters( 'wpforms_modal_select', array() ); $forms = wpforms()->form->get( '', $args ); if ( ! empty( $forms ) ) { printf( '<p><label for="wpforms-modal-select-form">%s</label></p>', esc_html__( 'Select a form below to insert', 'wpforms-lite' ) ); echo '<select id="wpforms-modal-select-form">'; foreach ( $forms as $form ) { printf( '<option value="%d">%s</option>', $form->ID, esc_html( $form->post_title ) ); } echo '</select><br>'; printf( '<p class="wpforms-modal-inline"><input type="checkbox" id="wpforms-modal-checkbox-title"><label for="wpforms-modal-checkbox-title">%s</label></p>', esc_html__( 'Show form name', 'wpforms-lite' ) ); printf( '<p class="wpforms-modal-inline"><input type="checkbox" id="wpforms-modal-checkbox-description"><label for="wpforms-modal-checkbox-description">%s</label></p>', esc_html__( 'Show form description', 'wpforms-lite' ) ); } else { echo '<p>'; printf( wp_kses( /* translators: %s - WPForms Builder page. */ __( 'Whoops, you haven\'t created a form yet. Want to <a href="%s">give it a go</a>?', 'wpforms-lite' ), array( 'a' => array( 'href' => array(), ), ) ), admin_url( 'admin.php?page=wpforms-builder' ) ); echo '</p>'; } ?> </div> </div> <div class="submitbox"> <div id="wpforms-modal-cancel"> <a class="submitdelete deletion" href="#"><?php esc_html_e( 'Cancel', 'wpforms-lite' ); ?></a> </div> <?php if ( ! empty( $forms ) ) : ?> <div id="wpforms-modal-update"> <button class="button button-primary" id="wpforms-modal-submit"><?php esc_html_e( 'Add Form', 'wpforms-lite' ); ?></button> </div> <?php endif; ?> </div> </form> </div> <style type="text/css"> .wpforms-insert-form-button svg path { fill: #0071a1; }
.wpforms-insert-form-button:hover svg path { fill: #016087; }
#wpforms-modal-wrap { display: none; background-color: #fff; -webkit-box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3); box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3); width: 500px; height: 285px; overflow: hidden; margin-left: -250px; margin-top: -125px; position: fixed; top: 50%; left: 50%; z-index: 100205; -webkit-transition: height 0.2s, margin-top 0.2s; transition: height 0.2s, margin-top 0.2s; }
#wpforms-modal-backdrop { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; min-height: 360px; background: #000; opacity: 0.7; filter: alpha(opacity=70); z-index: 100200; }
#wpforms-modal { position: relative; height: 100%; }
#wpforms-modal-title { background: #fcfcfc; border-bottom: 1px solid #dfdfdf; height: 36px; font-size: 18px; font-weight: 600; line-height: 36px; padding: 0 36px 0 16px; top: 0; right: 0; left: 0; }
#wpforms-modal-close { color: #666; padding: 0; position: absolute; top: 0; right: 0; width: 36px; height: 36px; text-align: center; background: none; border: none; cursor: pointer; }
#wpforms-modal-close:before { font: normal 20px/36px 'dashicons'; vertical-align: top; speak: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; width: 36px; height: 36px; content: '\f158'; }
#wpforms-modal-close:hover, #wpforms-modal-close:focus { color: #2ea2cc; }
#wpforms-modal-close:focus { outline: none; -webkit-box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8); box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8); }
#wpforms-modal-inner { padding: 0 16px 50px; }
#wpforms-modal-search-toggle:after { display: inline-block; font: normal 20px/1 'dashicons'; vertical-align: top; speak: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; content: '\f140'; }
#wpforms-modal-notice { background-color: #d9edf7; border: 1px solid #bce8f1; color: #31708f; padding: 10px; }
#wpforms-modal #wpforms-modal-options { padding: 8px 0 12px; }
#wpforms-modal #wpforms-modal-options .wpforms-modal-inline { display: inline-block; margin: 0; padding: 0 20px 0 0; }
#wpforms-modal-select-form { margin-bottom: 1em; max-width: 100%; }
#wpforms-modal .submitbox { padding: 8px 16px; background: #fcfcfc; border-top: 1px solid #dfdfdf; position: absolute; bottom: 0; left: 0; right: 0; }
#wpforms-modal-cancel { line-height: 25px; float: left; }
#wpforms-modal-update { line-height: 23px; float: right; }
#wpforms-modal-submit { float: right; margin-bottom: 0; }
@media screen and ( max-width: 782px ) { #wpforms-modal-wrap { height: 280px; margin-top: -140px; }
#wpforms-modal-inner { padding: 0 16px 60px; }
#wpforms-modal-cancel { line-height: 32px; } }
@media screen and ( max-width: 520px ) { #wpforms-modal-wrap { width: auto; margin-left: 0; left: 10px; right: 10px; max-width: 500px; } }
@media screen and ( max-height: 520px ) { #wpforms-modal-wrap { -webkit-transition: none; transition: none; } }
@media screen and ( max-height: 290px ) { #wpforms-modal-wrap { height: auto; margin-top: 0; top: 10px; bottom: 10px; }
#wpforms-modal-inner { overflow: auto; height: -webkit-calc(100% - 92px); height: calc(100% - 92px); padding-bottom: 2px; } } </style> <?php }
}
new WPForms_Admin_Editor();
|