setup-admin-menu-page.php
1367 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>ℹ</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>★</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">✚ <?php esc_html_e( 'Feedback', 'admin-site-enhancements' ); ?></a> |
| 36 | <a href="https://paypal.me/qriouslad" target="_blank" class="asenha-header-action">♥ <?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, publish date and file name. So, no existing links will break.', // 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 | // Obfuscate Author Slugs |
| 593 | |
| 594 | $field_id = 'obfuscate_author_slugs'; |
| 595 | $field_slug = 'obfuscate-author-slugs'; |
| 596 | |
| 597 | add_settings_field( |
| 598 | $field_id, // Field ID |
| 599 | 'Obfuscate Author Slugs', // 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' => 'Obfuscate publicly exposed author page URLs that shows the user slugs / usernames, e.g. <em>sitename.com/author/username1/</em> into <em>sitename.com/author/a6r5b8ytu9gp34bv/</em>, and output 404 errors for the original URLs. Also obfuscates in /wp-json/wp/v2/users/ REST API endpoint.', // Custom argument |
| 607 | 'field_options_wrapper' => false, // Custom argument. Add container for additional options |
| 608 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 609 | ) |
| 610 | ); |
| 611 | |
| 612 | // Redirect After Login |
| 613 | |
| 614 | $field_id = 'redirect_after_login'; |
| 615 | $field_slug = 'redirect-after-login'; |
| 616 | |
| 617 | add_settings_field( |
| 618 | $field_id, // Field ID |
| 619 | 'Redirect After Login', // Field title |
| 620 | 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below |
| 621 | ASENHA_SLUG, // Settings page slug |
| 622 | 'main-section', // Section ID |
| 623 | array( |
| 624 | 'field_id' => $field_id, // Custom argument |
| 625 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 626 | 'field_description' => 'Set custom redirect URL for all or some user roles after login.', // Custom argument |
| 627 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 628 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 629 | ) |
| 630 | ); |
| 631 | |
| 632 | $field_id = 'redirect_after_login_to_slug'; |
| 633 | $field_slug = 'redirect-after-login-to-slug'; |
| 634 | |
| 635 | add_settings_field( |
| 636 | $field_id, // Field ID |
| 637 | 'Redirect to:', // Field title |
| 638 | 'asenha_render_field_text_subfield', // Callback to render field with custom arguments in the array below |
| 639 | ASENHA_SLUG, // Settings page slug |
| 640 | 'main-section', // Section ID |
| 641 | array( |
| 642 | 'field_id' => $field_id, // Custom argument |
| 643 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 644 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 645 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 646 | 'field_suffix' => '/ for:', // Custom argument |
| 647 | 'field_description' => '', // Custom argument |
| 648 | 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element |
| 649 | ) |
| 650 | ); |
| 651 | |
| 652 | $field_id = 'redirect_after_login_for'; |
| 653 | $field_slug = 'redirect-after-login-for'; |
| 654 | |
| 655 | if ( is_array( $roles ) ) { |
| 656 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 657 | |
| 658 | add_settings_field( |
| 659 | $field_id . '_' . $role_slug, // Field ID |
| 660 | '', // Field title |
| 661 | 'asenha_render_field_checkbox_subfield', // Callback to render field with custom arguments in the array below |
| 662 | ASENHA_SLUG, // Settings page slug |
| 663 | 'main-section', // Section ID |
| 664 | array( |
| 665 | 'parent_field_id' => $field_id, // Custom argument |
| 666 | 'field_id' => $role_slug, // Custom argument |
| 667 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 668 | 'field_label' => $role_label, // Custom argument |
| 669 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 670 | ) |
| 671 | ); |
| 672 | |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // Redirect After Logout |
| 677 | |
| 678 | $field_id = 'redirect_after_logout'; |
| 679 | $field_slug = 'redirect-after-logout'; |
| 680 | |
| 681 | add_settings_field( |
| 682 | $field_id, // Field ID |
| 683 | 'Redirect After Logout', // Field title |
| 684 | 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below |
| 685 | ASENHA_SLUG, // Settings page slug |
| 686 | 'main-section', // Section ID |
| 687 | array( |
| 688 | 'field_id' => $field_id, // Custom argument |
| 689 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 690 | 'field_description' => 'Set custom redirect URL for all or some user roles after logout.', // Custom argument |
| 691 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 692 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 693 | ) |
| 694 | ); |
| 695 | |
| 696 | $field_id = 'redirect_after_logout_to_slug'; |
| 697 | $field_slug = 'redirect-after-logout-to-slug'; |
| 698 | |
| 699 | add_settings_field( |
| 700 | $field_id, // Field ID |
| 701 | 'Redirect to:', // Field title |
| 702 | 'asenha_render_field_text_subfield', // Callback to render field with custom arguments in the array below |
| 703 | ASENHA_SLUG, // Settings page slug |
| 704 | 'main-section', // Section ID |
| 705 | array( |
| 706 | 'field_id' => $field_id, // Custom argument |
| 707 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 708 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 709 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 710 | 'field_suffix' => '/ for:', // Custom argument |
| 711 | 'field_description' => '', // Custom argument |
| 712 | 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element |
| 713 | ) |
| 714 | ); |
| 715 | |
| 716 | $field_id = 'redirect_after_logout_for'; |
| 717 | $field_slug = 'redirect-after-logout-for'; |
| 718 | |
| 719 | if ( is_array( $roles ) ) { |
| 720 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 721 | |
| 722 | add_settings_field( |
| 723 | $field_id . '_' . $role_slug, // Field ID |
| 724 | '', // Field title |
| 725 | 'asenha_render_field_checkbox_subfield', // Callback to render field with custom arguments in the array below |
| 726 | ASENHA_SLUG, // Settings page slug |
| 727 | 'main-section', // Section ID |
| 728 | array( |
| 729 | 'parent_field_id' => $field_id, // Custom argument |
| 730 | 'field_id' => $role_slug, // Custom argument |
| 731 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 732 | 'field_label' => $role_label, // Custom argument |
| 733 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 734 | ) |
| 735 | ); |
| 736 | |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | // Redirect 404 to Homepage |
| 741 | |
| 742 | $field_id = 'redirect_404_to_homepage'; |
| 743 | $field_slug = 'redirect-404-to-homepage'; |
| 744 | |
| 745 | add_settings_field( |
| 746 | $field_id, // Field ID |
| 747 | 'Redirect 404 to Homepage', // Field title |
| 748 | 'asenha_render_field_checkbox_toggle', // Callback to render field with custom arguments in the array below |
| 749 | ASENHA_SLUG, // Settings page slug |
| 750 | 'main-section', // Section ID |
| 751 | array( |
| 752 | 'field_id' => $field_id, // Custom argument |
| 753 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 754 | 'field_description' => 'Perform 301 (permanent) redirect to the homepage for all 404 (not found) pages.', // Custom argument |
| 755 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 756 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 757 | ) |
| 758 | ); |
| 759 | |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Sanitize options |
| 764 | * |
| 765 | * @since 1.0.0 |
| 766 | */ |
| 767 | function asenha_sanitize_options( $options ) { |
| 768 | |
| 769 | // Call WordPress globals required for validating the fields |
| 770 | global $wp_roles; |
| 771 | $roles = $wp_roles->get_names(); |
| 772 | |
| 773 | // Content Management features |
| 774 | |
| 775 | // Enable Page and Post Duplication |
| 776 | if ( ! isset( $options['enable_duplication'] ) ) $options['enable_duplication'] = false; |
| 777 | $options['enable_duplication'] = ( 'on' == $options['enable_duplication'] ? true : false ); |
| 778 | |
| 779 | // Enable Media Replacement |
| 780 | if ( ! isset( $options['enable_media_replacement'] ) ) $options['enable_media_replacement'] = false; |
| 781 | $options['enable_media_replacement'] = ( 'on' == $options['enable_media_replacement'] ? true : false ); |
| 782 | |
| 783 | // Enhance List Tables |
| 784 | if ( ! isset( $options['enhance_list_tables'] ) ) $options['enhance_list_tables'] = false; |
| 785 | $options['enhance_list_tables'] = ( 'on' == $options['enhance_list_tables'] ? true : false ); |
| 786 | |
| 787 | // Show Featured Image Column |
| 788 | if ( ! isset( $options['show_featured_image_column'] ) ) $options['show_featured_image_column'] = false; |
| 789 | $options['show_featured_image_column'] = ( 'on' == $options['show_featured_image_column'] ? true : false ); |
| 790 | |
| 791 | // Show Excerpt Column |
| 792 | if ( ! isset( $options['show_excerpt_column'] ) ) $options['show_excerpt_column'] = false; |
| 793 | $options['show_excerpt_column'] = ( 'on' == $options['show_excerpt_column'] ? true : false ); |
| 794 | |
| 795 | // Show ID Column |
| 796 | if ( ! isset( $options['show_id_column'] ) ) $options['show_id_column'] = false; |
| 797 | $options['show_id_column'] = ( 'on' == $options['show_id_column'] ? true : false ); |
| 798 | |
| 799 | // Hide Comments Column |
| 800 | if ( ! isset( $options['hide_comments_column'] ) ) $options['hide_comments_column'] = false; |
| 801 | $options['hide_comments_column'] = ( 'on' == $options['hide_comments_column'] ? true : false ); |
| 802 | |
| 803 | // Hide Post Tags Column |
| 804 | if ( ! isset( $options['hide_post_tags_column'] ) ) $options['hide_post_tags_column'] = false; |
| 805 | $options['hide_post_tags_column'] = ( 'on' == $options['hide_post_tags_column'] ? true : false ); |
| 806 | |
| 807 | // Show Custom Taxonomy Filters |
| 808 | if ( ! isset( $options['show_custom_taxonomy_filters'] ) ) $options['show_custom_taxonomy_filters'] = false; |
| 809 | $options['show_custom_taxonomy_filters'] = ( 'on' == $options['show_custom_taxonomy_filters'] ? true : false ); |
| 810 | |
| 811 | // Admin Interface features |
| 812 | |
| 813 | // Hide Admin Notices |
| 814 | if ( ! isset( $options['hide_admin_notices'] ) ) $options['hide_admin_notices'] = false; |
| 815 | $options['hide_admin_notices'] = ( 'on' == $options['hide_admin_notices'] ? true : false ); |
| 816 | |
| 817 | // Hide Admin Bar |
| 818 | if ( ! isset( $options['hide_admin_bar'] ) ) $options['hide_admin_bar'] = false; |
| 819 | $options['hide_admin_bar'] = ( 'on' == $options['hide_admin_bar'] ? true : false ); |
| 820 | |
| 821 | if ( is_array( $roles ) ) { |
| 822 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 823 | if ( ! isset( $options['hide_admin_bar_for'][$role_slug] ) ) $options['hide_admin_bar_for'][$role_slug] = false; |
| 824 | $options['hide_admin_bar_for'][$role_slug] = ( 'on' == $options['hide_admin_bar_for'][$role_slug] ? true : false ); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | // View Admin as Role |
| 829 | if ( ! isset( $options['view_admin_as_role'] ) ) $options['view_admin_as_role'] = false; |
| 830 | $options['view_admin_as_role'] = ( 'on' == $options['view_admin_as_role'] ? true : false ); |
| 831 | |
| 832 | // Hide or Modify Elements |
| 833 | |
| 834 | if ( ! isset( $options['hide_modify_elements'] ) ) $options['hide_modify_elements'] = false; |
| 835 | $options['hide_modify_elements'] = ( 'on' == $options['hide_modify_elements'] ? true : false ); |
| 836 | |
| 837 | if ( ! isset( $options['hide_ab_wp_logo_menu'] ) ) $options['hide_ab_wp_logo_menu'] = false; |
| 838 | $options['hide_ab_wp_logo_menu'] = ( 'on' == $options['hide_ab_wp_logo_menu'] ? true : false ); |
| 839 | |
| 840 | if ( ! isset( $options['hide_ab_customize_menu'] ) ) $options['hide_ab_customize_menu'] = false; |
| 841 | $options['hide_ab_customize_menu'] = ( 'on' == $options['hide_ab_customize_menu'] ? true : false ); |
| 842 | |
| 843 | if ( ! isset( $options['hide_ab_comments_menu'] ) ) $options['hide_ab_comments_menu'] = false; |
| 844 | $options['hide_ab_comments_menu'] = ( 'on' == $options['hide_ab_comments_menu'] ? true : false ); |
| 845 | |
| 846 | if ( ! isset( $options['hide_ab_updates_menu'] ) ) $options['hide_ab_updates_menu'] = false; |
| 847 | $options['hide_ab_updates_menu'] = ( 'on' == $options['hide_ab_updates_menu'] ? true : false ); |
| 848 | |
| 849 | if ( ! isset( $options['hide_ab_new_content_menu'] ) ) $options['hide_ab_new_content_menu'] = false; |
| 850 | $options['hide_ab_new_content_menu'] = ( 'on' == $options['hide_ab_new_content_menu'] ? true : false ); |
| 851 | |
| 852 | if ( ! isset( $options['hide_ab_howdy'] ) ) $options['hide_ab_howdy'] = false; |
| 853 | $options['hide_ab_howdy'] = ( 'on' == $options['hide_ab_howdy'] ? true : false ); |
| 854 | |
| 855 | // Customize Admin Menu |
| 856 | |
| 857 | if ( ! isset( $options['customize_admin_menu'] ) ) $options['customize_admin_menu'] = false; |
| 858 | $options['customize_admin_menu'] = ( 'on' == $options['customize_admin_menu'] ? true : false ); |
| 859 | |
| 860 | if ( ! isset( $options['custom_menu_order'] ) ) $options['custom_menu_order'] = ''; |
| 861 | if ( ! isset( $options['custom_menu_hidden'] ) ) $options['custom_menu_hidden'] = ''; |
| 862 | |
| 863 | // Security features |
| 864 | |
| 865 | // Change Login URL |
| 866 | if ( ! isset( $options['change_login_url'] ) ) $options['change_login_url'] = false; |
| 867 | $options['change_login_url'] = ( 'on' == $options['change_login_url'] ? true : false ); |
| 868 | |
| 869 | if ( ! isset( $options['custom_login_slug'] ) ) $options['custom_login_slug'] = 'backend'; |
| 870 | $options['custom_login_slug'] = ( ! empty( $options['custom_login_slug'] ) ) ? sanitize_text_field( $options['custom_login_slug'] ) : 'backend'; |
| 871 | |
| 872 | // Obfuscate Author Slugs |
| 873 | if ( ! isset( $options['obfuscate_author_slugs'] ) ) $options['obfuscate_author_slugs'] = false; |
| 874 | $options['obfuscate_author_slugs'] = ( 'on' == $options['obfuscate_author_slugs'] ? true : false ); |
| 875 | |
| 876 | // Utilities features |
| 877 | |
| 878 | // Redirect After Login |
| 879 | if ( ! isset( $options['redirect_after_login'] ) ) $options['redirect_after_login'] = false; |
| 880 | $options['redirect_after_login'] = ( 'on' == $options['redirect_after_login'] ? true : false ); |
| 881 | |
| 882 | if ( ! isset( $options['redirect_after_login_to_slug'] ) ) $options['redirect_after_login_to_slug'] = ''; |
| 883 | $options['redirect_after_login_to_slug'] = ( ! empty( $options['redirect_after_login_to_slug'] ) ) ? sanitize_text_field( $options['redirect_after_login_to_slug'] ) : ''; |
| 884 | |
| 885 | if ( is_array( $roles ) ) { |
| 886 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 887 | if ( ! isset( $options['redirect_after_login_for'][$role_slug] ) ) $options['redirect_after_login_for'][$role_slug] = false; |
| 888 | $options['redirect_after_login_for'][$role_slug] = ( 'on' == $options['redirect_after_login_for'][$role_slug] ? true : false ); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | // Redirect After Logout |
| 893 | if ( ! isset( $options['redirect_after_logout'] ) ) $options['redirect_after_logout'] = false; |
| 894 | $options['redirect_after_logout'] = ( 'on' == $options['redirect_after_logout'] ? true : false ); |
| 895 | |
| 896 | if ( ! isset( $options['redirect_after_logout_to_slug'] ) ) $options['redirect_after_logout_to_slug'] = ''; |
| 897 | $options['redirect_after_logout_to_slug'] = ( ! empty( $options['redirect_after_logout_to_slug'] ) ) ? sanitize_text_field( $options['redirect_after_logout_to_slug'] ) : ''; |
| 898 | |
| 899 | if ( is_array( $roles ) ) { |
| 900 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 901 | if ( ! isset( $options['redirect_after_logout_for'][$role_slug] ) ) $options['redirect_after_logout_for'][$role_slug] = false; |
| 902 | $options['redirect_after_logout_for'][$role_slug] = ( 'on' == $options['redirect_after_logout_for'][$role_slug] ? true : false ); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | // Redirect 404 to Homepage |
| 907 | if ( ! isset( $options['redirect_404_to_homepage'] ) ) $options['redirect_404_to_homepage'] = false; |
| 908 | $options['redirect_404_to_homepage'] = ( 'on' == $options['redirect_404_to_homepage'] ? true : false ); |
| 909 | |
| 910 | return $options; |
| 911 | |
| 912 | } |
| 913 | |
| 914 | /** |
| 915 | * Sanitize checkbox field. For reference purpose. Not currently in use. |
| 916 | * |
| 917 | * @since 1.0.0 |
| 918 | */ |
| 919 | function asenha_sanitize_checkbox_field( $value ) { |
| 920 | |
| 921 | // 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) |
| 922 | return 'on' === $value ? true : false; |
| 923 | |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * Render checkbox field as a toggle/switcher |
| 928 | * |
| 929 | * @since 1.0.0 |
| 930 | */ |
| 931 | function asenha_render_field_checkbox_toggle( $args ) { |
| 932 | |
| 933 | $options = get_option( ASENHA_SLUG_U ); |
| 934 | |
| 935 | $field_name = $args['field_name']; |
| 936 | $field_description = $args['field_description']; |
| 937 | $field_option_value = ( array_key_exists( $args['field_id'], $options ) ) ? $options[$args['field_id']] : false; |
| 938 | |
| 939 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>'; |
| 940 | echo '<label for="' . esc_attr( $field_name ) . '"></label>'; |
| 941 | |
| 942 | // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions |
| 943 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 944 | echo '<div class="asenha-field-with-options">'; |
| 945 | } |
| 946 | |
| 947 | echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>'; |
| 948 | |
| 949 | // For field with additional options / sub-fields, we add wrapper for them |
| 950 | if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) { |
| 951 | echo '<div class="asenha-subfields" style="display:none"></div></div>'; |
| 952 | } |
| 953 | |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * Render checkbox field as sub-field of a toggle/switcher checkbox |
| 958 | * |
| 959 | * @since 1.9.0 |
| 960 | */ |
| 961 | function asenha_render_field_checkbox_plain( $args ) { |
| 962 | |
| 963 | $options = get_option( ASENHA_SLUG_U ); |
| 964 | |
| 965 | $field_name = $args['field_name']; |
| 966 | $field_label = $args['field_label']; |
| 967 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : false; |
| 968 | |
| 969 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>'; |
| 970 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>'; |
| 971 | |
| 972 | } |
| 973 | |
| 974 | /** |
| 975 | * Render checkbox field as sub-field of a toggle/switcher checkbox |
| 976 | * |
| 977 | * @since 1.3.0 |
| 978 | */ |
| 979 | function asenha_render_field_checkbox_subfield( $args ) { |
| 980 | |
| 981 | $options = get_option( ASENHA_SLUG_U ); |
| 982 | |
| 983 | $field_name = $args['field_name']; |
| 984 | $field_label = $args['field_label']; |
| 985 | $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ) ? $options[$args['parent_field_id']][$args['field_id']] : false; |
| 986 | |
| 987 | echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>'; |
| 988 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>'; |
| 989 | |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * Render text field as sub-field of a toggle/switcher checkbox |
| 994 | * |
| 995 | * @since 1.4.0 |
| 996 | */ |
| 997 | function asenha_render_field_text_subfield( $args ) { |
| 998 | |
| 999 | $options = get_option( ASENHA_SLUG_U ); |
| 1000 | |
| 1001 | $field_id = $args['field_id']; |
| 1002 | $field_name = $args['field_name']; |
| 1003 | $field_type = $args['field_type']; |
| 1004 | $field_prefix = $args['field_prefix']; |
| 1005 | $field_suffix = $args['field_suffix']; |
| 1006 | $field_description = $args['field_description']; |
| 1007 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 1008 | |
| 1009 | if ( $field_id == 'custom_login_slug' ) { |
| 1010 | $placeholder = 'e.g. backend'; |
| 1011 | } elseif ( $field_id == 'redirect_after_login_to_slug' ) { |
| 1012 | $placeholder = 'e.g. my-account'; |
| 1013 | } elseif ( $field_id == 'redirect_after_logout_to_slug' ) { |
| 1014 | $placeholder = 'e.g. come-visit-again'; |
| 1015 | } else {} |
| 1016 | |
| 1017 | 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; |
| 1018 | echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>'; |
| 1019 | |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Render sortable menu field |
| 1024 | * |
| 1025 | * @since 2.0.0 |
| 1026 | */ |
| 1027 | function asenha_render_field_sortable_menu( $args ) { |
| 1028 | |
| 1029 | ?> |
| 1030 | <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> |
| 1031 | <ul id="custom-admin-menu" class="menu ui-sortable"> |
| 1032 | <?php |
| 1033 | |
| 1034 | global $menu; |
| 1035 | global $submenu; |
| 1036 | $options = get_option( ASENHA_SLUG_U ); |
| 1037 | |
| 1038 | // Get hidden menu items |
| 1039 | if ( array_key_exists( 'custom_menu_hidden', $options ) ) { |
| 1040 | $hidden_menu = $options['custom_menu_hidden']; |
| 1041 | $hidden_menu = explode( ',', $hidden_menu ); |
| 1042 | } else { |
| 1043 | $hidden_menu = array(); |
| 1044 | } |
| 1045 | |
| 1046 | $i = 1; |
| 1047 | |
| 1048 | // Check if there's an existing custom menu order data stored in options |
| 1049 | |
| 1050 | if ( array_key_exists( 'custom_menu_order', $options ) ) { |
| 1051 | |
| 1052 | $custom_menu = $options['custom_menu_order']; |
| 1053 | $custom_menu = explode( ',', $custom_menu ); |
| 1054 | |
| 1055 | // Render sortables with data in custom menu order |
| 1056 | |
| 1057 | foreach ( $custom_menu as $custom_menu_item ) { |
| 1058 | |
| 1059 | foreach ( $menu as $menu_key => $menu_info ) { |
| 1060 | |
| 1061 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 1062 | $menu_item_id = $menu_info[2]; |
| 1063 | } else { |
| 1064 | $menu_item_id = $menu_info[5]; |
| 1065 | } |
| 1066 | |
| 1067 | if ( $custom_menu_item == $menu_item_id ) { |
| 1068 | |
| 1069 | ?> |
| 1070 | <li id="<?php echo wp_kses_post( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 1071 | <div class="menu-item-bar"> |
| 1072 | <div class="menu-item-handle ui-sortable-handle"> |
| 1073 | <div class="item-title"> |
| 1074 | <span class="menu-item-title"> |
| 1075 | <?php |
| 1076 | |
| 1077 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 1078 | $separator_name = $menu_info[2]; |
| 1079 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name ); |
| 1080 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 1081 | echo '~~ ' . wp_kses_post( $separator_name ) . ' ~~'; |
| 1082 | } else { |
| 1083 | echo wp_kses_post( $menu_info[0] ); |
| 1084 | } |
| 1085 | |
| 1086 | ?> |
| 1087 | </span> |
| 1088 | <label class="menu-item-checkbox-label"> |
| 1089 | <?php |
| 1090 | if ( in_array( $custom_menu_item, $hidden_menu ) ) { |
| 1091 | ?> |
| 1092 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>" checked> |
| 1093 | <span>Hide</span> |
| 1094 | <?php |
| 1095 | } else { |
| 1096 | ?> |
| 1097 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>"> |
| 1098 | <span>Hide</span> |
| 1099 | <?php |
| 1100 | } |
| 1101 | ?> |
| 1102 | </label> |
| 1103 | </div> |
| 1104 | </div> |
| 1105 | </div> |
| 1106 | <?php |
| 1107 | |
| 1108 | $i = 1; |
| 1109 | |
| 1110 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 1111 | ?> |
| 1112 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 1113 | <?php |
| 1114 | |
| 1115 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 1116 | |
| 1117 | $i++; |
| 1118 | |
| 1119 | // echo $submenu_item[0]; |
| 1120 | |
| 1121 | } |
| 1122 | ?> |
| 1123 | </div> |
| 1124 | <?php |
| 1125 | |
| 1126 | } |
| 1127 | ?> |
| 1128 | </li> |
| 1129 | |
| 1130 | <?php |
| 1131 | |
| 1132 | } |
| 1133 | |
| 1134 | } |
| 1135 | |
| 1136 | } |
| 1137 | |
| 1138 | } else { |
| 1139 | |
| 1140 | // Render sortables with existing items in the admin menu |
| 1141 | |
| 1142 | foreach ( $menu as $menu_key => $menu_info ) { |
| 1143 | |
| 1144 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 1145 | $menu_item_id = $menu_info[2]; |
| 1146 | } else { |
| 1147 | $menu_item_id = $menu_info[5]; |
| 1148 | } |
| 1149 | |
| 1150 | ?> |
| 1151 | <li id="<?php echo wp_kses_post( $menu_item_id ); ?>" class="menu-item menu-item-depth-0"> |
| 1152 | <div class="menu-item-bar"> |
| 1153 | <div class="menu-item-handle ui-sortable-handle"> |
| 1154 | <div class="item-title"> |
| 1155 | <span class="menu-item-title"> |
| 1156 | <?php |
| 1157 | |
| 1158 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 1159 | $separator_name = $menu_info[2]; |
| 1160 | $separator_name = str_replace( 'separator', 'Separator-', $separator_name ); |
| 1161 | $separator_name = str_replace( '--last', '-Last', $separator_name ); |
| 1162 | echo '~~ ' . wp_kses_post( $separator_name ) . ' ~~'; |
| 1163 | } else { |
| 1164 | echo wp_kses_post( $menu_info[0] ); |
| 1165 | } |
| 1166 | |
| 1167 | ?> |
| 1168 | </span> |
| 1169 | <label class="menu-item-checkbox-label"> |
| 1170 | <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>"> |
| 1171 | <span>Hide</span> |
| 1172 | </label> |
| 1173 | </div> |
| 1174 | </div> |
| 1175 | </div> |
| 1176 | <?php |
| 1177 | |
| 1178 | $i = 1; |
| 1179 | |
| 1180 | if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) { |
| 1181 | ?> |
| 1182 | <div class="menu-item-settings wp-clearfix" style="display:none;"> |
| 1183 | <?php |
| 1184 | |
| 1185 | foreach ( $submenu[$menu_info[2]] as $submenu_item ) { |
| 1186 | |
| 1187 | $i++; |
| 1188 | |
| 1189 | // echo $submenu_item[0]; |
| 1190 | |
| 1191 | } |
| 1192 | ?> |
| 1193 | </div> |
| 1194 | <?php |
| 1195 | |
| 1196 | } |
| 1197 | ?> |
| 1198 | </li> |
| 1199 | |
| 1200 | <?php |
| 1201 | |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | ?> |
| 1209 | </ul> |
| 1210 | <?php |
| 1211 | |
| 1212 | $field_id = $args['field_id']; |
| 1213 | $field_name = $args['field_name']; |
| 1214 | $field_description = $args['field_description']; |
| 1215 | $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : ''; |
| 1216 | |
| 1217 | // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes. |
| 1218 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 1219 | |
| 1220 | $field_id = 'custom_menu_hidden'; |
| 1221 | $field_name = ASENHA_SLUG_U . '['. $field_id .']'; |
| 1222 | $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : ''; |
| 1223 | |
| 1224 | // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes. |
| 1225 | echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">'; |
| 1226 | |
| 1227 | } |
| 1228 | |
| 1229 | /** |
| 1230 | * Suppress all notices, then add notice for successful settings update |
| 1231 | * |
| 1232 | * @since 1.1.0 |
| 1233 | */ |
| 1234 | function asenha_notices() { |
| 1235 | |
| 1236 | global $plugin_page; |
| 1237 | |
| 1238 | // Suppress all notices |
| 1239 | |
| 1240 | if ( ASENHA_SLUG === $plugin_page ) { |
| 1241 | |
| 1242 | remove_all_actions( 'admin_notices' ); |
| 1243 | |
| 1244 | } |
| 1245 | |
| 1246 | // Add notice for successful settings update |
| 1247 | |
| 1248 | if ( |
| 1249 | isset( $_GET[ 'page' ] ) |
| 1250 | && ASENHA_SLUG == $_GET[ 'page' ] |
| 1251 | && isset( $_GET[ 'settings-updated' ] ) |
| 1252 | && true == $_GET[ 'settings-updated' ] |
| 1253 | ) { |
| 1254 | ?> |
| 1255 | <script> |
| 1256 | jQuery(document).ready( function() { |
| 1257 | jQuery('.asenha-changes-saved').fadeIn(400).delay(2500).fadeOut(400); |
| 1258 | }); |
| 1259 | </script> |
| 1260 | |
| 1261 | <?php |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * Enqueue admin scripts |
| 1267 | * |
| 1268 | * @since 1.0.0 |
| 1269 | */ |
| 1270 | function asenha_admin_scripts( $hook_suffix ) { |
| 1271 | |
| 1272 | $current_screen = get_current_screen(); |
| 1273 | |
| 1274 | // Get all WP Enhancements options, default to empty array in case it's not been created yet |
| 1275 | $options = get_option( 'admin_site_enhancements', array() ); |
| 1276 | |
| 1277 | // For main page of this plugin |
| 1278 | |
| 1279 | if ( is_asenha() ) { |
| 1280 | wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 1281 | wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 1282 | wp_enqueue_script( 'asenha-jsticky', ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 1283 | wp_enqueue_style( 'asenha-admin-page', ASENHA_URL . 'assets/css/admin-page.css', array( 'asenha-jbox' ), ASENHA_VERSION ); |
| 1284 | wp_enqueue_script( 'asenha-admin-page', ASENHA_URL . 'assets/js/admin-page.js', array( 'asenha-jsticky', 'asenha-jbox' ), ASENHA_VERSION, false ); |
| 1285 | } |
| 1286 | |
| 1287 | // Enqueue on all wp-admin |
| 1288 | |
| 1289 | wp_enqueue_style( 'asenha-wp-admin', ASENHA_URL . 'assets/css/wp-admin.css', array(), ASENHA_VERSION ); |
| 1290 | |
| 1291 | // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page |
| 1292 | |
| 1293 | if ( ( false !== strpos( $current_screen->base, 'edit' ) ) // List tables for pages, posts, taxonomies |
| 1294 | || ( false !== strpos( $current_screen->base, 'users' ) ) // Users list table |
| 1295 | || ( false !== strpos( $current_screen->base, 'upload' ) ) // Media list table |
| 1296 | ) { |
| 1297 | wp_enqueue_style( 'asenha-list-table', ASENHA_URL . 'assets/css/list-table.css', array(), ASENHA_VERSION ); |
| 1298 | } |
| 1299 | |
| 1300 | // Content Management >> Enable Media Replacement |
| 1301 | |
| 1302 | if ( ( $current_screen->base == 'upload' ) // Media list table |
| 1303 | || ( $current_screen->id == 'attachment' ) // Media edit page |
| 1304 | ) { |
| 1305 | // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 1306 | // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 1307 | wp_enqueue_style( 'asenha-media-replace', ASENHA_URL . 'assets/css/media-replace.css', array(), ASENHA_VERSION ); |
| 1308 | wp_enqueue_script( 'asenha-media-replace', ASENHA_URL . 'assets/js/media-replace.js', array(), ASENHA_VERSION, false ); |
| 1309 | } |
| 1310 | |
| 1311 | // Content Management >> Hide Admin Notices |
| 1312 | if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { |
| 1313 | wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 1314 | wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 1315 | wp_enqueue_style( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/css/hide-admin-notices.css', array(), ASENHA_VERSION ); |
| 1316 | wp_enqueue_script( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/js/hide-admin-notices.js', array( 'asenha-jbox' ), ASENHA_VERSION, false ); |
| 1317 | } |
| 1318 | |
| 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * Add 'Access now' plugin action link. |
| 1323 | * |
| 1324 | * @since 1.0.0 |
| 1325 | */ |
| 1326 | |
| 1327 | function asenha_plugin_action_links( $links ) { |
| 1328 | |
| 1329 | $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Access now</a>'; |
| 1330 | |
| 1331 | array_unshift($links, $settings_link); |
| 1332 | |
| 1333 | return $links; |
| 1334 | |
| 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * Modify footer text |
| 1339 | * |
| 1340 | * @since 1.0.0 |
| 1341 | */ |
| 1342 | function asenha_footer_text() { |
| 1343 | |
| 1344 | if ( is_asenha() ) { |
| 1345 | ?> |
| 1346 | <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>. |
| 1347 | <?php |
| 1348 | } |
| 1349 | |
| 1350 | } |
| 1351 | |
| 1352 | /** |
| 1353 | * Check if current screen is this plugin's main page |
| 1354 | * |
| 1355 | * @since 1.0.0 |
| 1356 | */ |
| 1357 | function is_asenha() { |
| 1358 | |
| 1359 | $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug |
| 1360 | |
| 1361 | if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) { |
| 1362 | return true; // Yes, this is the plugin's main page |
| 1363 | } else { |
| 1364 | return false; // Nope, this is NOT the plugin's page |
| 1365 | } |
| 1366 | |
| 1367 | } |