-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathexperiments-page.php
121 lines (112 loc) · 3.53 KB
/
experiments-page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Bootstrapping the Gutenberg experiments page.
*
* @package gutenberg
*/
/**
* The main entry point for the Gutenberg experiments page.
*
* @since 6.3.0
*/
function the_gutenberg_experiments() {
?>
<div
id="experiments-editor"
class="wrap"
>
<h1><?php echo __( 'Experimental settings', 'gutenberg' ); ?></h1>
<?php settings_errors(); ?>
<form method="post" action="options.php">
<?php settings_fields( 'gutenberg-experiments' ); ?>
<?php do_settings_sections( 'gutenberg-experiments' ); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
/**
* Set up the experiments settings.
*
* @since 6.3.0
*/
function gutenberg_initialize_experiments_settings() {
add_settings_section(
'gutenberg_experiments_section',
// The empty string ensures the render function won't output a h2.
'',
'gutenberg_display_experiment_section',
'gutenberg-experiments'
);
add_settings_field(
'gutenberg-list-v2',
__( 'List block v2', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'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' ),
'id' => 'gutenberg-list-v2',
)
);
add_settings_field(
'gutenberg-quote-v2',
__( 'Quote block v2', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'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' ),
'id' => 'gutenberg-quote-v2',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
);
}
add_action( 'admin_init', 'gutenberg_initialize_experiments_settings' );
/**
* Display a checkbox field for a Gutenberg experiment.
*
* @since 6.3.0
*
* @param array $args ( $label, $id ).
*/
function gutenberg_display_experiment_field( $args ) {
$options = get_option( 'gutenberg-experiments' );
$value = isset( $options[ $args['id'] ] ) ? 1 : 0;
?>
<label for="<?php echo $args['id']; ?>">
<input type="checkbox" name="<?php echo 'gutenberg-experiments[' . $args['id'] . ']'; ?>" id="<?php echo $args['id']; ?>" value="1" <?php checked( 1, $value ); ?> />
<?php echo $args['label']; ?>
</label>
<?php
}
/**
* Display the experiments section.
*
* @since 6.3.0
*/
function gutenberg_display_experiment_section() {
?>
<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>
<?php
}
/**
* Extends default editor settings with experiments settings.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function gutenberg_experiments_editor_settings( $settings ) {
// The refactored gallery currently can't be run on sites with use_balanceTags option set.
// This bypass needs to remain in place until this is resolved and a patch released.
// https://core.trac.wordpress.org/ticket/54130.
$experiments_settings = array(
'__unstableGalleryWithImageBlocks' => (int) get_option( 'use_balanceTags' ) !== 1 || is_wp_version_compatible( '5.9' ),
);
return array_merge( $settings, $experiments_settings );
}
add_filter( 'block_editor_settings_all', 'gutenberg_experiments_editor_settings' );