PluginProbe
SimpleTOC – Table of Contents Block / 7.0.6
SimpleTOC – Table of Contents Block v7.0.6
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 5.0.32 5.0.33 All 159 releases
simpletoc / simpletoc-admin-settings.php

simpletoc-admin-settings.php in SimpleTOC – Table of Contents Block 7.0.6, at simpletoc-admin-settings.php

223 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SimpleTOC admin settings page.
4 *
5 * @package simpletoc
6 */
7
8 namespace MToensing\SimpleTOC;
9
10 /**
11 * Add SimpleTOC global settings page.
12 */
13 function simpletoc_add_settings_page() {
14 add_options_page(
15 __( 'SimpleTOC Settings', 'simpletoc' ),
16 __( 'SimpleTOC', 'simpletoc' ),
17 'manage_options',
18 'simpletoc',
19 __NAMESPACE__ . '\simpletoc_settings_page'
20 );
21 }
22 add_action( 'admin_menu', __NAMESPACE__ . '\simpletoc_add_settings_page' );
23
24 /**
25 * SimpleTOC settings page content.
26 */
27 function simpletoc_settings_page() {
28 if ( ! current_user_can( 'manage_options' ) ) {
29 return;
30 }
31
32 ?>
33 <div class="wrap">
34 <h1><?php _e( 'SimpleTOC Settings', 'simpletoc' ); ?></h1>
35 <form method="post" action="options.php">
36 <?php
37 settings_fields( 'simpletoc_settings' );
38 do_settings_sections( 'simpletoc' );
39 submit_button();
40 ?>
41 </form>
42 </div>
43 <?php
44 }
45
46 /**
47 * Register SimpleTOC settings.
48 */
49 function simpletoc_register_settings() {
50 // Register settings and filters for existing features.
51 $wrapper_enabled_filter = apply_filters( 'simpletoc_wrapper_enabled', null );
52 $accordion_enabled_filter = apply_filters( 'simpletoc_accordion_enabled', null );
53 $smooth_enabled_filter = apply_filters( 'simpletoc_smooth_enabled', null );
54 $absolute_urls_enabled_filter = apply_filters( 'simpletoc_absolute_urls_enabled', null );
55 $autoupdate_enabled_filter = apply_filters( 'simpletoc_autoupdate_enabled', null );
56 $box_style_enabled_filter = apply_filters( 'simpletoc_box_style_enabled', null );
57
58 if ( null === $wrapper_enabled_filter ) {
59 register_setting( 'simpletoc_settings', 'simpletoc_wrapper_enabled' );
60 }
61
62 if ( null === $accordion_enabled_filter ) {
63 register_setting( 'simpletoc_settings', 'simpletoc_accordion_enabled' );
64 }
65
66 if ( null === $smooth_enabled_filter ) {
67 register_setting( 'simpletoc_settings', 'simpletoc_smooth_enabled' );
68 }
69
70 if ( null === $absolute_urls_enabled_filter ) {
71 register_setting( 'simpletoc_settings', 'simpletoc_absolute_urls_enabled' );
72 }
73
74 if ( null === $autoupdate_enabled_filter ) {
75 register_setting( 'simpletoc_settings', 'simpletoc_autoupdate_enabled', array( 'show_in_rest' => true ) );
76 }
77
78 if ( null === $box_style_enabled_filter ) {
79 register_setting( 'simpletoc_settings', 'simpletoc_box_style_enabled' );
80 }
81
82 // Add settings sections and fields.
83 add_settings_section(
84 'simpletoc_wrapper_section',
85 esc_html__( 'Global settings', 'simpletoc' ),
86 __NAMESPACE__ . '\simpletoc_wrapper_section_callback',
87 'simpletoc'
88 );
89
90 add_settings_field(
91 'simpletoc_accordion_enabled',
92 esc_html__( 'Force accordion menu', 'simpletoc' ),
93 __NAMESPACE__ . '\simpletoc_accordion_enabled_callback',
94 'simpletoc',
95 'simpletoc_wrapper_section'
96 );
97
98 add_settings_field(
99 'simpletoc_wrapper_enabled',
100 esc_html__( 'Force wrapper div', 'simpletoc' ),
101 __NAMESPACE__ . '\simpletoc_wrapper_enabled_callback',
102 'simpletoc',
103 'simpletoc_wrapper_section'
104 );
105
106 add_settings_field(
107 'simpletoc_smooth_enabled',
108 esc_html__( 'Force smooth scrolling', 'simpletoc' ),
109 __NAMESPACE__ . '\simpletoc_smooth_enabled_callback',
110 'simpletoc',
111 'simpletoc_wrapper_section'
112 );
113
114 add_settings_field(
115 'simpletoc_absolute_urls_enabled',
116 esc_html__( 'Force absolute urls', 'simpletoc' ),
117 __NAMESPACE__ . '\simpletoc_absolute_urls_enabled_callback',
118 'simpletoc',
119 'simpletoc_wrapper_section'
120 );
121
122 // Add the autoupdate settings field.
123 add_settings_field(
124 'simpletoc_autoupdate_enabled',
125 esc_html__( 'Force no auto refresh', 'simpletoc' ),
126 __NAMESPACE__ . '\simpletoc_autoupdate_enabled_callback',
127 'simpletoc',
128 'simpletoc_wrapper_section'
129 );
130
131 add_settings_field(
132 'simpletoc_box_style_enabled',
133 esc_html__( 'Force box style', 'simpletoc' ),
134 __NAMESPACE__ . '\simpletoc_box_style_enabled_callback',
135 'simpletoc',
136 'simpletoc_wrapper_section'
137 );
138 }
139
140 add_action( 'admin_init', __NAMESPACE__ . '\simpletoc_register_settings' );
141
142 /**
143 * SimpleTOC wrapper section callback.
144 */
145 function simpletoc_wrapper_section_callback() {
146 $donatelink = '<a href="https://marc.tv/out/donate">' . esc_html__( 'Donate here!', 'simpletoc' ) . '</a>';
147
148 echo '<p>' .
149 esc_html__( 'Enforce these settings globally, ignoring any block-level configurations.', 'simpletoc' ) . '</p><p>' .
150 esc_html__( 'Think about making a donation if you use any of these features.', 'simpletoc' ) . ' ' .
151 $donatelink .
152 '</p>';
153 }
154
155 /**
156 * SimpleTOC wrapper enabled callback.
157 */
158 function simpletoc_wrapper_enabled_callback() {
159 $wrapper_enabled = get_option( 'simpletoc_wrapper_enabled', false );
160
161 if ( has_filter( 'simpletoc_wrapper_enabled' ) ) {
162 echo '<input type="checkbox" name="simpletoc_wrapper_enabled" id="simpletoc_wrapper_enabled" value="1" checked="checked" disabled="disabled" />';
163 echo '<label for="simpletoc_wrapper_enabled" class="description">' . esc_html__( 'Setting controlled by "simpletoc_wrapper_enabled" filter. Remove filter to adjust setting.', 'simpletoc' ) . '</label>';
164 } else {
165 echo '<input type="checkbox" name="simpletoc_wrapper_enabled" id="simpletoc_wrapper_enabled" value="1" ' . checked( 1, $wrapper_enabled, false ) . ' />';
166 echo '<label for="simpletoc_wrapper_enabled" class="description">' . esc_html__( 'Additionally adds the role "navigation" and ARIA attributes.', 'simpletoc' ) . '</label>';
167 }
168 }
169
170 /**
171 * SimpleTOC accordion enabled callback.
172 */
173 function simpletoc_accordion_enabled_callback() {
174 $accordion_enabled = get_option( 'simpletoc_accordion_enabled', false );
175 if ( $accordion_enabled ) {
176 update_option( 'simpletoc_wrapper_enabled', true );
177 }
178 echo '<input type="checkbox" name="simpletoc_accordion_enabled" id="simpletoc_accordion_enabled" value="1" ' . checked( 1, $accordion_enabled, false ) . ' />';
179 echo '<label for="simpletoc_accordion_enabled" class="description">' . esc_html__( 'Adds minimal JavaScript and css styles.', 'simpletoc' ) . ' <strong>' . esc_html__( 'Notice:', 'simpletoc' ) . '</strong> ' . esc_html__( 'This will automatically enable the wrapper div.', 'simpletoc' ) . '</label>';
180 }
181
182 /**
183 * SimpleTOC smooth enabled callback.
184 */
185 function simpletoc_smooth_enabled_callback() {
186 $smooth_enabled = get_option( 'simpletoc_smooth_enabled', false );
187 echo '<input type="checkbox" name="simpletoc_smooth_enabled" id="simpletoc_smooth_enabled" value="1" ' . checked( 1, $smooth_enabled, false ) . ' />';
188 echo '<label for="simpletoc_smooth_enabled" class="description">' . esc_html__( 'Adds the following CSS to the HTML element: "scroll-behavior: smooth;"', 'simpletoc' ) . '</label>';
189 }
190
191 /**
192 * SimpleTOC absolute urls enabled callback.
193 */
194 function simpletoc_absolute_urls_enabled_callback() {
195 $absolute_urls_enabled = get_option( 'simpletoc_absolute_urls_enabled', false );
196 echo '<input type="checkbox" name="simpletoc_absolute_urls_enabled" id="simpletoc_absolute_urls_enabled" value="1" ' . checked( 1, $absolute_urls_enabled, false ) . ' />';
197 echo '<label for="simpletoc_absolute_urls_enabled" class="description">' . esc_html__( 'Adds the permalink url to the fragment.', 'simpletoc' ) . '</label>';
198 }
199
200 /**
201 * SimpleTOC autoupdate enabled callback.
202 */
203 function simpletoc_autoupdate_enabled_callback() {
204 $autoupdate_enabled = get_option( 'simpletoc_autoupdate_enabled', false );
205 echo '<input type="checkbox" name="simpletoc_autoupdate_enabled" id="simpletoc_autoupdate_enabled" value="1" ' . checked( 1, $autoupdate_enabled, false ) . ' />';
206 echo '<label for="simpletoc_autoupdate_enabled" class="description">' . esc_html__( 'Deactivate the automatic table of contents refresh feature.', 'simpletoc' ) . '</label>';
207 }
208
209 /**
210 * SimpleTOC box style enabled callback.
211 */
212 function simpletoc_box_style_enabled_callback() {
213 $box_style_enabled = get_option( 'simpletoc_box_style_enabled', false );
214
215 if ( has_filter( 'simpletoc_box_style_enabled' ) ) {
216 echo '<input type="checkbox" name="simpletoc_box_style_enabled" id="simpletoc_box_style_enabled" value="1" checked="checked" disabled="disabled" />';
217 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>';
218 } else {
219 echo '<input type="checkbox" name="simpletoc_box_style_enabled" id="simpletoc_box_style_enabled" value="1" ' . checked( 1, $box_style_enabled, false ) . ' />';
220 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>';
221 }
222 }
223