PluginProbe
Gutenberg / 13.8.1
Gutenberg v13.8.1
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.8.1, at lib/experiments-page.php

111 lines 3.1 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 register_setting(
56 'gutenberg-experiments',
57 'gutenberg-experiments'
58 );
59 }
60
61 add_action( 'admin_init', 'gutenberg_initialize_experiments_settings' );
62
63 /**
64 * Display a checkbox field for a Gutenberg experiment.
65 *
66 * @since 6.3.0
67 *
68 * @param array $args ( $label, $id ).
69 */
70 function gutenberg_display_experiment_field( $args ) {
71 $options = get_option( 'gutenberg-experiments' );
72 $value = isset( $options[ $args['id'] ] ) ? 1 : 0;
73 ?>
74 <label for="<?php echo $args['id']; ?>">
75 <input type="checkbox" name="<?php echo 'gutenberg-experiments[' . $args['id'] . ']'; ?>" id="<?php echo $args['id']; ?>" value="1" <?php checked( 1, $value ); ?> />
76 <?php echo $args['label']; ?>
77 </label>
78 <?php
79 }
80
81 /**
82 * Display the experiments section.
83 *
84 * @since 6.3.0
85 */
86 function gutenberg_display_experiment_section() {
87 ?>
88 <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>
89
90 <?php
91 }
92
93 /**
94 * Extends default editor settings with experiments settings.
95 *
96 * @param array $settings Default editor settings.
97 *
98 * @return array Filtered editor settings.
99 */
100 function gutenberg_experiments_editor_settings( $settings ) {
101 // The refactored gallery currently can't be run on sites with use_balanceTags option set.
102 // This bypass needs to remain in place until this is resolved and a patch released.
103 // https://core.trac.wordpress.org/ticket/54130.
104 $experiments_settings = array(
105 '__unstableGalleryWithImageBlocks' => (int) get_option( 'use_balanceTags' ) !== 1 || is_wp_version_compatible( '5.9' ),
106 );
107 return array_merge( $settings, $experiments_settings );
108 }
109
110 add_filter( 'block_editor_settings_all', 'gutenberg_experiments_editor_settings' );
111