'sanitize_text_field', ]); } $textarea_fields = [ 'top_disclaimer_text' ]; foreach ( $textarea_fields as $f ) { register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_' . $f, [ 'sanitize_callback' => 'sanitize_textarea_field', ]); } $html_fields = [ 'description', 'disclaimer_text' ]; foreach ( $html_fields as $f ) { register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_' . $f, [ 'sanitize_callback' => 'wp_kses_post', ]); } register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_checkboxes', [ 'sanitize_callback' => 'ab_age_gate_sanitize_checkboxes', ]); $color_fields = [ 'button_color', 'accept_all_color', 'top_disclaimer_color', 'accent_color', 'bg_color' ]; foreach ( $color_fields as $f ) { register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_' . $f, [ 'sanitize_callback' => 'sanitize_hex_color', ]); } $url_fields = [ 'leave_url', 'disclaimer_link_url', 'logo_url' ]; foreach ( $url_fields as $f ) { register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_' . $f, [ 'sanitize_callback' => 'esc_url_raw', ]); } $int_fields = [ 'cookie_days', 'logo_height' ]; foreach ( $int_fields as $f ) { register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_' . $f, [ 'sanitize_callback' => 'absint', ]); } $bool_fields = [ 'enabled', 'bypass_logged_in' ]; foreach ( $bool_fields as $f ) { register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_' . $f, [ 'sanitize_callback' => function( $val ) { return ( $val === '1' || $val === 1 ) ? '1' : '0'; }, ]); } register_setting( 'ab_age_gate_settings_group', 'ab_age_gate_logo_align', [ 'sanitize_callback' => function( $val ) { return in_array( $val, [ 'left', 'center', 'right' ], true ) ? $val : 'center'; } ]); }); /* --------------------------------------------------------------- Enqueue admin styles & scripts --------------------------------------------------------------- */ add_action( 'admin_enqueue_scripts', function( $hook ) { if ( $hook !== 'settings_page_ab-age-gate' ) return; wp_enqueue_media(); wp_enqueue_editor(); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'ab-age-gate-admin-style', AB_AGE_GATE_URL . 'assets/css/admin.css', [], AB_AGE_GATE_VERSION ); wp_enqueue_script( 'ab-age-gate-admin-script', AB_AGE_GATE_URL . 'assets/js/admin.js', ['jquery', 'wp-color-picker'], AB_AGE_GATE_VERSION, true ); wp_localize_script( 'ab-age-gate-admin-script', 'abAgeGateI18n', [ 'select_logo_image' => __( 'Select Logo Image', 'ab-age-gate' ), 'use_image' => __( 'Use Image', 'ab-age-gate' ), 'checkbox_label_text' => __( 'Checkbox label text…', 'ab-age-gate' ), 'remove' => __( 'Remove', 'ab-age-gate' ), 'min_checkbox_alert' => __( 'You must keep at least one required checkbox.', 'ab-age-gate' ), ]); }); /* --------------------------------------------------------------- Settings page HTML --------------------------------------------------------------- */ function ab_age_gate_settings_page() { if ( ! current_user_can( 'manage_options' ) ) return; ?>