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 '
' . agevole_a11y_badge_html() . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Built and escaped in agevole_a11y_badge_html(). } add_action( 'wp_footer', 'agevole_a11y_footer_badge', 5 ); /* ------------------------------------------------------------------------- * Admin * ---------------------------------------------------------------------- */ /** * @param mixed $input Submitted values. * @return array */ function agevole_a11y_sanitize( $input ) { $input = is_array( $input ) ? $input : array(); $color = isset( $input['color'] ) ? sanitize_hex_color( $input['color'] ) : ''; return array( 'enabled' => empty( $input['enabled'] ) ? 0 : 1, 'position' => ( isset( $input['position'] ) && 'left' === $input['position'] ) ? 'left' : 'right', 'color' => $color ? $color : '#1d4ed8', 'credit' => empty( $input['credit'] ) ? 0 : 1, 'badge_footer' => empty( $input['badge_footer'] ) ? 0 : 1, ); } /** * Registers the option (Settings API handles nonces and capabilities). */ function agevole_a11y_register_settings() { register_setting( 'agevole_a11y', AGEVOLE_A11Y_OPTION, array( 'type' => 'array', 'sanitize_callback' => 'agevole_a11y_sanitize', 'default' => agevole_a11y_defaults(), ) ); } add_action( 'admin_init', 'agevole_a11y_register_settings' ); /** * "Settings > Agevole" menu entry. */ function agevole_a11y_admin_menu() { add_options_page( 'Agevole', 'Agevole', 'manage_options', 'agevole-accessibility', 'agevole_a11y_render_settings' ); } add_action( 'admin_menu', 'agevole_a11y_admin_menu' ); /** * "Settings" link in the plugins list. * * @param array $links Existing links. * @return array */ function agevole_a11y_action_links( $links ) { $url = admin_url( 'options-general.php?page=agevole-accessibility' ); array_unshift( $links, '' . esc_html__( 'Settings', 'agevole-accessibility' ) . '' ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'agevole_a11y_action_links' ); /** * Settings page. */ function agevole_a11y_render_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $o = agevole_a11y_get_options(); $name = AGEVOLE_A11Y_OPTION; $scan = add_query_arg( 'url', rawurlencode( home_url( '/' ) ), AGEVOLE_A11Y_INFO_URL ); ?>

Agevole