AI
2 years ago
admin-pages
2 years ago
api
2 years ago
blog
3 years ago
customizer
2 years ago
filters
2 years ago
full-site-editing
2 years ago
importer
4 years ago
integrations
2 years ago
menu
3 years ago
polyfills
3 years ago
preview
2 years ago
shapes
2 years ago
shortcodes
3 years ago
src
2 years ago
add-edit-in-kubio.php
2 years ago
editor-assets.php
2 years ago
env.php
2 years ago
filters.php
2 years ago
frontend.php
4 years ago
global-data.php
2 years ago
init.php
2 years ago
kubio-block-library.php
2 years ago
kubio-editor.php
2 years ago
load.php
2 years ago
kubio-editor.php
1259 lines
| 1 | <?php |
| 2 | |
| 3 | use IlluminateAgnostic\Arr\Support\Arr; |
| 4 | use Kubio\AssetsDependencyInjector; |
| 5 | use Kubio\Core\LodashBasic; |
| 6 | use Kubio\Core\Utils; |
| 7 | use Kubio\Flags; |
| 8 | |
| 9 | function kubio_is_kubio_editor_page() { |
| 10 | global $pagenow; |
| 11 | |
| 12 | $is = false; |
| 13 | if ( substr( $pagenow, 0, -4 ) === 'admin' ) { |
| 14 | $page = Arr::get( $_REQUEST, 'page', false ); |
| 15 | |
| 16 | if ( $page === 'kubio' ) { |
| 17 | $is = true; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | return apply_filters( 'kubio/is_kubio_editor_page', $is ); |
| 22 | } |
| 23 | |
| 24 | function kubio_is_kubio_editor_page_frontend_request() { |
| 25 | $kubio_flags = kubio_get_editor_requests_flags(); |
| 26 | $is_frontend_request = false; |
| 27 | foreach ( $kubio_flags as $flag ) { |
| 28 | if ( isset( $_REQUEST[ $flag ] ) ) { |
| 29 | $is_frontend_request = true; |
| 30 | } |
| 31 | } |
| 32 | return $is_frontend_request; |
| 33 | } |
| 34 | function kubio_edit_site_get_first_post_id( $loaded_id ) { |
| 35 | if ( ! $loaded_id ) { |
| 36 | $ids = get_posts( |
| 37 | array( |
| 38 | 'post_type' => 'page', |
| 39 | 'posts_per_page' => 1, |
| 40 | 'fields' => 'ids', |
| 41 | 'orderby' => 'date', |
| 42 | 'order' => 'ASC', |
| 43 | ) |
| 44 | ); |
| 45 | |
| 46 | if ( ! empty( $ids ) ) { |
| 47 | $loaded_id = $ids[0]; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if ( ! $loaded_id ) { |
| 52 | $ids = get_posts( |
| 53 | array( |
| 54 | 'post_type' => 'post', |
| 55 | 'posts_per_page' => 1, |
| 56 | 'fields' => 'ids', |
| 57 | ) |
| 58 | ); |
| 59 | |
| 60 | if ( ! empty( $ids ) ) { |
| 61 | $loaded_id = $ids[0]; |
| 62 | } |
| 63 | } |
| 64 | return $loaded_id; |
| 65 | } |
| 66 | //this should also treat the template parts case. But at the moment you can't preview template parts but if will in the future |
| 67 | //the logic should work the same |
| 68 | function kubio_edit_site_get_template_id( $loaded_id, $postType ) { |
| 69 | |
| 70 | $parts = explode( '//', $loaded_id ); |
| 71 | if ( count( $parts ) !== 2 ) { |
| 72 | return null; |
| 73 | } |
| 74 | $templateName = $parts[1]; |
| 75 | $query = array( |
| 76 | 'name' => $templateName, |
| 77 | 'post_type' => $postType, |
| 78 | 'fields' => 'ids', |
| 79 | 'post_status' => 'publish', |
| 80 | 'posts_per_page' => 1, |
| 81 | ); |
| 82 | $ids = get_posts( $query ); |
| 83 | $resultPostId = null; |
| 84 | if ( ! empty( $ids ) ) { |
| 85 | $resultPostId = $ids[0]; |
| 86 | } |
| 87 | return $resultPostId; |
| 88 | } |
| 89 | function kubio_edit_site_get_edited_entity() { |
| 90 | $pag_on_front = intval( get_option( 'page_on_front' ) ); |
| 91 | $loaded_id = isset( $_GET['postId'] ) ? intval( $_GET['postId'] ) : $pag_on_front; |
| 92 | $post_type = isset( $_GET['postType'] ) ? sanitize_text_field( $_GET['postType'] ) : null; |
| 93 | |
| 94 | if ( ! post_type_exists( $post_type ) || ! is_numeric( $loaded_id ) ) { |
| 95 | return array(); |
| 96 | } |
| 97 | |
| 98 | //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 |
| 99 | //in this case we'll load the index template |
| 100 | if ( $loaded_id === 0 ) { |
| 101 | $themeName = get_stylesheet(); |
| 102 | $indexTemplateId = strtr( ':theme//index', array( ':theme' => $themeName ) ); |
| 103 | $loaded_id = $indexTemplateId; |
| 104 | $post_type = 'wp_template'; |
| 105 | } |
| 106 | |
| 107 | $templatePostId = null; |
| 108 | if ( ! ! $loaded_id && ! is_numeric( $loaded_id ) ) { |
| 109 | $templatePostId = $loaded_id; |
| 110 | $loaded_id = kubio_edit_site_get_template_id( $loaded_id, $post_type ); |
| 111 | } |
| 112 | if ( ! $loaded_id || ! is_numeric( $loaded_id ) ) { |
| 113 | $loaded_id = kubio_edit_site_get_first_post_id( $loaded_id ); |
| 114 | } |
| 115 | |
| 116 | if ( $loaded_id ) { |
| 117 | $entity = get_post( $loaded_id ); |
| 118 | |
| 119 | return array( |
| 120 | 'path' => get_permalink( $loaded_id ), |
| 121 | 'context' => array( |
| 122 | 'postType' => $entity ? $entity->post_type : '', |
| 123 | 'postId' => $templatePostId ? $templatePostId : $loaded_id, |
| 124 | 'query' => '', |
| 125 | 'postTitle' => $entity ? $entity->post_title : '', |
| 126 | 'title' => $entity ? $entity->post_title : '', |
| 127 | ), |
| 128 | 'slug' => $entity ? $entity->post_name : '', |
| 129 | 'label' => $entity ? $entity->post_title : '', |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | return array(); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | function kubio_get_patterns_categories() { |
| 138 | return array( |
| 139 | array( |
| 140 | 'label' => __( 'Hero accent', 'kubio' ), |
| 141 | 'name' => 'kubio-content/hero accent', |
| 142 | ), |
| 143 | |
| 144 | array( |
| 145 | 'label' => __( 'About', 'kubio' ), |
| 146 | 'name' => 'kubio-content/about', |
| 147 | ), |
| 148 | |
| 149 | array( |
| 150 | 'label' => __( 'Features', 'kubio' ), |
| 151 | 'name' => 'kubio-content/features', |
| 152 | ), |
| 153 | |
| 154 | array( |
| 155 | 'label' => __( 'Content', 'kubio' ), |
| 156 | 'name' => 'kubio-content/content', |
| 157 | ), |
| 158 | |
| 159 | array( |
| 160 | 'label' => __( 'Call to action', 'kubio' ), |
| 161 | 'name' => 'kubio-content/cta', |
| 162 | ), |
| 163 | array( |
| 164 | 'label' => __( 'Blog', 'kubio' ), |
| 165 | 'name' => 'kubio-content/blog', |
| 166 | ), |
| 167 | |
| 168 | array( |
| 169 | 'label' => __( 'Counters', 'kubio' ), |
| 170 | 'name' => 'kubio-content/counters', |
| 171 | ), |
| 172 | |
| 173 | array( |
| 174 | 'label' => __( 'Portfolio', 'kubio' ), |
| 175 | 'name' => 'kubio-content/portfolio', |
| 176 | ), |
| 177 | |
| 178 | array( |
| 179 | 'label' => __( 'Photo gallery', 'kubio' ), |
| 180 | 'name' => 'kubio-content/photo gallery', |
| 181 | ), |
| 182 | |
| 183 | array( |
| 184 | 'label' => __( 'Testimonials', 'kubio' ), |
| 185 | 'name' => 'kubio-content/testimonials', |
| 186 | ), |
| 187 | |
| 188 | array( |
| 189 | 'label' => __( 'Clients', 'kubio' ), |
| 190 | 'name' => 'kubio-content/clients', |
| 191 | ), |
| 192 | |
| 193 | array( |
| 194 | 'label' => __( 'Team', 'kubio' ), |
| 195 | 'name' => 'kubio-content/team', |
| 196 | ), |
| 197 | |
| 198 | array( |
| 199 | 'label' => __( 'Contact', 'kubio' ), |
| 200 | 'name' => 'kubio-content/contact', |
| 201 | ), |
| 202 | |
| 203 | array( |
| 204 | 'label' => __( 'F.A.Q.', 'kubio' ), |
| 205 | 'name' => 'kubio-content/f.a.q.', |
| 206 | ), |
| 207 | |
| 208 | array( |
| 209 | 'label' => __( 'Pricing', 'kubio' ), |
| 210 | 'name' => 'kubio-content/pricing', |
| 211 | ), |
| 212 | array( |
| 213 | 'label' => __( 'Inner Headers', 'kubio' ), |
| 214 | 'name' => 'kubio-header/inner headers', |
| 215 | ), |
| 216 | |
| 217 | array( |
| 218 | 'label' => __( 'Headers', 'kubio' ), |
| 219 | 'name' => 'kubio-header/headers', |
| 220 | ), |
| 221 | |
| 222 | array( |
| 223 | 'label' => __( 'Footers', 'kubio' ), |
| 224 | 'name' => 'kubio-footer/footers', |
| 225 | ), |
| 226 | ); |
| 227 | } |
| 228 | |
| 229 | function kubio_get_editor_style( $get_css = false, $skiped_handlers = array() ) { |
| 230 | $style_handles = array( |
| 231 | 'wp-edit-blocks', |
| 232 | 'wp-block-editor', |
| 233 | 'wp-block-library', |
| 234 | 'wp-block-library-theme', |
| 235 | 'kubio-editor', |
| 236 | 'kubio-controls', |
| 237 | 'kubio-utils', |
| 238 | 'kubio-format-library', |
| 239 | 'kubio-pro', |
| 240 | 'kubio-block-library-editor', |
| 241 | 'kubio-third-party-blocks', |
| 242 | 'kubio-icons', |
| 243 | ); |
| 244 | |
| 245 | $style_handles = apply_filters( 'kubio/kubio_get_editor_style/style_handles', $style_handles ); |
| 246 | |
| 247 | $wp_styles = wp_styles(); |
| 248 | foreach ( array_keys( $wp_styles->registered ) as $handle ) { |
| 249 | if ( strpos( $handle, AssetsDependencyInjector::KUBIO_DEPENENCY_PREFIX ) === 0 ) { |
| 250 | $style_handles[] = $handle; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | foreach ( $skiped_handlers as $index => $handler ) { |
| 255 | $handler = preg_replace( '#(.*?)-inline-css$#', '$1', $handler ); |
| 256 | $handler = preg_replace( '#(.*?)-css$#', '$1', $handler ); |
| 257 | $skiped_handlers[ $index ] = $handler; |
| 258 | } |
| 259 | |
| 260 | $skiped_handlers = array_unique( $skiped_handlers ); |
| 261 | $style_handles = array_diff( $style_handles, $skiped_handlers ); |
| 262 | |
| 263 | $block_registry = WP_Block_Type_Registry::get_instance(); |
| 264 | |
| 265 | foreach ( $block_registry->get_all_registered() as $block_type ) { |
| 266 | if ( ! empty( $block_type->style ) ) { |
| 267 | $style_handles[] = $block_type->style; |
| 268 | } |
| 269 | |
| 270 | if ( ! empty( $block_type->editor_style ) ) { |
| 271 | $style_handles[] = $block_type->editor_style; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | $style_handles = Arr::flatten( $style_handles ); |
| 276 | $style_handles = array_values( array_unique( $style_handles ) ); |
| 277 | $done = wp_styles()->done; |
| 278 | ob_start(); |
| 279 | |
| 280 | ?> |
| 281 | <style><?php echo wp_get_global_stylesheet(); ?></style> |
| 282 | <?php |
| 283 | wp_styles()->done = $skiped_handlers; |
| 284 | wp_styles()->do_items( $style_handles ); |
| 285 | wp_styles()->done = $done; |
| 286 | |
| 287 | $style = ob_get_clean(); |
| 288 | |
| 289 | if ( $get_css ) { |
| 290 | $style = preg_replace( "#<link(.*)href='(.*?)'(.*)/>#", '@import url($2);', $style ); |
| 291 | $style = preg_replace( '#<style(.*)>#', '', $style ); |
| 292 | $style = preg_replace( '#</style>#', '', $style ); |
| 293 | } |
| 294 | |
| 295 | return $style; |
| 296 | } |
| 297 | |
| 298 | function kubio_get_editor_scripts( $skiped_handlers = array() ) { |
| 299 | $script_handles = kubio_get_frontend_scripts(); |
| 300 | |
| 301 | $wp_scripts = wp_scripts(); |
| 302 | foreach ( array_keys( $wp_scripts->registered ) as $handle ) { |
| 303 | if ( strpos( $handle, AssetsDependencyInjector::KUBIO_DEPENENCY_PREFIX ) === 0 ) { |
| 304 | array_unshift( $script_handles, $handle ); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | foreach ( $skiped_handlers as $index => $handler ) { |
| 309 | $handler = preg_replace( '#(.*?)-js-after#', '$1', $handler ); |
| 310 | $handler = preg_replace( '#(.*?)-js-before#', '$1', $handler ); |
| 311 | $handler = preg_replace( '#(.*?)-js-translations#', '$1', $handler ); |
| 312 | $handler = preg_replace( '#(.*?)-js-extra#', '$1', $handler ); |
| 313 | $skiped_handlers[ $index ] = $handler; |
| 314 | } |
| 315 | |
| 316 | $script = ''; |
| 317 | $done = wp_scripts()->done; |
| 318 | ob_start(); |
| 319 | wp_scripts()->done = $skiped_handlers; |
| 320 | wp_scripts()->do_items( $script_handles ); |
| 321 | wp_scripts()->done = $done; |
| 322 | $script = ob_get_clean(); |
| 323 | |
| 324 | return $script; |
| 325 | } |
| 326 | |
| 327 | function kubio_enqueue_editor_page_assets() { |
| 328 | // Editor default styles |
| 329 | wp_enqueue_media(); |
| 330 | wp_enqueue_style( 'wp-format-library' ); |
| 331 | wp_enqueue_style( 'kubio-format-library' ); |
| 332 | wp_enqueue_script( 'kubio-editor' ); |
| 333 | wp_enqueue_script( 'kubio-block-library' ); |
| 334 | wp_enqueue_style( 'kubio-admin-panel' ); |
| 335 | wp_enqueue_style( 'kubio-ai' ); |
| 336 | |
| 337 | wp_enqueue_style( 'kubio-editor' ); |
| 338 | wp_enqueue_style( 'kubio-icons' ); |
| 339 | wp_enqueue_style( 'kubio-advanced-panel' ); |
| 340 | wp_enqueue_style( 'kubio-block-library-editor' ); |
| 341 | wp_enqueue_style( 'kubio-controls' ); |
| 342 | wp_enqueue_style( 'kubio-utils' ); |
| 343 | wp_enqueue_style( 'kubio-scripts' ); |
| 344 | wp_enqueue_style( 'kubio-wp-global-styles' ); |
| 345 | |
| 346 | } |
| 347 | |
| 348 | function kubio_extend_block_editor_styles_html() { |
| 349 | $script = kubio_get_editor_scripts(); |
| 350 | $style = kubio_get_editor_style(); |
| 351 | $script = "<template id='kubio-scripts-template'>{$script}</template>"; |
| 352 | |
| 353 | printf( |
| 354 | '<script>window.__kubioEditorStyles = %s</script>', |
| 355 | wp_json_encode( array( 'html' => $style . $script ) ) |
| 356 | ); |
| 357 | |
| 358 | if ( function_exists( 'wp_add_iframed_editor_assets_html' ) ) { |
| 359 | wp_add_iframed_editor_assets_html(); |
| 360 | } |
| 361 | |
| 362 | } |
| 363 | |
| 364 | function kubio_edit_site_get_settings() { |
| 365 | $max_upload_size = wp_max_upload_size(); |
| 366 | if ( ! $max_upload_size ) { |
| 367 | $max_upload_size = 0; |
| 368 | } |
| 369 | |
| 370 | // This filter is documented in wp-admin/includes/media.php. |
| 371 | // This filter is documented in wp-admin/includes/media.php. |
| 372 | $image_size_names = apply_filters( |
| 373 | 'image_size_names_choose', |
| 374 | array( |
| 375 | 'thumbnail' => __( 'Thumbnail', 'kubio' ), |
| 376 | 'medium' => __( 'Medium', 'kubio' ), |
| 377 | 'large' => __( 'Large', 'kubio' ), |
| 378 | 'full' => __( 'Original Size', 'kubio' ), |
| 379 | ) |
| 380 | ); |
| 381 | $available_image_sizes = array(); |
| 382 | foreach ( $image_size_names as $image_size_slug => $image_size_name ) { |
| 383 | $available_image_sizes[] = array( |
| 384 | 'slug' => $image_size_slug, |
| 385 | 'name' => $image_size_name, |
| 386 | ); |
| 387 | } |
| 388 | |
| 389 | global $current_screen; |
| 390 | if ( function_exists( '_register_core_block_patterns_and_categories' ) ) { |
| 391 | _register_core_block_patterns_and_categories(); |
| 392 | } |
| 393 | |
| 394 | if ( function_exists( '_load_remote_block_patterns' ) ) { |
| 395 | _load_remote_block_patterns(); |
| 396 | } |
| 397 | |
| 398 | if ( function_exists( '_load_remote_featured_patterns' ) ) { |
| 399 | _load_remote_featured_patterns( $current_screen ); |
| 400 | } |
| 401 | |
| 402 | global $wp_version; |
| 403 | $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); |
| 404 | $settings = array_merge( |
| 405 | get_default_block_editor_settings(), |
| 406 | array( |
| 407 | 'alignWide' => true, //get_theme_support( 'align-wide' ), |
| 408 | 'siteUrl' => site_url( '/' ), |
| 409 | 'postsPerPage' => get_option( 'posts_per_page' ), |
| 410 | 'defaultTemplateTypes' => kubio_get_indexed_default_template_types(), |
| 411 | '__experimentalBlockPatterns' => array(), |
| 412 | '__experimentalBlockPatternCategories' => array_merge( |
| 413 | WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(), |
| 414 | kubio_get_patterns_categories() |
| 415 | ), |
| 416 | 'imageSizes' => $available_image_sizes, |
| 417 | 'isRTL' => is_rtl(), |
| 418 | 'maxUploadFileSize' => $max_upload_size, |
| 419 | |
| 420 | 'wpVersion' => preg_replace( '/([0-9]+).([0-9]+).*/', '$1.$2', $wp_version ), |
| 421 | ) |
| 422 | ); |
| 423 | |
| 424 | if ( function_exists( 'get_block_editor_settings' ) && class_exists( '\WP_Block_Editor_Context' ) ) { |
| 425 | $settings = get_block_editor_settings( $settings, $block_editor_context ); |
| 426 | } |
| 427 | |
| 428 | if ( function_exists( 'gutenberg_experimental_global_styles_settings' ) ) { |
| 429 | $settings = gutenberg_experimental_global_styles_settings( $settings ); |
| 430 | } |
| 431 | |
| 432 | $settings['state'] = array( |
| 433 | 'entity' => kubio_edit_site_get_edited_entity(), |
| 434 | ); |
| 435 | |
| 436 | $settings['kubioPrimaryMenuLocation'] = apply_filters( |
| 437 | 'kubio/primary_menu_location', |
| 438 | 'header-menu' |
| 439 | ); |
| 440 | |
| 441 | $settings['isKubioTheme'] = kubio_theme_has_kubio_block_support(); |
| 442 | |
| 443 | $settings['supportsTemplateMode'] = kubio_theme_has_block_templates_support(); |
| 444 | |
| 445 | global $post; |
| 446 | $settings = apply_filters( 'block_editor_settings_all', $settings, $post ); |
| 447 | $settings = apply_filters( 'kubio/block_editor_settings', $settings, $post ); |
| 448 | $settings['isWooCommerce'] = function_exists( 'WC' ); |
| 449 | |
| 450 | $settings['defaultTemplatePartAreas'] = kubio_get_allowed_template_part_areas(); |
| 451 | $settings['classicThemeTemplates'] = kubio_get_classic_theme_templates(); |
| 452 | $settings['kubioThemeAssetsUrlBase'] = untrailingslashit( apply_filters( 'kubio/importer/kubio-url-placeholder-replacement', '' ) ); |
| 453 | |
| 454 | // adding it here since `select('core').getCurrentTheme().theme_uri` returns an empty string. |
| 455 | $settings['themeUri'] = get_template_directory_uri(); |
| 456 | $settings['classicHasFrontPageTemplate'] = kubio_third_party_theme_has_front_page_template(); |
| 457 | $settings['classicThemePrimaryTemplates'] = array_keys( kubio_get_classic_theme_primary_templates() ); |
| 458 | |
| 459 | $scrollable_image_path = wp_get_theme()->get_file_path( 'resources/images/front-page-preview.jpg' ); |
| 460 | // Handle the Front page suggestion preview image |
| 461 | if ( file_exists( $scrollable_image_path ) ) { |
| 462 | $settings['kubioHasFpsScrollPreview'] = true; // 'resources/images/front-page-preview.jpg'; |
| 463 | } else { |
| 464 | $settings['kubioHasFpsScrollPreview'] = false; //'screenshot.jpg'; |
| 465 | } |
| 466 | |
| 467 | $settings['supportsLayout'] = isset( $settings['supportsLayout'] ) ? $settings['supportsLayout'] : false; |
| 468 | $layout = array_merge( array( 'contentSize' => '1172px' ), LodashBasic::get( $settings, '__experimentalFeatures.layout', array() ) ); |
| 469 | |
| 470 | LodashBasic::set( $settings, '__experimentalFeatures.layout', $layout ); |
| 471 | LodashBasic::set( $settings, '__experimentalFeatures.blocks.core/post-content.layout', $layout ); |
| 472 | |
| 473 | // use array_values to ensure that json_encode sees it as array not object |
| 474 | $styles = array_values( |
| 475 | array_merge( |
| 476 | function_exists( 'get_block_editor_theme_styles' ) ? get_block_editor_theme_styles() : array(), |
| 477 | array( |
| 478 | array( |
| 479 | 'css' => kubio_get_editor_style( true ), |
| 480 | '__unstableType' => 'theme', |
| 481 | ), |
| 482 | ) |
| 483 | ) |
| 484 | ); |
| 485 | |
| 486 | if ( function_exists( 'wp_get_global_stylesheet' ) ) { |
| 487 | $block_classes = array( |
| 488 | 'css' => 'base-layout-styles', |
| 489 | '__unstableType' => 'base-layout', |
| 490 | 'isGlobalStyles' => true, |
| 491 | ); |
| 492 | $actual_css = wp_get_global_stylesheet( array( $block_classes['css'] ) ); |
| 493 | |
| 494 | if ( $actual_css ) { |
| 495 | $block_classes['css'] = $actual_css; |
| 496 | $styles[] = $block_classes; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | $settings['styles'] = array_merge( $settings['styles'], $styles ); |
| 501 | |
| 502 | return $settings; |
| 503 | } |
| 504 | |
| 505 | function kubio_block_editor_general_settings( $settings ) { |
| 506 | $settings['__unstableEnableFullSiteEditingBlocks'] = true; |
| 507 | $settings['enableFSEBlocks'] = true; |
| 508 | $settings['kubioGlobalSettings'] = (object) Flags::getSettings(); |
| 509 | |
| 510 | // settings for outside Kubio editor |
| 511 | // __unstableResolvedAssets was added in WP 6.0 |
| 512 | if ( isset( $settings['__unstableResolvedAssets'] ) && ! kubio_is_kubio_editor_page() ) { |
| 513 | $current_style = Arr::get( $settings, '__unstableResolvedAssets.styles', '' ); |
| 514 | $current_scripts = Arr::get( $settings, '__unstableResolvedAssets.scripts', '' ); |
| 515 | |
| 516 | preg_match_all( "#id='(.*?)'#m", $current_style, $matches ); |
| 517 | $style_ids = Arr::get( $matches, 1, array() ); |
| 518 | |
| 519 | preg_match_all( "#id='(.*?)'#m", $current_scripts, $matches ); |
| 520 | $script_ids = Arr::get( $matches, 1, array() ); |
| 521 | |
| 522 | $style = array( |
| 523 | sprintf( '<style>%s</style>', kubio_render_global_colors() ), |
| 524 | kubio_get_editor_style( false, $style_ids ), |
| 525 | ); |
| 526 | |
| 527 | $script = kubio_get_editor_scripts( $script_ids ); |
| 528 | |
| 529 | Arr::set( |
| 530 | $settings, |
| 531 | '__unstableResolvedAssets.styles', |
| 532 | $current_style . "\n\n" . implode( "\n", $style ) |
| 533 | ); |
| 534 | |
| 535 | Arr::set( |
| 536 | $settings, |
| 537 | '__unstableResolvedAssets.scripts', |
| 538 | $current_scripts . "\n\n$script" |
| 539 | ); |
| 540 | |
| 541 | // kubio_enqueue_frontend_scripts(); |
| 542 | |
| 543 | } |
| 544 | |
| 545 | $settings['kubioLoaded'] = true; |
| 546 | |
| 547 | $settings['kubioThemesBaseURL'] = get_theme_root_uri(); |
| 548 | return $settings; |
| 549 | } |
| 550 | |
| 551 | add_filter( 'block_editor_settings_all', 'kubio_block_editor_general_settings', 50 ); |
| 552 | |
| 553 | function kubio_load_gutenberg_assets() { |
| 554 | |
| 555 | AssetsDependencyInjector::injectKubioScriptDependencies( 'swiper' ); |
| 556 | AssetsDependencyInjector::injectKubioFrontendStyleDependencies( 'swiper' ); |
| 557 | |
| 558 | AssetsDependencyInjector::injectKubioScriptDependencies( 'fancybox' ); |
| 559 | AssetsDependencyInjector::injectKubioFrontendStyleDependencies( 'fancybox' ); |
| 560 | |
| 561 | AssetsDependencyInjector::injectKubioScriptDependencies( 'typed' ); |
| 562 | AssetsDependencyInjector::injectKubioScriptDependencies( 'jquery-masonry', false ); |
| 563 | |
| 564 | wp_enqueue_style( 'kubio-pro' ); |
| 565 | |
| 566 | wp_enqueue_script( 'kubio-block-patterns' ); |
| 567 | wp_enqueue_script( 'kubio-third-party-blocks' ); |
| 568 | wp_localize_script( |
| 569 | 'kubio-block-patterns', |
| 570 | 'kubioBlockPatterns', |
| 571 | array( |
| 572 | 'inGutenbergEditor' => ! kubio_is_kubio_editor_page(), |
| 573 | ) |
| 574 | ); |
| 575 | |
| 576 | wp_add_inline_style( 'kubio-block-library', kubio_get_shapes_css() ); |
| 577 | } |
| 578 | |
| 579 | function kubio_get_post_types() { |
| 580 | $extra_types = get_post_types( |
| 581 | array( |
| 582 | '_builtin' => false, |
| 583 | 'public' => true, |
| 584 | ) |
| 585 | ); |
| 586 | |
| 587 | $types = array(); |
| 588 | global $wp_post_types; |
| 589 | |
| 590 | foreach ( $extra_types as $type ) { |
| 591 | $types[] = array( |
| 592 | 'entity' => $type, |
| 593 | 'kind' => 'postType', |
| 594 | 'title' => $wp_post_types[ $type ]->label, |
| 595 | ); |
| 596 | } |
| 597 | |
| 598 | return $types; |
| 599 | } |
| 600 | |
| 601 | add_action( 'enqueue_block_editor_assets', 'kubio_load_gutenberg_assets' ); |
| 602 | |
| 603 | |
| 604 | function kubio_add_endpoint_details( |
| 605 | $url, |
| 606 | $results_per_page = null |
| 607 | ) { |
| 608 | $vars = array( 'context' => 'edit' ); |
| 609 | if ( $results_per_page !== null ) { |
| 610 | $vars['per_page'] = $results_per_page; |
| 611 | } |
| 612 | return $url . '?' . build_query( $vars ); |
| 613 | } |
| 614 | |
| 615 | function kubio_edit_site_init( $hook ) { |
| 616 | if ( ! kubio_is_kubio_editor_page() ) { |
| 617 | return; |
| 618 | } |
| 619 | add_filter( 'use_block_editor_for_post_type', '__return_true' ); |
| 620 | |
| 621 | global $current_screen, $post; |
| 622 | $current_screen->is_block_editor( true ); |
| 623 | $active_theme = wp_get_theme()->get_stylesheet(); |
| 624 | |
| 625 | // Inline the Editor Settings |
| 626 | $settings = kubio_edit_site_get_settings(); |
| 627 | // Preload block editor paths. |
| 628 | // most of these are copied from edit-forms-blocks.php. |
| 629 | $preload_paths = array( |
| 630 | array( '/wp/v2/media', 'OPTIONS' ), |
| 631 | '/wp/v2/types?context=view', |
| 632 | '/wp/v2/types/wp_template?context=edit', |
| 633 | '/wp/v2/types/wp_template-part?context=edit', |
| 634 | '/wp/v2/templates?context=edit&per_page=-1', |
| 635 | '/wp/v2/template-parts?context=edit&per_page=-1', |
| 636 | '/wp/v2/themes?context=edit&status=active', |
| 637 | '/wp/v2/users/me', |
| 638 | |
| 639 | // contact and subscribe |
| 640 | '/kubio/v1/contact-form/forms_by_type', |
| 641 | '/kubio/v1/subscribe-form/forms_by_type', |
| 642 | |
| 643 | // menu locations and menus |
| 644 | '/__experimental/menu-locations?context=edit', |
| 645 | '/wp/v2/menu-locations?context=edit', |
| 646 | '/wp/v2/users/me?context=edit', |
| 647 | |
| 648 | // taxonimies |
| 649 | '/wp/v2/taxonomies?context=view', |
| 650 | |
| 651 | // global data |
| 652 | '/wp/v2/kubio/global-data/' . kubio_global_data_post_id(), |
| 653 | array( '/wp/v2/kubio/global-data/' . kubio_global_data_post_id(), 'OPTIONS' ), |
| 654 | '/wp/v2/kubio/global-data/' . kubio_global_data_post_id() . '?context=edit', |
| 655 | |
| 656 | // general |
| 657 | '/wp/v2/settings', |
| 658 | array( '/wp/v2/settings', 'OPTIONS' ), |
| 659 | |
| 660 | kubio_add_endpoint_details( "/wp/v2/template-parts/{$active_theme}//footer" ), |
| 661 | kubio_add_endpoint_details( "/wp/v2/template-parts/{$active_theme}//front-header" ), |
| 662 | kubio_add_endpoint_details( "/wp/v2/templates/{$active_theme}//front-page" ), |
| 663 | kubio_add_endpoint_details( "/wp/v2/templates/{$active_theme}//full-width" ), |
| 664 | kubio_add_endpoint_details( "/wp/v2/templates/{$active_theme}//front-page" ), |
| 665 | |
| 666 | ); |
| 667 | |
| 668 | // try to preload current page |
| 669 | |
| 670 | $wp_global_style = 0; |
| 671 | if ( class_exists( '\WP_Theme_JSON_Resolver' ) && method_exists( WP_Theme_JSON_Resolver::class, 'get_user_global_styles_post_id' ) ) { |
| 672 | $wp_global_style = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); |
| 673 | } |
| 674 | if ( $wp_global_style ) { |
| 675 | $preload_paths = array_merge( |
| 676 | $preload_paths, |
| 677 | array( |
| 678 | '/wp/v2/global-styles/' . $wp_global_style . '?context=edit', |
| 679 | '/wp/v2/global-styles/' . $wp_global_style, |
| 680 | '/wp/v2/global-styles/themes/' . $active_theme, |
| 681 | ) |
| 682 | ); |
| 683 | } |
| 684 | |
| 685 | // menus |
| 686 | $menus = wp_get_nav_menus(); |
| 687 | foreach ( $menus as $menu_term ) { |
| 688 | $preload_paths[] = "/kubio/v1/menu/{$menu_term->term_id}"; |
| 689 | $preload_paths[] = "/kubio/v1/menu/{$menu_term->term_id}?context=edit"; |
| 690 | } |
| 691 | |
| 692 | $preload_data = array_reduce( |
| 693 | $preload_paths, |
| 694 | 'rest_preload_api_request', |
| 695 | array() |
| 696 | ); |
| 697 | |
| 698 | // prepare editor context |
| 699 | $editor_context_props = array( 'name' => 'core/edit-site' ); |
| 700 | $query_post_id = Arr::get( $_REQUEST, 'postId', null ); |
| 701 | $query_post_type = Arr::get( $_REQUEST, 'postType', null ); |
| 702 | $page_on_front = get_option( 'page_on_front', null ); |
| 703 | $post_to_load = null; |
| 704 | |
| 705 | if ( ! $query_post_id && ! $query_post_type ) { |
| 706 | if ( $page_on_front ) { |
| 707 | $post_to_load = get_post( $page_on_front ); |
| 708 | if ( is_wp_error( $post_to_load ) ) { |
| 709 | $post_to_load = null; |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | if ( $query_post_type && $query_post_id ) { |
| 715 | if ( is_numeric( $query_post_id ) ) { |
| 716 | $post_to_load = get_post( $query_post_id ); |
| 717 | if ( is_wp_error( $post_to_load ) ) { |
| 718 | $post_to_load = null; |
| 719 | } |
| 720 | } else { |
| 721 | $post_to_load = kubio_get_block_template( $query_post_id, $query_post_type ); |
| 722 | |
| 723 | if ( ! $post_to_load || is_wp_error( $post_to_load ) ) { |
| 724 | $post_to_load = null; |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | if ( $post_to_load ) { |
| 730 | $post_to_load_type = property_exists( $post_to_load, 'type' ) ? $post_to_load->type : $post_to_load->post_type; |
| 731 | $post_to_load_id = property_exists( $post_to_load, 'wp_id' ) ? $post_to_load->wp_id : $post_to_load->ID; |
| 732 | |
| 733 | $editor_context_props['post'] = get_post( $post_to_load_id ); |
| 734 | $rest_path = rest_get_route_for_post( $post_to_load_id ); |
| 735 | $preload_paths[] = $rest_path; |
| 736 | $preload_paths[] = add_query_arg( 'context', 'edit', $rest_path ); |
| 737 | $preload_paths[] = sprintf( '/wp/v2/types/%s?context=edit', $post_to_load_type ); |
| 738 | } |
| 739 | |
| 740 | $block_editor_context = new \WP_Block_Editor_Context( $editor_context_props ); |
| 741 | |
| 742 | if ( function_exists( 'block_editor_rest_api_preload' ) ) { |
| 743 | block_editor_rest_api_preload( $preload_paths, $block_editor_context ); |
| 744 | } else { |
| 745 | wp_add_inline_script( |
| 746 | 'wp-api-fetch', |
| 747 | sprintf( |
| 748 | 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', |
| 749 | wp_json_encode( $preload_data ) |
| 750 | ), |
| 751 | 'after' |
| 752 | ); |
| 753 | } |
| 754 | |
| 755 | $server_side_settings = get_block_editor_server_block_settings(); |
| 756 | foreach ( array_keys( $server_side_settings ) as $server_side_block_name ) { |
| 757 | if ( strpos( $server_side_block_name, 'kubio/' ) === 0 ) { |
| 758 | unset( $server_side_settings[ $server_side_block_name ] ); |
| 759 | } |
| 760 | } |
| 761 | wp_add_inline_script( |
| 762 | 'wp-blocks', |
| 763 | sprintf( |
| 764 | 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions( %s );', |
| 765 | wp_json_encode( $server_side_settings ) |
| 766 | ), |
| 767 | 'after' |
| 768 | ); |
| 769 | |
| 770 | wp_add_inline_script( |
| 771 | 'wp-blocks', |
| 772 | sprintf( |
| 773 | 'wp.blocks.setCategories( %s );', |
| 774 | wp_json_encode( get_block_categories( $post ) ) |
| 775 | ), |
| 776 | 'after' |
| 777 | ); |
| 778 | |
| 779 | kubio_enqueue_editor_page_assets(); |
| 780 | $settings['postTypes'] = kubio_get_post_types(); |
| 781 | |
| 782 | $ai_hash = Flags::get( 'start_with_ai_hash', null ); |
| 783 | $ai_hash_param = Arr::get( $_REQUEST, 'ai', null ); |
| 784 | |
| 785 | $settings['startWithAIFrontPage'] = ( $ai_hash && $ai_hash_param && $ai_hash_param === $ai_hash ); |
| 786 | |
| 787 | if ( isset( $_REQUEST['generate-ai-frontpage'] ) && ! Flags::get( 'generated_from_getting_started', false ) ) { |
| 788 | $settings['startGeneratingAIFrontPage'] = true; |
| 789 | Flags::set( 'generated_from_getting_started', true ); |
| 790 | } |
| 791 | |
| 792 | wp_add_inline_script( |
| 793 | 'kubio-editor', |
| 794 | sprintf( |
| 795 | "window.kubioEditSiteSettings = %s;\n" . |
| 796 | 'wp.domReady( function() { kubio.editor.initialize( "kubio-editor", window.kubioEditSiteSettings ); } );', |
| 797 | wp_json_encode( $settings ) |
| 798 | ), |
| 799 | 'after' |
| 800 | ); |
| 801 | |
| 802 | wp_add_inline_style( 'kubio-editor', kubio_get_shapes_css() ); |
| 803 | wp_add_inline_style( 'kubio-editor', kubio_render_global_colors() ); |
| 804 | |
| 805 | add_action( 'admin_footer', 'kubio_extend_block_editor_styles_html' ); |
| 806 | do_action( 'enqueue_block_editor_assets' ); |
| 807 | do_action( 'kubio/editor/enqueue_assets' ); |
| 808 | |
| 809 | $editor_styles = function_exists( 'get_editor_stylesheets' ) ? get_editor_stylesheets() : null; |
| 810 | if ( |
| 811 | current_theme_supports( 'wp-block-styles' ) || |
| 812 | ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) |
| 813 | ) { |
| 814 | wp_enqueue_style( 'wp-block-library-theme' ); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | add_action( 'admin_enqueue_scripts', 'kubio_edit_site_init' ); |
| 819 | |
| 820 | // Add tinymce scripts within the Kubio Editor and WordPress Editor since we need them in blocks like Subscribe form. |
| 821 | // we use the `enqueue_block_editor_assets` action since it is called in both editors. |
| 822 | add_action( |
| 823 | 'enqueue_block_editor_assets', |
| 824 | function () { |
| 825 | wp_enqueue_script( 'wp-tinymce' ); |
| 826 | wp_enqueue_editor(); |
| 827 | wp_enqueue_code_editor( array() ); |
| 828 | wp_tinymce_inline_scripts(); |
| 829 | } |
| 830 | ); |
| 831 | |
| 832 | /** |
| 833 | * Renders the Menu Page |
| 834 | * |
| 835 | * @return void |
| 836 | */ |
| 837 | function kubio_edit_site_render_block_editor() { |
| 838 | ?> |
| 839 | <style> |
| 840 | div#wpcontent, |
| 841 | #wpbody-content { |
| 842 | position: fixed; |
| 843 | z-index: 1000000; |
| 844 | width: 100vw; |
| 845 | height: 100vh; |
| 846 | background: #fff; |
| 847 | top: 0%; |
| 848 | left: 0%; |
| 849 | right: 0; |
| 850 | border: 0; |
| 851 | display: block; |
| 852 | box-sizing: border-box; |
| 853 | } |
| 854 | |
| 855 | #wp-link-backdrop { |
| 856 | z-index: 1000050; |
| 857 | } |
| 858 | |
| 859 | #wp-link-wrap { |
| 860 | z-index: 1000100; |
| 861 | } |
| 862 | |
| 863 | #kubio-editor { |
| 864 | position: absolute; |
| 865 | top: 0; |
| 866 | bottom: 0; |
| 867 | left: 0; |
| 868 | right: 0; |
| 869 | z-index: 1000; |
| 870 | width: 100%; |
| 871 | height: 100%; |
| 872 | } |
| 873 | |
| 874 | .kubio-loading-editor { |
| 875 | position: absolute; |
| 876 | top: 50%; |
| 877 | left: 50%; |
| 878 | display: block; |
| 879 | font-size: 1.5em; |
| 880 | transform: translate(-50%, -50%); |
| 881 | } |
| 882 | |
| 883 | .kubio-loading-editor iframe { |
| 884 | margin: 0px auto 0px auto; |
| 885 | } |
| 886 | </style> |
| 887 | <div id="kubio-editor" class="kubio"> |
| 888 | <div class="kubio-loading-editor"> |
| 889 | <?php echo kubio_get_iframe_loader( array( 'size' => '120px' ) ); ?> |
| 890 | </div> |
| 891 | </div> |
| 892 | <?php |
| 893 | } |
| 894 | |
| 895 | /** |
| 896 | * Registers the new WP Admin Menu |
| 897 | * |
| 898 | * @return void |
| 899 | */ |
| 900 | function kubio_edit_site_add_menu_page() { |
| 901 | |
| 902 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | add_menu_page( |
| 907 | __( 'Kubio', 'kubio' ), |
| 908 | sprintf( |
| 909 | '<span class="kubio-menu-item"><span class="kubio-menu-item--icon">%s</span><span>%s</span></span>', |
| 910 | wp_kses_post( KUBIO_LOGO_SVG ), |
| 911 | __( 'Kubio', 'kubio' ) |
| 912 | ), |
| 913 | 'edit_posts', |
| 914 | 'kubio', |
| 915 | 'kubio_edit_site_render_block_editor', |
| 916 | 'data:image/svg+xml;base64,' . base64_encode( str_replace( '<svg', '<svg fill="#5246F1" ', KUBIO_LOGO_SVG ) ), |
| 917 | 20 |
| 918 | ); |
| 919 | |
| 920 | add_submenu_page( |
| 921 | 'themes.php', |
| 922 | __( 'Kubio', 'kubio' ), |
| 923 | __( 'Edit with Kubio', 'kubio' ), |
| 924 | 'edit_posts', |
| 925 | 'kubio_appearance_edit', |
| 926 | 'kubio_edit_site_render_block_editor', |
| 927 | 1 |
| 928 | ); |
| 929 | |
| 930 | global $submenu; |
| 931 | |
| 932 | if ( isset( $submenu['themes.php'] ) ) { |
| 933 | foreach ( $submenu['themes.php'] as $index => $submenu_item ) { |
| 934 | if ( $submenu_item[2] === 'kubio_appearance_edit' ) { |
| 935 | $submenu['themes.php'][ $index ][2] = Utils::kubioGetEditorURL(); |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | function kubio_admin_page_submenu_hook() { |
| 942 | global $submenu; |
| 943 | |
| 944 | $kubio_submenu = Arr::get( $submenu, 'kubio', null ); |
| 945 | |
| 946 | if ( is_array( $kubio_submenu ) ) { |
| 947 | foreach ( $kubio_submenu as $index => $submenu_data ) { |
| 948 | $menu_slug = Arr::get( $submenu_data, '2', null ); |
| 949 | if ( $menu_slug === 'kubio' ) { |
| 950 | $submenu['kubio'][ $index ][0] = __( 'Open Kubio Editor', 'kubio' ); |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | add_action( 'admin_menu', 'kubio_admin_page_submenu_hook', 200 ); |
| 957 | |
| 958 | add_action( 'admin_menu', 'kubio_edit_site_add_menu_page' ); |
| 959 | |
| 960 | function kubio_admin_menu_style() { |
| 961 | ?> |
| 962 | <style> |
| 963 | #adminmenu .toplevel_page_kubio .wp-menu-image { |
| 964 | display: none; |
| 965 | } |
| 966 | |
| 967 | .wp-admin.folded #adminmenu .toplevel_page_kubio .wp-menu-image { |
| 968 | display: block; |
| 969 | background-size: 16px auto; |
| 970 | } |
| 971 | |
| 972 | #adminmenu .kubio-menu-item { |
| 973 | display: flex; |
| 974 | align-items: center; |
| 975 | } |
| 976 | |
| 977 | #adminmenu .kubio-menu-item>span { |
| 978 | display: block; |
| 979 | line-height: 1; |
| 980 | } |
| 981 | |
| 982 | #adminmenu .kubio-menu-item--icon { |
| 983 | color: rgba(240, 246, 252, .6); |
| 984 | } |
| 985 | |
| 986 | #adminmenu .wp-menu-name:hover .kubio-menu-item--icon { |
| 987 | color: inherit; |
| 988 | } |
| 989 | |
| 990 | #adminmenu .kubio-menu-item--icon svg { |
| 991 | fill: currentColor; |
| 992 | height: 15px; |
| 993 | margin-right: 11px; |
| 994 | } |
| 995 | |
| 996 | #adminmenu .wp-menu-open .kubio-menu-item--icon svg { |
| 997 | fill: #fff; |
| 998 | } |
| 999 | |
| 1000 | #adminmenu .toplevel_page_kubio div.wp-menu-name { |
| 1001 | padding: 8px 8px 8px 10px; |
| 1002 | } |
| 1003 | |
| 1004 | #adminmenu .wp-submenu .kubio-menu-item--icon { |
| 1005 | display: none; |
| 1006 | } |
| 1007 | </style> |
| 1008 | <?php |
| 1009 | } |
| 1010 | |
| 1011 | add_action( 'admin_head', 'kubio_admin_menu_style' ); |
| 1012 | |
| 1013 | /** |
| 1014 | * Register a core site setting for front page information. |
| 1015 | */ |
| 1016 | function kubio_register_site_editor_homepage_settings() { |
| 1017 | global $wp_registered_settings; |
| 1018 | |
| 1019 | if ( ! isset( $wp_registered_settings['show_on_front'] ) ) { |
| 1020 | register_setting( |
| 1021 | 'reading', |
| 1022 | 'show_on_front', |
| 1023 | array( |
| 1024 | 'show_in_rest' => true, |
| 1025 | 'type' => 'string', |
| 1026 | 'description' => __( 'What to show on the front page', 'kubio' ), |
| 1027 | ) |
| 1028 | ); |
| 1029 | } |
| 1030 | |
| 1031 | if ( ! isset( $wp_registered_settings['page_on_front'] ) ) { |
| 1032 | register_setting( |
| 1033 | 'reading', |
| 1034 | 'page_on_front', |
| 1035 | array( |
| 1036 | 'show_in_rest' => true, |
| 1037 | 'type' => 'number', |
| 1038 | 'description' => __( |
| 1039 | 'The ID of the page that should be displayed on the front page', |
| 1040 | 'kubio' |
| 1041 | ), |
| 1042 | ) |
| 1043 | ); |
| 1044 | } |
| 1045 | if ( ! isset( $wp_registered_settings['page_for_posts'] ) ) { |
| 1046 | register_setting( |
| 1047 | 'reading', |
| 1048 | 'page_for_posts', |
| 1049 | array( |
| 1050 | 'show_in_rest' => true, |
| 1051 | 'type' => 'number', |
| 1052 | 'description' => __( |
| 1053 | 'The ID of the page that displays the posts', |
| 1054 | 'kubio' |
| 1055 | ), |
| 1056 | ) |
| 1057 | ); |
| 1058 | } |
| 1059 | |
| 1060 | if ( ! isset( $wp_registered_settings['site_icon'] ) ) { |
| 1061 | register_setting( |
| 1062 | 'general', |
| 1063 | 'site_icon', |
| 1064 | array( |
| 1065 | 'show_in_rest' => array( |
| 1066 | 'name' => 'site_icon', |
| 1067 | ), |
| 1068 | 'type' => 'integer', |
| 1069 | 'description' => __( 'Site icon.', 'kubio' ), |
| 1070 | ) |
| 1071 | ); |
| 1072 | } |
| 1073 | |
| 1074 | if ( class_exists( 'Jetpack_Notifications' ) ) { |
| 1075 | remove_action( 'wp_head', array( Jetpack_Notifications::init(), 'styles_and_scripts' ), 120 ); |
| 1076 | remove_action( 'admin_head', array( Jetpack_Notifications::init(), 'styles_and_scripts' ) ); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | add_action( 'init', 'kubio_register_site_editor_homepage_settings', 100 ); |
| 1081 | |
| 1082 | function kubio_editor_add_default_template_types( $template_types ) { |
| 1083 | if ( kubio_is_kubio_editor_page() && is_user_logged_in() ) { |
| 1084 | $kubio_templates = array( |
| 1085 | 'full-width' => array( |
| 1086 | 'title' => _x( 'Full Width', 'Template name', 'kubio' ), |
| 1087 | 'description' => __( |
| 1088 | 'Recommended Kubio template to display individual pages. This template works best with the Kubio provided blocks and predesigned sections.', |
| 1089 | 'kubio' |
| 1090 | ), |
| 1091 | ), |
| 1092 | 'kubio-full-width' => array( |
| 1093 | 'title' => _x( 'Kubio Full Width', 'Template name', 'kubio' ), |
| 1094 | 'description' => __( |
| 1095 | 'Recommended Kubio template to display individual pages. This template works best with the Kubio provided blocks and predesigned sections.', |
| 1096 | 'kubio' |
| 1097 | ), |
| 1098 | ), |
| 1099 | ); |
| 1100 | |
| 1101 | foreach ( $kubio_templates as $slug => $settings ) { |
| 1102 | $template_types[ $slug ] = $settings; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | return $template_types; |
| 1107 | } |
| 1108 | |
| 1109 | add_filter( 'default_template_types', 'kubio_editor_add_default_template_types' ); |
| 1110 | |
| 1111 | add_action( |
| 1112 | 'init', |
| 1113 | function () { |
| 1114 | if ( kubio_is_kubio_editor_page() && is_user_logged_in() ) { |
| 1115 | $has_valid_req = Utils::validateRequirements(); |
| 1116 | |
| 1117 | if ( is_wp_error( $has_valid_req ) ) { |
| 1118 | ob_start(); |
| 1119 | ?> |
| 1120 | <style> |
| 1121 | body#error-page { |
| 1122 | margin: 0; |
| 1123 | position: absolute; |
| 1124 | top: 50%; |
| 1125 | left: 50%; |
| 1126 | transform: translate(-50%, -50%); |
| 1127 | border-left: 4px solid #fb3e41; |
| 1128 | padding-top: 0; |
| 1129 | padding-bottom: 0; |
| 1130 | } |
| 1131 | |
| 1132 | body#error-page .kubio-mrn { |
| 1133 | flex-direction: column; |
| 1134 | align-items: flex-start; |
| 1135 | } |
| 1136 | |
| 1137 | body#error-page .kubio-mrn-icon-holder { |
| 1138 | padding-bottom: 12px; |
| 1139 | } |
| 1140 | |
| 1141 | body#error-page br { |
| 1142 | display: none; |
| 1143 | } |
| 1144 | |
| 1145 | p { |
| 1146 | margin: 12px 0 0 0; |
| 1147 | } |
| 1148 | |
| 1149 | body#error-page a { |
| 1150 | margin-top: 16px; |
| 1151 | display: block; |
| 1152 | } |
| 1153 | |
| 1154 | #error-page p.kubio-mrn-rollback-message>a { |
| 1155 | display: inline; |
| 1156 | } |
| 1157 | </style> |
| 1158 | <?php |
| 1159 | _kubio_requirements_not_met_notice(); |
| 1160 | $content = ob_get_clean(); |
| 1161 | wp_die( $content ); |
| 1162 | } |
| 1163 | |
| 1164 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
| 1165 | wp_die( |
| 1166 | '<h1>' . __( 'You need a higher level of permission.', 'kubio' ) . '</h1>' . |
| 1167 | '<p>' . __( 'Sorry, you are not allowed to customize this site.', 'kubio' ) . '</p>', |
| 1168 | 403 |
| 1169 | ); |
| 1170 | } |
| 1171 | } |
| 1172 | }, |
| 1173 | 5 |
| 1174 | ); |
| 1175 | |
| 1176 | /** |
| 1177 | * Registers block editor 'kubio_section' post type. |
| 1178 | */ |
| 1179 | function kubio_register_kubio_section_post_type() { |
| 1180 | if ( post_type_exists( 'kubio_section' ) ) { |
| 1181 | return; |
| 1182 | } |
| 1183 | |
| 1184 | $args = array( |
| 1185 | 'label' => __( 'Kubio Section', 'kubio' ), |
| 1186 | 'public' => false, |
| 1187 | 'show_ui' => false, |
| 1188 | 'show_in_rest' => true, |
| 1189 | 'show_in_menu' => false, |
| 1190 | 'show_in_nav_menus' => false, |
| 1191 | 'rewrite' => false, |
| 1192 | 'exclude_from_search' => true, |
| 1193 | 'publicly_queryable' => false, |
| 1194 | 'rest_base' => 'kubio_section', |
| 1195 | 'capabilities' => array( |
| 1196 | 'read' => 'edit_theme_options', |
| 1197 | 'create_posts' => 'edit_theme_options', |
| 1198 | 'edit_posts' => 'edit_theme_options', |
| 1199 | 'edit_published_posts' => 'edit_theme_options', |
| 1200 | 'delete_published_posts' => 'edit_theme_options', |
| 1201 | 'edit_others_posts' => 'edit_theme_options', |
| 1202 | 'delete_others_posts' => 'edit_theme_options', |
| 1203 | ), |
| 1204 | 'map_meta_cap' => true, |
| 1205 | 'supports' => array( |
| 1206 | 'title', |
| 1207 | 'editor', |
| 1208 | 'revisions', |
| 1209 | ), |
| 1210 | ); |
| 1211 | |
| 1212 | register_post_type( 'kubio_section', $args ); |
| 1213 | } |
| 1214 | |
| 1215 | add_action( 'init', 'kubio_register_kubio_section_post_type', 9 ); |
| 1216 | |
| 1217 | |
| 1218 | /** |
| 1219 | * Registers block editor 'kubio_section' post type. |
| 1220 | */ |
| 1221 | function kubio_register_kubio_favorites_post_type() { |
| 1222 | if ( post_type_exists( 'kubio_favorites' ) ) { |
| 1223 | return; |
| 1224 | } |
| 1225 | |
| 1226 | $args = array( |
| 1227 | 'label' => __( 'Kubio Favorites', 'kubio' ), |
| 1228 | 'public' => false, |
| 1229 | 'show_ui' => false, |
| 1230 | 'show_in_rest' => true, |
| 1231 | 'show_in_menu' => false, |
| 1232 | 'show_in_nav_menus' => false, |
| 1233 | 'rewrite' => false, |
| 1234 | 'exclude_from_search' => true, |
| 1235 | 'publicly_queryable' => false, |
| 1236 | 'rest_base' => 'kubio_favorites', |
| 1237 | 'capabilities' => array( |
| 1238 | 'read' => 'edit_theme_options', |
| 1239 | 'create_posts' => 'edit_theme_options', |
| 1240 | 'edit_posts' => 'edit_theme_options', |
| 1241 | 'edit_published_posts' => 'edit_theme_options', |
| 1242 | 'delete_published_posts' => 'edit_theme_options', |
| 1243 | 'edit_others_posts' => 'edit_theme_options', |
| 1244 | 'delete_others_posts' => 'edit_theme_options', |
| 1245 | ), |
| 1246 | 'map_meta_cap' => true, |
| 1247 | 'supports' => array( |
| 1248 | 'title', |
| 1249 | 'editor', |
| 1250 | 'revisions', |
| 1251 | ), |
| 1252 | 'can_export' => false, |
| 1253 | ); |
| 1254 | |
| 1255 | register_post_type( 'kubio_favorites', $args ); |
| 1256 | } |
| 1257 | |
| 1258 | add_action( 'init', 'kubio_register_kubio_favorites_post_type', 9 ); |
| 1259 |