PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.0
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 12.1.0, at lib/experiments-page.php

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