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-custom-code.php
3 years ago
class-deactivation.php
3 years ago
class-disable-components.php
3 years ago
class-login-logout.php
3 years ago
class-optimizations.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
687 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 |
| 21 | $wp_roles, |
| 22 | $asenha_public_post_types, |
| 23 | $asenha_gutenberg_post_types, |
| 24 | $asenha_revisions_post_types |
| 25 | ; |
| 26 | $roles = $wp_roles->get_names(); |
| 27 | // Content Duplication |
| 28 | if ( !isset( $options['enable_duplication'] ) ) { |
| 29 | $options['enable_duplication'] = false; |
| 30 | } |
| 31 | $options['enable_duplication'] = ( 'on' == $options['enable_duplication'] ? true : false ); |
| 32 | // Content Order |
| 33 | if ( !isset( $options['content_order'] ) ) { |
| 34 | $options['content_order'] = false; |
| 35 | } |
| 36 | $options['content_order'] = ( 'on' == $options['content_order'] ? true : false ); |
| 37 | if ( is_array( $asenha_public_post_types ) ) { |
| 38 | foreach ( $asenha_public_post_types as $post_type_slug => $post_type_label ) { |
| 39 | // e.g. $post_type_slug is post, $post_type_label is Posts |
| 40 | |
| 41 | if ( post_type_supports( $post_type_slug, 'page-attributes' ) || is_post_type_hierarchical( $post_type_slug ) ) { |
| 42 | if ( !isset( $options['content_order_for'][$post_type_slug] ) ) { |
| 43 | $options['content_order_for'][$post_type_slug] = false; |
| 44 | } |
| 45 | $options['content_order_for'][$post_type_slug] = ( 'on' == $options['content_order_for'][$post_type_slug] ? true : false ); |
| 46 | } |
| 47 | |
| 48 | } |
| 49 | } |
| 50 | // Enable Media Replacement |
| 51 | if ( !isset( $options['enable_media_replacement'] ) ) { |
| 52 | $options['enable_media_replacement'] = false; |
| 53 | } |
| 54 | $options['enable_media_replacement'] = ( 'on' == $options['enable_media_replacement'] ? true : false ); |
| 55 | // Enable SVG Upload |
| 56 | if ( !isset( $options['enable_svg_upload'] ) ) { |
| 57 | $options['enable_svg_upload'] = false; |
| 58 | } |
| 59 | $options['enable_svg_upload'] = ( 'on' == $options['enable_svg_upload'] ? true : false ); |
| 60 | if ( is_array( $roles ) ) { |
| 61 | foreach ( $roles as $role_slug => $role_label ) { |
| 62 | // e.g. $role_slug is administrator, $role_label is Administrator |
| 63 | if ( !isset( $options['enable_svg_upload_for'][$role_slug] ) ) { |
| 64 | $options['enable_svg_upload_for'][$role_slug] = false; |
| 65 | } |
| 66 | $options['enable_svg_upload_for'][$role_slug] = ( 'on' == $options['enable_svg_upload_for'][$role_slug] ? true : false ); |
| 67 | } |
| 68 | } |
| 69 | // Enable External Permalinks |
| 70 | if ( !isset( $options['enable_external_permalinks'] ) ) { |
| 71 | $options['enable_external_permalinks'] = false; |
| 72 | } |
| 73 | $options['enable_external_permalinks'] = ( 'on' == $options['enable_external_permalinks'] ? true : false ); |
| 74 | if ( is_array( $asenha_public_post_types ) ) { |
| 75 | foreach ( $asenha_public_post_types as $post_type_slug => $post_type_label ) { |
| 76 | // e.g. $post_type_slug is post, $post_type_label is Posts |
| 77 | if ( !isset( $options['enable_external_permalinks_for'][$post_type_slug] ) ) { |
| 78 | $options['enable_external_permalinks_for'][$post_type_slug] = false; |
| 79 | } |
| 80 | $options['enable_external_permalinks_for'][$post_type_slug] = ( 'on' == $options['enable_external_permalinks_for'][$post_type_slug] ? true : false ); |
| 81 | } |
| 82 | } |
| 83 | // Open All External Links in New Tab |
| 84 | if ( !isset( $options['external_links_new_tab'] ) ) { |
| 85 | $options['external_links_new_tab'] = false; |
| 86 | } |
| 87 | $options['external_links_new_tab'] = ( 'on' == $options['external_links_new_tab'] ? true : false ); |
| 88 | // Allow Custom Nav Menu Items to Open in New Tab |
| 89 | if ( !isset( $options['custom_nav_menu_items_new_tab'] ) ) { |
| 90 | $options['custom_nav_menu_items_new_tab'] = false; |
| 91 | } |
| 92 | $options['custom_nav_menu_items_new_tab'] = ( 'on' == $options['custom_nav_menu_items_new_tab'] ? true : false ); |
| 93 | // Enable Auto-Publishing of Posts with Missed Schedules |
| 94 | if ( !isset( $options['enable_missed_schedule_posts_auto_publish'] ) ) { |
| 95 | $options['enable_missed_schedule_posts_auto_publish'] = false; |
| 96 | } |
| 97 | $options['enable_missed_schedule_posts_auto_publish'] = ( 'on' == $options['enable_missed_schedule_posts_auto_publish'] ? true : false ); |
| 98 | // Enhance List Tables |
| 99 | if ( !isset( $options['enhance_list_tables'] ) ) { |
| 100 | $options['enhance_list_tables'] = false; |
| 101 | } |
| 102 | $options['enhance_list_tables'] = ( 'on' == $options['enhance_list_tables'] ? true : false ); |
| 103 | // Show Featured Image Column |
| 104 | if ( !isset( $options['show_featured_image_column'] ) ) { |
| 105 | $options['show_featured_image_column'] = false; |
| 106 | } |
| 107 | $options['show_featured_image_column'] = ( 'on' == $options['show_featured_image_column'] ? true : false ); |
| 108 | // Show Excerpt Column |
| 109 | if ( !isset( $options['show_excerpt_column'] ) ) { |
| 110 | $options['show_excerpt_column'] = false; |
| 111 | } |
| 112 | $options['show_excerpt_column'] = ( 'on' == $options['show_excerpt_column'] ? true : false ); |
| 113 | // Show ID Column |
| 114 | if ( !isset( $options['show_id_column'] ) ) { |
| 115 | $options['show_id_column'] = false; |
| 116 | } |
| 117 | $options['show_id_column'] = ( 'on' == $options['show_id_column'] ? true : false ); |
| 118 | // Show ID in Action Row |
| 119 | if ( !isset( $options['show_id_in_action_row'] ) ) { |
| 120 | $options['show_id_in_action_row'] = false; |
| 121 | } |
| 122 | $options['show_id_in_action_row'] = ( 'on' == $options['show_id_in_action_row'] ? true : false ); |
| 123 | // Show Custom Taxonomy Filters |
| 124 | if ( !isset( $options['show_custom_taxonomy_filters'] ) ) { |
| 125 | $options['show_custom_taxonomy_filters'] = false; |
| 126 | } |
| 127 | $options['show_custom_taxonomy_filters'] = ( 'on' == $options['show_custom_taxonomy_filters'] ? true : false ); |
| 128 | // Hide Comments Column |
| 129 | if ( !isset( $options['hide_comments_column'] ) ) { |
| 130 | $options['hide_comments_column'] = false; |
| 131 | } |
| 132 | $options['hide_comments_column'] = ( 'on' == $options['hide_comments_column'] ? true : false ); |
| 133 | // Hide Post Tags Column |
| 134 | if ( !isset( $options['hide_post_tags_column'] ) ) { |
| 135 | $options['hide_post_tags_column'] = false; |
| 136 | } |
| 137 | $options['hide_post_tags_column'] = ( 'on' == $options['hide_post_tags_column'] ? true : false ); |
| 138 | // ================================================================= |
| 139 | // ADMIN INTERFACE |
| 140 | // ================================================================= |
| 141 | // Hide Admin Notices |
| 142 | if ( !isset( $options['hide_admin_notices'] ) ) { |
| 143 | $options['hide_admin_notices'] = false; |
| 144 | } |
| 145 | $options['hide_admin_notices'] = ( 'on' == $options['hide_admin_notices'] ? true : false ); |
| 146 | // Hide Admin Bar |
| 147 | if ( !isset( $options['hide_admin_bar'] ) ) { |
| 148 | $options['hide_admin_bar'] = false; |
| 149 | } |
| 150 | $options['hide_admin_bar'] = ( 'on' == $options['hide_admin_bar'] ? true : false ); |
| 151 | if ( is_array( $roles ) ) { |
| 152 | foreach ( $roles as $role_slug => $role_label ) { |
| 153 | // e.g. $role_slug is administrator, $role_label is Administrator |
| 154 | if ( !isset( $options['hide_admin_bar_for'][$role_slug] ) ) { |
| 155 | $options['hide_admin_bar_for'][$role_slug] = false; |
| 156 | } |
| 157 | $options['hide_admin_bar_for'][$role_slug] = ( 'on' == $options['hide_admin_bar_for'][$role_slug] ? true : false ); |
| 158 | } |
| 159 | } |
| 160 | // Disable Dashboard Widgets |
| 161 | if ( !isset( $options['disable_dashboard_widgets'] ) ) { |
| 162 | $options['disable_dashboard_widgets'] = false; |
| 163 | } |
| 164 | $options['disable_dashboard_widgets'] = ( 'on' == $options['disable_dashboard_widgets'] ? true : false ); |
| 165 | $extra_options = get_option( 'admin_site_enhancements_extra', array() ); |
| 166 | $dashboard_widgets = $extra_options['dashboard_widgets']; |
| 167 | if ( is_array( $dashboard_widgets ) ) { |
| 168 | foreach ( $dashboard_widgets as $widget ) { |
| 169 | if ( !isset( $options['disabled_dashboard_widgets'][$widget['id'] . '__' . $widget['context'] . '__' . $widget['priority']] ) ) { |
| 170 | $options['disabled_dashboard_widgets'][$widget['id'] . '__' . $widget['context'] . '__' . $widget['priority']] = false; |
| 171 | } |
| 172 | $options['disabled_dashboard_widgets'][$widget['id'] . '__' . $widget['context'] . '__' . $widget['priority']] = ( 'on' == $options['disabled_dashboard_widgets'][$widget['id'] . '__' . $widget['context'] . '__' . $widget['priority']] ? true : false ); |
| 173 | } |
| 174 | } |
| 175 | // Hide or Modify Elements |
| 176 | if ( !isset( $options['hide_modify_elements'] ) ) { |
| 177 | $options['hide_modify_elements'] = false; |
| 178 | } |
| 179 | $options['hide_modify_elements'] = ( 'on' == $options['hide_modify_elements'] ? true : false ); |
| 180 | if ( !isset( $options['hide_ab_wp_logo_menu'] ) ) { |
| 181 | $options['hide_ab_wp_logo_menu'] = false; |
| 182 | } |
| 183 | $options['hide_ab_wp_logo_menu'] = ( 'on' == $options['hide_ab_wp_logo_menu'] ? true : false ); |
| 184 | if ( !isset( $options['hide_ab_customize_menu'] ) ) { |
| 185 | $options['hide_ab_customize_menu'] = false; |
| 186 | } |
| 187 | $options['hide_ab_customize_menu'] = ( 'on' == $options['hide_ab_customize_menu'] ? true : false ); |
| 188 | if ( !isset( $options['hide_ab_comments_menu'] ) ) { |
| 189 | $options['hide_ab_comments_menu'] = false; |
| 190 | } |
| 191 | $options['hide_ab_comments_menu'] = ( 'on' == $options['hide_ab_comments_menu'] ? true : false ); |
| 192 | if ( !isset( $options['hide_ab_updates_menu'] ) ) { |
| 193 | $options['hide_ab_updates_menu'] = false; |
| 194 | } |
| 195 | $options['hide_ab_updates_menu'] = ( 'on' == $options['hide_ab_updates_menu'] ? true : false ); |
| 196 | if ( !isset( $options['hide_ab_new_content_menu'] ) ) { |
| 197 | $options['hide_ab_new_content_menu'] = false; |
| 198 | } |
| 199 | $options['hide_ab_new_content_menu'] = ( 'on' == $options['hide_ab_new_content_menu'] ? true : false ); |
| 200 | if ( !isset( $options['hide_ab_howdy'] ) ) { |
| 201 | $options['hide_ab_howdy'] = false; |
| 202 | } |
| 203 | $options['hide_ab_howdy'] = ( 'on' == $options['hide_ab_howdy'] ? true : false ); |
| 204 | if ( !isset( $options['hide_help_drawer'] ) ) { |
| 205 | $options['hide_help_drawer'] = false; |
| 206 | } |
| 207 | $options['hide_help_drawer'] = ( 'on' == $options['hide_help_drawer'] ? true : false ); |
| 208 | // Wider Admin Menu |
| 209 | if ( !isset( $options['wider_admin_menu'] ) ) { |
| 210 | $options['wider_admin_menu'] = false; |
| 211 | } |
| 212 | $options['wider_admin_menu'] = ( 'on' == $options['wider_admin_menu'] ? true : false ); |
| 213 | if ( !isset( $options['admin_menu_width'] ) ) { |
| 214 | $options['admin_menu_width'] = 200; |
| 215 | } |
| 216 | $options['admin_menu_width'] = ( !empty($options['admin_menu_width']) ? sanitize_text_field( $options['admin_menu_width'] ) : 200 ); |
| 217 | // Customize Admin Menu |
| 218 | if ( !isset( $options['customize_admin_menu'] ) ) { |
| 219 | $options['customize_admin_menu'] = false; |
| 220 | } |
| 221 | $options['customize_admin_menu'] = ( 'on' == $options['customize_admin_menu'] ? true : false ); |
| 222 | if ( !isset( $options['custom_menu_order'] ) ) { |
| 223 | $options['custom_menu_order'] = ''; |
| 224 | } |
| 225 | // The following fields are added on rendering of custom_menu_order field |
| 226 | if ( !isset( $options['custom_menu_titles'] ) ) { |
| 227 | $options['custom_menu_titles'] = ''; |
| 228 | } |
| 229 | if ( !isset( $options['custom_menu_hidden'] ) ) { |
| 230 | $options['custom_menu_hidden'] = ''; |
| 231 | } |
| 232 | // ================================================================= |
| 233 | // LOG IN | LOG OUT |
| 234 | // ================================================================= |
| 235 | // Change Login URL |
| 236 | if ( !isset( $options['change_login_url'] ) ) { |
| 237 | $options['change_login_url'] = false; |
| 238 | } |
| 239 | $options['change_login_url'] = ( 'on' == $options['change_login_url'] ? true : false ); |
| 240 | if ( !isset( $options['custom_login_slug'] ) ) { |
| 241 | $options['custom_login_slug'] = 'backend'; |
| 242 | } |
| 243 | $options['custom_login_slug'] = ( !empty($options['custom_login_slug']) ? sanitize_text_field( $options['custom_login_slug'] ) : 'backend' ); |
| 244 | // Enable Login Logout Menu |
| 245 | if ( !isset( $options['enable_login_logout_menu'] ) ) { |
| 246 | $options['enable_login_logout_menu'] = false; |
| 247 | } |
| 248 | $options['enable_login_logout_menu'] = ( 'on' == $options['enable_login_logout_menu'] ? true : false ); |
| 249 | // Redirect After Login |
| 250 | if ( !isset( $options['redirect_after_login'] ) ) { |
| 251 | $options['redirect_after_login'] = false; |
| 252 | } |
| 253 | $options['redirect_after_login'] = ( 'on' == $options['redirect_after_login'] ? true : false ); |
| 254 | if ( !isset( $options['redirect_after_login_to_slug'] ) ) { |
| 255 | $options['redirect_after_login_to_slug'] = ''; |
| 256 | } |
| 257 | $options['redirect_after_login_to_slug'] = ( !empty($options['redirect_after_login_to_slug']) ? sanitize_text_field( $options['redirect_after_login_to_slug'] ) : '' ); |
| 258 | if ( is_array( $roles ) ) { |
| 259 | foreach ( $roles as $role_slug => $role_label ) { |
| 260 | // e.g. $role_slug is administrator, $role_label is Administrator |
| 261 | if ( !isset( $options['redirect_after_login_for'][$role_slug] ) ) { |
| 262 | $options['redirect_after_login_for'][$role_slug] = false; |
| 263 | } |
| 264 | $options['redirect_after_login_for'][$role_slug] = ( 'on' == $options['redirect_after_login_for'][$role_slug] ? true : false ); |
| 265 | } |
| 266 | } |
| 267 | // Redirect After Logout |
| 268 | if ( !isset( $options['redirect_after_logout'] ) ) { |
| 269 | $options['redirect_after_logout'] = false; |
| 270 | } |
| 271 | $options['redirect_after_logout'] = ( 'on' == $options['redirect_after_logout'] ? true : false ); |
| 272 | if ( !isset( $options['redirect_after_logout_to_slug'] ) ) { |
| 273 | $options['redirect_after_logout_to_slug'] = ''; |
| 274 | } |
| 275 | $options['redirect_after_logout_to_slug'] = ( !empty($options['redirect_after_logout_to_slug']) ? sanitize_text_field( $options['redirect_after_logout_to_slug'] ) : '' ); |
| 276 | if ( is_array( $roles ) ) { |
| 277 | foreach ( $roles as $role_slug => $role_label ) { |
| 278 | // e.g. $role_slug is administrator, $role_label is Administrator |
| 279 | if ( !isset( $options['redirect_after_logout_for'][$role_slug] ) ) { |
| 280 | $options['redirect_after_logout_for'][$role_slug] = false; |
| 281 | } |
| 282 | $options['redirect_after_logout_for'][$role_slug] = ( 'on' == $options['redirect_after_logout_for'][$role_slug] ? true : false ); |
| 283 | } |
| 284 | } |
| 285 | // Enable Last Login Column |
| 286 | if ( !isset( $options['enable_last_login_column'] ) ) { |
| 287 | $options['enable_last_login_column'] = false; |
| 288 | } |
| 289 | $options['enable_last_login_column'] = ( 'on' == $options['enable_last_login_column'] ? true : false ); |
| 290 | // ================================================================= |
| 291 | // CUSTOM CODE |
| 292 | // ================================================================= |
| 293 | // Enable Custom Admin CSS |
| 294 | if ( !isset( $options['enable_custom_admin_css'] ) ) { |
| 295 | $options['enable_custom_admin_css'] = false; |
| 296 | } |
| 297 | $options['enable_custom_admin_css'] = ( 'on' == $options['enable_custom_admin_css'] ? true : false ); |
| 298 | if ( !isset( $options['custom_admin_css'] ) ) { |
| 299 | $options['custom_admin_css'] = ''; |
| 300 | } |
| 301 | $options['custom_admin_css'] = ( !empty($options['custom_admin_css']) ? $options['custom_admin_css'] : '' ); |
| 302 | // Enable Custom Frontend CSS |
| 303 | if ( !isset( $options['enable_custom_frontend_css'] ) ) { |
| 304 | $options['enable_custom_frontend_css'] = false; |
| 305 | } |
| 306 | $options['enable_custom_frontend_css'] = ( 'on' == $options['enable_custom_frontend_css'] ? true : false ); |
| 307 | if ( !isset( $options['custom_frontend_css'] ) ) { |
| 308 | $options['custom_frontend_css'] = ''; |
| 309 | } |
| 310 | $options['custom_frontend_css'] = ( !empty($options['custom_frontend_css']) ? $options['custom_frontend_css'] : '' ); |
| 311 | // Custom Body Class |
| 312 | if ( !isset( $options['enable_custom_body_class'] ) ) { |
| 313 | $options['enable_custom_body_class'] = false; |
| 314 | } |
| 315 | $options['enable_custom_body_class'] = ( 'on' == $options['enable_custom_body_class'] ? true : false ); |
| 316 | if ( is_array( $asenha_public_post_types ) ) { |
| 317 | foreach ( $asenha_public_post_types as $post_type_slug => $post_type_label ) { |
| 318 | // e.g. $post_type_slug is post, $post_type_label is Posts |
| 319 | if ( !isset( $options['enable_custom_body_class_for'][$post_type_slug] ) ) { |
| 320 | $options['enable_custom_body_class_for'][$post_type_slug] = false; |
| 321 | } |
| 322 | $options['enable_custom_body_class_for'][$post_type_slug] = ( 'on' == $options['enable_custom_body_class_for'][$post_type_slug] ? true : false ); |
| 323 | } |
| 324 | } |
| 325 | // Manage ads.txt and app-ads.txt |
| 326 | if ( !isset( $options['manage_ads_appads_txt'] ) ) { |
| 327 | $options['manage_ads_appads_txt'] = false; |
| 328 | } |
| 329 | $options['manage_ads_appads_txt'] = ( 'on' == $options['manage_ads_appads_txt'] ? true : false ); |
| 330 | if ( !isset( $options['ads_txt_content'] ) ) { |
| 331 | $options['ads_txt_content'] = ''; |
| 332 | } |
| 333 | $options['ads_txt_content'] = ( !empty($options['ads_txt_content']) ? $options['ads_txt_content'] : '' ); |
| 334 | if ( !isset( $options['app_ads_txt_content'] ) ) { |
| 335 | $options['app_ads_txt_content'] = ''; |
| 336 | } |
| 337 | $options['app_ads_txt_content'] = ( !empty($options['app_ads_txt_content']) ? $options['app_ads_txt_content'] : '' ); |
| 338 | // Manage robots.txt |
| 339 | if ( !isset( $options['manage_robots_txt'] ) ) { |
| 340 | $options['manage_robots_txt'] = false; |
| 341 | } |
| 342 | $options['manage_robots_txt'] = ( 'on' == $options['manage_robots_txt'] ? true : false ); |
| 343 | |
| 344 | if ( !isset( $options['robots_txt_content'] ) ) { |
| 345 | $options['robots_txt_content'] = ''; |
| 346 | } else { |
| 347 | |
| 348 | if ( !empty($options['robots_txt_content']) ) { |
| 349 | $options['robots_txt_content'] = $options['robots_txt_content']; |
| 350 | $is_robots_txt_real_file = is_file( ABSPATH . 'robots.txt' ); |
| 351 | // rename real robots.txt file if it exists and Mange robots.txt is enabled |
| 352 | |
| 353 | if ( $is_robots_txt_real_file && 'on' == $options['manage_robots_txt'] ) { |
| 354 | $robots_txt_backup_filename = 'robots_backup_' . date( 'Y_m_d__H_i', time() ) . '.txt'; |
| 355 | $extra_options = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 356 | $extra_options['robots_txt_backup_file_name'] = $robots_txt_backup_filename; |
| 357 | update_option( ASENHA_SLUG_U . '_extra', $extra_options ); |
| 358 | rename( ABSPATH . 'robots.txt', ABSPATH . $robots_txt_backup_filename ); |
| 359 | } elseif ( 'on' != $options['manage_robots_txt'] ) { |
| 360 | $extra_options = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 361 | if ( array_key_exists( 'robots_txt_backup_file_name', $extra_options ) ) { |
| 362 | if ( is_file( ABSPATH . $extra_options['robots_txt_backup_file_name'] ) ) { |
| 363 | rename( ABSPATH . $extra_options['robots_txt_backup_file_name'], ABSPATH . 'robots.txt' ); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | } else { |
| 369 | $options['robots_txt_content'] = ''; |
| 370 | } |
| 371 | |
| 372 | } |
| 373 | |
| 374 | // Insert <head>, <body> and <footer> code |
| 375 | if ( !isset( $options['insert_head_body_footer_code'] ) ) { |
| 376 | $options['insert_head_body_footer_code'] = false; |
| 377 | } |
| 378 | $options['insert_head_body_footer_code'] = ( 'on' == $options['insert_head_body_footer_code'] ? true : false ); |
| 379 | if ( !isset( $options['head_code_priority'] ) ) { |
| 380 | $options['head_code_priority'] = ''; |
| 381 | } |
| 382 | $options['head_code_priority'] = ( isset( $options['head_code_priority'] ) ? $options['head_code_priority'] : 10 ); |
| 383 | if ( !isset( $options['head_code'] ) ) { |
| 384 | $options['head_code'] = ''; |
| 385 | } |
| 386 | $options['head_code'] = ( !empty($options['head_code']) ? $options['head_code'] : '' ); |
| 387 | if ( !isset( $options['body_code_priority'] ) ) { |
| 388 | $options['body_code_priority'] = ''; |
| 389 | } |
| 390 | $options['body_code_priority'] = ( isset( $options['body_code_priority'] ) ? $options['body_code_priority'] : 10 ); |
| 391 | if ( !isset( $options['body_code'] ) ) { |
| 392 | $options['body_code'] = ''; |
| 393 | } |
| 394 | $options['body_code'] = ( !empty($options['body_code']) ? $options['body_code'] : '' ); |
| 395 | if ( !isset( $options['footer_code_priority'] ) ) { |
| 396 | $options['footer_code_priority'] = ''; |
| 397 | } |
| 398 | $options['footer_code_priority'] = ( isset( $options['footer_code_priority'] ) ? $options['footer_code_priority'] : 10 ); |
| 399 | if ( !isset( $options['footer_code'] ) ) { |
| 400 | $options['footer_code'] = ''; |
| 401 | } |
| 402 | $options['footer_code'] = ( !empty($options['footer_code']) ? $options['footer_code'] : '' ); |
| 403 | // ================================================================= |
| 404 | // DISABLE COMPONENTS |
| 405 | // ================================================================= |
| 406 | // Disable Gutenberg |
| 407 | if ( !isset( $options['disable_gutenberg'] ) ) { |
| 408 | $options['disable_gutenberg'] = false; |
| 409 | } |
| 410 | $options['disable_gutenberg'] = ( 'on' == $options['disable_gutenberg'] ? true : false ); |
| 411 | if ( is_array( $asenha_gutenberg_post_types ) ) { |
| 412 | foreach ( $asenha_gutenberg_post_types as $post_type_slug => $post_type_label ) { |
| 413 | // e.g. $post_type_slug is post, |
| 414 | if ( !isset( $options['disable_gutenberg_for'][$post_type_slug] ) ) { |
| 415 | $options['disable_gutenberg_for'][$post_type_slug] = false; |
| 416 | } |
| 417 | $options['disable_gutenberg_for'][$post_type_slug] = ( 'on' == $options['disable_gutenberg_for'][$post_type_slug] ? true : false ); |
| 418 | } |
| 419 | } |
| 420 | if ( !isset( $options['disable_gutenberg_frontend_styles'] ) ) { |
| 421 | $options['disable_gutenberg_frontend_styles'] = false; |
| 422 | } |
| 423 | $options['disable_gutenberg_frontend_styles'] = ( 'on' == $options['disable_gutenberg_frontend_styles'] ? true : false ); |
| 424 | // Disable Block-Based Widgets Screen |
| 425 | if ( !isset( $options['disable_block_widgets'] ) ) { |
| 426 | $options['disable_block_widgets'] = false; |
| 427 | } |
| 428 | $options['disable_block_widgets'] = ( 'on' == $options['disable_block_widgets'] ? true : false ); |
| 429 | // Disable Comments |
| 430 | if ( !isset( $options['disable_comments'] ) ) { |
| 431 | $options['disable_comments'] = false; |
| 432 | } |
| 433 | $options['disable_comments'] = ( 'on' == $options['disable_comments'] ? true : false ); |
| 434 | if ( is_array( $asenha_public_post_types ) ) { |
| 435 | foreach ( $asenha_public_post_types as $post_type_slug => $post_type_label ) { |
| 436 | // e.g. $post_type_slug is post, $post_type_label is Posts |
| 437 | if ( !isset( $options['disable_comments_for'][$post_type_slug] ) ) { |
| 438 | $options['disable_comments_for'][$post_type_slug] = false; |
| 439 | } |
| 440 | $options['disable_comments_for'][$post_type_slug] = ( 'on' == $options['disable_comments_for'][$post_type_slug] ? true : false ); |
| 441 | } |
| 442 | } |
| 443 | // Disable REST API |
| 444 | if ( !isset( $options['disable_rest_api'] ) ) { |
| 445 | $options['disable_rest_api'] = false; |
| 446 | } |
| 447 | $options['disable_rest_api'] = ( 'on' == $options['disable_rest_api'] ? true : false ); |
| 448 | // Disable Feeds |
| 449 | if ( !isset( $options['disable_feeds'] ) ) { |
| 450 | $options['disable_feeds'] = false; |
| 451 | } |
| 452 | $options['disable_feeds'] = ( 'on' == $options['disable_feeds'] ? true : false ); |
| 453 | // Disable Auto Updates |
| 454 | if ( !isset( $options['disable_all_updates'] ) ) { |
| 455 | $options['disable_all_updates'] = false; |
| 456 | } |
| 457 | $options['disable_all_updates'] = ( 'on' == $options['disable_all_updates'] ? true : false ); |
| 458 | // Disable Smaller Components |
| 459 | if ( !isset( $options['disable_smaller_components'] ) ) { |
| 460 | $options['disable_smaller_components'] = false; |
| 461 | } |
| 462 | $options['disable_smaller_components'] = ( 'on' == $options['disable_smaller_components'] ? true : false ); |
| 463 | if ( !isset( $options['disable_head_generator_tag'] ) ) { |
| 464 | $options['disable_head_generator_tag'] = false; |
| 465 | } |
| 466 | $options['disable_head_generator_tag'] = ( 'on' == $options['disable_head_generator_tag'] ? true : false ); |
| 467 | if ( !isset( $options['disable_head_wlwmanifest_tag'] ) ) { |
| 468 | $options['disable_head_wlwmanifest_tag'] = false; |
| 469 | } |
| 470 | $options['disable_head_wlwmanifest_tag'] = ( 'on' == $options['disable_head_wlwmanifest_tag'] ? true : false ); |
| 471 | if ( !isset( $options['disable_head_rsd_tag'] ) ) { |
| 472 | $options['disable_head_rsd_tag'] = false; |
| 473 | } |
| 474 | $options['disable_head_rsd_tag'] = ( 'on' == $options['disable_head_rsd_tag'] ? true : false ); |
| 475 | if ( !isset( $options['disable_head_shortlink_tag'] ) ) { |
| 476 | $options['disable_head_shortlink_tag'] = false; |
| 477 | } |
| 478 | $options['disable_head_shortlink_tag'] = ( 'on' == $options['disable_head_shortlink_tag'] ? true : false ); |
| 479 | if ( !isset( $options['disable_frontend_dashicons'] ) ) { |
| 480 | $options['disable_frontend_dashicons'] = false; |
| 481 | } |
| 482 | $options['disable_frontend_dashicons'] = ( 'on' == $options['disable_frontend_dashicons'] ? true : false ); |
| 483 | if ( !isset( $options['disable_emoji_support'] ) ) { |
| 484 | $options['disable_emoji_support'] = false; |
| 485 | } |
| 486 | $options['disable_emoji_support'] = ( 'on' == $options['disable_emoji_support'] ? true : false ); |
| 487 | // ================================================================= |
| 488 | // SECURITY |
| 489 | // ================================================================= |
| 490 | // Limit Login Attempts |
| 491 | if ( !isset( $options['limit_login_attempts'] ) ) { |
| 492 | $options['limit_login_attempts'] = false; |
| 493 | } |
| 494 | $options['limit_login_attempts'] = ( 'on' == $options['limit_login_attempts'] ? true : false ); |
| 495 | if ( !isset( $options['login_fails_allowed'] ) ) { |
| 496 | $options['login_fails_allowed'] = 3; |
| 497 | } |
| 498 | $options['login_fails_allowed'] = ( !empty($options['login_fails_allowed']) ? sanitize_text_field( $options['login_fails_allowed'] ) : 3 ); |
| 499 | if ( !isset( $options['login_lockout_maxcount'] ) ) { |
| 500 | $options['login_lockout_maxcount'] = 3; |
| 501 | } |
| 502 | $options['login_lockout_maxcount'] = ( !empty($options['login_lockout_maxcount']) ? sanitize_text_field( $options['login_lockout_maxcount'] ) : 3 ); |
| 503 | if ( !isset( $options['login_attempts_log_table'] ) ) { |
| 504 | $options['login_attempts_log_table'] = ''; |
| 505 | } |
| 506 | $options['login_attempts_log_table'] = ''; |
| 507 | // Obfuscate Author Slugs |
| 508 | if ( !isset( $options['obfuscate_author_slugs'] ) ) { |
| 509 | $options['obfuscate_author_slugs'] = false; |
| 510 | } |
| 511 | $options['obfuscate_author_slugs'] = ( 'on' == $options['obfuscate_author_slugs'] ? true : false ); |
| 512 | // Obfuscate Email Address |
| 513 | if ( !isset( $options['obfuscate_email_address'] ) ) { |
| 514 | $options['obfuscate_email_address'] = false; |
| 515 | } |
| 516 | $options['obfuscate_email_address'] = ( 'on' == $options['obfuscate_email_address'] ? true : false ); |
| 517 | // Disable XML-RPC |
| 518 | if ( !isset( $options['disable_xmlrpc'] ) ) { |
| 519 | $options['disable_xmlrpc'] = false; |
| 520 | } |
| 521 | $options['disable_xmlrpc'] = ( 'on' == $options['disable_xmlrpc'] ? true : false ); |
| 522 | // ================================================================= |
| 523 | // OPTIMIZATIONS |
| 524 | // ================================================================= |
| 525 | // Image Upload Control |
| 526 | if ( !isset( $options['image_upload_control'] ) ) { |
| 527 | $options['image_upload_control'] = false; |
| 528 | } |
| 529 | $options['image_upload_control'] = ( 'on' == $options['image_upload_control'] ? true : false ); |
| 530 | if ( !isset( $options['image_max_width'] ) ) { |
| 531 | $options['image_max_width'] = 1920; |
| 532 | } |
| 533 | $options['image_max_width'] = ( !empty($options['image_max_width']) ? sanitize_text_field( $options['image_max_width'] ) : 1920 ); |
| 534 | if ( !isset( $options['image_max_height'] ) ) { |
| 535 | $options['image_max_height'] = 1920; |
| 536 | } |
| 537 | $options['image_max_height'] = ( !empty($options['image_max_height']) ? sanitize_text_field( $options['image_max_height'] ) : 1920 ); |
| 538 | // Enable Revisions Control |
| 539 | if ( !isset( $options['enable_revisions_control'] ) ) { |
| 540 | $options['enable_revisions_control'] = false; |
| 541 | } |
| 542 | $options['enable_revisions_control'] = ( 'on' == $options['enable_revisions_control'] ? true : false ); |
| 543 | if ( !isset( $options['revisions_max_number'] ) ) { |
| 544 | $options['revisions_max_number'] = 10; |
| 545 | } |
| 546 | $options['revisions_max_number'] = ( !empty($options['revisions_max_number']) ? sanitize_text_field( $options['revisions_max_number'] ) : 10 ); |
| 547 | if ( is_array( $asenha_revisions_post_types ) ) { |
| 548 | foreach ( $asenha_revisions_post_types as $post_type_slug => $post_type_label ) { |
| 549 | // e.g. $post_type_slug is post, |
| 550 | if ( !isset( $options['enable_revisions_control_for'][$post_type_slug] ) ) { |
| 551 | $options['enable_revisions_control_for'][$post_type_slug] = false; |
| 552 | } |
| 553 | $options['enable_revisions_control_for'][$post_type_slug] = ( 'on' == $options['enable_revisions_control_for'][$post_type_slug] ? true : false ); |
| 554 | } |
| 555 | } |
| 556 | // Enable Heartbeat Control |
| 557 | if ( !isset( $options['enable_heartbeat_control'] ) ) { |
| 558 | $options['enable_heartbeat_control'] = false; |
| 559 | } |
| 560 | $options['enable_heartbeat_control'] = ( 'on' == $options['enable_heartbeat_control'] ? true : false ); |
| 561 | if ( !isset( $options['heartbeat_control_for_admin_pages'] ) ) { |
| 562 | $options['heartbeat_control_for_admin_pages'] = 'default'; |
| 563 | } |
| 564 | if ( !isset( $options['heartbeat_control_for_post_edit'] ) ) { |
| 565 | $options['heartbeat_control_for_post_edit'] = 'default'; |
| 566 | } |
| 567 | if ( !isset( $options['heartbeat_control_for_frontend'] ) ) { |
| 568 | $options['heartbeat_control_for_frontend'] = 'default'; |
| 569 | } |
| 570 | if ( !isset( $options['heartbeat_interval_for_admin_pages'] ) ) { |
| 571 | $options['heartbeat_interval_for_admin_pages'] = 60; |
| 572 | } |
| 573 | $options['heartbeat_interval_for_admin_pages'] = ( !empty($options['heartbeat_interval_for_admin_pages']) ? sanitize_text_field( $options['heartbeat_interval_for_admin_pages'] ) : 60 ); |
| 574 | if ( !isset( $options['heartbeat_interval_for_post_edit'] ) ) { |
| 575 | $options['heartbeat_interval_for_post_edit'] = 15; |
| 576 | } |
| 577 | $options['heartbeat_interval_for_post_edit'] = ( !empty($options['heartbeat_interval_for_post_edit']) ? sanitize_text_field( $options['heartbeat_interval_for_post_edit'] ) : 15 ); |
| 578 | if ( !isset( $options['heartbeat_interval_for_frontend'] ) ) { |
| 579 | $options['heartbeat_interval_for_frontend'] = 60; |
| 580 | } |
| 581 | $options['heartbeat_interval_for_frontend'] = ( !empty($options['heartbeat_interval_for_frontend']) ? sanitize_text_field( $options['heartbeat_interval_for_frontend'] ) : 60 ); |
| 582 | // ================================================================= |
| 583 | // UTILITIES |
| 584 | // ================================================================= |
| 585 | // SMTP Email Delivery |
| 586 | if ( !isset( $options['smtp_email_delivery'] ) ) { |
| 587 | $options['smtp_email_delivery'] = false; |
| 588 | } |
| 589 | $options['smtp_email_delivery'] = ( 'on' == $options['smtp_email_delivery'] ? true : false ); |
| 590 | if ( !isset( $options['smtp_host'] ) ) { |
| 591 | $options['smtp_host'] = ''; |
| 592 | } |
| 593 | $options['smtp_host'] = ( !empty($options['smtp_host']) ? sanitize_text_field( $options['smtp_host'] ) : '' ); |
| 594 | if ( !isset( $options['smtp_port'] ) ) { |
| 595 | $options['smtp_port'] = ''; |
| 596 | } |
| 597 | $options['smtp_port'] = ( !empty($options['smtp_port']) ? $options['smtp_port'] : '' ); |
| 598 | if ( !isset( $options['smtp_security'] ) ) { |
| 599 | $options['smtp_security'] = 'none'; |
| 600 | } |
| 601 | $options['smtp_security'] = ( !empty($options['smtp_security']) ? $options['smtp_security'] : 'none' ); |
| 602 | if ( !isset( $options['smtp_username'] ) ) { |
| 603 | $options['smtp_username'] = ''; |
| 604 | } |
| 605 | $options['smtp_username'] = ( !empty($options['smtp_username']) ? sanitize_text_field( $options['smtp_username'] ) : '' ); |
| 606 | if ( !isset( $options['smtp_password'] ) ) { |
| 607 | $options['smtp_password'] = ''; |
| 608 | } |
| 609 | $options['smtp_password'] = ( !empty($options['smtp_password']) ? $options['smtp_password'] : '' ); |
| 610 | if ( !isset( $options['smtp_default_from_name'] ) ) { |
| 611 | $options['smtp_default_from_name'] = ''; |
| 612 | } |
| 613 | $options['smtp_default_from_name'] = ( !empty($options['smtp_default_from_name']) ? sanitize_text_field( $options['smtp_default_from_name'] ) : '' ); |
| 614 | if ( !isset( $options['smtp_default_from_email'] ) ) { |
| 615 | $options['smtp_default_from_email'] = ''; |
| 616 | } |
| 617 | $options['smtp_default_from_email'] = ( !empty($options['smtp_default_from_email']) ? sanitize_text_field( $options['smtp_default_from_email'] ) : '' ); |
| 618 | if ( !isset( $options['smtp_default_from_description'] ) ) { |
| 619 | $options['smtp_default_from_description'] = ''; |
| 620 | } |
| 621 | if ( !isset( $options['smtp_force_from'] ) ) { |
| 622 | $options['smtp_force_from'] = false; |
| 623 | } |
| 624 | $options['smtp_force_from'] = ( 'on' == $options['smtp_force_from'] ? true : false ); |
| 625 | if ( !isset( $options['smtp_debug'] ) ) { |
| 626 | $options['smtp_debug'] = false; |
| 627 | } |
| 628 | $options['smtp_debug'] = ( 'on' == $options['smtp_debug'] ? true : false ); |
| 629 | // Multiple User Roles |
| 630 | if ( !isset( $options['multiple_user_roles'] ) ) { |
| 631 | $options['multiple_user_roles'] = false; |
| 632 | } |
| 633 | $options['multiple_user_roles'] = ( 'on' == $options['multiple_user_roles'] ? true : false ); |
| 634 | // View Admin as Role |
| 635 | if ( !isset( $options['view_admin_as_role'] ) ) { |
| 636 | $options['view_admin_as_role'] = false; |
| 637 | } |
| 638 | $options['view_admin_as_role'] = ( 'on' == $options['view_admin_as_role'] ? true : false ); |
| 639 | // Enable Password Protection |
| 640 | if ( !isset( $options['enable_password_protection'] ) ) { |
| 641 | $options['enable_password_protection'] = false; |
| 642 | } |
| 643 | $options['enable_password_protection'] = ( 'on' == $options['enable_password_protection'] ? true : false ); |
| 644 | if ( !isset( $options['password_protection_password'] ) ) { |
| 645 | $options['password_protection_password'] = 'secret'; |
| 646 | } |
| 647 | $options['password_protection_password'] = ( !empty($options['password_protection_password']) ? $options['password_protection_password'] : 'secret' ); |
| 648 | // Redirect 404 to Homepage |
| 649 | if ( !isset( $options['maintenance_mode'] ) ) { |
| 650 | $options['maintenance_mode'] = false; |
| 651 | } |
| 652 | $options['maintenance_mode'] = ( 'on' == $options['maintenance_mode'] ? true : false ); |
| 653 | if ( !isset( $options['maintenance_page_heading'] ) ) { |
| 654 | $options['maintenance_page_heading'] = 'We\'ll be back soon.'; |
| 655 | } |
| 656 | $options['maintenance_page_heading'] = ( !empty($options['maintenance_page_heading']) ? sanitize_text_field( $options['maintenance_page_heading'] ) : 'We\'ll be back soon.' ); |
| 657 | if ( !isset( $options['maintenance_page_description'] ) ) { |
| 658 | $options['maintenance_page_description'] = 'This site is undergoing maintenance for an extended period today. Thanks for your patience.'; |
| 659 | } |
| 660 | $options['maintenance_page_description'] = ( !empty($options['maintenance_page_description']) ? sanitize_text_field( $options['maintenance_page_description'] ) : 'This site is undergoing maintenance for an extended period today. Thanks for your patience.' ); |
| 661 | if ( !isset( $options['maintenance_page_background'] ) ) { |
| 662 | $options['maintenance_page_background'] = 'stripes'; |
| 663 | } |
| 664 | $options['maintenance_page_background'] = ( !empty($options['maintenance_page_background']) ? $options['maintenance_page_background'] : 'stripes' ); |
| 665 | if ( !isset( $options['maintenance_mode_description'] ) ) { |
| 666 | $options['maintenance_mode_description'] = ''; |
| 667 | } |
| 668 | // Redirect 404 to Homepage |
| 669 | if ( !isset( $options['redirect_404_to_homepage'] ) ) { |
| 670 | $options['redirect_404_to_homepage'] = false; |
| 671 | } |
| 672 | $options['redirect_404_to_homepage'] = ( 'on' == $options['redirect_404_to_homepage'] ? true : false ); |
| 673 | return $options; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Sanitize checkbox field. For reference purpose. Not currently in use. |
| 678 | * |
| 679 | * @since 1.0.0 |
| 680 | */ |
| 681 | function asenha_sanitize_checkbox_field( $value ) |
| 682 | { |
| 683 | // 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) |
| 684 | return ( 'on' === $value ? true : false ); |
| 685 | } |
| 686 | |
| 687 | } |