class-activation.php
3 years ago
class-admin-interface.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
730 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; |
| 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 | // Obfuscate Author Slugs |
| 530 | |
| 531 | $field_id = 'obfuscate_author_slugs'; |
| 532 | $field_slug = 'obfuscate-author-slugs'; |
| 533 | |
| 534 | add_settings_field( |
| 535 | $field_id, // Field ID |
| 536 | 'Obfuscate Author Slugs', // 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' => '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 |
| 545 | 'field_options_wrapper' => false, // Custom argument. Add container for additional options |
| 546 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 547 | ) |
| 548 | ); |
| 549 | |
| 550 | // Disable XML-RPC |
| 551 | |
| 552 | $field_id = 'disable_xmlrpc'; |
| 553 | $field_slug = 'disable-xmlrpc'; |
| 554 | |
| 555 | add_settings_field( |
| 556 | $field_id, // Field ID |
| 557 | 'Disable XML-RPC', // Field title |
| 558 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 559 | ASENHA_SLUG, // Settings page slug |
| 560 | 'main-section', // Section ID |
| 561 | array( |
| 562 | 'field_id' => $field_id, // Custom argument |
| 563 | 'field_slug' => $field_slug, // Custom argument |
| 564 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 565 | '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 |
| 566 | 'field_options_wrapper' => false, // Custom argument. Add container for additional options |
| 567 | 'class' => 'asenha-toggle security ' . $field_slug, // Custom class for the <tr> element |
| 568 | ) |
| 569 | ); |
| 570 | |
| 571 | // ===== UTILITIES ====== |
| 572 | |
| 573 | // Redirect After Login |
| 574 | |
| 575 | $field_id = 'redirect_after_login'; |
| 576 | $field_slug = 'redirect-after-login'; |
| 577 | |
| 578 | add_settings_field( |
| 579 | $field_id, // Field ID |
| 580 | 'Redirect After Login', // Field title |
| 581 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 582 | ASENHA_SLUG, // Settings page slug |
| 583 | 'main-section', // Section ID |
| 584 | array( |
| 585 | 'field_id' => $field_id, // Custom argument |
| 586 | 'field_slug' => $field_slug, // Custom argument |
| 587 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 588 | 'field_description' => 'Set custom redirect URL for all or some user roles after login.', // Custom argument |
| 589 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 590 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 591 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 592 | ) |
| 593 | ); |
| 594 | |
| 595 | $field_id = 'redirect_after_login_to_slug'; |
| 596 | $field_slug = 'redirect-after-login-to-slug'; |
| 597 | |
| 598 | add_settings_field( |
| 599 | $field_id, // Field ID |
| 600 | 'Redirect to:', // Field title |
| 601 | [ $render_field, 'render_text_subfield' ], // Callback to render field with custom arguments in the array below |
| 602 | ASENHA_SLUG, // Settings page slug |
| 603 | 'main-section', // Section ID |
| 604 | array( |
| 605 | 'field_id' => $field_id, // Custom argument |
| 606 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 607 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 608 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 609 | 'field_suffix' => '/ for:', // Custom argument |
| 610 | 'field_description' => '', // Custom argument |
| 611 | 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element |
| 612 | ) |
| 613 | ); |
| 614 | |
| 615 | $field_id = 'redirect_after_login_for'; |
| 616 | $field_slug = 'redirect-after-login-for'; |
| 617 | |
| 618 | if ( is_array( $roles ) ) { |
| 619 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 620 | |
| 621 | add_settings_field( |
| 622 | $field_id . '_' . $role_slug, // Field ID |
| 623 | '', // Field title |
| 624 | [ $render_field, 'render_checkbox_subfield' ], // Callback to render field with custom arguments in the array below |
| 625 | ASENHA_SLUG, // Settings page slug |
| 626 | 'main-section', // Section ID |
| 627 | array( |
| 628 | 'parent_field_id' => $field_id, // Custom argument |
| 629 | 'field_id' => $role_slug, // Custom argument |
| 630 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 631 | 'field_label' => $role_label, // Custom argument |
| 632 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 633 | ) |
| 634 | ); |
| 635 | |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | // Redirect After Logout |
| 640 | |
| 641 | $field_id = 'redirect_after_logout'; |
| 642 | $field_slug = 'redirect-after-logout'; |
| 643 | |
| 644 | add_settings_field( |
| 645 | $field_id, // Field ID |
| 646 | 'Redirect After Logout', // Field title |
| 647 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 648 | ASENHA_SLUG, // Settings page slug |
| 649 | 'main-section', // Section ID |
| 650 | array( |
| 651 | 'field_id' => $field_id, // Custom argument |
| 652 | 'field_slug' => $field_slug, // Custom argument |
| 653 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 654 | 'field_description' => 'Set custom redirect URL for all or some user roles after logout.', // Custom argument |
| 655 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 656 | 'field_options_moreless' => true, // Custom argument. Add show more/less toggler. |
| 657 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 658 | ) |
| 659 | ); |
| 660 | |
| 661 | $field_id = 'redirect_after_logout_to_slug'; |
| 662 | $field_slug = 'redirect-after-logout-to-slug'; |
| 663 | |
| 664 | add_settings_field( |
| 665 | $field_id, // Field ID |
| 666 | 'Redirect to:', // Field title |
| 667 | [ $render_field, 'render_text_subfield' ], // Callback to render field with custom arguments in the array below |
| 668 | ASENHA_SLUG, // Settings page slug |
| 669 | 'main-section', // Section ID |
| 670 | array( |
| 671 | 'field_id' => $field_id, // Custom argument |
| 672 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 673 | 'field_type' => 'with-prefix-suffix', // Custom argument |
| 674 | 'field_prefix' => get_site_url() . '/', // Custom argument |
| 675 | 'field_suffix' => '/ for:', // Custom argument |
| 676 | 'field_description' => '', // Custom argument |
| 677 | 'class' => 'asenha-text with-prefix-suffix utilities ' . $field_slug, // Custom class for the <tr> element |
| 678 | ) |
| 679 | ); |
| 680 | |
| 681 | $field_id = 'redirect_after_logout_for'; |
| 682 | $field_slug = 'redirect-after-logout-for'; |
| 683 | |
| 684 | if ( is_array( $roles ) ) { |
| 685 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 686 | |
| 687 | add_settings_field( |
| 688 | $field_id . '_' . $role_slug, // Field ID |
| 689 | '', // Field title |
| 690 | [ $render_field, 'render_checkbox_subfield' ], // Callback to render field with custom arguments in the array below |
| 691 | ASENHA_SLUG, // Settings page slug |
| 692 | 'main-section', // Section ID |
| 693 | array( |
| 694 | 'parent_field_id' => $field_id, // Custom argument |
| 695 | 'field_id' => $role_slug, // Custom argument |
| 696 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .'][' . $role_slug . ']', // Custom argument |
| 697 | 'field_label' => $role_label, // Custom argument |
| 698 | 'class' => 'asenha-checkbox asenha-hide-th asenha-half utilities ' . $field_slug . ' ' . $role_slug, // Custom class for the <tr> element |
| 699 | ) |
| 700 | ); |
| 701 | |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | // Redirect 404 to Homepage |
| 706 | |
| 707 | $field_id = 'redirect_404_to_homepage'; |
| 708 | $field_slug = 'redirect-404-to-homepage'; |
| 709 | |
| 710 | add_settings_field( |
| 711 | $field_id, // Field ID |
| 712 | 'Redirect 404 to Homepage', // Field title |
| 713 | [ $render_field, 'render_checkbox_toggle' ], // Callback to render field with custom arguments in the array below |
| 714 | ASENHA_SLUG, // Settings page slug |
| 715 | 'main-section', // Section ID |
| 716 | array( |
| 717 | 'field_id' => $field_id, // Custom argument |
| 718 | 'field_slug' => $field_slug, // Custom argument |
| 719 | 'field_name' => ASENHA_SLUG_U . '['. $field_id .']', // Custom argument |
| 720 | 'field_description' => 'Perform 301 (permanent) redirect to the homepage for all 404 (not found) pages.', // Custom argument |
| 721 | 'field_options_wrapper' => true, // Custom argument. Add container for additional options |
| 722 | 'class' => 'asenha-toggle utilities ' . $field_slug, // Custom class for the <tr> element |
| 723 | ) |
| 724 | ); |
| 725 | |
| 726 | // ===== DISABLE COMPONENTS ===== |
| 727 | |
| 728 | } |
| 729 | |
| 730 | } |