1, 'mobile_enabled' => 1 ] ); } } public function load_textdomain() { load_plugin_textdomain( 'adjust-accessibility', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } public function enqueue_color_picker_assets( $hook_suffix ) { if ( $hook_suffix !== 'toplevel_page_adjst_acsiblty_settings' ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'adjst_acsiblty_color_picker_init', plugin_dir_url( __FILE__ ) . 'assets/js/color-picker-init.js', [ 'jquery', 'wp-color-picker' ], '1.0.0', true ); } public function adjst_acsiblty_enqueue_admin_styles() { wp_enqueue_style( 'adjst_acsiblty_admin', plugin_dir_url( __FILE__ ) . 'assets/css/admin.css', [], '1.0.0' ); } public function adjst_acsiblty_enqueue_styles() { $css_file = plugin_dir_path(__FILE__) . 'assets/css/accessibility.tailwind.css'; wp_enqueue_style( 'adjst_acsiblty_front', plugin_dir_url(__FILE__) . 'assets/css/accessibility.tailwind.css', [], file_exists( $css_file ) ? filemtime( $css_file ) : '1.0.0' ); $primary = get_option( 'adjst_acsiblty_primary_color', '#0073aa' ); wp_add_inline_style( 'adjst_acsiblty_front', ":root { --aa-primary-color: " . esc_attr( $primary ) . "; }" ); } public function adjst_acsiblty_enqueue_assets() { wp_enqueue_style( 'adjst_acsiblty_fontawesome', plugin_dir_url( __FILE__ ) . 'assets/css/fontawesome.min.css', [], '6.4.0' ); wp_enqueue_script( 'adjst_acsiblty_script', plugin_dir_url( __FILE__ ) . 'assets/js/accessibility.js', [ 'jquery' ], '1.1.1', true ); $enabled = get_option( 'adjst_acsiblty_enabled_features', [ 'brightness' ] ); $opts = get_option( 'adjst_acsiblty_settings', [ 'desktop_enabled' => 1, 'mobile_enabled' => 1 ] ); wp_localize_script( 'adjst_acsiblty_script', 'adjstAcsibltySettings', [ 'enabledFeatures' => $enabled, 'desktopEnabled' => ! empty( $opts['desktop_enabled'] ), 'mobileEnabled' => ! empty( $opts['mobile_enabled'] ), ] ); } public function adjst_acsiblty_render_panel() { // Prevent double output (because we hook wp_body_open + wp_footer) if ( self::$rendered ) { return; } self::$rendered = true; $opts = get_option( 'adjst_acsiblty_settings', [ 'desktop_enabled' => 1, 'mobile_enabled' => 1 ] ); if ( wp_is_mobile() && empty( $opts['mobile_enabled'] ) ) return; if ( ! wp_is_mobile() && empty( $opts['desktop_enabled'] ) ) return; $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' ] ); 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' ] ); 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' ); 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' ] ); $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 ] ); } } 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 ) ); } public function adjst_acsiblty_sanitize_settings( $input ) { return [ 'desktop_enabled' => ! empty( $input['desktop_enabled'] ) ? 1 : 0, 'mobile_enabled' => ! empty( $input['mobile_enabled'] ) ? 1 : 0, ]; } 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'; } 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 ) ); } 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 ); } 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 ); } 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( ''; } public function settings_page() { ?>