array( 'isGutenberg' => true, 'isBlockEditor' => true, 'isPage' => $pagenow == 'post.php' || $pagenow == 'post-new.php', 'isPostType' => get_post_type(), ), ) ); if (function_exists('\register_block_type')) { \register_block_type( 'fluent-community/page-layout', array( 'api_version' => '3', // WP core uses int but stub declares string 'editor_script' => 'custom-layout-block-editor', 'editor_style' => 'custom-layout-block-editor-style', 'style' => 'fluent_community_global', 'render_callback' => [$this, 'render'], 'supports' => [ 'html' => false ], 'attributes' => array( 'showPageHeader' => array( 'type' => 'boolean', 'default' => true, ), 'useFullWidth' => array( 'type' => 'boolean', 'default' => false, ), 'hideCommunityHeader' => array( 'type' => 'boolean', 'default' => false, ), 'useBuildInTheme' => array( 'type' => 'boolean', 'default' => true, ), ), ) ); } $this->registerBuiltInTemplate(); } private function registerBuiltInTemplate() { if (!wp_is_block_theme() || !function_exists('\register_block_template')) { return; } $supportedPostTypes = apply_filters('fluent_communuty/block_templates_post_types', ['page', 'post']); register_block_template('fluent-community//frame-template', [ 'title' => __('FluentCommunity Page Template', 'fluent-community'), 'description' => __('A Page Template that render your WP content into FluentCommunity UI Frame', 'fluent-community'), 'content' => '', 'post_types' => $supportedPostTypes ]); add_filter('get_block_templates', function ($templates) { if (isset($templates['fluent-community//frame-template'])) { return array_values($templates); } return $templates; }); } public function render($attributes, $content) { static $isLoaded; if ($isLoaded) { return esc_html__('Layout is already loaded before', 'fluent-community'); } if (!$isLoaded) { $isLoaded = true; } $contenx = 'wp'; if (isset($_REQUEST['context']) && $_REQUEST['context'] == 'edit' && Helper::isSiteAdmin()) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $contenx = 'block_editor'; } $useBuildInTheme = $attributes['useBuildInTheme'] ?? false; do_action('fluent_community/enqueue_global_assets', $useBuildInTheme); $useFullWidth = $attributes['useFullWidth'] ?? true; $hideCommunityHeader = false; $className = Arr::get($attributes, 'className', ''); $widthClass = $useFullWidth ? 'fcom_template_full' : 'fcom_template_standard'; $disableDarkMode = Arr::has($attributes, 'disableDarkMode'); if ($disableDarkMode) { add_filter('body_class', function ($classes) { $classes[] = 'fcom_disable_dark_mode'; return $classes; }); } else if (Helper::hasColorScheme()) { add_action('wp_head', function () { Helper::renderColorSchemePrePaintScript(); }); } ob_start(); ?>