PluginProbe
Gutenberg / 13.5.2
Gutenberg v13.5.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / experiments-page.php

experiments-page.php in Gutenberg 13.5.2, at lib/experiments-page.php

122 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bootstrapping the Gutenberg experiments page.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * The main entry point for the Gutenberg experiments page.
10 *
11 * @since 6.3.0
12 */
13 function the_gutenberg_experiments() {
14 ?>
15 <div
16 id="experiments-editor"
17 class="wrap"
18 >
19 <h1><?php echo __( 'Experimental settings', 'gutenberg' ); ?></h1>
20 <?php settings_errors(); ?>
21 <form method="post" action="options.php">
22 <?php settings_fields( 'gutenberg-experiments' ); ?>
23 <?php do_settings_sections( 'gutenberg-experiments' ); ?>
24 <?php submit_button(); ?>
25 </form>
26 </div>
27 <?php
28 }
29
30 /**
31 * Set up the experiments settings.
32 *
33 * @since 6.3.0
34 */
35 function gutenberg_initialize_experiments_settings() {
36 add_settings_section(
37 'gutenberg_experiments_section',
38 // The empty string ensures the render function won't output a h2.
39 '',
40 'gutenberg_display_experiment_section',
41 'gutenberg-experiments'
42 );
43
44 add_settings_field(
45 'gutenberg-list-v2',
46 __( 'List block v2', 'gutenberg' ),
47 'gutenberg_display_experiment_field',
48 'gutenberg-experiments',
49 'gutenberg_experiments_section',
50 array(
51 'label' => __( 'Test a new list block that uses nested list item blocks (Warning: The new block is not ready. You may experience content loss, avoid using it on production sites)', 'gutenberg' ),
52 'id' => 'gutenberg-list-v2',
53 )
54 );
55 add_settings_field(
56 'gutenberg-quote-v2',
57 __( 'Quote block v2', 'gutenberg' ),
58 'gutenberg_display_experiment_field',
59 'gutenberg-experiments',
60 'gutenberg_experiments_section',
61 array(
62 'label' => __( 'Test a new quote block that allows nested blocks (Warning: The new block is not ready. You may experience content loss, avoid using it on production sites)', 'gutenberg' ),
63 'id' => 'gutenberg-quote-v2',
64 )
65 );
66 register_setting(
67 'gutenberg-experiments',
68 'gutenberg-experiments'
69 );
70 }
71
72 add_action( 'admin_init', 'gutenberg_initialize_experiments_settings' );
73
74 /**
75 * Display a checkbox field for a Gutenberg experiment.
76 *
77 * @since 6.3.0
78 *
79 * @param array $args ( $label, $id ).
80 */
81 function gutenberg_display_experiment_field( $args ) {
82 $options = get_option( 'gutenberg-experiments' );
83 $value = isset( $options[ $args['id'] ] ) ? 1 : 0;
84 ?>
85 <label for="<?php echo $args['id']; ?>">
86 <input type="checkbox" name="<?php echo 'gutenberg-experiments[' . $args['id'] . ']'; ?>" id="<?php echo $args['id']; ?>" value="1" <?php checked( 1, $value ); ?> />
87 <?php echo $args['label']; ?>
88 </label>
89 <?php
90 }
91
92 /**
93 * Display the experiments section.
94 *
95 * @since 6.3.0
96 */
97 function gutenberg_display_experiment_section() {
98 ?>
99 <p><?php echo __( "The block editor includes experimental features that are useable while they're in development. Select the ones you'd like to enable. These features are likely to change, so avoid using them in production.", 'gutenberg' ); ?></p>
100
101 <?php
102 }
103
104 /**
105 * Extends default editor settings with experiments settings.
106 *
107 * @param array $settings Default editor settings.
108 *
109 * @return array Filtered editor settings.
110 */
111 function gutenberg_experiments_editor_settings( $settings ) {
112 // The refactored gallery currently can't be run on sites with use_balanceTags option set.
113 // This bypass needs to remain in place until this is resolved and a patch released.
114 // https://core.trac.wordpress.org/ticket/54130.
115 $experiments_settings = array(
116 '__unstableGalleryWithImageBlocks' => (int) get_option( 'use_balanceTags' ) !== 1 || is_wp_version_compatible( '5.9' ),
117 );
118 return array_merge( $settings, $experiments_settings );
119 }
120
121 add_filter( 'block_editor_settings_all', 'gutenberg_experiments_editor_settings' );
122