PluginProbe
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes / trunk
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes vtrunk
5.7.3 5.7.2 5.7.1 1.8.1 1.8.10 1.8.11 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 All 146 releases
quillforms / includes / admin / class-admin-loader.php

class-admin-loader.php in Quill Forms | Conversational Multi Step Forms, Surveys & quizzes trunk, at includes/admin/class-admin-loader.php

549 lines 18.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin: class Admin_Loader
4 *
5 * @since 1.0.0
6 * @package Admin
7 * @subpackage Loader
8 */
9
10 namespace QuillForms\Admin;
11
12 use QuillForms\Core;
13 use QuillForms\Managers\Blocks_Manager;
14 use QuillForms\Settings;
15
16 /**
17 * Register the scripts, styles, and includes needed for pieces of the QuillForms Admin experience.
18 */
19 class Admin_Loader {
20
21 /**
22 * Class instance.
23 *
24 * @var Admin_Loader instance
25 */
26 private static $instance = null;
27
28 /**
29 * Get class instance.
30 */
31 public static function instance() {
32 if ( ! self::$instance ) {
33 self::$instance = new self();
34 }
35 return self::$instance;
36 }
37
38 /**
39 * Returns true if we are on a JS powered admin page.
40 */
41 public static function is_admin_page() : bool {
42 $current_screen = get_current_screen();
43 if ( 'toplevel_page_quillforms' === $current_screen->id ) {
44 return true;
45 }
46 return false;
47 }
48
49 /**
50 * Constructor.
51 */
52 private function __construct() {
53 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_inline_scripts' ), 14 );
54 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'localize_scripts' ) );
55 add_action( 'admin_enqueue_scripts', array( __CLASS__, 'remove_all_scripts' ), 999 );
56
57 /*
58 * Remove the emoji script.
59 * We have faced an issue when using emojis with Slate React rich text editor; they were converted to images.
60 * Now after removing this action, they are working correctly.
61 */
62 // remove_action( 'wp_head', 'print_emoji_detection_script', 20 );
63 // add_action( 'admin_init', [ $this, 'disable_admin_emojis' ] );
64 // Remove DNS prefetch s.w.org (used for emojis, since WP 4.7)
65
66 add_action( 'admin_head', array( __CLASS__, 'remove_notices' ) );
67 add_action( 'admin_notices', array( __CLASS__, 'inject_before_notices' ), -9999 );
68 add_action( 'admin_notices', array( __CLASS__, 'inject_after_notices' ), PHP_INT_MAX );
69 add_filter( 'admin_body_class', array( __CLASS__, 'add_admin_body_class' ), PHP_INT_MAX );
70 }
71
72
73
74 /**
75 * Add admin body class.
76 *
77 * @since 1.0.0
78 *
79 * @param string $classes Body classes.
80 */
81 public static function add_admin_body_class( $classes ) {
82 if ( self::is_admin_page() ) {
83 $classes .= ' js is-fullscreen-mode';
84 }
85
86 return $classes;
87 }
88
89 /**
90 * Localize scripts
91 *
92 * @since 1.0.0
93 */
94 public static function localize_scripts() {
95 global $submenu;
96 $user = wp_get_current_user();
97
98 $plugins_dir = trailingslashit( dirname( dirname( QUILLFORMS_PLUGIN_FILE ) ) );
99
100 // DoubleScale is our partner CRM/mailer. Its free version ships an SMTP
101 // module that Quill Forms relies on to deliver email notifications.
102 // Free version: https://wordpress.org/plugins/doublescale/
103 $doublescale_plugin_file = $plugins_dir . 'doublescale/doublescale.php';
104 $doublescale_installed = file_exists( $doublescale_plugin_file );
105 $doublescale_active = defined( 'DOUBLESCALE_VERSION' ) || is_plugin_active( 'doublescale/doublescale.php' );
106
107 $doublescale_smtp = self::get_doublescale_smtp_status( $doublescale_active );
108
109 wp_localize_script(
110 'quillforms-client',
111 'qfAdmin',
112 array(
113 'adminUrl' => admin_url(),
114 'assetsBuildUrl' => QUILLFORMS_PLUGIN_URL,
115 'submenuPages' => $submenu['quillforms'] ?? array(),
116 // Drives the "New" badge on the MCP Server menu item. Cleared
117 // once the page has been opened, so it stops nagging.
118 'mcpIsNew' => ! get_option( 'quillforms_mcp_page_seen' ),
119 'site_store_nonce' => wp_create_nonce( 'quillforms_site_store' ),
120 'license_nonce' => wp_create_nonce( 'quillforms_license' ),
121 'duplicate_nonce' => wp_create_nonce( 'quillforms_duplicate' ),
122 'current_user_name' => $user->display_name,
123 'current_user_avatar_url' => esc_url(
124 get_avatar_url( $user->ID )
125 ),
126 // DoubleScale (our partner) provides email delivery via its SMTP module.
127 'is_doublescale_installed' => $doublescale_installed,
128 'is_doublescale_active' => $doublescale_active,
129 'is_doublescale_smtp_module_active' => $doublescale_smtp['module_active'],
130 'doublescale_smtp_has_connections' => $doublescale_smtp['has_connections'],
131 'doublescale_smtp_settings_url' => $doublescale_smtp['settings_url'],
132 'doublescale_wporg_url' => 'https://wordpress.org/plugins/doublescale/',
133 'settings' => Settings::get_all(),
134 )
135 );
136
137 // DoubleScale integration - check installation and activation status.
138 wp_localize_script(
139 'quillforms-client',
140 'quillformsDoubleScaleIntegration',
141 array(
142 'isInstalled' => $doublescale_installed,
143 'isActive' => $doublescale_active,
144 'installNonce' => wp_create_nonce( 'quillforms_install_doublescale' ),
145 'activateNonce' => wp_create_nonce( 'quillforms_activate_doublescale' ),
146 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
147 )
148 );
149 }
150
151 /**
152 * Resolve DoubleScale SMTP module status for the admin client.
153 *
154 * Reports whether the bundled SMTP module is active and whether it has at
155 * least one connection configured, so the notifications editor can warn the
156 * user before their email notifications silently fail to deliver.
157 *
158 * @since 3.5.0
159 *
160 * @param bool $doublescale_active Whether the DoubleScale plugin is active.
161 * @return array{module_active:bool,has_connections:bool,settings_url:string}
162 */
163 private static function get_doublescale_smtp_status( $doublescale_active ) {
164 $status = array(
165 'module_active' => false,
166 'has_connections' => false,
167 'settings_url' => '',
168 );
169
170 if ( ! $doublescale_active ) {
171 return $status;
172 }
173
174 // Module toggle state (SMTP module lives in the free DoubleScale plugin).
175 if ( function_exists( 'doublescale_is_module_active' ) ) {
176 $status['module_active'] = (bool) doublescale_is_module_active( 'smtp' );
177 }
178
179 // Connections are stored in the SMTP module settings option.
180 $settings = get_option( 'doublescale_smtp_settings', array() );
181 $connections = ( is_array( $settings ) && ! empty( $settings['connections'] ) && is_array( $settings['connections'] ) )
182 ? $settings['connections']
183 : array();
184 $status['has_connections'] = ! empty( $connections );
185
186 // Deep link to the SMTP settings screen inside DoubleScale.
187 $slug = apply_filters( 'doublescale_admin_menu_slug', 'doublescale' );
188 $status['settings_url'] = admin_url( 'admin.php?page=' . rawurlencode( $slug ) . '&path=smtp%2Fsettings' );
189
190 return $status;
191 }
192
193 /**
194 * Remove all scripts
195 *
196 * @since 1.0.0
197 */
198 public static function remove_all_scripts() {
199 global $wp_scripts;
200 global $wp_styles;
201
202 if ( self::is_admin_page() ) {
203 $wp_scripts->queue = array( 'jquery', 'media-audiovideo' );
204 wp_enqueue_media();
205
206 // filter the scripts so they don't have this script: elementor-ai-media-library
207 $wp_scripts->queue = array_filter(
208 $wp_scripts->queue,
209 function( $script ) {
210 return 'elementor-ai-media-library' !== $script;
211 }
212 );
213 }
214 }
215
216 /**
217 * Add inline scripts.
218 *
219 * @since 1.0.0
220 */
221 public static function add_inline_scripts() {
222 Core::register_block_types_by_js();
223 Core::set_admin_config();
224 Core::add_gallery_themes();
225 // Core::add_tailwind_config();
226 }
227
228 /**
229 * Removes notices that should not be displayed on QF Admin pages.
230 *
231 * @since 1.0.0
232 */
233 public static function remove_notices() {
234 if ( ! self::is_admin_page() ) {
235 return;
236 }
237
238 // Hello Dolly.
239 if ( function_exists( 'hello_dolly' ) ) {
240 remove_action( 'admin_notices', 'hello_dolly' );
241 }
242 }
243
244 /**
245 * Runs before admin notices action and hides them.
246 *
247 * @since 1.0.0
248 */
249 public static function inject_before_notices() {
250 if ( ! self::is_admin_page() ) {
251 return;
252 }
253
254 // Wrap the notices in a hidden div to prevent flickering before
255 // they are moved elsewhere in the page by WordPress Core.
256 echo '<div class="quillforms-layout__notice-list-hide" style="display: none;" id="wp__notice-list">';
257
258 if ( self::is_admin_page() ) {
259 // Capture all notices and hide them. WordPress Core looks for
260 // `.wp-header-end` and appends notices after it if found.
261 // https://github.com/WordPress/WordPress/blob/f6a37e7d39e2534d05b9e542045174498edfe536/wp-admin/js/common.js#L737 .
262 echo '<div class="wp-header-end" id="quillforms-layout__notice-catcher"></div>';
263 }
264 }
265
266 /**
267 * Runs after admin notices and closes div.
268 *
269 * @since 1.0.0
270 */
271 public static function inject_after_notices() {
272 if ( ! self::is_admin_page() ) {
273 return;
274 }
275 // Close the hidden div used to prevent notices from flickering before
276 // they are inserted elsewhere in the page.
277 echo '</div>';
278 }
279
280 /**
281 * Set up a div for the app to render into.
282 */
283 public static function page_wrapper() {
284 ?>
285 <?php
286 // add_filter( 'emoji_svg_url', '__return_false' );
287 // if ( get_site_option( 'initial_db_version' ) >= 32453 )
288 // remove_action( 'init', 'smilies_init', 5 ); // This re
289
290 // Load client script and style. Client is main app entry.
291 wp_enqueue_script( 'quillforms-client' );
292 wp_enqueue_style( 'quillforms-client' );
293 // Load builder core package style.
294 wp_enqueue_style( 'quillforms-builder-core' );
295 // wp_enqueue_script( 'tailwindcss' );
296
297 // Important to check for authentication.
298 wp_auth_check_load();
299
300 // load all block styles and scripts.
301 foreach ( Blocks_Manager::instance()->get_all_registered() as $block ) {
302 if ( ! empty( $block->block_admin_assets ) ) {
303 if ( ! empty( $block->block_admin_assets['style'] ) ) {
304 wp_enqueue_style( $block->block_admin_assets['style'] );
305 }
306 if ( ! empty( $block->block_admin_assets['script'] ) ) {
307 wp_enqueue_script( $block->block_admin_assets['script'] );
308 }
309 }
310
311 if ( ! empty( $block->block_renderer_assets ) ) {
312 if ( ! empty( $block->block_renderer_assets['style'] ) ) {
313 wp_enqueue_style( $block->block_renderer_assets['style'] );
314 }
315 if ( ! empty( $block->block_renderer_assets['script'] ) ) {
316 wp_enqueue_script( $block->block_renderer_assets['script'] );
317 }
318 }
319 }
320 ?>
321 <div class="wrap">
322 <div id="qf-admin-root">
323 <div id="qf-admin-root__loader-container" style="
324 display: flex;
325 align-items: center;
326 justify-content: center;
327 width: 100%;
328 height: 600px;
329 ">
330 <svg viewBox="0 0 95 95" width="80px" height="80px">
331 <defs>
332 <clipPath id="_clipPath_kOTYkDI0w4OkXPM1kIsIznMY6S2kafD3">
333 <rect width="95" height="95" />
334 </clipPath>
335 </defs>
336 <g clipPath="url(#_clipPath_kOTYkDI0w4OkXPM1kIsIznMY6S2kafD3)">
337 <linearGradient
338 id="_lgradient_12"
339 x1="171.18907"
340 y1="90.6548"
341 x2="126.56409"
342 y2="125.34236000000001"
343 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
344 gradientUnits="userSpaceOnUse"
345 >
346 <stop
347 offset="0%"
348 stopOpacity="1"
349 style="stop-color: rgb(42,86,132);"
350 />
351 <stop
352 offset="100%"
353 stopOpacity="1"
354 style="stop-color: rgb(0,175,239);"
355 />
356 </linearGradient>
357 <path
358 d=" M 54.886 61.279 C 35.697 55.97 21.638 41.984 27.946 21.599 C 27.946 21.599 14.842 37.616 30.785 57.595 C 30.785 57.595 23.348 55.303 20.334 47.826 C 20.334 47.826 21.941 68.924 53.066 66.011 C 53.066 66.011 49.347 71.538 35.045 68.195 C 35.045 68.195 44.874 75.657 66.596 75.657 C 75.095 75.657 83.877 84.892 88.686 94 C 85.156 82.209 76.388 67.74 54.886 61.279 Z "
359 fill="url(#_lgradient_12)"
360 />
361 <linearGradient
362 id="_lgradient_13"
363 x1="141.08428"
364 y1="142.3715"
365 x2="167.544"
366 y2="105.50069"
367 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
368 gradientUnits="userSpaceOnUse"
369 >
370 <stop
371 offset="0%"
372 stopOpacity="1"
373 style="stop-color: rgb(140,59,139);"
374 />
375 <stop
376 offset="100%"
377 stopOpacity="1"
378 style="stop-color: rgb(235,40,143);"
379 />
380 </linearGradient>
381 <path
382 d=" M 56.646 41.681 C 56.646 41.681 58.385 48.699 72.663 60.612 C 82.189 68.56 86.774 84.839 86.774 84.839 C 74.981 62.491 63.804 62.916 45.421 54.726 C 22.492 44.51 29.707 19.353 29.707 19.353 C 29.707 19.353 32.619 40.104 43.055 45.503 C 43.055 45.503 41.053 38.527 43.236 31.61 C 43.236 31.61 43.358 44.776 58.284 53.513 C 58.284 53.513 54.279 47.081 56.646 41.681 Z "
383 fill="url(#_lgradient_13)"
384 />
385 <linearGradient
386 id="_lgradient_14"
387 x1="132.92447"
388 y1="173.82841"
389 x2="182.45367"
390 y2="130.10655"
391 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
392 gradientUnits="userSpaceOnUse"
393 >
394 <stop
395 offset="0%"
396 stopOpacity="1"
397 style="stop-color: rgb(42,86,132)"
398 />
399 <stop
400 offset="100%"
401 stopOpacity="1"
402 style="stop-color: rgb(0,175,239)"
403 />
404 </linearGradient>
405 <path
406 d=" M 86.263 40.216 C 86.263 18.005 68.257 0 46.046 0 C 43.32 0 40.658 0.274 38.084 0.792 C 34.08 6.28 31.846 11.667 30.622 15.594 C 35.473 12.52 41.213 10.72 47.345 10.72 C 64.646 10.72 78.67 24.745 78.67 42.046 C 78.67 47.588 77.214 52.783 74.689 57.298 C 80.377 62.618 84.593 73.458 84.593 73.458 C 83.799 68.354 82.492 64.191 81.077 60.3 C 84.707 53.493 86.263 47.158 86.263 40.216 Z "
407 fill="url(#_lgradient_14)"
408 />
409 <linearGradient
410 id="_lgradient_15"
411 x1="124.31395"
412 y1="101.90494"
413 x2="99.56409"
414 y2="152.34236"
415 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
416 gradientUnits="userSpaceOnUse"
417 >
418 <stop
419 offset="0%"
420 stopOpacity="1"
421 style="stop-color: rgb(140,59,139)"
422 />
423 <stop
424 offset="100%"
425 stopOpacity="1"
426 style="stop-color: rgb(235,40,143)"
427 />
428 </linearGradient>
429 <path
430 d=" M 5.829 40.216 C 5.829 62.428 23.834 80.433 46.046 80.433 C 50.348 80.433 54.49 79.751 58.376 78.499 C 48.658 78.345 42.796 76.388 38.4 74.507 C 31.12 71.232 16.247 62.703 16.018 42.046 C 15.897 31.04 21.783 21.194 30.622 15.594 C 31.846 11.667 34.08 6.28 38.084 0.792 C 19.687 4.486 5.829 20.731 5.829 40.216 Z "
431 fill="url(#_lgradient_15)"
432 />
433 <linearGradient
434 id="_lgradient_16"
435 x1="139.74491"
436 y1="123.55313"
437 x2="118.25858"
438 y2="136.15909"
439 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
440 gradientUnits="userSpaceOnUse"
441 >
442 <stop
443 offset="0%"
444 stopOpacity="1"
445 style="stop-color: rgb(42,86,132);"
446 />
447 <stop
448 offset="100%"
449 stopOpacity="1"
450 style="stop-color: rgb(0,175,239)"
451 />
452 </linearGradient>
453 <path
454 d=" M 47.911 58.864 C 32.479 52.345 22.433 39.417 27.946 21.599 C 27.946 21.599 14.842 37.616 30.785 57.595 C 30.785 57.595 23.348 55.303 20.334 47.826 C 20.334 47.826 20.813 54.105 26.302 59.34 C 29.439 59.967 32.697 60.3 36.041 60.3 C 40.15 60.3 44.129 59.798 47.911 58.864 Z "
455 fill="url(#_lgradient_16)"
456 />
457 <linearGradient
458 id="_lgradient_17"
459 x1="134.43987"
460 y1="148.73584"
461 x2="149.74781"
462 y2="126.84643"
463 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
464 gradientUnits="userSpaceOnUse"
465 >
466 <stop
467 offset="0%"
468 stopOpacity="1"
469 style="stop-color: rgb(140,59,139)"
470 />
471 <stop
472 offset="100%"
473 stopOpacity="1"
474 style="stop-color: rgb(235,40,143)"
475 />
476 </linearGradient>
477 <path
478 d=" M 56.646 41.681 C 56.646 41.681 57.555 45.346 63.446 51.873 C 60.068 54.224 56.313 56.15 52.276 57.565 C 50.102 56.719 47.824 55.797 45.421 54.726 C 22.492 44.51 29.707 19.353 29.707 19.353 C 29.707 19.353 32.619 40.104 43.055 45.503 C 43.055 45.503 41.053 38.527 43.236 31.61 C 43.236 31.61 43.358 44.776 58.284 53.513 C 58.284 53.513 54.279 47.081 56.646 41.681 Z "
479 fill="url(#_lgradient_17)"
480 />
481 <linearGradient
482 id="_lgradient_18"
483 x1="144.3668"
484 y1="182.42135"
485 x2="165.06028"
486 y2="147.4217"
487 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
488 gradientUnits="userSpaceOnUse"
489 >
490 <stop
491 offset="0%"
492 stopOpacity="1"
493 style="stop-color: rgb(42,86,132)"
494 />
495 <stop
496 offset="100%"
497 stopOpacity="1"
498 style="stop-color: rgb(0,175,239)"
499 />
500 </linearGradient>
501 <path
502 d=" M 81.063 20.428 C 74.156 8.232 61.064 0 46.046 0 C 43.32 0 40.658 0.274 38.084 0.792 C 34.08 6.28 31.846 11.667 30.622 15.594 C 35.473 12.52 41.213 10.72 47.345 10.72 C 62.136 10.72 74.53 20.972 77.816 34.757 C 79.795 30.315 80.937 25.486 81.063 20.428 Z "
503 fill="url(#_lgradient_18)"
504 />
505 <linearGradient
506 id="_lgradient_19"
507 x1="117.30813"
508 y1="124.32161"
509 x2="98.16378"
510 y2="157.97027"
511 gradientTransform="matrix(1,0,0,-1,-95.226,176.556)"
512 gradientUnits="userSpaceOnUse"
513 >
514 <stop
515 offset="0%"
516 stopOpacity="1"
517 style="stop-color: rgb(140,59,139)"
518 />
519 <stop
520 offset="100%"
521 stopOpacity="1"
522 style="stop-color: rgb(235,40,143)"
523 />
524 </linearGradient>
525 <path
526 d=" M 5.829 40.216 C 5.829 43.908 6.329 47.482 7.26 50.877 C 10.911 53.63 15.049 55.869 19.541 57.473 C 17.457 53.288 16.087 48.207 16.018 42.046 C 15.897 31.04 21.783 21.194 30.622 15.594 C 31.846 11.667 34.08 6.28 38.084 0.792 C 19.687 4.486 5.829 20.731 5.829 40.216 Z "
527 fill="url(#_lgradient_19)"
528 />
529 </g>
530 </svg>
531 </div>
532 </div>
533 </div>
534 <?php
535 }
536
537 public function disable_emojis_tinymce( $plugins ) {
538 return is_array( $plugins ) ? array_diff( $plugins, array( 'wpemoji' ) ) : array();
539 }
540
541 public function disable_admin_emojis() {
542 // if(self::is_admin_page()) {
543 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); // Admin browser support detection script
544 remove_action( 'admin_print_styles', 'print_emoji_styles' ); // Admin emoji styles
545
546 }
547
548 }
549