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-sanitization.php
187 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class related to sanitization of settings fields for saving as options |
| 7 | * |
| 8 | * @since 2.2.0 |
| 9 | */ |
| 10 | class Settings_Sanitization { |
| 11 | |
| 12 | /** |
| 13 | * Sanitize options |
| 14 | * |
| 15 | * @since 1.0.0 |
| 16 | */ |
| 17 | function sanitize_for_options( $options ) { |
| 18 | |
| 19 | // Call WordPress globals required for validating the fields |
| 20 | global $wp_roles; |
| 21 | $roles = $wp_roles->get_names(); |
| 22 | |
| 23 | // Content Management features |
| 24 | |
| 25 | // Enable Page and Post Duplication |
| 26 | if ( ! isset( $options['enable_duplication'] ) ) $options['enable_duplication'] = false; |
| 27 | $options['enable_duplication'] = ( 'on' == $options['enable_duplication'] ? true : false ); |
| 28 | |
| 29 | // Enable Media Replacement |
| 30 | if ( ! isset( $options['enable_media_replacement'] ) ) $options['enable_media_replacement'] = false; |
| 31 | $options['enable_media_replacement'] = ( 'on' == $options['enable_media_replacement'] ? true : false ); |
| 32 | |
| 33 | // Enhance List Tables |
| 34 | if ( ! isset( $options['enhance_list_tables'] ) ) $options['enhance_list_tables'] = false; |
| 35 | $options['enhance_list_tables'] = ( 'on' == $options['enhance_list_tables'] ? true : false ); |
| 36 | |
| 37 | // Show Featured Image Column |
| 38 | if ( ! isset( $options['show_featured_image_column'] ) ) $options['show_featured_image_column'] = false; |
| 39 | $options['show_featured_image_column'] = ( 'on' == $options['show_featured_image_column'] ? true : false ); |
| 40 | |
| 41 | // Show Excerpt Column |
| 42 | if ( ! isset( $options['show_excerpt_column'] ) ) $options['show_excerpt_column'] = false; |
| 43 | $options['show_excerpt_column'] = ( 'on' == $options['show_excerpt_column'] ? true : false ); |
| 44 | |
| 45 | // Show ID Column |
| 46 | if ( ! isset( $options['show_id_column'] ) ) $options['show_id_column'] = false; |
| 47 | $options['show_id_column'] = ( 'on' == $options['show_id_column'] ? true : false ); |
| 48 | |
| 49 | // Hide Comments Column |
| 50 | if ( ! isset( $options['hide_comments_column'] ) ) $options['hide_comments_column'] = false; |
| 51 | $options['hide_comments_column'] = ( 'on' == $options['hide_comments_column'] ? true : false ); |
| 52 | |
| 53 | // Hide Post Tags Column |
| 54 | if ( ! isset( $options['hide_post_tags_column'] ) ) $options['hide_post_tags_column'] = false; |
| 55 | $options['hide_post_tags_column'] = ( 'on' == $options['hide_post_tags_column'] ? true : false ); |
| 56 | |
| 57 | // Show Custom Taxonomy Filters |
| 58 | if ( ! isset( $options['show_custom_taxonomy_filters'] ) ) $options['show_custom_taxonomy_filters'] = false; |
| 59 | $options['show_custom_taxonomy_filters'] = ( 'on' == $options['show_custom_taxonomy_filters'] ? true : false ); |
| 60 | |
| 61 | // Admin Interface features |
| 62 | |
| 63 | // Hide Admin Notices |
| 64 | if ( ! isset( $options['hide_admin_notices'] ) ) $options['hide_admin_notices'] = false; |
| 65 | $options['hide_admin_notices'] = ( 'on' == $options['hide_admin_notices'] ? true : false ); |
| 66 | |
| 67 | // Hide Admin Bar |
| 68 | if ( ! isset( $options['hide_admin_bar'] ) ) $options['hide_admin_bar'] = false; |
| 69 | $options['hide_admin_bar'] = ( 'on' == $options['hide_admin_bar'] ? true : false ); |
| 70 | |
| 71 | if ( is_array( $roles ) ) { |
| 72 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 73 | if ( ! isset( $options['hide_admin_bar_for'][$role_slug] ) ) $options['hide_admin_bar_for'][$role_slug] = false; |
| 74 | $options['hide_admin_bar_for'][$role_slug] = ( 'on' == $options['hide_admin_bar_for'][$role_slug] ? true : false ); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // View Admin as Role |
| 79 | if ( ! isset( $options['view_admin_as_role'] ) ) $options['view_admin_as_role'] = false; |
| 80 | $options['view_admin_as_role'] = ( 'on' == $options['view_admin_as_role'] ? true : false ); |
| 81 | |
| 82 | // Hide or Modify Elements |
| 83 | |
| 84 | if ( ! isset( $options['hide_modify_elements'] ) ) $options['hide_modify_elements'] = false; |
| 85 | $options['hide_modify_elements'] = ( 'on' == $options['hide_modify_elements'] ? true : false ); |
| 86 | |
| 87 | if ( ! isset( $options['hide_ab_wp_logo_menu'] ) ) $options['hide_ab_wp_logo_menu'] = false; |
| 88 | $options['hide_ab_wp_logo_menu'] = ( 'on' == $options['hide_ab_wp_logo_menu'] ? true : false ); |
| 89 | |
| 90 | if ( ! isset( $options['hide_ab_customize_menu'] ) ) $options['hide_ab_customize_menu'] = false; |
| 91 | $options['hide_ab_customize_menu'] = ( 'on' == $options['hide_ab_customize_menu'] ? true : false ); |
| 92 | |
| 93 | if ( ! isset( $options['hide_ab_comments_menu'] ) ) $options['hide_ab_comments_menu'] = false; |
| 94 | $options['hide_ab_comments_menu'] = ( 'on' == $options['hide_ab_comments_menu'] ? true : false ); |
| 95 | |
| 96 | if ( ! isset( $options['hide_ab_updates_menu'] ) ) $options['hide_ab_updates_menu'] = false; |
| 97 | $options['hide_ab_updates_menu'] = ( 'on' == $options['hide_ab_updates_menu'] ? true : false ); |
| 98 | |
| 99 | if ( ! isset( $options['hide_ab_new_content_menu'] ) ) $options['hide_ab_new_content_menu'] = false; |
| 100 | $options['hide_ab_new_content_menu'] = ( 'on' == $options['hide_ab_new_content_menu'] ? true : false ); |
| 101 | |
| 102 | if ( ! isset( $options['hide_ab_howdy'] ) ) $options['hide_ab_howdy'] = false; |
| 103 | $options['hide_ab_howdy'] = ( 'on' == $options['hide_ab_howdy'] ? true : false ); |
| 104 | |
| 105 | // Customize Admin Menu |
| 106 | |
| 107 | if ( ! isset( $options['customize_admin_menu'] ) ) $options['customize_admin_menu'] = false; |
| 108 | $options['customize_admin_menu'] = ( 'on' == $options['customize_admin_menu'] ? true : false ); |
| 109 | |
| 110 | if ( ! isset( $options['custom_menu_order'] ) ) $options['custom_menu_order'] = ''; |
| 111 | if ( ! isset( $options['custom_menu_hidden'] ) ) $options['custom_menu_hidden'] = ''; |
| 112 | |
| 113 | // Security features |
| 114 | |
| 115 | // Change Login URL |
| 116 | if ( ! isset( $options['change_login_url'] ) ) $options['change_login_url'] = false; |
| 117 | $options['change_login_url'] = ( 'on' == $options['change_login_url'] ? true : false ); |
| 118 | |
| 119 | if ( ! isset( $options['custom_login_slug'] ) ) $options['custom_login_slug'] = 'backend'; |
| 120 | $options['custom_login_slug'] = ( ! empty( $options['custom_login_slug'] ) ) ? sanitize_text_field( $options['custom_login_slug'] ) : 'backend'; |
| 121 | |
| 122 | // Obfuscate Author Slugs |
| 123 | if ( ! isset( $options['obfuscate_author_slugs'] ) ) $options['obfuscate_author_slugs'] = false; |
| 124 | $options['obfuscate_author_slugs'] = ( 'on' == $options['obfuscate_author_slugs'] ? true : false ); |
| 125 | |
| 126 | // Utilities features |
| 127 | |
| 128 | // Redirect After Login |
| 129 | if ( ! isset( $options['redirect_after_login'] ) ) $options['redirect_after_login'] = false; |
| 130 | $options['redirect_after_login'] = ( 'on' == $options['redirect_after_login'] ? true : false ); |
| 131 | |
| 132 | if ( ! isset( $options['redirect_after_login_to_slug'] ) ) $options['redirect_after_login_to_slug'] = ''; |
| 133 | $options['redirect_after_login_to_slug'] = ( ! empty( $options['redirect_after_login_to_slug'] ) ) ? sanitize_text_field( $options['redirect_after_login_to_slug'] ) : ''; |
| 134 | |
| 135 | if ( is_array( $roles ) ) { |
| 136 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 137 | if ( ! isset( $options['redirect_after_login_for'][$role_slug] ) ) $options['redirect_after_login_for'][$role_slug] = false; |
| 138 | $options['redirect_after_login_for'][$role_slug] = ( 'on' == $options['redirect_after_login_for'][$role_slug] ? true : false ); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // Redirect After Logout |
| 143 | if ( ! isset( $options['redirect_after_logout'] ) ) $options['redirect_after_logout'] = false; |
| 144 | $options['redirect_after_logout'] = ( 'on' == $options['redirect_after_logout'] ? true : false ); |
| 145 | |
| 146 | if ( ! isset( $options['redirect_after_logout_to_slug'] ) ) $options['redirect_after_logout_to_slug'] = ''; |
| 147 | $options['redirect_after_logout_to_slug'] = ( ! empty( $options['redirect_after_logout_to_slug'] ) ) ? sanitize_text_field( $options['redirect_after_logout_to_slug'] ) : ''; |
| 148 | |
| 149 | if ( is_array( $roles ) ) { |
| 150 | foreach ( $roles as $role_slug => $role_label ) { // e.g. $role_slug is administrator, $role_label is Administrator |
| 151 | if ( ! isset( $options['redirect_after_logout_for'][$role_slug] ) ) $options['redirect_after_logout_for'][$role_slug] = false; |
| 152 | $options['redirect_after_logout_for'][$role_slug] = ( 'on' == $options['redirect_after_logout_for'][$role_slug] ? true : false ); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // Redirect 404 to Homepage |
| 157 | if ( ! isset( $options['redirect_404_to_homepage'] ) ) $options['redirect_404_to_homepage'] = false; |
| 158 | $options['redirect_404_to_homepage'] = ( 'on' == $options['redirect_404_to_homepage'] ? true : false ); |
| 159 | |
| 160 | // Disable XML-RPC |
| 161 | if ( ! isset( $options['disable_xmlrpc'] ) ) $options['disable_xmlrpc'] = false; |
| 162 | $options['disable_xmlrpc'] = ( 'on' == $options['disable_xmlrpc'] ? true : false ); |
| 163 | |
| 164 | // Enable Custom Admin CSS |
| 165 | if ( ! isset( $options['enable_custom_admin_css'] ) ) $options['enable_custom_admin_css'] = false; |
| 166 | $options['enable_custom_admin_css'] = ( 'on' == $options['enable_custom_admin_css'] ? true : false ); |
| 167 | |
| 168 | if ( ! isset( $options['custom_admin_css'] ) ) $options['custom_admin_css'] = ''; |
| 169 | $options['custom_admin_css'] = ( ! empty( $options['custom_admin_css'] ) ) ? $options['custom_admin_css'] : ''; |
| 170 | |
| 171 | return $options; |
| 172 | |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Sanitize checkbox field. For reference purpose. Not currently in use. |
| 177 | * |
| 178 | * @since 1.0.0 |
| 179 | */ |
| 180 | function asenha_sanitize_checkbox_field( $value ) { |
| 181 | |
| 182 | // 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) |
| 183 | return 'on' === $value ? true : false; |
| 184 | |
| 185 | } |
| 186 | |
| 187 | } |