PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.7
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.7
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 1 year ago interactivity-api 1 year ago block-editor-settings-mobile.php 1 year ago block-editor-settings.php 1 year ago blocks.php 1 year ago class-gutenberg-rest-global-styles-revisions-controller.php 1 year ago class-wp-classic-to-block-menu-converter.php 1 year ago class-wp-navigation-fallback-gutenberg.php 1 year ago class-wp-rest-block-editor-settings-controller.php 1 year ago class-wp-rest-customizer-nonces.php 1 year ago class-wp-rest-navigation-fallback-controller.php 1 year ago editor-settings.php 1 year ago kses.php 1 year ago l10n.php 1 year ago navigation-fallback.php 1 year ago navigation-theme-opt-in.php 1 year ago rest-api.php 1 year 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