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', ) ); $lang = substr( determine_locale(), 0, 2 ); $config = array( 'lang' => in_array( $lang, array( 'it', 'de', 'fr', 'es' ), true ) ? $lang : '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 ); /** * Accessibility checks in the block editor (bundled script, no external requests). */ function agevole_a11y_editor_assets() { // Only in the post/page editor: the site and widget editors do not load wp-edit-post. $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || 'post' !== $screen->base ) { return; } wp_enqueue_script( 'agevole-accessibility-editor', plugins_url( 'assets/editor-checks.js', __FILE__ ), array( 'wp-plugins', 'wp-element', 'wp-data', 'wp-i18n', 'wp-editor', 'wp-edit-post' ), AGEVOLE_A11Y_VERSION, true ); wp_set_script_translations( 'agevole-accessibility-editor', 'agevole-accessibility' ); } add_action( 'enqueue_block_editor_assets', 'agevole_a11y_editor_assets' ); /* ------------------------------------------------------------------------- * 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' ); /** * "Leave a review" and "Support" links in the plugin row (no notices, no popups). * * @param array $links Row meta links. * @param string $file Plugin file. * @return array */ function agevole_a11y_row_meta( $links, $file ) { if ( plugin_basename( __FILE__ ) === $file ) { $links[] = '' . esc_html__( 'Leave a review', 'agevole-accessibility' ) . ''; $links[] = '' . esc_html__( 'Support and suggestions', 'agevole-accessibility' ) . ''; } return $links; } add_filter( 'plugin_row_meta', 'agevole_a11y_row_meta', 10, 2 ); /** * Short feedback line shown at the bottom of the plugin pages. */ function agevole_a11y_feedback_line() { ?>

·

Agevole