da11y = $da11y;
$this->da11y_options = $da11y_options;
$this->version = $version;
$this->settings = $settings;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles( $hook ) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'divi-accessibility-admin-style', plugin_dir_url( __FILE__ ) . 'css/divi-accessibility-admin.css', array(), $this->version, 'all' );
}
/**
* Register the scripts for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts( $hook ) {
wp_enqueue_script( 'divi-accessibility-admin-script', plugin_dir_url( __FILE__ ) . 'js/divi-accessibility-admin.js', array( 'wp-color-picker' ), $this->version, true );
}
/**
* Add an options page under the Divi menu.
*
* @since 1.0.0
*/
public function add_options_page() {
add_submenu_page(
'et_divi_options',
__( 'Divi Accessibility', 'divi-accessibility' ),
__( 'Accessibility', 'divi-accessibility' ),
'manage_options',
$this->da11y,
array( $this, 'display_options_page' )
);
}
/**
* Adds a link to the plugin settings page.
*
* @since 1.0.0
* @param array $links The current array of links
* @return array The modified array of links
*/
public function link_settings( $links ) {
$links[] = sprintf(
'%s',
esc_url( admin_url( 'admin.php?page=' . $this->da11y ) ),
esc_html__( 'Settings', 'divi-accessibility' )
);
$links[] = sprintf(
'%s',
esc_url( 'https://github.com/campuspress/divi-accessibility' ),
esc_html__( 'GitHub', 'divi-accessibility' )
);
return $links;
}
/**
* Render the options page for the plugin.
*
* @since 1.0.0
*/
public function display_options_page() {
include_once 'partials/divi-accessibility-admin-display.php';
}
/**
* Returns an array of options names and their default values.
*
* @since 1.0.0
* @return array An array of options
*/
public static function get_options_list() {
$options = array(
'aria_support' => 1,
'dropdown_keyboard_navigation' => 1,
'fix_labels' => 1,
'focusable_modules' => 1,
'keyboard_navigation_outline' => 1,
'outline_color' => '#2ea3f2',
'screen_reader_text' => 1,
'skip_navigation_link' => 1,
'aria_hidden_icons' => 1,
'fix_duplicate_menu_ids' => 1,
'tota11y' => 0,
'developer_mode' => 0,
);
return $options;
}
/**
* Register all related settings of this plugin.
*
* @since 1.1.0
*/
public function register_settings() {
$general_section = $this->da11y_options . '_general_section';
$tools_section = $this->da11y_options . '_tools_section';
register_setting(
$this->da11y,
$this->da11y_options,
array( $this, 'divi_accessibility_validate_options' )
);
// Add general section.
add_settings_section(
$general_section,
'General',
null, // Don't use section callback.
$this->da11y
);
// ARIA support.
add_settings_field(
$this->da11y . '_aria_support',
'ARIA support',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'aria_support',
'label_for' => $this->da11y . '_aria_support',
'label_text' => 'Add appropriate ARIA attributes across Divi elements & modules.',
'label_subtext' => '',
)
);
// Dropdown keyboard navigation.
add_settings_field(
$this->da11y . '_dropdown_keyboard_navigation',
'Dropdown keyboard navigation',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'dropdown_keyboard_navigation',
'label_for' => $this->da11y . '_dropdown_keyboard_navigation',
'label_text' => 'Allow easier navigation of Divi dropdown menus with the keyboard.',
'label_subtext' => '',
)
);
// Fix labels.
add_settings_field(
$this->da11y . '_fix_labels',
'Fix labels',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'fix_labels',
'label_for' => $this->da11y . '_fix_labels',
'label_text' => 'Fix missing labels & incorrect or missing assignments to their corresponding inputs.',
'label_subtext' => '',
)
);
// Focusable modules.
add_settings_field(
$this->da11y . '_focusable_modules',
'Focusable modules',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'focusable_modules',
'label_for' => $this->da11y . '_focusable_modules',
'label_text' => 'Allow Divi modules such as Toggle & Accordion to be focusable with keyboard navigation. Hitting enter will open/close when focused.',
'label_subtext' => '',
)
);
// Keyboard navigation outline.
add_settings_field(
$this->da11y . '_keyboard_navigation_outline',
'Keyboard navigation outline',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'keyboard_navigation_outline',
'label_for' => $this->da11y . '_keyboard_navigation_outline',
'label_text' => 'Add an outline to focused elements when navigation with the keyboard.',
'label_subtext' => '',
)
);
// Outline color.
add_settings_field(
$this->da11y . '_outline_color',
'Outline color',
array( $this, 'divi_accessibility_color_picker_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'outline_color',
'label_for' => $this->da11y . '_outline_color',
'label_text' => '',
'label_subtext' => 'Keyboard navigation outline',
)
);
// Screen reader text.
add_settings_field(
$this->da11y . '_screen_reader_text',
'Screen reader text',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'screen_reader_text',
'label_for' => $this->da11y . '_screen_reader_text',
'label_text' => 'Add plugin screen reader class used on certain labels & reverses Divi incorrectly applying display: none; on its own screen reader classes.',
'label_subtext' => '',
)
);
// Skip navigation link.
add_settings_field(
$this->da11y . '_skip_navigation_link',
'Skip navigation link',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'skip_navigation_link',
'label_for' => $this->da11y . '_skip_navigation_link',
'label_text' => 'Allow user to skip over Divi navigation when using keyboard and go straight to content.',
'label_subtext' => 'Requires screen reader text option to be on',
)
);
// Aria-hidden on icons.
add_settings_field(
$this->da11y . '_aria_hidden_icons',
'Hide icons',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'aria_hidden_icons',
'label_for' => $this->da11y . '_aria_hidden_icons',
'label_text' => 'Hide all icons to screen readers so text is read normally.',
'label_subtext' => 'This may not work for all icons',
)
);
// Fix duplicate menu ids.
add_settings_field(
$this->da11y . '_fix_duplicate_menu_ids',
'Fix duplicate menu ids',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$general_section,
array(
'name' => 'fix_duplicate_menu_ids',
'label_for' => $this->da11y . '_fix_duplicate_menu_ids',
'label_text' => 'Because Divi uses the same menu twice (Once for the primary menu and again for the mobile menu), the unique ID\'s are duplicated causing validation issues. This option prevents WordPress from adding a unique ID to the menu list items.',
'label_subtext' => '',
)
);
// Add tools section.
add_settings_section(
$tools_section,
'Tools',
null, // Don't use section callback.
$this->da11y
);
// Tota11y.
add_settings_field(
$this->da11y . '_tota11y',
'Tota11y',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$tools_section,
array(
'name' => 'tota11y',
'label_for' => $this->da11y . '_tota11y',
'label_text' => 'Add a small button to the bottom corner of site to visualize how your site performs with assistive technology.',
'label_subtext' => 'Admin users only',
)
);
// Developer mode.
add_settings_field(
$this->da11y . '_developer_mode',
'Developer mode',
array( $this, 'divi_accessibility_checkbox_cb' ),
$this->da11y,
$tools_section,
array(
'name' => 'developer_mode',
'label_for' => $this->da11y . '_developer_mode',
'label_text' => 'Log plugin info to console.',
'label_subtext' => 'Admin users only',
)
);
}
/**
* Validate options before saving to DB.
*
* @since 1.0.0
* @param array $input
*/
public function divi_accessibility_validate_options( $input ) {
$valid_options = array();
$option_list = $this->get_options_list();
// Loop through all available options.
foreach ( $option_list as $key => $option ) {
// If color-picker.
if ( 'outline_color' == $key ) {
$default_color = $option;
if ( $this->is_valid_color( $input[ $key ] ) ) {
$valid_options[ $key ] = sanitize_text_field( $input[ $key ] );
} else {
$valid_options[ $key ] = $default_color;
}
} elseif ( isset( $input[ $key ] ) && 1 == $input[ $key ] ) {
$valid_options[ $key ] = 1;
} else {
$valid_options[ $key ] = 0;
}
} // End foreach().
return $valid_options;
}
/**
* Check if value is a valid HEX color.
*
* @since 1.0.0
* @return boolean
*/
public function is_valid_color( $value ) {
if ( preg_match( '/^#[a-f0-9]{6}$/i', $value ) ) { // if user insert a HEX color with #.
return true;
}
return false;
}
/**
* Callback for checkbox settings.
*
* @since 1.0.0
* @param array $arg
*/
public function divi_accessibility_checkbox_cb( $arg ) {
$name = $arg['name'];
$label_for = $arg['label_for'];
$label_text = $arg['label_text'];
$label_subtext = $arg['label_subtext'];
if ( isset( $this->settings[ $name ] ) ) {
$checked = $this->settings[ $name ];
}
?>