add_data( 'aw-scripts', 'type', 'module' ); } } } add_action( 'wp_enqueue_scripts', 'accesly_enqueue_scripts' ); /** * Enqueue admin scripts and styles for the Accesly Widget. * * @param string $hook_suffix The current admin page. */ function accesly_widget_admin_enqueue_scripts( $hook_suffix ) { // Nur laden, wenn wir auf der Plugin Admin Page sind. if ( 'toplevel_page_accesly-settings' !== $hook_suffix ) { return; } // JS-Datei registrieren und enqueuen. $js_url = ACCESLY_PLUGIN_URL . 'assets/js/aw-admin.js'; wp_register_script( 'accesly-widget-admin', $js_url, array( 'jquery' ), '1.0.0', true ); wp_enqueue_script( 'accesly-widget-admin' ); $localize_data = array( 'icon_dark' => esc_url( ACCESLY_PLUGIN_URL . 'assets/icons/accessly-dark.svg' ), 'icon_light' => esc_url( ACCESLY_PLUGIN_URL . 'assets/icons/accessly-light.svg' ), 'choose_icon_title' => esc_attr__( 'Choose Icon', 'accesly-widget' ), 'choose_icon_btn' => esc_attr__( 'Choose Icon', 'accesly-widget' ), ); wp_localize_script( 'accesly-widget-admin', 'acceslyDefaults', $localize_data ); // Admin CSS registrieren und enqueuen. $css_url = ACCESLY_PLUGIN_URL . 'assets/css/aw-admin.css'; wp_register_style( 'accesly-widget-admin-style', $css_url, array(), '1.0.0' ); wp_enqueue_style( 'accesly-widget-admin-style' ); } add_action( 'admin_enqueue_scripts', 'accesly_widget_admin_enqueue_scripts' ); /** * Registers the admin menu page as a top-level menu item. */ function accesly_register_admin_menu() { add_menu_page( 'Accessibility Widget Settings', 'Accesly Widget', 'manage_options', 'accesly-settings', 'accesly_admin_settings_page', plugins_url( 'assets/icons/accessly-favicon.svg', __FILE__ ), 81 ); } add_action( 'admin_menu', 'accesly_register_admin_menu' ); /** * Removes the admin footer text. * * @return string Empty footer text. */ function accesly_footer_text() { return ''; } add_filter( 'admin_footer_text', 'accesly_footer_text' ); /** * Enqueues additional admin scripts. */ function accesly_admin_enqueue_scripts() { wp_enqueue_media(); } add_action( 'admin_enqueue_scripts', 'accesly_admin_enqueue_scripts' ); /** * Displays the admin settings page for the Accessibility Widget. * This function properly includes the new admin page. */ function accesly_admin_settings_page() { include_once ACCESLY_PLUGIN_DIR . 'includes/admin-settings-sections.php'; } /** * Sanitization callback for the settings. * * @param array $input Input settings. * @return array Sanitized settings. */ function accesly_sanitize_settings( $input ) { // Hier kannst Du bei Bedarf weitere Sanitization vornehmen. return $input; } /** * Registers all settings and associated sections. * * @return void */ function accesly_register_settings() { register_setting( 'accesly_settings_group', 'accesly_settings', 'accesly_sanitize_settings' ); add_settings_section( 'accesly_settings_section', __( 'Widget Settings', 'accesly-widget' ), 'accesly_settings_section_callback', 'accesly-settings' ); add_settings_field( 'accesly_widget_active', __( 'Activate Widget', 'accesly-widget' ), 'accesly_widget_active_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_button_colors', __( 'Button Colors (Accent, Background, Text)', 'accesly-widget' ), 'accesly_button_colors_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_widget_theme', __( 'Widget Theme', 'accesly-widget' ), 'accesly_widget_theme_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_widget_position', __( 'Floating Button Position', 'accesly-widget' ), 'accesly_widget_position_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_menu_position', __( 'Widget Menu Position', 'accesly-widget' ), 'accesly_menu_position_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_shortcode', __( 'Use Widget as Shortcode', 'accesly-widget' ), 'accesly_shortcode_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_excluded_pages', __( 'Exclude Pages', 'accesly-widget' ), 'accesly_excluded_pages_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_custom_icon', __( 'Custom Floating Button Icon', 'accesly-widget' ), 'accesly_custom_icon_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_remove_branding', __( 'Remove Branding', 'accesly-widget' ), 'accesly_remove_branding_callback', 'accesly-settings', 'accesly_settings_section' ); add_settings_field( 'accesly_language', __( 'Language Settings', 'accesly-widget' ), 'accesly_language_callback', 'accesly-settings', 'accesly_settings_section' ); } add_action( 'admin_init', 'accesly_register_settings' ); function accesly_handle_settings_update() { // Diese Funktion wird automatisch aufgerufen, wenn Einstellungen gespeichert wurden. // Füge eine Erfolgsmeldung hinzu: add_settings_error( 'accesly_messages', // Fehler- oder Nachrichten-Identifikator (beliebig wählbar) 'accesly_message', // Fehlercode (beliebig) __( 'Settings saved!', 'accesly-widget' ), // Die angezeigte Meldung 'updated' // Typ: 'updated' (Erfolg) oder 'error' ); } add_action( 'admin_notices', 'accesly_handle_settings_update' ); /** * Callback: Outputs the description for the settings section. * * @return void */ function accesly_settings_section_callback() { echo '

' . esc_html__( 'Configure the settings for the Accessibility Widget here.', 'accesly-widget' ) . '

'; } /** * Callback: Displays the widget activation switch. * * @return void */ function accesly_widget_active_callback() { $options = get_option( 'accesly_settings' ); $active = isset( $options['widget_active'] ) ? $options['widget_active'] : 0; ?> />

/> ID, (array)$excluded ); echo '
'; } } else { echo esc_html__( 'No pages found.', 'accesly-widget' ); } } /** * Callback: Displays the custom icon upload. * * @return void */ function accesly_custom_icon_callback() { $options = get_option( 'accesly_settings' ); $custom_icon = isset( $options['custom_icon'] ) ? $options['custom_icon'] : ''; ?>

$product_id, 'serial_key' => $license_key, 'request' => 'activate', 'instance' => $instance, ); $response = wp_remote_post( $api_url, array( 'timeout' => 15, 'sslverify' => true, 'body' => $body, ) ); if ( is_wp_error( $response ) ) { return array( 'code' => 'error', 'message' => $response->get_error_message() ); } return json_decode( wp_remote_retrieve_body( $response ), true ); } /** * Validates a license key via the Accesly API. * * @param int $product_id Product ID. * @param string $license_key License key. * @return array API response. */ function accesly_validate_license( $product_id, $license_key ) { $api_url = add_query_arg( array( 'wc-api' => 'serial-numbers-api', 'request' => 'validate', 'product_id' => $product_id, 'serial_key' => $license_key, ), 'https://accesly.io/' ); $response = wp_remote_get( $api_url, array( 'timeout' => 15, 'sslverify' => true, ) ); if ( is_wp_error( $response ) ) { return array( 'code' => 'error', 'message' => $response->get_error_message() ); } return json_decode( wp_remote_retrieve_body( $response ), true ); } /** * Deactivates a license key via the Accesly API. * * @param int $product_id Product ID. * @param string $license_key License key. * @param string $instance Instance (e.g., HTTP_HOST). * @return array API response. */ function accesly_deactivate_license( $product_id, $license_key, $instance ) { $api_url = 'https://accesly.io/?wc-api=serial-numbers-api'; $body = array( 'product_id' => $product_id, 'serial_key' => $license_key, 'request' => 'deactivate', 'instance' => $instance, ); $response = wp_remote_post( $api_url, array( 'timeout' => 15, 'sslverify' => true, 'body' => $body, ) ); if ( is_wp_error( $response ) ) { return array( 'code' => 'error', 'message' => $response->get_error_message() ); } return json_decode( wp_remote_retrieve_body( $response ), true ); } /** * Performs a daily license check. * * @return void */ function accesly_daily_license_check() { $last_check = get_option( 'accesly_last_license_check' ); $today = gmdate( 'Y-m-d' ); if ( $last_check === $today ) { return; } $license_key = get_option( 'accesly_license_key', '' ); if ( empty( $license_key ) ) { update_option( 'accesly_last_license_check', $today ); return; } $product_id = 61; $response = accesly_validate_license( $product_id, $license_key ); if ( isset( $response['code'] ) && ( $response['code'] === 'key_valid' || $response['code'] === 'key_activated' ) ) { update_option( 'accesly_license_status', 'active' ); set_transient( 'accesly_license_message', esc_html__( 'License activated successfully.', 'accesly-widget' ), 10 ); } else { update_option( 'accesly_license_status', 'inactive' ); wp_schedule_single_event( time() + 60, 'accesly_daily_license_check_retry' ); } update_option( 'accesly_last_license_check', $today ); } add_action( 'accesly_daily_license_check', 'accesly_daily_license_check' ); /** * Retry callback for the daily license check. * * @return void */ function accesly_daily_license_check_retry() { $license_key = get_option( 'accesly_license_key', '' ); if ( empty( $license_key ) ) { return; } $product_id = 61; $response = accesly_validate_license( $product_id, $license_key ); if ( isset( $response['code'] ) && ( $response['code'] === 'key_valid' || $response['code'] === 'key_activated' ) ) { update_option( 'accesly_license_status', 'active' ); set_transient( 'accesly_license_message', esc_html__( 'License activated successfully.', 'accesly-widget' ), 10 ); } else { update_option( 'accesly_license_status', 'inactive' ); } } add_action( 'accesly_daily_license_check_retry', 'accesly_daily_license_check_retry' ); /** * Schedules the daily license check cron job. * * @return void */ function accesly_schedule_license_check() { if ( ! wp_next_scheduled( 'accesly_daily_license_check' ) ) { wp_schedule_event( time(), 'daily', 'accesly_daily_license_check' ); } } add_action( 'wp', 'accesly_schedule_license_check' ); /** * Unschedules the license check cron job upon plugin deactivation. * * @return void */ function accesly_unschedule_license_check() { $timestamp = wp_next_scheduled( 'accesly_daily_license_check' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'accesly_daily_license_check' ); } } register_deactivation_hook( __FILE__, 'accesly_unschedule_license_check' ); ?>