PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.5
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.5
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / widgets / gutenberg / lib / experimental / block-editor-settings.php
widget-options / includes / widgets / gutenberg / lib / experimental Last commit date
fonts-api 2 years ago interactivity-api 2 years ago block-editor-settings-mobile.php 2 years ago block-editor-settings.php 2 years ago blocks.php 2 years ago class-gutenberg-rest-global-styles-revisions-controller.php 2 years ago class-wp-classic-to-block-menu-converter.php 2 years ago class-wp-navigation-fallback-gutenberg.php 2 years ago class-wp-rest-block-editor-settings-controller.php 2 years ago class-wp-rest-customizer-nonces.php 2 years ago class-wp-rest-navigation-fallback-controller.php 2 years ago editor-settings.php 2 years ago kses.php 2 years ago l10n.php 2 years ago navigation-fallback.php 2 years ago navigation-theme-opt-in.php 2 years ago rest-api.php 2 years ago
block-editor-settings.php
90 lines
1 <?php
2 /**
3 * Adds settings to the block editor.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Finds the first occurrence of a specific block in an array of blocks.
10 *
11 * @param string $block_name Name of the block to find.
12 * @param array $blocks Array of blocks.
13 * @return array Found block, or empty array if none found.
14 */
15 function gutenberg_find_first_block( $block_name, $blocks ) {
16 foreach ( $blocks as $block ) {
17 if ( $block_name === $block['blockName'] ) {
18 return $block;
19 }
20 if ( ! empty( $block['innerBlocks'] ) ) {
21 $found_block = gutenberg_find_first_block( $block_name, $block['innerBlocks'] );
22
23 if ( ! empty( $found_block ) ) {
24 return $found_block;
25 }
26 }
27 }
28
29 return array();
30 }
31
32 /**
33 * Adds styles and __experimentalFeatures to the block editor settings.
34 *
35 * @param array $settings Existing block editor settings.
36 *
37 * @return array New block editor settings.
38 */
39 function gutenberg_get_block_editor_settings_experimental( $settings ) {
40 $is_block_theme = wp_is_block_theme();
41
42 global $post_ID;
43
44 if ( ! $is_block_theme || ! $post_ID ) {
45 return $settings;
46 }
47
48 $template_slug = get_page_template_slug( $post_ID );
49
50 if ( ! $template_slug ) {
51 $post_slug = 'singular';
52 $page_slug = 'singular';
53 $template_types = get_block_templates();
54
55 foreach ( $template_types as $template_type ) {
56 if ( 'page' === $template_type->slug ) {
57 $page_slug = 'page';
58 }
59 if ( 'single' === $template_type->slug ) {
60 $post_slug = 'single';
61 }
62 }
63
64 $what_post_type = get_post_type( $post_ID );
65 switch ( $what_post_type ) {
66 case 'page':
67 $template_slug = $page_slug;
68 break;
69 default:
70 $template_slug = $post_slug;
71 break;
72 }
73 }
74
75 $current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) );
76
77 if ( ! empty( $current_template ) ) {
78 $template_blocks = parse_blocks( $current_template[0]->content );
79 $post_content_block = gutenberg_find_first_block( 'core/post-content', $template_blocks );
80
81 if ( ! empty( $post_content_block['attrs'] ) ) {
82 $settings['postContentAttributes'] = $post_content_block['attrs'];
83 }
84 }
85
86 return $settings;
87 }
88
89 add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_experimental', PHP_INT_MAX );
90