*/ class Frontend { /** * The ID of this plugin. * * @since 3.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 3.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Admin modules of the plugin * * @var array */ private static $modules; /** * Currently active modules * * @var array */ private static $active_modules; /** * Existing modules * * @var array */ public static $existing_modules; /** * Initialize the class and set its properties. * * @since 3.0.0 * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; self::$modules = $this->get_default_modules(); $this->load_modules(); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); add_action( 'wp_head', array( $this, 'inject_toolbar_widget' ), 1 ); } /** * Get the default modules array * * @since 3.0.0 * @return array */ public function get_default_modules() { $modules = array( 'fixes' ); return $modules; } /** * Load all the modules * * @return void */ public function load_modules() { foreach ( self::$modules as $module ) { $parts = explode( '_', $module ); $class = implode( '_', $parts ); $class_name = 'WebYes\AccessibilityPlus\Lite\\Frontend\\Modules\\' . ucfirst( $module ) . '\\' . ucfirst( $class ); if ( class_exists( $class_name ) ) { $module_obj = new $class_name( $module ); if ( $module_obj instanceof $class_name ) { if ( $module_obj->is_active() ) { self::$active_modules[ $module ] = true; } } } } } /** * Enqueue front end scripts * * @return void */ public function enqueue_scripts() { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'assets/js/script' . $suffix . '.js', array(), $this->version, true ); $config = Settings::get_instance()->get(); $config = apply_filters( 'wya11y_config', $config ); wp_localize_script( $this->plugin_name, '_wyA11yConfig', $config ); } /** * Inject toolbar widget script in the header * * @return void */ public function inject_toolbar_widget() { $settings = Settings::get_instance(); $toolbar_settings = $settings->get( 'toolbar' ); // Check if toolbar is enabled if ( empty( $toolbar_settings['enabled'] ) ) { return; } // Prepare the configuration for the widget // $position_mobile = $toolbar_settings['placement']['position']; $position_desktop = $toolbar_settings['placement']['position']; $vertical_offset = $toolbar_settings['placement']['verticalOffset']; $allowed_settings_options = array( 'font-size' => 'fontSize', 'high-contrast' => 'contrast', 'grayscale' => 'grayscale', 'hide-on-small-screens' => 'hideFromSmallScreen' , ); foreach ( $allowed_settings_options as $key => $value ) { $allowed_settings[ $key ] = $toolbar_settings['features'][ $value ] &&!empty( $toolbar_settings['features'][ $value ] ) ? true : false; } // Get the widget script URL $widget_url = plugin_dir_url( __FILE__ ) . 'assets/js/widget.min.js'; // Output the script ?>