1, 'mobile_enabled' => 1, ] ); wp_localize_script( 'adjst_acsiblty_script', 'adjstAcsibltySettings', [ 'enabledFeatures' => $enabled, 'desktopEnabled' => ! empty( $opts['desktop_enabled'] ), 'mobileEnabled' => ! empty( $opts['mobile_enabled'] ), ] ); } /** * Render the front-end accessibility panel. */ public function adjst_acsiblty_render_panel() { $opts = get_option( 'adjst_acsiblty_settings', [ 'desktop_enabled' => 1, 'mobile_enabled' => 1, ] ); // Device visibility checks. if ( wp_is_mobile() && empty( $opts['mobile_enabled'] ) ) { return; } if ( ! wp_is_mobile() && empty( $opts['desktop_enabled'] ) ) { return; } // Features to output; default to ['brightness']. $enabled = get_option( 'adjst_acsiblty_enabled_features', [ 'brightness' ] ); $desktop = get_option( 'adjst_acsiblty_panel_position', 'bottom-right' ); $mobile = get_option( 'adjst_acsiblty_mobile_panel_position', 'bottom-left' ); $pos = wp_is_mobile() ? $mobile : $desktop; ?>

'desktop_enabled' ] ); add_settings_field( 'mobile_enabled', __( 'Enable on Mobile', 'adjust-accessibility' ), [ $this, 'field_checkbox_cb' ], 'adjst_acsiblty_settings', 'adjst_acsiblty_main_section', [ 'label_for' => 'mobile_enabled' ] ); // Primary color picker. register_setting( 'adjst_acsiblty_settings_group', 'adjst_acsiblty_primary_color', [ 'sanitize_callback' => 'sanitize_hex_color', 'default' => '#0073aa', ] ); add_settings_section( 'adjst_acsiblty_style_section', __( 'Appearance', 'adjust-accessibility' ), function () { echo '

' . esc_html__( 'Pick your panel’s primary color:', 'adjust-accessibility' ) . '

'; }, 'adjst_acsiblty_settings' ); add_settings_field( 'adjst_acsiblty_primary_color', __( 'Primary Color', 'adjust-accessibility' ), [ $this, 'adjst_acsiblty_color_picker_field_cb' ], 'adjst_acsiblty_settings', 'adjst_acsiblty_style_section', [ 'label_for' => 'adjst_acsiblty_primary_color' ] ); // Feature toggles. register_setting( 'adjst_acsiblty_settings_group', 'adjst_acsiblty_enabled_features', [ 'sanitize_callback' => [ $this, 'adjst_acsiblty_sanitize_features' ], 'default' => [ 'brightness' ], ] ); add_settings_section( 'adjst_acsiblty_features_section', __( 'Front-end Features', 'adjust-accessibility' ), function () { echo '

' . esc_html__( 'Select which controls show up on the front end:', 'adjust-accessibility' ) . '

'; }, 'adjst_acsiblty_settings' ); // Panel position options. register_setting( 'adjst_acsiblty_settings_group', 'adjst_acsiblty_panel_position', [ 'sanitize_callback' => [ $this, 'adjst_acsiblty_sanitize_panel_position' ], 'default' => 'bottom-right', ] ); add_settings_field( 'adjst_acsiblty_panel_position', __( 'Panel Position for Desktop', 'adjust-accessibility' ), [ $this, 'adjst_acsiblty_panel_position_field_cb' ], 'adjst_acsiblty_settings', 'adjst_acsiblty_style_section', [ 'label_for' => 'adjst_acsiblty_panel_position' ] ); register_setting( 'adjst_acsiblty_settings_group', 'adjst_acsiblty_mobile_panel_position', [ 'sanitize_callback' => [ $this, 'adjst_acsiblty_sanitize_panel_position' ], 'default' => 'bottom-left', ] ); add_settings_field( 'adjst_acsiblty_mobile_panel_position', __( 'Panel Position for Mobile', 'adjust-accessibility' ), [ $this, 'adjst_acsiblty_panel_position_field_cb' ], 'adjst_acsiblty_settings', 'adjst_acsiblty_style_section', [ 'label_for' => 'adjst_acsiblty_mobile_panel_position' ] ); // Feature list. $features = [ 'brightness' => 'Brightness / Saturation / Contrast', 'font_size' => 'Font Size', 'line_height' => 'Line Height', 'letter_spacing' => 'Letter Spacing', 'dark_light_mode' => 'Dark / Light Mode', 'highlight_links' => 'Highlight Links', 'highlight_titles' => 'Highlight Titles', ]; foreach ( $features as $key => $label ) { add_settings_field( 'adjst_acsiblty_feat_' . $key, esc_html( $label ), [ $this, 'feature_checkbox_cb' ], 'adjst_acsiblty_settings', 'adjst_acsiblty_features_section', [ 'feature_key' => $key ] ); } } /** * Color picker field callback. */ public function adjst_acsiblty_color_picker_field_cb( $args ) { $color = get_option( 'adjst_acsiblty_primary_color', '#0073aa' ); printf( '', esc_attr( $args['label_for'] ), esc_attr( $color ) ); } /** * Sanitize settings for device visibility. */ public function adjst_acsiblty_sanitize_settings( $input ) { return [ 'desktop_enabled' => ! empty( $input['desktop_enabled'] ) ? 1 : 0, 'mobile_enabled' => ! empty( $input['mobile_enabled'] ) ? 1 : 0, ]; } /** * Sanitize panel position. */ public function adjst_acsiblty_sanitize_panel_position( $input ) { $allowed = [ 'center-right', 'center-left', 'bottom-right', 'bottom-left' ]; return in_array( $input, $allowed, true ) ? $input : 'bottom-right'; } /** * Checkbox field for device visibility. */ public function field_checkbox_cb( $args ) { $opts = get_option( 'adjst_acsiblty_settings', [ 'desktop_enabled' => 1, 'mobile_enabled' => 1, ] ); $id = $args['label_for']; $checked = ! empty( $opts[ $id ] ) ? 'checked' : ''; printf( '', esc_attr( $id ), esc_attr( $checked ) ); } /** * Sanitize enabled features. */ public function adjst_acsiblty_sanitize_features( $input ) { $allowed = [ 'brightness', 'font_size', 'line_height', 'letter_spacing', 'dark_light_mode', 'highlight_links', 'highlight_titles', ]; $vals = array_intersect( $allowed, (array) $input ); if ( empty( $vals ) ) { $vals = [ 'brightness' ]; } return array_values( $vals ); } /** * Feature checkbox callbacks. */ public function feature_checkbox_cb( $args ) { $opts = get_option( 'adjst_acsiblty_enabled_features', [ 'brightness' ] ); $key = $args['feature_key']; $id = 'adjst_acsiblty_feat_' . $key; $checked = in_array( $key, $opts, true ) ? 'checked="checked"' : ''; printf( '', esc_attr( $id ), esc_attr( $key ), $checked ); } /** * Panel position select field (desktop & mobile). */ public function adjst_acsiblty_panel_position_field_cb( $args ) { $option_key = $args['label_for']; $current = get_option( $option_key, 'bottom-right' ); $options = [ 'center-right' => __( 'Center Right', 'adjust-accessibility' ), 'center-left' => __( 'Center Left', 'adjust-accessibility' ), 'bottom-right' => __( 'Bottom Right', 'adjust-accessibility' ), 'bottom-left' => __( 'Bottom Left', 'adjust-accessibility' ), ]; printf( ''; } /** * Settings page output. */ public function settings_page() { ?>