'', 'primary' => '', 'on_primary' => '', 'bg' => '', 'text' => '', 'border' => '', 'busy' => '', 'fee' => '', 'radius' => '', 'radius_btn' => '', 'radius_day' => '', 'radius_card' => '', 'radius_input' => '', 'font_size' => '', 'gap' => '', 'mode_style' => 'switch', 'time_style' => 'list', 'date_style' => 'calendar', 'match' => 'no', ); } /** * Ready-made looks. */ function dayslot_style_presets() { return apply_filters( 'dayslot_style_presets', array( 'light' => array( 'label' => __( 'Light', 'dayslot' ), 'primary' => '#222222', 'on_primary' => '#ffffff', 'bg' => '#ffffff', 'text' => '#222222', 'border' => '#e2e2e2', 'busy' => '#b5b5b5', 'fee' => '#c98a12', 'radius' => '10', 'mode_style' => 'switch', 'time_style' => 'list', ), 'dark' => array( 'label' => __( 'Dark', 'dayslot' ), 'primary' => '#f2f2f2', 'on_primary' => '#111111', 'bg' => '#1d1f23', 'text' => '#f1f1f1', 'border' => '#3a3d44', 'busy' => '#80848d', 'fee' => '#f0c060', 'radius' => '10', 'mode_style' => 'switch', 'time_style' => 'list', ), 'minimal' => array( 'label' => __( 'Minimal', 'dayslot' ), 'primary' => '#111111', 'on_primary' => '#ffffff', 'bg' => '#ffffff', 'text' => '#111111', 'border' => '#d8d8d8', 'busy' => '#aaaaaa', 'fee' => '#8a5a00', 'radius' => '0', 'mode_style' => 'buttons', 'time_style' => 'select', ), 'soft' => array( 'label' => __( 'Soft', 'dayslot' ), 'primary' => '#9c4f73', 'on_primary' => '#ffffff', 'bg' => '#fffafb', 'text' => '#4a3540', 'border' => '#f0dbe4', 'busy' => '#c9b3bd', 'fee' => '#b86b2e', 'radius' => '16', 'mode_style' => 'cards', 'time_style' => 'grid', ), 'candy' => array( 'label' => __( 'Candy pink', 'dayslot' ), 'primary' => '#f7cecd', 'on_primary' => '#242e42', 'bg' => '#ffffff', 'text' => '#242e42', 'border' => '#e5e7eb', 'busy' => '#9aa1ad', 'fee' => '#2f7f8f', 'radius' => '12', 'mode_style' => 'cards', 'time_style' => 'grid', ), ) ); } /** * Saved style merged with defaults. */ function dayslot_style_settings() { $saved = dayslot_get_settings()['style']; return wp_parse_args( is_array( $saved ) ? $saved : array(), dayslot_style_defaults() ); } /** * Clean submitted style values. */ function dayslot_sanitize_style( $input ) { $input = is_array( $input ) ? $input : array(); $out = dayslot_style_defaults(); foreach ( array( 'primary', 'on_primary', 'bg', 'text', 'border', 'busy', 'fee' ) as $key ) { $out[ $key ] = isset( $input[ $key ] ) ? (string) sanitize_hex_color( $input[ $key ] ) : ''; } foreach ( array( 'radius', 'radius_btn', 'radius_day', 'radius_card', 'radius_input', 'font_size', 'gap' ) as $key ) { $max = 0 === strpos( $key, 'radius' ) ? 999 : 64; $out[ $key ] = isset( $input[ $key ] ) && '' !== trim( (string) $input[ $key ] ) ? (string) min( $max, absint( $input[ $key ] ) ) : ''; } $out['mode_style'] = isset( $input['mode_style'] ) && in_array( $input['mode_style'], array( 'switch', 'cards', 'buttons' ), true ) ? $input['mode_style'] : 'switch'; $out['time_style'] = isset( $input['time_style'] ) && in_array( $input['time_style'], array( 'list', 'grid', 'select' ), true ) ? $input['time_style'] : 'list'; $out['date_style'] = isset( $input['date_style'] ) && 'select' === $input['date_style'] ? 'select' : 'calendar'; $out['match'] = isset( $input['match'] ) && 'yes' === $input['match'] ? 'yes' : 'no'; $out['preset'] = isset( $input['preset'] ) ? sanitize_key( $input['preset'] ) : ''; return $out; } /** * CSS variable declarations for a style array (no selector). */ function dayslot_style_vars( $style ) { $map = array( 'primary' => '--dys-primary', 'on_primary' => '--dys-on-primary', 'bg' => '--dys-bg', 'text' => '--dys-text', 'border' => '--dys-border', 'busy' => '--dys-busy', 'fee' => '--dys-fee', ); $vars = array(); foreach ( $map as $key => $var ) { $color = isset( $style[ $key ] ) ? sanitize_hex_color( $style[ $key ] ) : ''; if ( $color ) { $vars[] = $var . ':' . $color; } } foreach ( array( 'radius' => '--dys-radius', 'radius_btn' => '--dys-radius-btn', 'radius_day' => '--dys-radius-day', 'radius_card' => '--dys-radius-card', 'radius_input' => '--dys-radius-input', 'font_size' => '--dys-font-size', 'gap' => '--dys-gap', ) as $key => $var ) { if ( isset( $style[ $key ] ) && '' !== (string) $style[ $key ] ) { $vars[] = $var . ':' . absint( $style[ $key ] ) . 'px'; } } return implode( ';', $vars ); } /** * Style keys the shop set itself: "match my checkout" leaves them as they are. */ function dayslot_style_fixed( $style ) { $keys = array( 'primary', 'on_primary', 'text', 'border', 'radius', 'radius_btn', 'radius_input' ); return array_values( array_filter( $keys, function ( $key ) use ( $style ) { return isset( $style[ $key ] ) && '' !== (string) $style[ $key ]; } ) ); } /** * Inline CSS for the front end: the look's variables (Pro adds the shop's own CSS through the filter). */ function dayslot_style_css() { $vars = dayslot_style_vars( dayslot_style_settings() ); return (string) apply_filters( 'dayslot_style_css', $vars ? '.dys-picker{' . $vars . '}' : '' ); }