PluginProbe
SimpleTOC – Table of Contents Block / 7.4.0
SimpleTOC – Table of Contents Block v7.4.0
7.4.0 7.3.1 7.2.0 7.3.0 7.1.1 7.1.0 7.0.10 7.0.9 7.0.8 7.0.7 7.0.6 7.0.4 7.0.5 5.0.21.1 5.0.22 5.0.23 5.0.24 5.0.25 5.0.25.1 5.0.27 5.0.28 5.0.29 5.0.3 5.0.30 5.0.31 All 161 releases
← All changes | simpletoc-admin-settings.php +42 -1 7.2.07.4.0 View file →
@@ -7,8 +7,17 @@
7 7
8 8 namespace MToensing\SimpleTOC;
9 9
10 10 /**
11 + * Whether scroll highlighting is enforced globally.
12 + *
13 + * @return bool
14 + */
15 +function simpletoc_scroll_spy_enabled() {
16 + return (bool) apply_filters( 'simpletoc_scroll_spy_enabled', (bool) get_option( 'simpletoc_scroll_spy_enabled', false ) );
17 +}
18 +
19 +/**
11 20 * Add SimpleTOC global settings page.
12 21 */
13 22 function simpletoc_add_settings_page() {
14 23 add_options_page(
@@ -73,8 +82,20 @@
73 82 if ( null === $box_style_enabled_filter ) {
74 83 register_setting( 'simpletoc_settings', 'simpletoc_box_style_enabled' );
75 84 }
76 85
86 + if ( null === apply_filters( 'simpletoc_scroll_spy_enabled', null ) ) {
87 + register_setting(
88 + 'simpletoc_settings',
89 + 'simpletoc_scroll_spy_enabled',
90 + array(
91 + 'type' => 'boolean',
92 + 'sanitize_callback' => 'rest_sanitize_boolean',
93 + 'default' => false,
94 + )
95 + );
96 + }
97 +
77 98 // Add settings sections and fields.
78 99 add_settings_section(
79 100 'simpletoc_wrapper_section',
80 101 esc_html__( 'Global settings', 'simpletoc' ),
@@ -115,8 +136,16 @@
115 136 'simpletoc_wrapper_section'
116 137 );
117 138
118 139 add_settings_field(
140 + 'simpletoc_scroll_spy_enabled',
141 + esc_html__( 'Force highlight current section', 'simpletoc' ),
142 + __NAMESPACE__ . '\simpletoc_scroll_spy_enabled_callback',
143 + 'simpletoc',
144 + 'simpletoc_wrapper_section'
145 + );
146 +
147 + add_settings_field(
119 148 'simpletoc_box_style_enabled',
120 149 esc_html__( 'Force box style', 'simpletoc' ),
121 150 __NAMESPACE__ . '\simpletoc_box_style_enabled_callback',
122 151 'simpletoc',
@@ -185,7 +214,19 @@
185 214 echo '<input type="checkbox" name="simpletoc_box_style_enabled" id="simpletoc_box_style_enabled" value="1" checked="checked" disabled="disabled" />';
186 215 echo '<label for="simpletoc_box_style_enabled" class="description">' . esc_html__( 'Setting controlled by "simpletoc_box_style_enabled" filter. Remove filter to adjust setting.', 'simpletoc' ) . '</label>';
187 216 } else {
188 217 echo '<input type="checkbox" name="simpletoc_box_style_enabled" id="simpletoc_box_style_enabled" value="1" ' . checked( 1, $box_style_enabled, false ) . ' />';
189 - echo '<label for="simpletoc_box_style_enabled" class="description">' . esc_html__( 'Enables the box style for all SimpleTOC blocks with the default gray background. Wrapper markup is added automatically.', 'simpletoc' ) . '</label>';
218 + echo '<label for="simpletoc_box_style_enabled" class="description">' . esc_html__( 'Applies the Box style with the default gray background to all SimpleTOC blocks.', 'simpletoc' ) . '</label>';
219 + }
220 +}
221 +
222 +/**
223 + * Scroll highlighting setting.
224 + */
225 +function simpletoc_scroll_spy_enabled_callback() {
226 + $controlled = null !== apply_filters( 'simpletoc_scroll_spy_enabled', null );
227 + echo '<input type="checkbox" name="simpletoc_scroll_spy_enabled" id="simpletoc_scroll_spy_enabled" value="1" ' . checked( true, simpletoc_scroll_spy_enabled(), false ) . disabled( $controlled, true, false ) . ' />';
228 + echo '<label for="simpletoc_scroll_spy_enabled" class="description">' . esc_html__( 'Underlines the current section link in all SimpleTOC blocks in supported browsers. No JavaScript fallback.', 'simpletoc' ) . '</label>';
229 + if ( $controlled ) {
230 + echo '<p class="description">' . esc_html__( 'Setting controlled by the simpletoc_scroll_spy_enabled filter.', 'simpletoc' ) . '</p>';
190 231 }
191 232 }