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 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
479 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>
41 </div>
42
43 <div class="asenha-body">
44 <form action="options.php" method="post">
45 <?php settings_fields( ASENHA_ID ); ?>
46 <?php do_settings_sections( ASENHA_SLUG ); ?>
47 <?php submit_button(
48 'Save Changes', // Button copy
49 'primary', // Type: 'primary', 'small', or 'large'
50 'submit', // The 'name' attribute
51 true, // Whether to wrap in <p> tag
52 array( 'id' => 'asenha-submit' ), // additional attributes
53 ); ?>
54 </form>
55 </div>
56
57 <div class="asenha-footer">
58 </div>
59
60 </div>
61 <?php
62
63 }
64
65 /**
66 * Register plugin settings and the corresponding fields
67 *
68 * @link https://wpshout.com/making-an-admin-options-page-with-the-wordpress-settings-api/
69 * @link https://rudrastyh.com/wordpress/creating-options-pages.html
70 * @since 1.0.0
71 */
72 function asenha_register_settings() {
73
74 // Add "Content Management" section
75
76 add_settings_section(
77 'content-management', // Section ID
78 '', // Section title. Can be blank.
79 '', // Callback function to output section intro. Can be blank.
80 ASENHA_SLUG // Settings page slug
81 );
82
83 // Register main setttings
84
85 register_setting(
86 ASENHA_ID, // Option group or option_page
87 ASENHA_SLUG_U, // Option name in wp_options table
88 array(
89 'type' => 'array', // 'string', 'boolean', 'integer', 'number', 'array', or 'object'
90 'description' => '', // A description of the data attached to this setting.
91 'sanitize_callback' => 'asenha_sanitize_options',
92 'show_in_rest' => false,
93 'default' => array(), // When calling get_option()
94 )
95 );
96
97 // Register fields for "Content Management" section
98
99 // Show Featured Image Column
100
101 $field_id = 'show_featured_image_column';
102
103 add_settings_field(
104 $field_id, // Field ID
105 'Show Featured Image Column', // Field title
106 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
107 ASENHA_SLUG, // Settings page slug
108 'content-management', // Section ID
109 array(
110 'field_id' => $field_id, // Custom argument
111 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
112 'field_description' => 'Show featured image column in list tables for pages and post types that support featured images.', // Custom argument
113 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
114 )
115 );
116
117 // Show Excerpt Column
118
119 $field_id = 'show_excerpt_column';
120
121 add_settings_field(
122 $field_id, // Field ID
123 'Show Excerpt Column', // Field title
124 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
125 ASENHA_SLUG, // Settings page slug
126 'content-management', // Section ID
127 array(
128 'field_id' => $field_id, // Custom argument
129 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
130 'field_description' => 'Show excerpt column in list tables for pages and post types that support excerpt.', // Custom argument
131 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
132 )
133 );
134
135 // Show ID Column
136
137 $field_id = 'show_id_column';
138
139 add_settings_field(
140 $field_id, // Field ID
141 'Show ID Column', // Field title
142 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
143 ASENHA_SLUG, // Settings page slug
144 'content-management', // Section ID
145 array(
146 'field_id' => $field_id, // Custom argument
147 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
148 'field_description' => 'Show ID column in list tables for pages, all post types, all taxonomies, media, users and comments.', // Custom argument
149 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
150 )
151 );
152
153 // Hide Comments Column
154
155 $field_id = 'hide_comments_column';
156
157 add_settings_field(
158 $field_id, // Field ID
159 'Hide Comments Column', // Field title
160 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
161 ASENHA_SLUG, // Settings page slug
162 'content-management', // Section ID
163 array(
164 'field_id' => $field_id, // Custom argument
165 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
166 'field_description' => 'Hide comments column in list tables for pages, post types that support comments, and alse media/attachments.', // Custom argument
167 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
168 )
169 );
170
171 // Hide Post Tags Column
172
173 $field_id = 'hide_post_tags_column';
174
175 add_settings_field(
176 $field_id, // Field ID
177 'Hide Post Tags Column', // Field title
178 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
179 ASENHA_SLUG, // Settings page slug
180 'content-management', // Section ID
181 array(
182 'field_id' => $field_id, // Custom argument
183 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
184 'field_description' => 'Hide tags column in list tables for posts.', // Custom argument
185 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
186 )
187 );
188
189 // Show Custom Taxonomy Filters
190
191 $field_id = 'show_custom_taxonomy_filters';
192
193 add_settings_field(
194 $field_id, // Field ID
195 'Show Custom Taxonomy Filters', // Field title
196 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
197 ASENHA_SLUG, // Settings page slug
198 'content-management', // Section ID
199 array(
200 'field_id' => $field_id, // Custom argument
201 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
202 'field_description' => 'Show additional filter(s) for hierarchical, custom taxonomies on list tables of all post types. This will work similarly with the post categories filter.', // Custom argument
203 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
204 )
205 );
206
207 // Enable Page and Post Duplication
208
209 $field_id = 'enable_duplication';
210
211 add_settings_field(
212 $field_id, // Field ID
213 'Enable Page and Post Duplication', // Field title
214 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
215 ASENHA_SLUG, // Settings page slug
216 'content-management', // Section ID
217 array(
218 'field_id' => $field_id, // Custom argument
219 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
220 '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
221 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
222 )
223 );
224
225 // Enable Media Replacement
226
227 $field_id = 'enable_media_replacement';
228
229 add_settings_field(
230 $field_id, // Field ID
231 'Enable Media Replacement', // Field title
232 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
233 ASENHA_SLUG, // Settings page slug
234 'content-management', // Section ID
235 array(
236 'field_id' => $field_id, // Custom argument
237 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
238 'field_description' => 'Easily replace any type of media file with a new one while retaining the existing media ID and file name.', // Custom argument
239 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
240 )
241 );
242
243 // Hide Admin Notices
244
245 $field_id = 'hide_admin_notices';
246
247 add_settings_field(
248 $field_id, // Field ID
249 'Hide Admin Notices', // Field title
250 'asenha_render_field_checkbox', // Callback to render field with custom arguments in the array below
251 ASENHA_SLUG, // Settings page slug
252 'content-management', // Section ID
253 array(
254 'field_id' => $field_id, // Custom argument
255 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument
256 'field_description' => 'Clean up admin pages by moving notices into a separate panel easily accessible via the admin bar.', // Custom argument
257 'class' => 'asenha-toggle content-management', // Custom class for the <tr> element
258 )
259 );
260
261 }
262
263 /**
264 * Sanitize options
265 *
266 * @since 1.0.0
267 */
268 function asenha_sanitize_options( $options ) {
269
270 // Show Featured Image Column
271 if ( ! isset( $options['show_featured_image_column'] ) ) $options['show_featured_image_column'] = false;
272 $options['show_featured_image_column'] = ( 'on' == $options['show_featured_image_column'] ? true : false );
273
274 // Show Excerpt Column
275 if ( ! isset( $options['show_excerpt_column'] ) ) $options['show_excerpt_column'] = false;
276 $options['show_excerpt_column'] = ( 'on' == $options['show_excerpt_column'] ? true : false );
277
278 // Show ID Column
279 if ( ! isset( $options['show_id_column'] ) ) $options['show_id_column'] = false;
280 $options['show_id_column'] = ( 'on' == $options['show_id_column'] ? true : false );
281
282 // Hide Comments Column
283 if ( ! isset( $options['hide_comments_column'] ) ) $options['hide_comments_column'] = false;
284 $options['hide_comments_column'] = ( 'on' == $options['hide_comments_column'] ? true : false );
285
286 // Hide Post Tags Column
287 if ( ! isset( $options['hide_post_tags_column'] ) ) $options['hide_post_tags_column'] = false;
288 $options['hide_post_tags_column'] = ( 'on' == $options['hide_post_tags_column'] ? true : false );
289
290 // Show Custom Taxonomy Filters
291 if ( ! isset( $options['show_custom_taxonomy_filters'] ) ) $options['show_custom_taxonomy_filters'] = false;
292 $options['show_custom_taxonomy_filters'] = ( 'on' == $options['show_custom_taxonomy_filters'] ? true : false );
293
294 // Enable Page and Post Duplication
295 if ( ! isset( $options['enable_duplication'] ) ) $options['enable_duplication'] = false;
296 $options['enable_duplication'] = ( 'on' == $options['enable_duplication'] ? true : false );
297
298 // Enable Media Replacement
299 if ( ! isset( $options['enable_media_replacement'] ) ) $options['enable_media_replacement'] = false;
300 $options['enable_media_replacement'] = ( 'on' == $options['enable_media_replacement'] ? true : false );
301
302 // Hide Admin Notices
303 if ( ! isset( $options['hide_admin_notices'] ) ) $options['hide_admin_notices'] = false;
304 $options['hide_admin_notices'] = ( 'on' == $options['hide_admin_notices'] ? true : false );
305
306 return $options;
307
308 }
309
310 /**
311 * Sanitize checkbox field. For reference purpose. Not currently in use.
312 *
313 * @since 1.0.0
314 */
315 function asenha_sanitize_checkbox_field( $value ) {
316
317 // 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)
318 return 'on' === $value ? true : false;
319
320 }
321
322 /**
323 * Render checkbox fields
324 *
325 * @since 1.0.0
326 */
327 function asenha_render_field_checkbox( $args ) {
328
329 $options = get_option( ASENHA_SLUG_U );
330
331 $field_name = $args['field_name'];
332 $field_description = $args['field_description'];
333 $field_option_value = ( array_key_exists( $args['field_id'], $options ) ) ? $options[$args['field_id']] : false;
334
335 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
336 echo '<label for="' . esc_attr( $field_name ) . '"></label>';
337 echo '<div class="asenha-field-description">' . esc_html( $field_description ) . '</div>';
338
339 }
340
341 /**
342 * Suppress all notices, then add notice for successful settings update
343 *
344 * @since 1.1.0
345 */
346 function asenha_notices() {
347
348 global $plugin_page;
349
350 // Suppress all notices
351
352 if ( ASENHA_SLUG === $plugin_page ) {
353
354 remove_all_actions( 'admin_notices' );
355
356 }
357
358 // Add notice for successful settings update
359
360 if (
361 isset( $_GET[ 'page' ] )
362 && ASENHA_SLUG == $_GET[ 'page' ]
363 && isset( $_GET[ 'settings-updated' ] )
364 && true == $_GET[ 'settings-updated' ]
365 ) {
366 // Prevent notice from moved under page heading by adding 'inline' class: https://iandunn.name/2019/06/01/prevent-manual-admin-notices-from-being-moved-to-the-top/
367 ?>
368 <div class="notice notice-success inline">
369 <p>
370 <strong>Changes have been saved.</strong>
371 </p>
372 </div>
373 <?php
374 }
375 }
376
377 /**
378 * Enqueue admin scripts
379 *
380 * @since 1.0.0
381 */
382 function asenha_admin_scripts( $hook_suffix ) {
383
384 $current_screen = get_current_screen();
385
386 // Get all WP Enhancements options, default to empty array in case it's not been created yet
387 $options = get_option( 'admin_site_enhancements', array() );
388
389 // For main page of this plugin
390
391 if ( is_asenha() ) {
392 wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
393 wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
394 wp_enqueue_script( 'asenha-jsticky', DLM_URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), DLM_VERSION, false );
395 wp_enqueue_style( 'asenha-admin-page', ASENHA_URL . 'assets/css/admin-page.css', array( 'asenha-jbox' ), ASENHA_VERSION );
396 wp_enqueue_script( 'asenha-admin-page', ASENHA_URL . 'assets/js/admin-page.js', array( 'asenha-jsticky', 'asenha-jbox' ), ASENHA_VERSION, false );
397 }
398
399 // Enqueue on all wp-admin
400
401 wp_enqueue_style( 'asenha-wp-admin', ASENHA_URL . 'assets/css/wp-admin.css', array(), ASENHA_VERSION );
402
403 // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page
404
405 if ( ( false !== strpos( $current_screen->base, 'edit' ) ) // List tables for pages, posts, taxonomies
406 || ( false !== strpos( $current_screen->base, 'users' ) ) // Users list table
407 || ( false !== strpos( $current_screen->base, 'upload' ) ) // Media list table
408 ) {
409 wp_enqueue_style( 'asenha-list-table', ASENHA_URL . 'assets/css/list-table.css', array(), ASENHA_VERSION );
410 }
411
412 // Content Management >> Enable Media Replacement
413
414 if ( ( $current_screen->base == 'upload' ) // Media list table
415 || ( $current_screen->id == 'attachment' ) // Media edit page
416 ) {
417 // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
418 // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
419 wp_enqueue_style( 'asenha-media-replace', ASENHA_URL . 'assets/css/media-replace.css', array(), ASENHA_VERSION );
420 wp_enqueue_script( 'asenha-media-replace', ASENHA_URL . 'assets/js/media-replace.js', array(), ASENHA_VERSION, false );
421 }
422
423 // Content Management >> Hide Admin Notices
424 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
425 wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
426 wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
427 wp_enqueue_style( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/css/hide-admin-notices.css', array(), ASENHA_VERSION );
428 wp_enqueue_script( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/js/hide-admin-notices.js', array( 'asenha-jbox' ), ASENHA_VERSION, false );
429 }
430
431 }
432
433 /**
434 * Add 'Access now' plugin action link.
435 *
436 * @since 1.0.0
437 */
438
439 function asenha_plugin_action_links( $links ) {
440
441 $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Access now</a>';
442
443 array_unshift($links, $settings_link);
444
445 return $links;
446
447 }
448
449 /**
450 * Modify footer text
451 *
452 * @since 1.0.0
453 */
454 function asenha_footer_text() {
455
456 if ( is_asenha() ) {
457 ?>
458 <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>.
459 <?php
460 }
461
462 }
463
464 /**
465 * Check if current screen is this plugin's main page
466 *
467 * @since 1.0.0
468 */
469 function is_asenha() {
470
471 $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug
472
473 if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) {
474 return true; // Yes, this is the plugin's main page
475 } else {
476 return false; // Nope, this is NOT the plugin's page
477 }
478
479 }