class-activation.php
3 years ago
class-admin-interface.php
3 years ago
class-common-methods.php
3 years ago
class-content-management.php
3 years ago
class-deactivation.php
3 years ago
class-disable-components.php
3 years ago
class-security.php
3 years ago
class-settings-fields-render.php
3 years ago
class-settings-sanitization.php
3 years ago
class-settings-sections-fields.php
3 years ago
class-utilities.php
3 years ago
class-settings-sections-fields.php
899 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class related to registration of settings fields |
| 7 | * |
| 8 | * @since 2.2.0 |
| 9 | */ |
| 10 | class Settings_Sections_Fields { |
| 11 | |
| 12 | /** |
| 13 | * Register plugin settings and the corresponding fields |
| 14 | * |
| 15 | * @link https://wpshout.com/making-an-admin-options-page-with-the-wordpress-settings-api/ |
| 16 | * @link https://rudrastyh.com/wordpress/creating-options-pages.html |
| 17 | * @since 1.0.0 |
| 18 | */ |
| 19 | function register_sections_fields() { |
| 20 | |
| 21 | // Add "Content Management" section |
| 22 | |
| 23 | add_settings_section( |
| 24 | 'main-section', // Section ID |
| 25 | '', // Section title. Can be blank. |
| 26 | '', // Callback function to output section intro. Can be blank. |
| 27 | ASENHA_SLUG // Settings page slug |
| 28 | ); |
| 29 | |
| 30 | // Register main setttings |
| 31 | |
| 32 | // Instantiate object for sanitization of settings fields values |
| 33 | $sanitization = new Settings_Sanitization; |
| 34 | |
| 35 | // Instantiate object for rendering of settings fields for the admin page |
| 36 | $render_field = new Settings_Fields_Render; |
| 37 | |
| 38 | register_setting( |
| 39 | ASENHA_ID, // Option group or option_page |
| 40 | ASENHA_SLUG_U, // Option name in wp_options table |
| 41 | array( |
| 42 | 'type' => 'array', // 'string', 'boolean', 'integer', 'number', 'array', or 'object' |
| 43 | 'description' => '', // A description of the data attached to this setting. |
| 44 | 'sanitize_callback' => [ $sanitization, 'sanitize_for_options' ], |
| 45 | 'show_in_rest' => false, |
| 46 | 'default' => array(), // When calling get_option() |
| 47 | ) |
| 48 | ); |
| 49 | |
| 50 | // Call WordPress globals required for the fields |
| 51 | |
| 52 | global $wp_roles, $wpdb; |
| 53 | $roles = $wp_roles->get_names(); |
| 54 | |
| 55 | // ===== CONTENT MANAGEMENT ===== |
| 56 | |
| 57 | // Enable Page and Post Duplication |
| 58 | |
| 59 | $field_id = 'enable_duplication'; |
| 60 | $field_slug = 'enable-duplication'; |
| 61 | |
| 62 | add_settings_field( |
| 63 | $field_id, // Field ID |
| 64 | 'Enable Page and Post Duplication', // Field title |
| 65 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 66 | ASENHA_SLUG, // Settings page slug |
| 67 | 'main-section', // Section ID |
| 68 | array( |
| 69 | 'field_id' => $field_id, // Custom argument |
| 70 | 'field_slug' => $field_slug, // Custom argument |
| 71 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 72 | '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 |
| 73 | 'class' => 'asenha-toggle content-management ' . $field_slug, // Custom class for the <tr> element |
| 74 | ) |
| 75 | ); |
| 76 | |
| 77 | // Enable Media Replacement |
| 78 | |
| 79 | $field_id = 'enable_media_replacement'; |
| 80 | $field_slug = 'enable-media-replacement'; |
| 81 | |
| 82 | add_settings_field( |
| 83 | $field_id, // Field ID |
| 84 | 'Enable Media Replacement', // Field title |
| 85 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 86 | ASENHA_SLUG, // Settings page slug |
| 87 | 'main-section', // Section ID |
| 88 | array( |
| 89 | 'field_id' => $field_id, // Custom argument |
| 90 | 'field_slug' => $field_slug, // Custom argument |
| 91 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 92 | '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 |
| 93 | 'class' => 'asenha-toggle content-management ' . $field_slug, // Custom class for the <tr> element |
| 94 | ) |
| 95 | ); |
| 96 | |
| 97 | // Enhance List Tables |
| 98 | |
| 99 | $field_id = 'enhance_list_tables'; |
| 100 | $field_slug = 'enhance-list-tables'; |
| 101 | |
| 102 | add_settings_field( |
| 103 | $field_id, // Field ID |
| 104 | 'Enhance List Tables', // Field title |
| 105 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 106 | ASENHA_SLUG, // Settings page slug |
| 107 | 'main-section', // Section ID |
| 108 | array( |
| 109 | 'field_id' => $field_id, // Custom argument |
| 110 | 'field_slug' => $field_slug, // Custom argument |
| 111 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 112 | 'field_description' => 'Improve the usefulness of listing pages of various post types by adding / removing columns and elements.', // Custom argument |
| 113 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 114 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 115 | 'class' => 'asenha-toggle content-management ' . $field_slug, // Custom class for the <tr> element |
| 116 | ) |
| 117 | ); |
| 118 | |
| 119 | // Show Featured Image Column |
| 120 | |
| 121 | $field_id = 'show_featured_image_column'; |
| 122 | $field_slug = 'show-featured-image-column'; |
| 123 | |
| 124 | add_settings_field( |
| 125 | $field_id, // Field ID |
| 126 | '', // Field title |
| 127 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 128 | ASENHA_SLUG, // Settings page slug |
| 129 | 'main-section', // Section ID |
| 130 | array( |
| 131 | 'field_id' => $field_id, // Custom argument |
| 132 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 133 | 'field_label' => 'Show featured image column.', // Custom argument |
| 134 | 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element |
| 135 | ) |
| 136 | ); |
| 137 | |
| 138 | // Show Excerpt Column |
| 139 | |
| 140 | $field_id = 'show_excerpt_column'; |
| 141 | $field_slug = 'show-excerpt-column'; |
| 142 | |
| 143 | add_settings_field( |
| 144 | $field_id, // Field ID |
| 145 | '', // Field title |
| 146 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 147 | ASENHA_SLUG, // Settings page slug |
| 148 | 'main-section', // Section ID |
| 149 | array( |
| 150 | 'field_id' => $field_id, // Custom argument |
| 151 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 152 | 'field_label' => 'Show excerpt column.', // Custom argument |
| 153 | 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element |
| 154 | ) |
| 155 | ); |
| 156 | |
| 157 | // Show ID Column |
| 158 | |
| 159 | $field_id = 'show_id_column'; |
| 160 | $field_slug = 'show-id-column'; |
| 161 | |
| 162 | add_settings_field( |
| 163 | $field_id, // Field ID |
| 164 | '', // Field title |
| 165 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 166 | ASENHA_SLUG, // Settings page slug |
| 167 | 'main-section', // Section ID |
| 168 | array( |
| 169 | 'field_id' => $field_id, // Custom argument |
| 170 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 171 | 'field_label' => 'Show ID column.', // Custom argument |
| 172 | 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element |
| 173 | ) |
| 174 | ); |
| 175 | |
| 176 | // Hide Comments Column |
| 177 | |
| 178 | $field_id = 'hide_comments_column'; |
| 179 | $field_slug = 'hide-comments-column'; |
| 180 | |
| 181 | add_settings_field( |
| 182 | $field_id, // Field ID |
| 183 | '', // Field title |
| 184 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 185 | ASENHA_SLUG, // Settings page slug |
| 186 | 'main-section', // Section ID |
| 187 | array( |
| 188 | 'field_id' => $field_id, // Custom argument |
| 189 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 190 | 'field_label' => 'Remove comments column.', // Custom argument |
| 191 | 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element |
| 192 | ) |
| 193 | ); |
| 194 | |
| 195 | // Hide Post Tags Column |
| 196 | |
| 197 | $field_id = 'hide_post_tags_column'; |
| 198 | $field_slug = 'hide-post-tags-column'; |
| 199 | |
| 200 | add_settings_field( |
| 201 | $field_id, // Field ID |
| 202 | '', // Field title |
| 203 | [ $render_field, 'render_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' => 'Remove tags column (for posts).', // Custom argument |
| 210 | 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element |
| 211 | ) |
| 212 | ); |
| 213 | |
| 214 | // Show Custom Taxonomy Filters |
| 215 | |
| 216 | $field_id = 'show_custom_taxonomy_filters'; |
| 217 | $field_slug = 'show-custom-taxonomy-filters'; |
| 218 | |
| 219 | add_settings_field( |
| 220 | $field_id, // Field ID |
| 221 | '', // Field title |
| 222 | [ $render_field, 'render_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 additional filter(s) for hierarchical, custom taxonomies.', // Custom argument |
| 229 | 'class' => 'asenha-checkbox asenha-hide-th content-management ' . $field_slug, // Custom class for the <tr> element |
| 230 | ) |
| 231 | ); |
| 232 | |
| 233 | // ===== ADMIN INTERFACE ===== |
| 234 | |
| 235 | // Hide Admin Notices |
| 236 | |
| 237 | $field_id = 'hide_admin_notices'; |
| 238 | $field_slug = 'hide-admin-notices'; |
| 239 | |
| 240 | add_settings_field( |
| 241 | $field_id, // Field ID |
| 242 | 'Hide Admin Notices', // Field title |
| 243 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 244 | ASENHA_SLUG, // Settings page slug |
| 245 | 'main-section', // Section ID |
| 246 | array( |
| 247 | 'field_id' => $field_id, // Custom argument |
| 248 | 'field_slug' => $field_slug, // Custom argument |
| 249 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 250 | 'field_description' => 'Clean up admin pages by moving notices into a separate panel easily accessible via the admin bar.', // Custom argument |
| 251 | 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 252 | ) |
| 253 | ); |
| 254 | |
| 255 | // View Admin as Role |
| 256 | |
| 257 | $field_id = 'view_admin_as_role'; |
| 258 | $field_slug = 'view-admin-as-role'; |
| 259 | |
| 260 | add_settings_field( |
| 261 | $field_id, // Field ID |
| 262 | 'View Admin as Role', // Field title |
| 263 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 264 | ASENHA_SLUG, // Settings page slug |
| 265 | 'main-section', // Section ID |
| 266 | array( |
| 267 | 'field_id' => $field_id, // Custom argument |
| 268 | 'field_slug' => $field_slug, // Custom argument |
| 269 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 270 | 'field_description' => 'View admin pages and the site (logged-in) as one of the non-administrator user roles.', // Custom argument |
| 271 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 272 | 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 273 | ) |
| 274 | ); |
| 275 | |
| 276 | // Hide or Modify Elements |
| 277 | |
| 278 | $field_id = 'hide_modify_elements'; |
| 279 | $field_slug = 'hide-modify-elements'; |
| 280 | |
| 281 | add_settings_field( |
| 282 | $field_id, // Field ID |
| 283 | 'Clean Up Admin Bar', // Field title |
| 284 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 285 | ASENHA_SLUG, // Settings page slug |
| 286 | 'main-section', // Section ID |
| 287 | array( |
| 288 | 'field_id' => $field_id, // Custom argument |
| 289 | 'field_slug' => $field_slug, // Custom argument |
| 290 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 291 | 'field_description' => 'Remove various elements from the admin bar.', // Custom argument |
| 292 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 293 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 294 | 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 295 | ) |
| 296 | ); |
| 297 | |
| 298 | $field_id = 'hide_ab_wp_logo_menu'; |
| 299 | $field_slug = 'hide-ab-wp-logo-menu'; |
| 300 | |
| 301 | add_settings_field( |
| 302 | $field_id, // Field ID |
| 303 | '', // Field title |
| 304 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 305 | ASENHA_SLUG, // Settings page slug |
| 306 | 'main-section', // Section ID |
| 307 | array( |
| 308 | 'field_id' => $field_id, // Custom argument |
| 309 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 310 | 'field_label' => 'Remove WordPress logo/menu', // Custom argument |
| 311 | 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 312 | ) |
| 313 | ); |
| 314 | |
| 315 | $field_id = 'hide_ab_customize_menu'; |
| 316 | $field_slug = 'hide-ab-customize-menu'; |
| 317 | |
| 318 | add_settings_field( |
| 319 | $field_id, // Field ID |
| 320 | '', // Field title |
| 321 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 322 | ASENHA_SLUG, // Settings page slug |
| 323 | 'main-section', // Section ID |
| 324 | array( |
| 325 | 'field_id' => $field_id, // Custom argument |
| 326 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 327 | 'field_label' => 'Remove customize menu', // Custom argument |
| 328 | 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 329 | ) |
| 330 | ); |
| 331 | |
| 332 | $field_id = 'hide_ab_updates_menu'; |
| 333 | $field_slug = 'hide-ab-updates-menu'; |
| 334 | |
| 335 | add_settings_field( |
| 336 | $field_id, // Field ID |
| 337 | '', // Field title |
| 338 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 339 | ASENHA_SLUG, // Settings page slug |
| 340 | 'main-section', // Section ID |
| 341 | array( |
| 342 | 'field_id' => $field_id, // Custom argument |
| 343 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 344 | 'field_label' => 'Remove updates counter/link', // Custom argument |
| 345 | 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 346 | ) |
| 347 | ); |
| 348 | |
| 349 | $field_id = 'hide_ab_comments_menu'; |
| 350 | $field_slug = 'hide-ab-comments-menu'; |
| 351 | |
| 352 | add_settings_field( |
| 353 | $field_id, // Field ID |
| 354 | '', // Field title |
| 355 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 356 | ASENHA_SLUG, // Settings page slug |
| 357 | 'main-section', // Section ID |
| 358 | array( |
| 359 | 'field_id' => $field_id, // Custom argument |
| 360 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 361 | 'field_label' => 'Remove comments counter/link', // Custom argument |
| 362 | 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 363 | ) |
| 364 | ); |
| 365 | |
| 366 | $field_id = 'hide_ab_new_content_menu'; |
| 367 | $field_slug = 'hide-ab-new-content-menu'; |
| 368 | |
| 369 | add_settings_field( |
| 370 | $field_id, // Field ID |
| 371 | '', // Field title |
| 372 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 373 | ASENHA_SLUG, // Settings page slug |
| 374 | 'main-section', // Section ID |
| 375 | array( |
| 376 | 'field_id' => $field_id, // Custom argument |
| 377 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 378 | 'field_label' => 'Remove new content menu', // Custom argument |
| 379 | 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 380 | ) |
| 381 | ); |
| 382 | |
| 383 | $field_id = 'hide_ab_howdy'; |
| 384 | $field_slug = 'hide-ab-howdy'; |
| 385 | |
| 386 | add_settings_field( |
| 387 | $field_id, // Field ID |
| 388 | '', // Field title |
| 389 | [ $render_field, 'render_checkbox_plain' ], // Callback to render field with custom arguments in the array below |
| 390 | ASENHA_SLUG, // Settings page slug |
| 391 | 'main-section', // Section ID |
| 392 | array( |
| 393 | 'field_id' => $field_id, // Custom argument |
| 394 | 'field_name' => ASENHA_SLUG_U . '[' . $field_id . ']', // Custom argument |
| 395 | 'field_label' => 'Remove \'Howdy\'', // Custom argument |
| 396 | 'class' => 'asenha-checkbox asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 397 | ) |
| 398 | ); |
| 399 | |
| 400 | // Hide Admin Bar |
| 401 | |
| 402 | $field_id = 'hide_admin_bar'; |
| 403 | $field_slug = 'hide-admin-bar'; |
| 404 | |
| 405 | add_settings_field( |
| 406 | $field_id, // Field ID |
| 407 | 'Hide Admin Bar', // Field title |
| 408 | [ $render_field, 'render_checkbox_toggle' ], // 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_slug' => $field_slug, // Custom argument |
| 414 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 415 | 'field_description' => 'Hide admin bar on the front end for all or some user roles.', // Custom argument |
| 416 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 417 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 418 | 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 419 | ) |
| 420 | ); |
| 421 | |
| 422 | $field_id = 'hide_admin_bar_for'; |
| 423 | $field_slug = 'hide-admin-bar-for'; |
| 424 | |
| 425 | if ( is_array( $roles ) ) { |
| 426 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 427 | |
| 428 | add_settings_field( |
| 429 | $field_id . '_' . $role_slug, // Field ID |
| 430 | '', // Field title |
| 431 | [ $render_field, 'render_checkbox_subfield' ], // Callback to render field with custom arguments in the array below |
| 432 | ASENHA_SLUG, // Settings page slug |
| 433 | 'main-section', // Section ID |
| 434 | array( |
| 435 | 'parent_field_id' => $field_id, // Custom argument |
| 436 | 'field_id' => $role_slug, // Custom argument |
| 437 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 438 | 'field_label' => $role_label, // Custom argument |
| 439 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half admin-interface ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 440 | ) |
| 441 | ); |
| 442 | |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | // Customize Admin Menu |
| 447 | |
| 448 | $field_id = 'customize_admin_menu'; |
| 449 | $field_slug = 'customize-admin-menu'; |
| 450 | |
| 451 | add_settings_field( |
| 452 | $field_id, // Field ID |
| 453 | 'Admin Menu Organizer', // Field title |
| 454 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 455 | ASENHA_SLUG, // Settings page slug |
| 456 | 'main-section', // Section ID |
| 457 | array( |
| 458 | 'field_id' => $field_id, // Custom argument |
| 459 | 'field_slug' => $field_slug, // Custom argument |
| 460 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 461 | 'field_description' => 'Customize the order of the admin menu and optionally hide some items.', // Custom argument |
| 462 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options. |
| 463 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 464 | 'class' => 'asenha-toggle admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 465 | ) |
| 466 | ); |
| 467 | |
| 468 | $field_id = 'custom_menu_order'; |
| 469 | $field_slug = 'custom-menu-order'; |
| 470 | |
| 471 | add_settings_field( |
| 472 | $field_id, // Field ID |
| 473 | '', // Field title |
| 474 | [ $render_field, 'render_sortable_menu' ], // Callback to render field with custom arguments in the array below |
| 475 | ASENHA_SLUG, // Settings page slug |
| 476 | 'main-section', // Section ID |
| 477 | array( |
| 478 | 'field_id' => $field_id, // Custom argument |
| 479 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 480 | 'field_type' => 'sortable-menu', // Custom argument |
| 481 | 'field_description' => '', // Custom argument |
| 482 | 'class' => 'asenha-sortable asenha-hide-th admin-interface ' . $field_slug, // Custom class for the <tr> element |
| 483 | ) |
| 484 | ); |
| 485 | |
| 486 | // ===== SECURITY ===== |
| 487 | |
| 488 | // Change Login URL |
| 489 | |
| 490 | $field_id = 'change_login_url'; |
| 491 | $field_slug = 'change-login-url'; |
| 492 | |
| 493 | add_settings_field( |
| 494 | $field_id, // Field ID |
| 495 | 'Change Login URL', // Field title |
| 496 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 497 | ASENHA_SLUG, // Settings page slug |
| 498 | 'main-section', // Section ID |
| 499 | array( |
| 500 | 'field_id' => $field_id, // Custom argument |
| 501 | 'field_slug' => $field_slug, // Custom argument |
| 502 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 503 | 'field_description' => 'Default is ' . get_site_url() . '/wp-admin/', // Custom argument |
| 504 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 505 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 506 | ) |
| 507 | ); |
| 508 | |
| 509 | $field_id = 'custom_login_slug'; |
| 510 | $field_slug = 'custom-login-slug'; |
| 511 | |
| 512 | add_settings_field( |
| 513 | $field_id, // Field ID |
| 514 | 'New URL:', // Field title |
| 515 | [ $render_field, 'render_text_subfield' ], // Callback to render field with custom arguments in the array below |
| 516 | ASENHA_SLUG, // Settings page slug |
| 517 | 'main-section', // Section ID |
| 518 | array( |
| 519 | 'field_id' => $field_id, // Custom argument |
| 520 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 521 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 522 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 523 | 'field_suffix' => '/', // Custom argument |
| 524 | 'field_description' => '', // Custom argument |
| 525 | 'class' => 'asenha-text with-prefix-suffix security ' . $field_slug, // Custom class for the <tr> element |
| 526 | ) |
| 527 | ); |
| 528 | |
| 529 | // Limit Login Attempts |
| 530 | |
| 531 | $field_id = 'limit_login_attempts'; |
| 532 | $field_slug = 'limit-login-attempts'; |
| 533 | |
| 534 | add_settings_field( |
| 535 | $field_id, // Field ID |
| 536 | 'Limit Login Attempts', // Field title |
| 537 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 538 | ASENHA_SLUG, // Settings page slug |
| 539 | 'main-section', // Section ID |
| 540 | array( |
| 541 | 'field_id' => $field_id, // Custom argument |
| 542 | 'field_slug' => $field_slug, // Custom argument |
| 543 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 544 | 'field_description' => 'Prevent brute force attacks by limiting the number of failed login attempts allowed per IP address.', // Custom argument |
| 545 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 546 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 547 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 548 | ) |
| 549 | ); |
| 550 | |
| 551 | $field_id = 'login_fails_allowed'; |
| 552 | $field_slug = 'login-fails-allowed'; |
| 553 | |
| 554 | add_settings_field( |
| 555 | $field_id, // Field ID |
| 556 | '', // Field title |
| 557 | [ $render_field, 'render_text_subfield' ], // Callback to render field with custom arguments in the array below |
| 558 | ASENHA_SLUG, // Settings page slug |
| 559 | 'main-section', // Section ID |
| 560 | array( |
| 561 | 'field_id' => $field_id, // Custom argument |
| 562 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 563 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 564 | 'field_prefix' => '', // Custom argument |
| 565 | 'field_suffix' => 'failed login attempts allowed before 15 minutes lockout', // Custom argument |
| 566 | 'field_description' => '', // Custom argument |
| 567 | 'class' => 'asenha-text with-prefix-suffix narrow no-margin security ' . $field_slug, // Custom class for the <tr> element |
| 568 | ) |
| 569 | ); |
| 570 | |
| 571 | $field_id = 'login_lockout_maxcount'; |
| 572 | $field_slug = 'login-lockout-maxcount'; |
| 573 | |
| 574 | add_settings_field( |
| 575 | $field_id, // Field ID |
| 576 | '', // Field title |
| 577 | [ $render_field, 'render_text_subfield' ], // Callback to render field with custom arguments in the array below |
| 578 | ASENHA_SLUG, // Settings page slug |
| 579 | 'main-section', // Section ID |
| 580 | array( |
| 581 | 'field_id' => $field_id, // Custom argument |
| 582 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 583 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 584 | 'field_prefix' => '', // Custom argument |
| 585 | 'field_suffix' => 'lockout(s) will block further login attempts for 24 hours', // Custom argument |
| 586 | 'field_description' => '', // Custom argument |
| 587 | 'class' => 'asenha-text with-prefix-suffix narrow no-margin security ' . $field_slug, // Custom class for the <tr> element |
| 588 | ) |
| 589 | ); |
| 590 | |
| 591 | $field_id = 'login_attempts_log_table'; |
| 592 | $field_slug = 'login-attempts-log-table'; |
| 593 | |
| 594 | add_settings_field( |
| 595 | $field_id, // Field ID |
| 596 | '', // Field title |
| 597 | [ $render_field, 'render_datatable' ], // Callback to render field with custom arguments in the array below |
| 598 | ASENHA_SLUG, // Settings page slug |
| 599 | 'main-section', // Section ID |
| 600 | array( |
| 601 | 'field_id' => $field_id, // Custom argument |
| 602 | 'field_slug' => $field_slug, // Custom argument |
| 603 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 604 | 'field_type' => 'datatable', // Custom argument |
| 605 | 'field_description' => '', // Custom argument |
| 606 | 'class' => 'asenha-text datatable asenha-hide-th security ' . $field_slug, // Custom class for the <tr> element |
| 607 | 'table_title' => 'Failed Login Attempts Log', |
| 608 | 'table_name' => $wpdb->prefix . 'asenha_failed_logins', |
| 609 | ) |
| 610 | ); |
| 611 | |
| 612 | // Obfuscate Author Slugs |
| 613 | |
| 614 | $field_id = 'obfuscate_author_slugs'; |
| 615 | $field_slug = 'obfuscate-author-slugs'; |
| 616 | |
| 617 | add_settings_field( |
| 618 | $field_id, // Field ID |
| 619 | 'Obfuscate Author Slugs', // Field title |
| 620 | [ $render_field, 'render_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_slug' => $field_slug, // Custom argument |
| 626 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 627 | '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 |
| 628 | 'field_options_wrapper' => false, // Custom argument. Add container for additional options |
| 629 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 630 | ) |
| 631 | ); |
| 632 | |
| 633 | // Disable XML-RPC |
| 634 | |
| 635 | $field_id = 'disable_xmlrpc'; |
| 636 | $field_slug = 'disable-xmlrpc'; |
| 637 | |
| 638 | add_settings_field( |
| 639 | $field_id, // Field ID |
| 640 | 'Disable XML-RPC', // Field title |
| 641 | [ $render_field, 'render_checkbox_toggle' ], // 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 | 'field_id' => $field_id, // Custom argument |
| 646 | 'field_slug' => $field_slug, // Custom argument |
| 647 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 648 | 'field_description' => 'Protect your site from brute force, DOS and DDOS attacks via <a href="https://kinsta.com/blog/xmlrpc-php/#what-is-xmlrpcphp" target="_blank">XML-RPC</a>. Also disables trackbacks and pingbacks. ', // Custom argument |
| 649 | 'field_options_wrapper' => false, // Custom argument. Add container for additional options |
| 650 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 651 | ) |
| 652 | ); |
| 653 | |
| 654 | // ===== UTILITIES ====== |
| 655 | |
| 656 | // Redirect After Login |
| 657 | |
| 658 | $field_id = 'redirect_after_login'; |
| 659 | $field_slug = 'redirect-after-login'; |
| 660 | |
| 661 | add_settings_field( |
| 662 | $field_id, // Field ID |
| 663 | 'Redirect After Login', // Field title |
| 664 | [ $render_field, 'render_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_slug' => $field_slug, // Custom argument |
| 670 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 671 | 'field_description' => 'Set custom redirect URL for all or some user roles after login.', // Custom argument |
| 672 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 673 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 674 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 675 | ) |
| 676 | ); |
| 677 | |
| 678 | $field_id = 'redirect_after_login_to_slug'; |
| 679 | $field_slug = 'redirect-after-login-to-slug'; |
| 680 | |
| 681 | add_settings_field( |
| 682 | $field_id, // Field ID |
| 683 | 'Redirect to:', // Field title |
| 684 | [ $render_field, 'render_text_subfield' ], // 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_type' => 'with-prefix-suffix', // Custom argument |
| 691 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 692 | 'field_suffix' => '/ for:', // Custom argument |
| 693 | 'field_description' => '', // Custom argument |
| 694 | 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element |
| 695 | ) |
| 696 | ); |
| 697 | |
| 698 | $field_id = 'redirect_after_login_for'; |
| 699 | $field_slug = 'redirect-after-login-for'; |
| 700 | |
| 701 | if ( is_array( $roles ) ) { |
| 702 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 703 | |
| 704 | add_settings_field( |
| 705 | $field_id . '_' . $role_slug, // Field ID |
| 706 | '', // Field title |
| 707 | [ $render_field, 'render_checkbox_subfield' ], // Callback to render field with custom arguments in the array below |
| 708 | ASENHA_SLUG, // Settings page slug |
| 709 | 'main-section', // Section ID |
| 710 | array( |
| 711 | 'parent_field_id' => $field_id, // Custom argument |
| 712 | 'field_id' => $role_slug, // Custom argument |
| 713 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 714 | 'field_label' => $role_label, // Custom argument |
| 715 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 716 | ) |
| 717 | ); |
| 718 | |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | // Redirect After Logout |
| 723 | |
| 724 | $field_id = 'redirect_after_logout'; |
| 725 | $field_slug = 'redirect-after-logout'; |
| 726 | |
| 727 | add_settings_field( |
| 728 | $field_id, // Field ID |
| 729 | 'Redirect After Logout', // Field title |
| 730 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 731 | ASENHA_SLUG, // Settings page slug |
| 732 | 'main-section', // Section ID |
| 733 | array( |
| 734 | 'field_id' => $field_id, // Custom argument |
| 735 | 'field_slug' => $field_slug, // Custom argument |
| 736 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 737 | 'field_description' => 'Set custom redirect URL for all or some user roles after logout.', // Custom argument |
| 738 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 739 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 740 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 741 | ) |
| 742 | ); |
| 743 | |
| 744 | $field_id = 'redirect_after_logout_to_slug'; |
| 745 | $field_slug = 'redirect-after-logout-to-slug'; |
| 746 | |
| 747 | add_settings_field( |
| 748 | $field_id, // Field ID |
| 749 | 'Redirect to:', // Field title |
| 750 | [ $render_field, 'render_text_subfield' ], // Callback to render field with custom arguments in the array below |
| 751 | ASENHA_SLUG, // Settings page slug |
| 752 | 'main-section', // Section ID |
| 753 | array( |
| 754 | 'field_id' => $field_id, // Custom argument |
| 755 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 756 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 757 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 758 | 'field_suffix' => '/ for:', // Custom argument |
| 759 | 'field_description' => '', // Custom argument |
| 760 | 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element |
| 761 | ) |
| 762 | ); |
| 763 | |
| 764 | $field_id = 'redirect_after_logout_for'; |
| 765 | $field_slug = 'redirect-after-logout-for'; |
| 766 | |
| 767 | if ( is_array( $roles ) ) { |
| 768 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 769 | |
| 770 | add_settings_field( |
| 771 | $field_id . '_' . $role_slug, // Field ID |
| 772 | '', // Field title |
| 773 | [ $render_field, 'render_checkbox_subfield' ], // Callback to render field with custom arguments in the array below |
| 774 | ASENHA_SLUG, // Settings page slug |
| 775 | 'main-section', // Section ID |
| 776 | array( |
| 777 | 'parent_field_id' => $field_id, // Custom argument |
| 778 | 'field_id' => $role_slug, // Custom argument |
| 779 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 780 | 'field_label' => $role_label, // Custom argument |
| 781 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 782 | ) |
| 783 | ); |
| 784 | |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | // Redirect 404 to Homepage |
| 789 | |
| 790 | $field_id = 'redirect_404_to_homepage'; |
| 791 | $field_slug = 'redirect-404-to-homepage'; |
| 792 | |
| 793 | add_settings_field( |
| 794 | $field_id, // Field ID |
| 795 | 'Redirect 404 to Homepage', // Field title |
| 796 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 797 | ASENHA_SLUG, // Settings page slug |
| 798 | 'main-section', // Section ID |
| 799 | array( |
| 800 | 'field_id' => $field_id, // Custom argument |
| 801 | 'field_slug' => $field_slug, // Custom argument |
| 802 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 803 | 'field_description' => 'Perform 301 (permanent) redirect to the homepage for all 404 (not found) pages.', // Custom argument |
| 804 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 805 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 806 | ) |
| 807 | ); |
| 808 | |
| 809 | // Enable Custom Admin CSS |
| 810 | |
| 811 | $field_id = 'enable_custom_admin_css'; |
| 812 | $field_slug = 'enable-custom-admin-css'; |
| 813 | |
| 814 | add_settings_field( |
| 815 | $field_id, // Field ID |
| 816 | 'Enable Custom Admin CSS', // Field title |
| 817 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 818 | ASENHA_SLUG, // Settings page slug |
| 819 | 'main-section', // Section ID |
| 820 | array( |
| 821 | 'field_id' => $field_id, // Custom argument |
| 822 | 'field_slug' => $field_slug, // Custom argument |
| 823 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 824 | 'field_description' => 'Add custom CSS on all admin pages for all user roles.', // Custom argument |
| 825 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options. |
| 826 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 827 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 828 | ) |
| 829 | ); |
| 830 | |
| 831 | $field_id = 'custom_admin_css'; |
| 832 | $field_slug = 'custom-admin-css'; |
| 833 | |
| 834 | add_settings_field( |
| 835 | $field_id, // Field ID |
| 836 | '', // Field title |
| 837 | [ $render_field, 'render_textarea_subfield' ], // Callback to render field with custom arguments in the array below |
| 838 | ASENHA_SLUG, // Settings page slug |
| 839 | 'main-section', // Section ID |
| 840 | array( |
| 841 | 'field_id' => $field_id, // Custom argument |
| 842 | 'field_slug' => $field_slug, // Custom argument |
| 843 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 844 | 'field_type' => 'textarea', // Custom argument |
| 845 | 'field_prefix' => '', // Custom argument |
| 846 | 'field_suffix' => '', // Custom argument |
| 847 | 'field_description' => '', // Custom argument |
| 848 | 'class' => 'asenha-textarea asenha-hide-th syntax-highlighted utilities ' . $field_slug, // Custom class for the <tr> element |
| 849 | ) |
| 850 | ); |
| 851 | |
| 852 | // Enable Custom Frontend CSS |
| 853 | |
| 854 | $field_id = 'enable_custom_frontend_css'; |
| 855 | $field_slug = 'enable-custom-frontend-css'; |
| 856 | |
| 857 | add_settings_field( |
| 858 | $field_id, // Field ID |
| 859 | 'Enable Custom Frontend CSS', // Field title |
| 860 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 861 | ASENHA_SLUG, // Settings page slug |
| 862 | 'main-section', // Section ID |
| 863 | array( |
| 864 | 'field_id' => $field_id, // Custom argument |
| 865 | 'field_slug' => $field_slug, // Custom argument |
| 866 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 867 | 'field_description' => 'Add custom CSS on all frontend pages for all user roles.', // Custom argument |
| 868 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options. |
| 869 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 870 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 871 | ) |
| 872 | ); |
| 873 | |
| 874 | $field_id = 'custom_frontend_css'; |
| 875 | $field_slug = 'custom-frontend-css'; |
| 876 | |
| 877 | add_settings_field( |
| 878 | $field_id, // Field ID |
| 879 | '', // Field title |
| 880 | [ $render_field, 'render_textarea_subfield' ], // Callback to render field with custom arguments in the array below |
| 881 | ASENHA_SLUG, // Settings page slug |
| 882 | 'main-section', // Section ID |
| 883 | array( |
| 884 | 'field_id' => $field_id, // Custom argument |
| 885 | 'field_slug' => $field_slug, // Custom argument |
| 886 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 887 | 'field_type' => 'textarea', // Custom argument |
| 888 | 'field_prefix' => '', // Custom argument |
| 889 | 'field_suffix' => '', // Custom argument |
| 890 | 'field_description' => '', // Custom argument |
| 891 | 'class' => 'asenha-textarea asenha-hide-th syntax-highlighted utilities ' . $field_slug, // Custom class for the <tr> element |
| 892 | ) |
| 893 | ); |
| 894 | |
| 895 | // ===== DISABLE COMPONENTS ===== |
| 896 | |
| 897 | } |
| 898 | |
| 899 | } |