PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.2.3
Kubio AI Page Builder v1.2.3
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / kubio-editor.php
kubio / lib Last commit date
admin-pages 4 years ago api 4 years ago blog 4 years ago filters 4 years ago full-site-editing 4 years ago importer 4 years ago integrations 4 years ago menu 4 years ago polyfills 4 years ago preview 4 years ago shapes 4 years ago shortcodes 4 years ago src 4 years ago add-edit-in-kubio.php 4 years ago editor-assets.php 4 years ago env.php 4 years ago filters.php 4 years ago frontend.php 4 years ago global-data.php 4 years ago init.php 4 years ago kubio-block-library.php 4 years ago kubio-editor.php 4 years ago load.php 4 years ago
kubio-editor.php
1030 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4 use Kubio\Core\Utils;
5 use Kubio\Flags;
6 use Kubio\Core\LodashBasic;
7
8 function kubio_is_kubio_editor_page() {
9 global $pagenow;
10
11 if ( substr( $pagenow, 0, -4 ) === 'admin' ) {
12 $page = Arr::get( $_REQUEST, 'page', false );
13
14 if ( $page === 'kubio' ) {
15 return true;
16 }
17 }
18 }
19
20 function kubio_edit_site_get_first_post_id( $loaded_id ) {
21 if ( ! $loaded_id ) {
22 $ids = get_posts(
23 array(
24 'post_type' => 'page',
25 'posts_per_page' => 1,
26 'fields' => 'ids',
27 'orderby' => 'date',
28 'order' => 'ASC',
29 )
30 );
31
32 if ( ! empty( $ids ) ) {
33 $loaded_id = $ids[0];
34 }
35 }
36
37 if ( ! $loaded_id ) {
38 $ids = get_posts(
39 array(
40 'post_type' => 'post',
41 'posts_per_page' => 1,
42 'fields' => 'ids',
43 )
44 );
45
46 if ( ! empty( $ids ) ) {
47 $loaded_id = $ids[0];
48 }
49 }
50 return $loaded_id;
51 }
52 //this should also treat the template parts case. But at the moment you can't preview template parts but if will in the future
53 //the logic should work the same
54 function kubio_edit_site_get_template_id( $loaded_id, $postType ) {
55
56 $parts = explode( '//', $loaded_id );
57 if ( count( $parts ) !== 2 ) {
58 return null;
59 }
60 $templateName = $parts[1];
61 $query = array(
62 'name' => $templateName,
63 'post_type' => $postType,
64 'fields' => 'ids',
65 'post_status' => 'publish',
66 'posts_per_page' => 1,
67 );
68 $ids = get_posts( $query );
69 $resultPostId = null;
70 if ( ! empty( $ids ) ) {
71 $resultPostId = $ids[0];
72 }
73 return $resultPostId;
74 }
75 function kubio_edit_site_get_edited_entity() {
76 $pag_on_front = intval( get_option( 'page_on_front' ) );
77 $loaded_id = isset( $_GET['postId'] ) ? intval( $_GET['postId'] ) : $pag_on_front;
78 $post_type = isset( $_GET['postType'] ) ? sanitize_text_field( $_GET['postType'] ) : null;
79
80 if ( ! post_type_exists( $post_type ) || ! is_numeric( $loaded_id ) ) {
81 return array();
82 }
83
84 //when you have latest post set as your home page and you enter the builder without the post id the loaded_id will be 0
85 //in this case we'll load the index template
86 if ( $loaded_id === 0 ) {
87 $themeName = get_stylesheet();
88 $indexTemplateId = strtr( ':theme//index', array( ':theme' => $themeName ) );
89 $loaded_id = $indexTemplateId;
90 $post_type = 'wp_template';
91 }
92
93 $templatePostId = null;
94 if ( ! ! $loaded_id && ! is_numeric( $loaded_id ) ) {
95 $templatePostId = $loaded_id;
96 $loaded_id = kubio_edit_site_get_template_id( $loaded_id, $post_type );
97 }
98 if ( ! $loaded_id || ! is_numeric( $loaded_id ) ) {
99 $loaded_id = kubio_edit_site_get_first_post_id( $loaded_id );
100 }
101
102 if ( $loaded_id ) {
103 $entity = get_post( $loaded_id );
104
105 return array(
106 'path' => get_permalink( $loaded_id ),
107 'context' => array(
108 'postType' => $entity ? $entity->post_type : '',
109 'postId' => $templatePostId ? $templatePostId : $loaded_id,
110 'query' => '',
111 'postTitle' => $entity ? $entity->post_title : '',
112 'title' => $entity ? $entity->post_title : '',
113 ),
114 'slug' => $entity ? $entity->post_name : '',
115 'label' => $entity ? $entity->post_title : '',
116 );
117 }
118
119 return array();
120 }
121
122
123 function kubio_get_patterns_categories() {
124 return array(
125 array(
126 'label' => __( 'Hero accent', 'kubio' ),
127 'name' => 'kubio-content/overlappable',
128 ),
129
130 array(
131 'label' => __( 'About', 'kubio' ),
132 'name' => 'kubio-content/about',
133 ),
134
135 array(
136 'label' => __( 'Features', 'kubio' ),
137 'name' => 'kubio-content/features',
138 ),
139
140 array(
141 'label' => __( 'Content', 'kubio' ),
142 'name' => 'kubio-content/content',
143 ),
144
145 array(
146 'label' => __( 'Call to action', 'kubio' ),
147 'name' => 'kubio-content/cta',
148 ),
149 array(
150 'label' => __( 'Blog', 'kubio' ),
151 'name' => 'kubio-content/blog',
152 ),
153
154 array(
155 'label' => __( 'Counters', 'kubio' ),
156 'name' => 'kubio-content/counters',
157 ),
158
159 array(
160 'label' => __( 'Portfolio', 'kubio' ),
161 'name' => 'kubio-content/portfolio',
162 ),
163
164 array(
165 'label' => __( 'Photo gallery', 'kubio' ),
166 'name' => 'kubio-content/photo gallery',
167 ),
168
169 array(
170 'label' => __( 'Testimonials', 'kubio' ),
171 'name' => 'kubio-content/testimonials',
172 ),
173
174 array(
175 'label' => __( 'Clients', 'kubio' ),
176 'name' => 'kubio-content/clients',
177 ),
178
179 array(
180 'label' => __( 'Team', 'kubio' ),
181 'name' => 'kubio-content/team',
182 ),
183
184 array(
185 'label' => __( 'Contact', 'kubio' ),
186 'name' => 'kubio-content/contact',
187 ),
188
189 array(
190 'label' => __( 'F.A.Q.', 'kubio' ),
191 'name' => 'kubio-content/f.a.q.',
192 ),
193
194 array(
195 'label' => __( 'Pricing', 'kubio' ),
196 'name' => 'kubio-content/pricing',
197 ),
198 array(
199 'label' => __( 'Inner Headers', 'kubio' ),
200 'name' => 'kubio-header/inner headers',
201 ),
202
203 array(
204 'label' => __( 'Headers', 'kubio' ),
205 'name' => 'kubio-header/headers',
206 ),
207
208 array(
209 'label' => __( 'Footers', 'kubio' ),
210 'name' => 'kubio-footer/footers',
211 ),
212 );
213 }
214
215 function kubio_get_editor_style( $get_css = false ) {
216 $style_handles = array(
217 'wp-edit-blocks',
218 'wp-block-editor',
219 'wp-block-library',
220 'wp-block-library-theme',
221 'kubio-editor',
222 'kubio-controls',
223 'kubio-format-library',
224 'kubio-pro',
225 'kubio-block-library-editor',
226 'kubio-third-party-blocks',
227 );
228
229 $block_registry = WP_Block_Type_Registry::get_instance();
230
231 foreach ( $block_registry->get_all_registered() as $block_type ) {
232 if ( ! empty( $block_type->style ) ) {
233 $style_handles[] = $block_type->style;
234 }
235
236 if ( ! empty( $block_type->editor_style ) ) {
237 $style_handles[] = $block_type->editor_style;
238 }
239 }
240
241 $style_handles = array_unique( $style_handles );
242 $done = wp_styles()->done;
243
244 ob_start();
245 wp_styles()->done = array();
246 wp_styles()->do_items( $style_handles );
247 wp_styles()->done = $done;
248
249 $style = ob_get_clean();
250
251 if ( $get_css ) {
252 $style = preg_replace( "#<link(.*)href='(.*?)'(.*)/>#", '@import url($2);', $style );
253 $style = preg_replace( '#<style(.*)>#', '', $style );
254 $style = preg_replace( '#</style>#', '', $style );
255 }
256
257 return $style;
258 }
259
260 function kubio_get_editor_scripts() {
261 $script_handles = array( 'kubio-frontend' );
262
263 $script = '';
264 $done = wp_scripts()->done;
265 ob_start();
266 wp_scripts()->done = array();
267 wp_scripts()->do_items( $script_handles );
268 wp_scripts()->done = $done;
269 $script = ob_get_clean();
270
271 return $script;
272 }
273
274 function kubio_extend_block_editor_styles_html() {
275
276 $script = kubio_get_editor_scripts();
277 $style = kubio_get_editor_style();
278 $script = "<template id='kubio-scripts-template'>{$script}</template>";
279
280 printf(
281 '<script>window.__kubioEditorStyles = %s</script>',
282 wp_json_encode( array( 'html' => $style . $script ) )
283 );
284
285 if ( function_exists( 'wp_add_iframed_editor_assets_html' ) ) {
286 wp_add_iframed_editor_assets_html();
287 }
288 }
289
290 function kubio_edit_site_get_settings() {
291 $max_upload_size = wp_max_upload_size();
292 if ( ! $max_upload_size ) {
293 $max_upload_size = 0;
294 }
295
296 // This filter is documented in wp-admin/includes/media.php.
297 // This filter is documented in wp-admin/includes/media.php.
298 $image_size_names = apply_filters(
299 'image_size_names_choose',
300 array(
301 'thumbnail' => __( 'Thumbnail', 'kubio' ),
302 'medium' => __( 'Medium', 'kubio' ),
303 'large' => __( 'Large', 'kubio' ),
304 'full' => __( 'Full Size', 'kubio' ),
305 )
306 );
307 $available_image_sizes = array();
308 foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
309 $available_image_sizes[] = array(
310 'slug' => $image_size_slug,
311 'name' => $image_size_name,
312 );
313 }
314
315 // use array_values to ensure that json_encode sees it as array not object
316 $styles = array_values(
317 array_merge(
318 function_exists( 'get_block_editor_theme_styles' ) ? get_block_editor_theme_styles() : array(),
319 array(
320 array(
321 'css' => kubio_get_editor_style( true ),
322 '__unstableType' => 'theme',
323 ),
324 )
325 )
326 );
327
328 global $current_screen;
329 if ( function_exists( '_register_core_block_patterns_and_categories' ) ) {
330 _register_core_block_patterns_and_categories();
331 }
332
333 if ( function_exists( '_load_remote_block_patterns' ) ) {
334 _load_remote_block_patterns();
335 }
336
337 if ( function_exists( '_load_remote_featured_patterns' ) ) {
338 _load_remote_featured_patterns( $current_screen );
339 }
340
341 $settings = array_merge(
342 get_default_block_editor_settings(),
343 array(
344 'alignWide' => true, //get_theme_support( 'align-wide' ),
345 'siteUrl' => site_url( '/' ),
346 'postsPerPage' => get_option( 'posts_per_page' ),
347 'defaultTemplateTypes' => kubio_get_indexed_default_template_types(),
348 '__experimentalBlockPatterns' => WP_Block_Patterns_Registry::get_instance()->get_all_registered(),
349 '__experimentalBlockPatternCategories' => array_merge(
350 WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(),
351 kubio_get_patterns_categories()
352 ),
353 'imageSizes' => $available_image_sizes,
354 'isRTL' => is_rtl(),
355 'maxUploadFileSize' => $max_upload_size,
356 'styles' => $styles,
357 )
358 );
359
360 if ( function_exists( 'get_block_editor_settings' ) && class_exists( '\WP_Block_Editor_Context' ) ) {
361 $settings = get_block_editor_settings( $settings, new \WP_Block_Editor_Context() );
362 }
363
364 if ( function_exists( 'gutenberg_experimental_global_styles_settings' ) ) {
365 $settings = gutenberg_experimental_global_styles_settings( $settings );
366 }
367
368 $settings['state'] = array(
369 'entity' => kubio_edit_site_get_edited_entity(),
370 );
371
372 $settings['kubioPrimaryMenuLocation'] = apply_filters(
373 'kubio/primary_menu_location',
374 'header-menu'
375 );
376
377 $settings['isKubioTheme'] = kubio_theme_has_kubio_block_support();
378
379 $settings['supportsTemplateMode'] = kubio_theme_has_block_templates_support();
380
381 global $post;
382 $settings = apply_filters( 'block_editor_settings_all', $settings, $post );
383 $settings = apply_filters( 'kubio/block_editor_settings', $settings, $post );
384 $settings['isWooCommerce'] = function_exists( 'WC' );
385
386 $settings['defaultTemplatePartAreas'] = kubio_get_allowed_template_part_areas();
387 $settings['classicThemeTemplates'] = kubio_get_classic_theme_templates();
388 $settings['kubioThemeAssetsUrlBase'] = untrailingslashit( apply_filters( 'kubio/importer/kubio-url-placeholder-replacement', '' ) );
389
390 // adding it here since `select('core').getCurrentTheme().theme_uri` returns an empty string.
391 $settings['themeUri'] = get_template_directory_uri();
392 $settings['classicHasFrontPageTemplate'] = kubio_third_party_theme_has_front_page_template();
393 $settings['classicThemePrimaryTemplates'] = array_keys( kubio_get_classic_theme_primary_templates() );
394
395 $scrollableImagePath = wp_get_theme()->get_file_path( 'resources/images/front-page-preview.jpg' );
396 // Handle the Front page suggestion preview image
397 if ( file_exists( $scrollableImagePath ) ) {
398 $settings['kubioHasFpsScrollPreview'] = true; // 'resources/images/front-page-preview.jpg';
399 } else {
400 $settings['kubioHasFpsScrollPreview'] = false; //'screenshot.jpg';
401 }
402 $settings['supportsLayout'] = true;
403 $layout = LodashBasic::get( $settings, '__experimentalFeatures.layout', array() );
404 $mergedLayout = array_merge( array( 'contentSize' => '1172px' ), $layout );
405 if ( ! isset( $settings['__experimentalFeatures'] ) ) {
406 $settings['__experimentalFeatures'] = array();
407 }
408 $settings['__experimentalFeatures']['layout'] = $mergedLayout;
409 LodashBasic::set($settings, '__experimentalFeatures.blocks.core/post-content.layout', $mergedLayout);
410
411 return $settings;
412 }
413
414 add_filter(
415 'block_editor_settings_all',
416 function ( $settings ) {
417 $settings['__unstableEnableFullSiteEditingBlocks'] = true;
418 $settings['enableFSEBlocks'] = true;
419 $settings['kubioGlobalSettings'] = (object) Flags::getSettings();
420
421 return $settings;
422 },
423 50
424 );
425
426 function kubio_load_gutenberg_assets() {
427 wp_enqueue_style( 'kubio-pro' );
428
429 wp_enqueue_script( 'kubio-block-patterns' );
430 wp_enqueue_script( 'kubio-third-party-blocks' );
431 wp_localize_script(
432 'kubio-block-patterns',
433 'kubioBlockPatterns',
434 array(
435 'inGutenbergEditor' => ! kubio_is_kubio_editor_page(),
436 )
437 );
438
439 wp_add_inline_style( 'kubio-block-library', kubio_get_shapes_css() );
440 }
441
442 function kubio_get_post_types() {
443 $extra_types = get_post_types(
444 array(
445 '_builtin' => false,
446 'public' => true,
447 )
448 );
449
450 $types = array();
451 global $wp_post_types;
452
453 foreach ( $extra_types as $type ) {
454 $types[] = array(
455 'entity' => $type,
456 'kind' => 'postType',
457 'title' => $wp_post_types[ $type ]->label,
458 );
459 }
460
461 return $types;
462 }
463
464 add_action( 'enqueue_block_editor_assets', 'kubio_load_gutenberg_assets' );
465
466 function kubio_navigation_get_menu_items_endpoint(
467 $menu_id,
468 $results_per_page = 100
469 ) {
470 return '/__experimental/menu-items?' .
471 build_query(
472 array(
473 'context' => 'edit',
474 'menus' => $menu_id,
475 'per_page' => $results_per_page,
476 '_locale' => 'user',
477 )
478 );
479 }
480
481 function kubio_add_endpoint_details(
482 $url,
483 $results_per_page = null,
484 $locale = null
485 ) {
486 $vars = array( 'context' => 'edit' );
487 if ( $results_per_page !== null ) {
488 $vars['per_page'] = $results_per_page;
489 }
490 if ( $locale !== null ) {
491 $vars['_locale'] = 'user';
492 }
493 return $url . '?' . build_query( $vars );
494 }
495
496 function kubio_edit_site_init( $hook ) {
497 if ( ! kubio_is_kubio_editor_page() ) {
498 return;
499 }
500 add_filter( 'use_block_editor_for_post_type', '__return_true' );
501
502 global $current_screen, $post;
503 $current_screen->is_block_editor( true );
504
505 // Inline the Editor Settings
506 $settings = kubio_edit_site_get_settings();
507
508 $menus = wp_get_nav_menus();
509 $first_menu_id = ! empty( $menus ) ? $menus[0]->term_id : null;
510
511 $stylesheet = get_stylesheet();
512
513 // Preload block editor paths.
514 // most of these are copied from edit-forms-blocks.php.
515 $preload_paths = array(
516 array( '/wp/v2/media', 'OPTIONS' ),
517 '/',
518 '/?context=edit',
519 '/wp/v2/types?context=edit',
520 '/wp/v2/taxonomies?context=edit',
521 '/wp/v2/categories?context=edit',
522 '/wp/v2/categories/1?context=edit',
523 '/wp/v2/tags?context=edit',
524
525 '/wp/v2/settings',
526
527 array( '/wp/v2/pages', 'OPTIONS' ),
528 array( '/wp/v2/posts', 'OPTIONS' ),
529
530 kubio_add_endpoint_details( '/wp/v2/pages', 100 ),
531 kubio_add_endpoint_details( '/wp/v2/posts', 100 ),
532 kubio_add_endpoint_details( '/wp/v2/templates', 100 ),
533 kubio_add_endpoint_details( '/wp/v2/template-parts', 100 ),
534
535 '/kubio/v1/contact-form/forms_by_type',
536 '/kubio/v1/subscribe-form/forms_by_type',
537 '/kubio/v1/page-templates/get',
538
539 '/__experimental/menus?_locale=user&context=edit&per_page=100',
540 '/__experimental/menus?context=edit&per_page=-1',
541 '/__experimental/menu-locations?context=edit',
542
543 kubio_add_endpoint_details( "/wp/v2/template-parts/{$stylesheet}//footer" ),
544 kubio_add_endpoint_details( "/wp/v2/template-parts/{$stylesheet}//front-header" ),
545 kubio_add_endpoint_details( "/wp/v2/templates/kub{$stylesheet}io//front-page" ),
546
547 '/wp/v2/types/wp_template?context=edit',
548 '/wp/v2/types/wp_template-part?context=edit',
549 '/wp/v2/pages?context=edit',
550 '/wp/v2/posts?context=edit',
551 '/wp/v2/templates?context=edit&per_page=-1',
552 '/wp/v2/template-parts?context=edit&per_page=-1',
553 '/wp/v2/themes?context=edit&status=active',
554 );
555
556 $active_global_styles_id = 0;
557 $active_theme = wp_get_theme()->get_stylesheet();
558
559 if ( class_exists( '\WP_Theme_JSON_Resolver' ) && method_exists( WP_Theme_JSON_Resolver::class, 'get_user_global_styles_post_id' ) ) {
560 $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
561 }
562
563 if ( $active_global_styles_id ) {
564 $preload_paths = array_merge(
565 $preload_paths,
566 array(
567 '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
568 '/wp/v2/global-styles/' . $active_global_styles_id,
569 '/wp/v2/global-styles/themes/' . $active_theme,
570 )
571 );
572 }
573
574 wp_enqueue_media();
575
576 $preload_paths[] =
577 '/wp/v2/kubio/global-data/' .
578 kubio_global_data_post_id() .
579 '?context=edit';
580
581 $preload_paths[] = '/kubio/v1/menu/';
582 $preload_paths[] =
583 '/wp/v2/pages/' . get_option( 'page_on_front' ) . '?context=edit';
584
585 $preload_paths[] = '/wp/v2/users/1?context=edit';
586 $preload_paths[] = '/wp/v2/comments?context=edit&post=1';
587
588 if ( $first_menu_id ) {
589 $preload_paths[] = "/kubio/v1/menu/${first_menu_id}";
590 $preload_paths[] = kubio_navigation_get_menu_items_endpoint(
591 $first_menu_id
592 );
593 }
594
595 $preload_data = array_reduce(
596 $preload_paths,
597 'rest_preload_api_request',
598 array()
599 );
600
601 if ( function_exists( 'block_editor_rest_api_preload' ) ) {
602 block_editor_rest_api_preload( $preload_paths, new \WP_Block_Editor_Context() );
603 } else {
604 wp_add_inline_script(
605 'wp-api-fetch',
606 sprintf(
607 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
608 wp_json_encode( $preload_data )
609 ),
610 'after'
611 );
612 }
613
614 wp_add_inline_script(
615 'wp-blocks',
616 sprintf(
617 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions( %s );',
618 wp_json_encode( get_block_editor_server_block_settings() )
619 ),
620 'after'
621 );
622
623 wp_add_inline_script(
624 'wp-blocks',
625 sprintf(
626 'wp.blocks.setCategories( %s );',
627 wp_json_encode( get_block_categories( $post ) )
628 ),
629 'after'
630 );
631
632 // Editor default styles
633 wp_enqueue_style( 'wp-format-library' );
634 wp_enqueue_style( 'kubio-format-library' );
635 wp_enqueue_script( 'kubio-editor' );
636 wp_enqueue_script( 'kubio-block-library' );
637 wp_enqueue_style( 'kubio-admin-panel' );
638
639 wp_enqueue_style( 'kubio-editor' );
640 wp_enqueue_style( 'kubio-advanced-panel' );
641 wp_enqueue_style( 'kubio-block-library-editor' );
642 wp_enqueue_style( 'kubio-controls' );
643 wp_enqueue_style( 'kubio-scripts' );
644 wp_enqueue_style( 'kubio-wp-global-styles' );
645
646 $settings['postTypes'] = kubio_get_post_types();
647
648 wp_add_inline_script(
649 'kubio-editor',
650 sprintf(
651 'window.kubioEditSiteSettings = %s;' .
652 "\n" .
653 'wp.domReady( function() { kubio.editor.initialize( "kubio-editor", window.kubioEditSiteSettings ); } );',
654 wp_json_encode( $settings )
655 ),
656 'after'
657 );
658
659 wp_add_inline_style( 'kubio-editor', kubio_get_shapes_css() );
660
661 add_action( 'admin_footer', 'kubio_extend_block_editor_styles_html' );
662 do_action( 'enqueue_block_editor_assets' );
663 do_action( 'kubio/editor/enqueue_assets' );
664
665 $editor_styles = function_exists( 'get_editor_stylesheets' ) ? get_editor_stylesheets() : null;
666 if (
667 current_theme_supports( 'wp-block-styles' ) ||
668 ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
669 ) {
670 wp_enqueue_style( 'wp-block-library-theme' );
671 }
672 }
673
674 add_action( 'admin_enqueue_scripts', 'kubio_edit_site_init', 500 );
675
676 // Add tinymce scripts within the Kubio Editor and WordPress Editor since we need them in blocks like Subscribe form.
677 // we use the `enqueue_block_editor_assets` action since it is called in both editors.
678 add_action(
679 'enqueue_block_editor_assets',
680 function () {
681 wp_enqueue_script( 'wp-tinymce' );
682 wp_enqueue_editor();
683 wp_enqueue_code_editor( array() );
684 wp_tinymce_inline_scripts();
685
686 }
687 );
688
689 /**
690 * Renders the Menu Page
691 *
692 * @return void
693 */
694 function kubio_edit_site_render_block_editor() {
695 ?>
696 <style>
697 div#wpcontent,
698 #wpbody-content {
699 position: fixed;
700 z-index: 1000000;
701 width: 100vw;
702 height: 100vh;
703 background: #fff;
704 top: 0%;
705 left: 0%;
706 right: 0;
707 border: 0;
708 display: block;
709 box-sizing: border-box;
710 }
711 #wp-link-backdrop {
712 z-index: 1000050;
713 }
714 #wp-link-wrap {
715 z-index: 1000100;
716 }
717 #kubio-editor {
718 position: absolute;
719 top: 0;
720 bottom: 0;
721 left: 0;
722 right: 0;
723 z-index: 1000;
724 width: 100%;
725 height: 100%;
726 }
727
728 .kubio-loading-editor {
729 position: absolute;
730 top: 50%;
731 left: 50%;
732 display: block;
733 font-size: 1.5em;
734 transform: translate(-50%, -50%);
735 }
736
737 .kubio-loading-editor iframe {
738 margin: 0px auto 0px auto;
739 }
740 </style>
741 <div id="kubio-editor" class="kubio">
742 <div class="kubio-loading-editor">
743 <?php echo kubio_get_iframe_loader( array( 'size' => '120px' ) ); ?>
744 </div>
745 </div>
746 <?php
747 }
748
749 /**
750 * Registers the new WP Admin Menu
751 *
752 * @return void
753 */
754 function kubio_edit_site_add_menu_page() {
755 add_menu_page(
756 __( 'Kubio', 'kubio' ),
757 sprintf(
758 '<span class="kubio-menu-item"><span class="kubio-menu-item--icon">%s</span><span>%s</span></span>',
759 wp_kses_post( KUBIO_LOGO_SVG ),
760 __( 'Kubio', 'kubio' )
761 ),
762 'edit_posts',
763 'kubio',
764 'kubio_edit_site_render_block_editor',
765 'data:image/svg+xml;base64,' . base64_encode( str_replace( '<svg', '<svg fill="#5246F1" ', KUBIO_LOGO_SVG ) ),
766 20
767 );
768
769 add_submenu_page(
770 'themes.php',
771 __( 'Kubio', 'kubio' ),
772 __( 'Edit with Kubio', 'kubio' ),
773 'edit_posts',
774 'kubio_appearance_edit',
775 'kubio_edit_site_render_block_editor',
776 1
777 );
778
779 global $submenu;
780
781 foreach ( $submenu['themes.php'] as $index => $submenu_item ) {
782 if ( $submenu_item[2] === 'kubio_appearance_edit' ) {
783 $submenu['themes.php'][ $index ][2] = add_query_arg(
784 array(
785 'page' => 'kubio',
786 ),
787 'admin.php'
788 );
789 }
790 }
791 }
792
793 function kubio_admin_page_submenu_hook() {
794 global $submenu;
795
796 $kubio_submenu = Arr::get( $submenu, 'kubio', null );
797
798 if ( is_array( $kubio_submenu ) ) {
799 foreach ( $kubio_submenu as $index => $submenu_data ) {
800 $menu_slug = Arr::get( $submenu_data, '2', null );
801 if ( $menu_slug === 'kubio' ) {
802 $submenu['kubio'][ $index ][0] = __( 'Open Kubio Editor', 'kubio' );
803 }
804 }
805 }
806
807 }
808
809 add_action( 'admin_menu', 'kubio_admin_page_submenu_hook', 200 );
810
811 add_action( 'admin_menu', 'kubio_edit_site_add_menu_page' );
812
813 function kubio_admin_menu_style() {
814 ?>
815 <style>
816 #adminmenu .toplevel_page_kubio .wp-menu-image {
817 display: none;
818 }
819
820 .wp-admin.folded #adminmenu .toplevel_page_kubio .wp-menu-image{
821 display:block;
822 background-size: 16px auto;
823 }
824
825 #adminmenu .kubio-menu-item {
826 display: flex;
827 align-items: center;
828 }
829
830 #adminmenu .kubio-menu-item > span {
831 display: block;
832 line-height: 1;
833 }
834
835 #adminmenu .kubio-menu-item--icon {
836 color: rgba(240,246,252,.6);
837 }
838 #adminmenu .wp-menu-name:hover .kubio-menu-item--icon {
839 color: inherit;
840 }
841 #adminmenu .kubio-menu-item--icon svg {
842 fill: currentColor;
843 height: 15px;
844 margin-right: 11px;
845 }
846
847 #adminmenu .wp-menu-open .kubio-menu-item--icon svg {
848 fill: #fff;
849 }
850
851 #adminmenu .toplevel_page_kubio div.wp-menu-name {
852 padding: 8px 8px 8px 10px;
853 }
854
855 #adminmenu .wp-submenu .kubio-menu-item--icon {
856 display: none;
857 }
858 </style>
859 <?php
860 }
861
862 add_action( 'admin_head', 'kubio_admin_menu_style' );
863
864 /**
865 * Register a core site setting for front page information.
866 */
867 function kubio_register_site_editor_homepage_settings() {
868 global $wp_registered_settings;
869
870 if ( ! isset( $wp_registered_settings['show_on_front'] ) ) {
871 register_setting(
872 'reading',
873 'show_on_front',
874 array(
875 'show_in_rest' => true,
876 'type' => 'string',
877 'description' => __( 'What to show on the front page', 'kubio' ),
878 )
879 );
880 }
881
882 if ( ! isset( $wp_registered_settings['page_on_front'] ) ) {
883 register_setting(
884 'reading',
885 'page_on_front',
886 array(
887 'show_in_rest' => true,
888 'type' => 'number',
889 'description' => __(
890 'The ID of the page that should be displayed on the front page',
891 'kubio'
892 ),
893 )
894 );
895 }
896 if ( ! isset( $wp_registered_settings['page_for_posts'] ) ) {
897 register_setting(
898 'reading',
899 'page_for_posts',
900 array(
901 'show_in_rest' => true,
902 'type' => 'number',
903 'description' => __(
904 'The ID of the page that displays the posts',
905 'kubio'
906 ),
907 )
908 );
909 }
910
911 if ( ! isset( $wp_registered_settings['site_icon'] ) ) {
912 register_setting(
913 'general',
914 'site_icon',
915 array(
916 'show_in_rest' => array(
917 'name' => 'site_icon',
918 ),
919 'type' => 'integer',
920 'description' => __( 'Site icon.', 'kubio' ),
921 )
922 );
923 }
924 }
925
926 add_filter(
927 'block_editor_settings_all',
928 function ( $settings ) {
929 $settings['kubioLoaded'] = true;
930
931 return $settings;
932 }
933 );
934
935 add_action( 'init', 'kubio_register_site_editor_homepage_settings', 100 );
936
937 function kubio_editor_add_default_template_types( $template_types ) {
938 if ( kubio_is_kubio_editor_page() && is_user_logged_in() ) {
939 $kubio_templates = array(
940 'full-width' => array(
941 'title' => _x( 'Full Width', 'Template name', 'kubio' ),
942 'description' => __(
943 'Recommended Kubio template to display individual pages. This template works best with the Kubio provided blocks and predesigned sections.',
944 'kubio'
945 ),
946 ),
947 'kubio-full-width' => array(
948 'title' => _x( 'Kubio Full Width', 'Template name', 'kubio' ),
949 'description' => __(
950 'Recommended Kubio template to display individual pages. This template works best with the Kubio provided blocks and predesigned sections.',
951 'kubio'
952 ),
953 ),
954 );
955
956 foreach ( $kubio_templates as $slug => $settings ) {
957 $template_types[ $slug ] = $settings;
958 }
959 }
960
961 return $template_types;
962 }
963
964 add_filter( 'default_template_types', 'kubio_editor_add_default_template_types' );
965
966 add_action(
967 'init',
968 function() {
969 if ( kubio_is_kubio_editor_page() && is_user_logged_in() ) {
970 $has_valid_req = Utils::validateRequirements();
971
972 if ( is_wp_error( $has_valid_req ) ) {
973 ob_start();
974 ?>
975 <style>
976 body#error-page {
977 margin: 0;
978 position: absolute;
979 top: 50%;
980 left: 50%;
981 transform: translate(-50%, -50%);
982 border-left: 4px solid #fb3e41;
983 padding-top: 0;
984 padding-bottom: 0;
985 }
986
987 body#error-page .kubio-mrn {
988 flex-direction: column;
989 align-items: flex-start;
990 }
991
992 body#error-page .kubio-mrn-icon-holder {
993 padding-bottom: 12px;
994 }
995
996 body#error-page br {
997 display: none;
998 }
999
1000 p {
1001 margin:12px 0 0 0;
1002 }
1003 body#error-page a {
1004 margin-top:16px;
1005 display:block;
1006 }
1007 #error-page p.kubio-mrn-rollback-message > a {
1008 display: inline;
1009 }
1010
1011 </style>
1012 <?php
1013 _kubio_requirements_not_met_notice();
1014 $content = ob_get_clean();
1015 wp_die( $content );
1016 }
1017
1018 if ( ! current_user_can( 'edit_theme_options' ) ) {
1019 wp_die(
1020 '<h1>' . __( 'You need a higher level of permission.', 'kubio' ) . '</h1>' .
1021 '<p>' . __( 'Sorry, you are not allowed to customize this site.', 'kubio' ) . '</p>',
1022 403
1023 );
1024 }
1025 }
1026
1027 },
1028 5
1029 );
1030