1, 'position' => 'right', 'color' => '#1d4ed8', 'credit' => 0, 'badge_footer' => 0, ); } /** * @return array */ function agevole_a11y_get_options() { $saved = get_option( AGEVOLE_A11Y_OPTION, array() ); return wp_parse_args( is_array( $saved ) ? $saved : array(), agevole_a11y_defaults() ); } /* ------------------------------------------------------------------------- * Front end * ---------------------------------------------------------------------- */ /** * Loads the widget (bundled with the plugin: no requests to external servers). */ function agevole_a11y_enqueue() { $o = agevole_a11y_get_options(); if ( empty( $o['enabled'] ) ) { return; } wp_register_script( 'agevole-accessibility', plugins_url( 'assets/widget.js', __FILE__ ), array(), AGEVOLE_A11Y_VERSION, array( 'in_footer' => true, 'strategy' => 'defer', ) ); $config = array( 'lang' => 0 === strpos( determine_locale(), 'it' ) ? 'it' : 'en', 'position' => 'left' === $o['position'] ? 'left' : 'right', 'color' => sanitize_hex_color( $o['color'] ) ? $o['color'] : '#1d4ed8', 'credit' => empty( $o['credit'] ) ? 'false' : 'true', ); wp_add_inline_script( 'agevole-accessibility', 'window.AGEVOLE_CONFIG = ' . wp_json_encode( $config ) . ';', 'before' ); wp_enqueue_script( 'agevole-accessibility' ); } add_action( 'wp_enqueue_scripts', 'agevole_a11y_enqueue' ); /** * Badge HTML: visible branded link, no JavaScript. * * @return string */ function agevole_a11y_badge_html() { $style = 'display:inline-flex;align-items:center;gap:8px;padding:6px 12px;border:1px solid #767676;border-radius:6px;'; $style .= 'background:#fff;color:#111;font:600 13px/1.3 system-ui,-apple-system,"Segoe UI",Arial,sans-serif;text-decoration:none;position:relative'; $sr = 'position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap'; $icon = ''; return '' . $icon . '' . esc_html__( 'Accessibility tools', 'agevole-accessibility' ) . ' · Agevole by DACSO' . ' ' . esc_html__( '(opens in a new tab)', 'agevole-accessibility' ) . '' . ''; } /** * Shortcode [agevole_badge]: places the badge where the site owner chooses (adding it is an explicit opt-in). * * @return string */ function agevole_a11y_badge_shortcode() { return agevole_a11y_badge_html(); } add_shortcode( 'agevole_badge', 'agevole_a11y_badge_shortcode' ); /** * Footer badge, only when enabled in the settings. */ function agevole_a11y_footer_badge() { $o = agevole_a11y_get_options(); if ( empty( $o['badge_footer'] ) ) { return; } echo '