PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 2.0.0
Admin and Site Enhancements (ASE) v2.0.0
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / includes / setup-admin-menu-page.php
admin-site-enhancements / includes Last commit date
setup-admin-menu-page.php 3 years ago
setup-admin-menu-page.php
1343 lines
1 <?php
2
3 /**
4 * Register admin menu
5 *
6 * @since 1.0.0
7 */
8 function asenha_register_admin_menu() {
9
10 add_submenu_page(
11 'tools.php', // Parent page/menu
12 'Admin and Site Enhancements', // Browser tab/window title
13 'Enhancements', // Sube menu title
14 'manage_options', // Minimal user capabililty
15 ASENHA_SLUG, // Page slug. Shows up in URL.
16 'asenha_add_settings_page'
17 );
18
19 }
20
21 /**
22 * Create the settings page of the plugin
23 *
24 * @since 1.0.0
25 */
26 function asenha_add_settings_page() {
27 ?>
28 <div class="wrap asenha">
29
30 <div id="asenha-header" class="asenha-header">
31 <div class="asenha-header-left">
32 <h1 class="asenha-heading"><?php echo get_admin_page_title(); ?> <small><?php esc_html_e( 'by', 'admin-site-enhancements' ); ?> <a href="https://bowo.io" target="_blank">bowo.io</a></small></h1>
33 <!-- <a href="https://wordpress.org/plugins/admin-site-enhancements/" target="_blank" class="asenha-header-action"><span>&#8505;</span> <?php // esc_html_e( 'Info', 'admin-site-enhancements' ); ?></a> -->
34 <a href="https://wordpress.org/plugins/admin-site-enhancements/#reviews" target="_blank" class="asenha-header-action"><span>&starf;</span> <?php esc_html_e( 'Review', 'admin-site-enhancements' ); ?></a>
35 <a href="https://wordpress.org/support/plugin/admin-site-enhancements/" target="_blank" class="asenha-header-action">&#10010; <?php esc_html_e( 'Feedback', 'admin-site-enhancements' ); ?></a>
36 <a href="https://paypal.me/qriouslad" target="_blank" class="asenha-header-action">&#9829; <?php esc_html_e( 'Donate', 'admin-site-enhancements' ); ?></a>
37 </div>
38 <div class="asenha-header-right">
39 <a class="button button-primary asenha-save-button">Save Changes</a>
40 <div class="asenha-changes-saved" style="display:none;">Changes have been saved.</div>
41 </div>
42 </div>
43
44 <div class="asenha-body">
45 <form action="options.php" method="post">
46 <div class="asenha-vertical-tabs">
47 <div class="asenha-tab-buttons">
48 <input id="tab-content-management" type="radio" name="tabs" checked><label for="tab-content-management">Content Management</label>
49 <input id="tab-admin-interface" type="radio" name="tabs"><label for="tab-admin-interface">Admin Interface</label>
50 <input id="tab-security" type="radio" name="tabs"><label for="tab-security">Security</label>
51 <input id="tab-utilities" type="radio" name="tabs"><label for="tab-utilities">Utilities</label>
52 </div>
53 <div class="asenha-tab-contents">
54 <section class="asenha-fields fields-content-management">
55 <table class="form-table" role="presentation">
56 <tbody></tbody>
57 </table>
58 </section>
59 <section class="asenha-fields fields-admin-interface">
60 <table class="form-table" role="presentation">
61 <tbody></tbody>
62 </table>
63 </section>
64 <section class="asenha-fields fields-security">
65 <table class="form-table" role="presentation">
66 <tbody></tbody>
67 </table>
68 </section>
69 <section class="asenha-fields fields-utilities">
70 <table class="form-table" role="presentation">
71 <tbody></tbody>
72 </table>
73 </section>
74 </div>
75 </div>
76 <div style="display:none;"><!-- Hide to prevent flash of fields appearing at the bottom of the page -->
77 <?php settings_fields( ASENHA_ID ); ?>
78 <?php do_settings_sections( ASENHA_SLUG ); ?>
79 <?php submit_button(
80 'Save Changes', // Button copy
81 'primary', // Type: 'primary', 'small', or 'large'
82 'submit', // The 'name' attribute
83 true, // Whether to wrap in <p> tag
84 array( 'id' => 'asenha-submit' ), // additional attributes
85 ); ?>
86 </div>
87 </form>
88 </div>
89
90 <div class="asenha-footer">
91 </div>
92
93 </div>
94 <?php
95
96 }
97
98 /**
99 * Register plugin settings and the corresponding fields
100 *
101 * @link https://wpshout.com/making-an-admin-options-page-with-the-wordpress-settings-api/
102 * @link https://rudrastyh.com/wordpress/creating-options-pages.html
103 * @since 1.0.0
104 */
105 function asenha_register_settings() {
106
107 // Add "Content Management" section
108
109 add_settings_section(
110 'main-section', // Section ID
111 '', // Section title. Can be blank.
112 '', // Callback function to output section intro. Can be blank.
113 ASENHA_SLUG // Settings page slug
114 );
115
116 // Register main setttings
117
118 register_setting(
119 ASENHA_ID, // Option group or option_page
120 ASENHA_SLUG_U, // Option name in wp_options table
121 array(
122 'type' => 'array', // 'string', 'boolean', 'integer', 'number', 'array', or 'object'
123 'description' => '', // A description of the data attached to this setting.
124 'sanitize_callback' => 'asenha_sanitize_options',
125 'show_in_rest' => false,
126 'default' => array(), // When calling get_option()
127 )
128 );
129
130 // Register fields for "Content Management" section
131
132 // Call WordPress globals required for the fields
133
134 global $wp_roles;
135 $roles = $wp_roles->get_names();
136
137 // Enable Page and Post Duplication
138
139 $field_id = 'enable_duplication';
140 $field_slug = 'enable-duplication';
141
142 add_settings_field(
143 $field_id, // Field ID
144 'Enable Page and Post Duplication', // Field title
145 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
146 ASENHA_SLUG, // Settings page slug
147 'main-section', // Section ID
148 array(
149 'field_id' => $field_id, // Custom argument
150 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
151 'field_description' => 'Enable one-click duplication of pages, posts and custom posts. The corresponding taxonomy terms and post meta will also be duplicated.', // Custom argument
152 'class' => 'asenha-toggle content-management ' . $field_slug, // Custom class for the <tr> element
153 )
154 );
155
156 // Enable Media Replacement
157
158 $field_id = 'enable_media_replacement';
159 $field_slug = 'enable-media-replacement';
160
161 add_settings_field(
162 $field_id, // Field ID
163 'Enable Media Replacement', // Field title
164 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
165 ASENHA_SLUG, // Settings page slug
166 'main-section', // Section ID
167 array(
168 'field_id' => $field_id, // Custom argument
169 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
170 'field_description' => 'Easily replace any type of media file with a new one while retaining the existing media ID and file name.', // Custom argument
171 'class' => 'asenha-toggle content-management ' . $field_slug, // Custom class for the <tr> element
172 )
173 );
174
175 // Enhance List Tables
176
177 $field_id = 'enhance_list_tables';
178 $field_slug = 'enhance-list-tables';
179
180 add_settings_field(
181 $field_id, // Field ID
182 'Enhance List Tables', // Field title
183 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
184 ASENHA_SLUG, // Settings page slug
185 'main-section', // Section ID
186 array(
187 'field_id' => $field_id, // Custom argument
188 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
189 'field_description' => 'Improve the usefulness of listing pages of various post types by adding / removing columns and elements.', // Custom argument
190 'field_options_wrapper' => true, // Custom argument. Add container for additional options
191 'class' => 'asenha-toggle content-management ' . $field_slug, // Custom class for the <tr> element
192 )
193 );
194
195 // Show Featured Image Column
196
197 $field_id = 'show_featured_image_column';
198 $field_slug = 'show-featured-image-column';
199
200 add_settings_field(
201 $field_id, // Field ID
202 '', // Field title
203 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
204 ASENHA_SLUG, // Settings page slug
205 'main-section', // Section ID
206 array(
207 'field_id' => $field_id, // Custom argument
208 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
209 'field_label' => 'Show featured image column.', // Custom argument
210 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element
211 )
212 );
213
214 // Show Excerpt Column
215
216 $field_id = 'show_excerpt_column';
217 $field_slug = 'show-excerpt-column';
218
219 add_settings_field(
220 $field_id, // Field ID
221 '', // Field title
222 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
223 ASENHA_SLUG, // Settings page slug
224 'main-section', // Section ID
225 array(
226 'field_id' => $field_id, // Custom argument
227 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
228 'field_label' => 'Show excerpt column.', // Custom argument
229 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element
230 )
231 );
232
233 // Show ID Column
234
235 $field_id = 'show_id_column';
236 $field_slug = 'show-id-column';
237
238 add_settings_field(
239 $field_id, // Field ID
240 '', // Field title
241 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
242 ASENHA_SLUG, // Settings page slug
243 'main-section', // Section ID
244 array(
245 'field_id' => $field_id, // Custom argument
246 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
247 'field_label' => 'Show ID column.', // Custom argument
248 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element
249 )
250 );
251
252 // Hide Comments Column
253
254 $field_id = 'hide_comments_column';
255 $field_slug = 'hide-comments-column';
256
257 add_settings_field(
258 $field_id, // Field ID
259 '', // Field title
260 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
261 ASENHA_SLUG, // Settings page slug
262 'main-section', // Section ID
263 array(
264 'field_id' => $field_id, // Custom argument
265 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
266 'field_label' => 'Remove comments column.', // Custom argument
267 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element
268 )
269 );
270
271 // Hide Post Tags Column
272
273 $field_id = 'hide_post_tags_column';
274 $field_slug = 'hide-post-tags-column';
275
276 add_settings_field(
277 $field_id, // Field ID
278 '', // Field title
279 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
280 ASENHA_SLUG, // Settings page slug
281 'main-section', // Section ID
282 array(
283 'field_id' => $field_id, // Custom argument
284 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
285 'field_label' => 'Remove tags column (for posts).', // Custom argument
286 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element
287 )
288 );
289
290 // Show Custom Taxonomy Filters
291
292 $field_id = 'show_custom_taxonomy_filters';
293 $field_slug = 'show-custom-taxonomy-filters';
294
295 add_settings_field(
296 $field_id, // Field ID
297 '', // Field title
298 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
299 ASENHA_SLUG, // Settings page slug
300 'main-section', // Section ID
301 array(
302 'field_id' => $field_id, // Custom argument
303 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
304 'field_label' => 'Show additional filter(s) for hierarchical, custom taxonomies.', // Custom argument
305 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element
306 )
307 );
308
309 // Hide Admin Notices
310
311 $field_id = 'hide_admin_notices';
312 $field_slug = 'hide-admin-notices';
313
314 add_settings_field(
315 $field_id, // Field ID
316 'Hide Admin Notices', // Field title
317 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
318 ASENHA_SLUG, // Settings page slug
319 'main-section', // Section ID
320 array(
321 'field_id' => $field_id, // Custom argument
322 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
323 'field_description' => 'Clean up admin pages by moving notices into a separate panel easily accessible via the admin bar.', // Custom argument
324 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element
325 )
326 );
327
328 // View Admin as Role
329
330 $field_id = 'view_admin_as_role';
331 $field_slug = 'view-admin-as-role';
332
333 add_settings_field(
334 $field_id, // Field ID
335 'View Admin as Role', // Field title
336 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
337 ASENHA_SLUG, // Settings page slug
338 'main-section', // Section ID
339 array(
340 'field_id' => $field_id, // Custom argument
341 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
342 'field_description' => 'View admin pages and the site (logged-in) as one of the non-administrator user roles.', // Custom argument
343 'field_options_wrapper' => true, // Custom argument. Add container for additional options
344 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element
345 )
346 );
347
348 // Hide or Modify Elements
349
350 $field_id = 'hide_modify_elements';
351 $field_slug = 'hide-modify-elements';
352
353 add_settings_field(
354 $field_id, // Field ID
355 'Clean Up Admin Bar', // Field title
356 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
357 ASENHA_SLUG, // Settings page slug
358 'main-section', // Section ID
359 array(
360 'field_id' => $field_id, // Custom argument
361 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
362 'field_description' => 'Remove various elements from the admin bar.', // Custom argument
363 'field_options_wrapper' => true, // Custom argument. Add container for additional options
364 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element
365 )
366 );
367
368 $field_id = 'hide_ab_wp_logo_menu';
369 $field_slug = 'hide-ab-wp-logo-menu';
370
371 add_settings_field(
372 $field_id, // Field ID
373 '', // Field title
374 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
375 ASENHA_SLUG, // Settings page slug
376 'main-section', // Section ID
377 array(
378 'field_id' => $field_id, // Custom argument
379 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
380 'field_label' => 'Remove WordPress logo/menu', // Custom argument
381 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
382 )
383 );
384
385 $field_id = 'hide_ab_customize_menu';
386 $field_slug = 'hide-ab-customize-menu';
387
388 add_settings_field(
389 $field_id, // Field ID
390 '', // Field title
391 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
392 ASENHA_SLUG, // Settings page slug
393 'main-section', // Section ID
394 array(
395 'field_id' => $field_id, // Custom argument
396 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
397 'field_label' => 'Remove customize menu', // Custom argument
398 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
399 )
400 );
401
402 $field_id = 'hide_ab_updates_menu';
403 $field_slug = 'hide-ab-updates-menu';
404
405 add_settings_field(
406 $field_id, // Field ID
407 '', // Field title
408 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
409 ASENHA_SLUG, // Settings page slug
410 'main-section', // Section ID
411 array(
412 'field_id' => $field_id, // Custom argument
413 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
414 'field_label' => 'Remove updates counter/link', // Custom argument
415 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
416 )
417 );
418
419 $field_id = 'hide_ab_comments_menu';
420 $field_slug = 'hide-ab-comments-menu';
421
422 add_settings_field(
423 $field_id, // Field ID
424 '', // Field title
425 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
426 ASENHA_SLUG, // Settings page slug
427 'main-section', // Section ID
428 array(
429 'field_id' => $field_id, // Custom argument
430 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
431 'field_label' => 'Remove comments counter/link', // Custom argument
432 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
433 )
434 );
435
436 $field_id = 'hide_ab_new_content_menu';
437 $field_slug = 'hide-ab-new-content-menu';
438
439 add_settings_field(
440 $field_id, // Field ID
441 '', // Field title
442 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
443 ASENHA_SLUG, // Settings page slug
444 'main-section', // Section ID
445 array(
446 'field_id' => $field_id, // Custom argument
447 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
448 'field_label' => 'Remove new content menu', // Custom argument
449 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
450 )
451 );
452
453 $field_id = 'hide_ab_howdy';
454 $field_slug = 'hide-ab-howdy';
455
456 add_settings_field(
457 $field_id, // Field ID
458 '', // Field title
459 'asenha_render_field_checkbox_plain', // Callback to render field with custom arguments in the array below
460 ASENHA_SLUG, // Settings page slug
461 'main-section', // Section ID
462 array(
463 'field_id' => $field_id, // Custom argument
464 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument
465 'field_label' => 'Remove \'Howdy\'', // Custom argument
466 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
467 )
468 );
469
470 // Hide Admin Bar
471
472 $field_id = 'hide_admin_bar';
473 $field_slug = 'hide-admin-bar';
474
475 add_settings_field(
476 $field_id, // Field ID
477 'Hide Admin Bar', // Field title
478 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
479 ASENHA_SLUG, // Settings page slug
480 'main-section', // Section ID
481 array(
482 'field_id' => $field_id, // Custom argument
483 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
484 'field_description' => 'Hide admin bar on the front end for all or some user roles.', // Custom argument
485 'field_options_wrapper' => true, // Custom argument. Add container for additional options
486 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element
487 )
488 );
489
490 $field_id = 'hide_admin_bar_for';
491 $field_slug = 'hide-admin-bar-for';
492
493 if ( is_array( $roles ) ) {
494 foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator
495
496 add_settings_field(
497 $field_id . '_' . $role_slug, // Field ID
498 '', // Field title
499 'asenha_render_field_checkbox_subfield', // Callback to render field with custom arguments in the array below
500 ASENHA_SLUG, // Settings page slug
501 'main-section', // Section ID
502 array(
503 'parent_field_id' => $field_id, // Custom argument
504 'field_id' => $role_slug, // Custom argument
505 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument
506 'field_label' => $role_label, // Custom argument
507 'class' => 'asenha-checkbox asenha-hide-th asenha-half admin-interface ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element
508 )
509 );
510
511 }
512 }
513
514 // Customize Admin Menu
515
516 $field_id = 'customize_admin_menu';
517 $field_slug = 'customize-admin-menu';
518
519 add_settings_field(
520 $field_id, // Field ID
521 'Admin Menu Organizer', // Field title
522 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
523 ASENHA_SLUG, // Settings page slug
524 'main-section', // Section ID
525 array(
526 'field_id' => $field_id, // Custom argument
527 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
528 'field_description' => 'Customize the order of the admin menu and optionally hide some items.', // Custom argument
529 'field_options_wrapper' => true, // Custom argument. Add container for additional options
530 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element
531 )
532 );
533
534 $field_id = 'custom_menu_order';
535 $field_slug = 'custom-menu-order';
536
537 add_settings_field(
538 $field_id, // Field ID
539 '', // Field title
540 'asenha_render_field_sortable_menu', // Callback to render field with custom arguments in the array below
541 ASENHA_SLUG, // Settings page slug
542 'main-section', // Section ID
543 array(
544 'field_id' => $field_id, // Custom argument
545 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
546 'field_type' => 'sortable-menu', // Custom argument
547 'field_description' => '', // Custom argument
548 'class' => 'asenha-sortable asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element
549 )
550 );
551
552 // Change Login URL
553
554 $field_id = 'change_login_url';
555 $field_slug = 'change-login-url';
556
557 add_settings_field(
558 $field_id, // Field ID
559 'Change Login URL', // Field title
560 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
561 ASENHA_SLUG, // Settings page slug
562 'main-section', // Section ID
563 array(
564 'field_id' => $field_id, // Custom argument
565 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
566 'field_description' => 'Default is ' . get_site_url() . '/wp-admin/', // Custom argument
567 'field_options_wrapper' => true, // Custom argument. Add container for additional options
568 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element
569 )
570 );
571
572 $field_id = 'custom_login_slug';
573 $field_slug = 'custom-login-slug';
574
575 add_settings_field(
576 $field_id, // Field ID
577 'New URL:', // Field title
578 'asenha_render_field_text_subfield', // Callback to render field with custom arguments in the array below
579 ASENHA_SLUG, // Settings page slug
580 'main-section', // Section ID
581 array(
582 'field_id' => $field_id, // Custom argument
583 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
584 'field_type' => 'with-prefix-suffix', // Custom argument
585 'field_prefix' => get_site_url() . '/', // Custom argument
586 'field_suffix' => '/', // Custom argument
587 'field_description' => '', // Custom argument
588 'class' => 'asenha-text with-prefix-suffix security ' . $field_slug, // Custom class for the <tr> element
589 )
590 );
591
592 // Redirect After Login
593
594 $field_id = 'redirect_after_login';
595 $field_slug = 'redirect-after-login';
596
597 add_settings_field(
598 $field_id, // Field ID
599 'Redirect After Login', // Field title
600 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
601 ASENHA_SLUG, // Settings page slug
602 'main-section', // Section ID
603 array(
604 'field_id' => $field_id, // Custom argument
605 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
606 'field_description' => 'Set custom redirect URL for all or some user roles after login.', // Custom argument
607 'field_options_wrapper' => true, // Custom argument. Add container for additional options
608 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element
609 )
610 );
611
612 $field_id = 'redirect_after_login_to_slug';
613 $field_slug = 'redirect-after-login-to-slug';
614
615 add_settings_field(
616 $field_id, // Field ID
617 'Redirect to:', // Field title
618 'asenha_render_field_text_subfield', // Callback to render field with custom arguments in the array below
619 ASENHA_SLUG, // Settings page slug
620 'main-section', // Section ID
621 array(
622 'field_id' => $field_id, // Custom argument
623 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
624 'field_type' => 'with-prefix-suffix', // Custom argument
625 'field_prefix' => get_site_url() . '/', // Custom argument
626 'field_suffix' => '/ for:', // Custom argument
627 'field_description' => '', // Custom argument
628 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element
629 )
630 );
631
632 $field_id = 'redirect_after_login_for';
633 $field_slug = 'redirect-after-login-for';
634
635 if ( is_array( $roles ) ) {
636 foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator
637
638 add_settings_field(
639 $field_id . '_' . $role_slug, // Field ID
640 '', // Field title
641 'asenha_render_field_checkbox_subfield', // Callback to render field with custom arguments in the array below
642 ASENHA_SLUG, // Settings page slug
643 'main-section', // Section ID
644 array(
645 'parent_field_id' => $field_id, // Custom argument
646 'field_id' => $role_slug, // Custom argument
647 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument
648 'field_label' => $role_label, // Custom argument
649 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element
650 )
651 );
652
653 }
654 }
655
656 // Redirect After Logout
657
658 $field_id = 'redirect_after_logout';
659 $field_slug = 'redirect-after-logout';
660
661 add_settings_field(
662 $field_id, // Field ID
663 'Redirect After Logout', // Field title
664 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
665 ASENHA_SLUG, // Settings page slug
666 'main-section', // Section ID
667 array(
668 'field_id' => $field_id, // Custom argument
669 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
670 'field_description' => 'Set custom redirect URL for all or some user roles after logout.', // Custom argument
671 'field_options_wrapper' => true, // Custom argument. Add container for additional options
672 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element
673 )
674 );
675
676 $field_id = 'redirect_after_logout_to_slug';
677 $field_slug = 'redirect-after-logout-to-slug';
678
679 add_settings_field(
680 $field_id, // Field ID
681 'Redirect to:', // Field title
682 'asenha_render_field_text_subfield', // Callback to render field with custom arguments in the array below
683 ASENHA_SLUG, // Settings page slug
684 'main-section', // Section ID
685 array(
686 'field_id' => $field_id, // Custom argument
687 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
688 'field_type' => 'with-prefix-suffix', // Custom argument
689 'field_prefix' => get_site_url() . '/', // Custom argument
690 'field_suffix' => '/ for:', // Custom argument
691 'field_description' => '', // Custom argument
692 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element
693 )
694 );
695
696 $field_id = 'redirect_after_logout_for';
697 $field_slug = 'redirect-after-logout-for';
698
699 if ( is_array( $roles ) ) {
700 foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator
701
702 add_settings_field(
703 $field_id . '_' . $role_slug, // Field ID
704 '', // Field title
705 'asenha_render_field_checkbox_subfield', // Callback to render field with custom arguments in the array below
706 ASENHA_SLUG, // Settings page slug
707 'main-section', // Section ID
708 array(
709 'parent_field_id' => $field_id, // Custom argument
710 'field_id' => $role_slug, // Custom argument
711 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument
712 'field_label' => $role_label, // Custom argument
713 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element
714 )
715 );
716
717 }
718 }
719
720 // Redirect 404 to Homepage
721
722 $field_id = 'redirect_404_to_homepage';
723 $field_slug = 'redirect-404-to-homepage';
724
725 add_settings_field(
726 $field_id, // Field ID
727 'Redirect 404 to Homepage', // Field title
728 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below
729 ASENHA_SLUG, // Settings page slug
730 'main-section', // Section ID
731 array(
732 'field_id' => $field_id, // Custom argument
733 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
734 'field_description' => 'Perform 301 (permanent) redirect to the homepage for all 404 (not found) pages.', // Custom argument
735 'field_options_wrapper' => true, // Custom argument. Add container for additional options
736 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element
737 )
738 );
739
740 }
741
742 /**
743 * Sanitize options
744 *
745 * @since 1.0.0
746 */
747 function asenha_sanitize_options( $options ) {
748
749 // Call WordPress globals required for validating the fields
750 global $wp_roles;
751 $roles = $wp_roles->get_names();
752
753 // Content Management features
754
755 // Enable Page and Post Duplication
756 if ( ! isset( $options['enable_duplication'] ) ) $options['enable_duplication'] = false;
757 $options['enable_duplication'] = ( 'on' == $options['enable_duplication'] ? true : false );
758
759 // Enable Media Replacement
760 if ( ! isset( $options['enable_media_replacement'] ) ) $options['enable_media_replacement'] = false;
761 $options['enable_media_replacement'] = ( 'on' == $options['enable_media_replacement'] ? true : false );
762
763 // Enhance List Tables
764 if ( ! isset( $options['enhance_list_tables'] ) ) $options['enhance_list_tables'] = false;
765 $options['enhance_list_tables'] = ( 'on' == $options['enhance_list_tables'] ? true : false );
766
767 // Show Featured Image Column
768 if ( ! isset( $options['show_featured_image_column'] ) ) $options['show_featured_image_column'] = false;
769 $options['show_featured_image_column'] = ( 'on' == $options['show_featured_image_column'] ? true : false );
770
771 // Show Excerpt Column
772 if ( ! isset( $options['show_excerpt_column'] ) ) $options['show_excerpt_column'] = false;
773 $options['show_excerpt_column'] = ( 'on' == $options['show_excerpt_column'] ? true : false );
774
775 // Show ID Column
776 if ( ! isset( $options['show_id_column'] ) ) $options['show_id_column'] = false;
777 $options['show_id_column'] = ( 'on' == $options['show_id_column'] ? true : false );
778
779 // Hide Comments Column
780 if ( ! isset( $options['hide_comments_column'] ) ) $options['hide_comments_column'] = false;
781 $options['hide_comments_column'] = ( 'on' == $options['hide_comments_column'] ? true : false );
782
783 // Hide Post Tags Column
784 if ( ! isset( $options['hide_post_tags_column'] ) ) $options['hide_post_tags_column'] = false;
785 $options['hide_post_tags_column'] = ( 'on' == $options['hide_post_tags_column'] ? true : false );
786
787 // Show Custom Taxonomy Filters
788 if ( ! isset( $options['show_custom_taxonomy_filters'] ) ) $options['show_custom_taxonomy_filters'] = false;
789 $options['show_custom_taxonomy_filters'] = ( 'on' == $options['show_custom_taxonomy_filters'] ? true : false );
790
791 // Admin Interface features
792
793 // Hide Admin Notices
794 if ( ! isset( $options['hide_admin_notices'] ) ) $options['hide_admin_notices'] = false;
795 $options['hide_admin_notices'] = ( 'on' == $options['hide_admin_notices'] ? true : false );
796
797 // Hide Admin Bar
798 if ( ! isset( $options['hide_admin_bar'] ) ) $options['hide_admin_bar'] = false;
799 $options['hide_admin_bar'] = ( 'on' == $options['hide_admin_bar'] ? true : false );
800
801 if ( is_array( $roles ) ) {
802 foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator
803 if ( ! isset( $options['hide_admin_bar_for'][$role_slug] ) ) $options['hide_admin_bar_for'][$role_slug] = false;
804 $options['hide_admin_bar_for'][$role_slug] = ( 'on' == $options['hide_admin_bar_for'][$role_slug] ? true : false );
805 }
806 }
807
808 // View Admin as Role
809 if ( ! isset( $options['view_admin_as_role'] ) ) $options['view_admin_as_role'] = false;
810 $options['view_admin_as_role'] = ( 'on' == $options['view_admin_as_role'] ? true : false );
811
812 // Hide or Modify Elements
813
814 if ( ! isset( $options['hide_modify_elements'] ) ) $options['hide_modify_elements'] = false;
815 $options['hide_modify_elements'] = ( 'on' == $options['hide_modify_elements'] ? true : false );
816
817 if ( ! isset( $options['hide_ab_wp_logo_menu'] ) ) $options['hide_ab_wp_logo_menu'] = false;
818 $options['hide_ab_wp_logo_menu'] = ( 'on' == $options['hide_ab_wp_logo_menu'] ? true : false );
819
820 if ( ! isset( $options['hide_ab_customize_menu'] ) ) $options['hide_ab_customize_menu'] = false;
821 $options['hide_ab_customize_menu'] = ( 'on' == $options['hide_ab_customize_menu'] ? true : false );
822
823 if ( ! isset( $options['hide_ab_comments_menu'] ) ) $options['hide_ab_comments_menu'] = false;
824 $options['hide_ab_comments_menu'] = ( 'on' == $options['hide_ab_comments_menu'] ? true : false );
825
826 if ( ! isset( $options['hide_ab_updates_menu'] ) ) $options['hide_ab_updates_menu'] = false;
827 $options['hide_ab_updates_menu'] = ( 'on' == $options['hide_ab_updates_menu'] ? true : false );
828
829 if ( ! isset( $options['hide_ab_new_content_menu'] ) ) $options['hide_ab_new_content_menu'] = false;
830 $options['hide_ab_new_content_menu'] = ( 'on' == $options['hide_ab_new_content_menu'] ? true : false );
831
832 if ( ! isset( $options['hide_ab_howdy'] ) ) $options['hide_ab_howdy'] = false;
833 $options['hide_ab_howdy'] = ( 'on' == $options['hide_ab_howdy'] ? true : false );
834
835 // Customize Admin Menu
836
837 if ( ! isset( $options['customize_admin_menu'] ) ) $options['customize_admin_menu'] = false;
838 $options['customize_admin_menu'] = ( 'on' == $options['customize_admin_menu'] ? true : false );
839
840 if ( ! isset( $options['custom_menu_order'] ) ) $options['custom_menu_order'] = '';
841 if ( ! isset( $options['custom_menu_hidden'] ) ) $options['custom_menu_hidden'] = '';
842
843 // Security features
844
845 // Change Login URL
846 if ( ! isset( $options['change_login_url'] ) ) $options['change_login_url'] = false;
847 $options['change_login_url'] = ( 'on' == $options['change_login_url'] ? true : false );
848
849 if ( ! isset( $options['custom_login_slug'] ) ) $options['custom_login_slug'] = 'backend';
850 $options['custom_login_slug'] = ( ! empty( $options['custom_login_slug'] ) ) ? sanitize_text_field( $options['custom_login_slug'] ) : 'backend';
851
852 // Utilities features
853
854 // Redirect After Login
855 if ( ! isset( $options['redirect_after_login'] ) ) $options['redirect_after_login'] = false;
856 $options['redirect_after_login'] = ( 'on' == $options['redirect_after_login'] ? true : false );
857
858 if ( ! isset( $options['redirect_after_login_to_slug'] ) ) $options['redirect_after_login_to_slug'] = '';
859 $options['redirect_after_login_to_slug'] = ( ! empty( $options['redirect_after_login_to_slug'] ) ) ? sanitize_text_field( $options['redirect_after_login_to_slug'] ) : '';
860
861 if ( is_array( $roles ) ) {
862 foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator
863 if ( ! isset( $options['redirect_after_login_for'][$role_slug] ) ) $options['redirect_after_login_for'][$role_slug] = false;
864 $options['redirect_after_login_for'][$role_slug] = ( 'on' == $options['redirect_after_login_for'][$role_slug] ? true : false );
865 }
866 }
867
868 // Redirect After Logout
869 if ( ! isset( $options['redirect_after_logout'] ) ) $options['redirect_after_logout'] = false;
870 $options['redirect_after_logout'] = ( 'on' == $options['redirect_after_logout'] ? true : false );
871
872 if ( ! isset( $options['redirect_after_logout_to_slug'] ) ) $options['redirect_after_logout_to_slug'] = '';
873 $options['redirect_after_logout_to_slug'] = ( ! empty( $options['redirect_after_logout_to_slug'] ) ) ? sanitize_text_field( $options['redirect_after_logout_to_slug'] ) : '';
874
875 if ( is_array( $roles ) ) {
876 foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator
877 if ( ! isset( $options['redirect_after_logout_for'][$role_slug] ) ) $options['redirect_after_logout_for'][$role_slug] = false;
878 $options['redirect_after_logout_for'][$role_slug] = ( 'on' == $options['redirect_after_logout_for'][$role_slug] ? true : false );
879 }
880 }
881
882 // Redirect 404 to Homepage
883 if ( ! isset( $options['redirect_404_to_homepage'] ) ) $options['redirect_404_to_homepage'] = false;
884 $options['redirect_404_to_homepage'] = ( 'on' == $options['redirect_404_to_homepage'] ? true : false );
885
886 return $options;
887
888 }
889
890 /**
891 * Sanitize checkbox field. For reference purpose. Not currently in use.
892 *
893 * @since 1.0.0
894 */
895 function asenha_sanitize_checkbox_field( $value ) {
896
897 // A checked checkbox field will originally be saved as an 'on' value in the option. We transform that into true (shown as 1) or false (shown as empty value)
898 return 'on' === $value ? true : false;
899
900 }
901
902 /**
903 * Render checkbox field as a toggle/switcher
904 *
905 * @since 1.0.0
906 */
907 function asenha_render_field_checkbox_toggle( $args ) {
908
909 $options = get_option( ASENHA_SLUG_U );
910
911 $field_name = $args['field_name'];
912 $field_description = $args['field_description'];
913 $field_option_value = ( array_key_exists( $args['field_id'], $options ) ) ? $options[$args['field_id']] : false;
914
915 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
916 echo '<label for="' . esc_attr( $field_name ) . '"></label>';
917
918 // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions
919 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
920 echo '<div class="asenha-field-with-options">';
921 }
922
923 echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>';
924
925 // For field with additional options / sub-fields, we add wrapper for them
926 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
927 echo '<div class="asenha-subfields" style="display:none"></div></div>';
928 }
929
930 }
931
932 /**
933 * Render checkbox field as sub-field of a toggle/switcher checkbox
934 *
935 * @since 1.9.0
936 */
937 function asenha_render_field_checkbox_plain( $args ) {
938
939 $options = get_option( ASENHA_SLUG_U );
940
941 $field_name = $args['field_name'];
942 $field_label = $args['field_label'];
943 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : false;
944
945 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
946 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>';
947
948 }
949
950 /**
951 * Render checkbox field as sub-field of a toggle/switcher checkbox
952 *
953 * @since 1.3.0
954 */
955 function asenha_render_field_checkbox_subfield( $args ) {
956
957 $options = get_option( ASENHA_SLUG_U );
958
959 $field_name = $args['field_name'];
960 $field_label = $args['field_label'];
961 $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ) ? $options[$args['parent_field_id']][$args['field_id']] : false;
962
963 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
964 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>';
965
966 }
967
968 /**
969 * Render text field as sub-field of a toggle/switcher checkbox
970 *
971 * @since 1.4.0
972 */
973 function asenha_render_field_text_subfield( $args ) {
974
975 $options = get_option( ASENHA_SLUG_U );
976
977 $field_id = $args['field_id'];
978 $field_name = $args['field_name'];
979 $field_type = $args['field_type'];
980 $field_prefix = $args['field_prefix'];
981 $field_suffix = $args['field_suffix'];
982 $field_description = $args['field_description'];
983 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
984
985 if ( $field_id == 'custom_login_slug' ) {
986 $placeholder = 'e.g. backend';
987 } elseif ( $field_id == 'redirect_after_login_to_slug' ) {
988 $placeholder = 'e.g. my-account';
989 } elseif ( $field_id == 'redirect_after_logout_to_slug' ) {
990 $placeholder = 'e.g. come-visit-again';
991 } else {}
992
993 echo $field_prefix . '<input type="text" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix;
994 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
995
996 }
997
998 /**
999 * Render sortable menu field
1000 *
1001 * @since 2.0.0
1002 */
1003 function asenha_render_field_sortable_menu( $args ) {
1004
1005 ?>
1006 <div class="subfield-description">Drag and drop menu items to the desired position. Click on the checkbox to hide it on page load. Hidden menu items can be shown by clicking on "Show All" at the bottom of the admin menu.</div>
1007 <ul id="custom-admin-menu" class="menu ui-sortable">
1008 <?php
1009
1010 global $menu;
1011 global $submenu;
1012 $options = get_option( ASENHA_SLUG_U );
1013
1014 // Get hidden menu items
1015 if ( array_key_exists( 'custom_menu_hidden', $options ) ) {
1016 $hidden_menu = $options['custom_menu_hidden'];
1017 $hidden_menu = explode( ',', $hidden_menu );
1018 } else {
1019 $hidden_menu = array();
1020 }
1021
1022 $i = 1;
1023
1024 // Check if there's an existing custom menu order data stored in options
1025
1026 if ( array_key_exists( 'custom_menu_order', $options ) ) {
1027
1028 $custom_menu = $options['custom_menu_order'];
1029 $custom_menu = explode( ',', $custom_menu );
1030
1031 // Render sortables with data in custom menu order
1032
1033 foreach ( $custom_menu as $custom_menu_item ) {
1034
1035 foreach ( $menu as $menu_key => $menu_info ) {
1036
1037 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
1038 $menu_item_id = $menu_info[2];
1039 } else {
1040 $menu_item_id = $menu_info[5];
1041 }
1042
1043 if ( $custom_menu_item == $menu_item_id ) {
1044
1045 ?>
1046 <li id="<?php echo wp_kses_post( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
1047 <div class="menu-item-bar">
1048 <div class="menu-item-handle ui-sortable-handle">
1049 <div class="item-title">
1050 <span class="menu-item-title">
1051 <?php
1052
1053 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
1054 $separator_name = $menu_info[2];
1055 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
1056 $separator_name = str_replace( '--last', '-Last', $separator_name );
1057 echo '~~ ' . wp_kses_post( $separator_name ) . ' ~~';
1058 } else {
1059 echo wp_kses_post( $menu_info[0] );
1060 }
1061
1062 ?>
1063 </span>
1064 <label class="menu-item-checkbox-label">
1065 <?php
1066 if ( in_array( $custom_menu_item, $hidden_menu ) ) {
1067 ?>
1068 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>" checked>
1069 <span>Hide</span>
1070 <?php
1071 } else {
1072 ?>
1073 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>">
1074 <span>Hide</span>
1075 <?php
1076 }
1077 ?>
1078 </label>
1079 </div>
1080 </div>
1081 </div>
1082 <?php
1083
1084 $i = 1;
1085
1086 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
1087 ?>
1088 <div class="menu-item-settings wp-clearfix" style="display:none;">
1089 <?php
1090
1091 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
1092
1093 $i++;
1094
1095 // echo $submenu_item[0];
1096
1097 }
1098 ?>
1099 </div>
1100 <?php
1101
1102 }
1103 ?>
1104 </li>
1105
1106 <?php
1107
1108 }
1109
1110 }
1111
1112 }
1113
1114 } else {
1115
1116 // Render sortables with existing items in the admin menu
1117
1118 foreach ( $menu as $menu_key => $menu_info ) {
1119
1120 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
1121 $menu_item_id = $menu_info[2];
1122 } else {
1123 $menu_item_id = $menu_info[5];
1124 }
1125
1126 ?>
1127 <li id="<?php echo wp_kses_post( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
1128 <div class="menu-item-bar">
1129 <div class="menu-item-handle ui-sortable-handle">
1130 <div class="item-title">
1131 <span class="menu-item-title">
1132 <?php
1133
1134 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
1135 $separator_name = $menu_info[2];
1136 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
1137 $separator_name = str_replace( '--last', '-Last', $separator_name );
1138 echo '~~ ' . wp_kses_post( $separator_name ) . ' ~~';
1139 } else {
1140 echo wp_kses_post( $menu_info[0] );
1141 }
1142
1143 ?>
1144 </span>
1145 <label class="menu-item-checkbox-label">
1146 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>">
1147 <span>Hide</span>
1148 </label>
1149 </div>
1150 </div>
1151 </div>
1152 <?php
1153
1154 $i = 1;
1155
1156 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
1157 ?>
1158 <div class="menu-item-settings wp-clearfix" style="display:none;">
1159 <?php
1160
1161 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
1162
1163 $i++;
1164
1165 // echo $submenu_item[0];
1166
1167 }
1168 ?>
1169 </div>
1170 <?php
1171
1172 }
1173 ?>
1174 </li>
1175
1176 <?php
1177
1178 }
1179
1180
1181 }
1182
1183
1184 ?>
1185 </ul>
1186 <?php
1187
1188 $field_id = $args['field_id'];
1189 $field_name = $args['field_name'];
1190 $field_description = $args['field_description'];
1191 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
1192
1193 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
1194 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
1195
1196 $field_id = 'custom_menu_hidden';
1197 $field_name = ASENHA_SLUG_U . '['. $field_id .']';
1198 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : '';
1199
1200 // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
1201 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
1202
1203 }
1204
1205 /**
1206 * Suppress all notices, then add notice for successful settings update
1207 *
1208 * @since 1.1.0
1209 */
1210 function asenha_notices() {
1211
1212 global $plugin_page;
1213
1214 // Suppress all notices
1215
1216 if ( ASENHA_SLUG === $plugin_page ) {
1217
1218 remove_all_actions( 'admin_notices' );
1219
1220 }
1221
1222 // Add notice for successful settings update
1223
1224 if (
1225 isset( $_GET[ 'page' ] )
1226 && ASENHA_SLUG == $_GET[ 'page' ]
1227 && isset( $_GET[ 'settings-updated' ] )
1228 && true == $_GET[ 'settings-updated' ]
1229 ) {
1230 ?>
1231 <script>
1232 jQuery(document).ready( function() {
1233 jQuery('.asenha-changes-saved').fadeIn(400).delay(2500).fadeOut(400);
1234 });
1235 </script>
1236
1237 <?php
1238 }
1239 }
1240
1241 /**
1242 * Enqueue admin scripts
1243 *
1244 * @since 1.0.0
1245 */
1246 function asenha_admin_scripts( $hook_suffix ) {
1247
1248 $current_screen = get_current_screen();
1249
1250 // Get all WP Enhancements options, default to empty array in case it's not been created yet
1251 $options = get_option( 'admin_site_enhancements', array() );
1252
1253 // For main page of this plugin
1254
1255 if ( is_asenha() ) {
1256 wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
1257 wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
1258 wp_enqueue_script( 'asenha-jsticky', ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), ASENHA_VERSION, false );
1259 wp_enqueue_style( 'asenha-admin-page', ASENHA_URL . 'assets/css/admin-page.css', array( 'asenha-jbox' ), ASENHA_VERSION );
1260 wp_enqueue_script( 'asenha-admin-page', ASENHA_URL . 'assets/js/admin-page.js', array( 'asenha-jsticky', 'asenha-jbox' ), ASENHA_VERSION, false );
1261 }
1262
1263 // Enqueue on all wp-admin
1264
1265 wp_enqueue_style( 'asenha-wp-admin', ASENHA_URL . 'assets/css/wp-admin.css', array(), ASENHA_VERSION );
1266
1267 // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page
1268
1269 if ( ( false !== strpos( $current_screen->base, 'edit' ) ) // List tables for pages, posts, taxonomies
1270 || ( false !== strpos( $current_screen->base, 'users' ) ) // Users list table
1271 || ( false !== strpos( $current_screen->base, 'upload' ) ) // Media list table
1272 ) {
1273 wp_enqueue_style( 'asenha-list-table', ASENHA_URL . 'assets/css/list-table.css', array(), ASENHA_VERSION );
1274 }
1275
1276 // Content Management >> Enable Media Replacement
1277
1278 if ( ( $current_screen->base == 'upload' ) // Media list table
1279 || ( $current_screen->id == 'attachment' ) // Media edit page
1280 ) {
1281 // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
1282 // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
1283 wp_enqueue_style( 'asenha-media-replace', ASENHA_URL . 'assets/css/media-replace.css', array(), ASENHA_VERSION );
1284 wp_enqueue_script( 'asenha-media-replace', ASENHA_URL . 'assets/js/media-replace.js', array(), ASENHA_VERSION, false );
1285 }
1286
1287 // Content Management >> Hide Admin Notices
1288 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
1289 wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
1290 wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
1291 wp_enqueue_style( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/css/hide-admin-notices.css', array(), ASENHA_VERSION );
1292 wp_enqueue_script( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/js/hide-admin-notices.js', array( 'asenha-jbox' ), ASENHA_VERSION, false );
1293 }
1294
1295 }
1296
1297 /**
1298 * Add 'Access now' plugin action link.
1299 *
1300 * @since 1.0.0
1301 */
1302
1303 function asenha_plugin_action_links( $links ) {
1304
1305 $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Access now</a>';
1306
1307 array_unshift($links, $settings_link);
1308
1309 return $links;
1310
1311 }
1312
1313 /**
1314 * Modify footer text
1315 *
1316 * @since 1.0.0
1317 */
1318 function asenha_footer_text() {
1319
1320 if ( is_asenha() ) {
1321 ?>
1322 <a href="https://wordpress.org/plugins/admin-site-enhancements/" target="_blank">Admin Site Enhancements</a> is on <a href="https://github.com/qriouslad/admin-site-enhancements" target="_blank">github</a>.
1323 <?php
1324 }
1325
1326 }
1327
1328 /**
1329 * Check if current screen is this plugin's main page
1330 *
1331 * @since 1.0.0
1332 */
1333 function is_asenha() {
1334
1335 $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug
1336
1337 if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) {
1338 return true; // Yes, this is the plugin's main page
1339 } else {
1340 return false; // Nope, this is NOT the plugin's page
1341 }
1342
1343 }