'integer', 'sanitize_callback' => 'absint', 'default' => 1, ]); // Label-Stil: 'custom' = eigenes Badge mit EU-Basis-Piktogramm (Default, // damit bestehende Seiten sich beim Update nicht veraendern), // 'official' = vollstaendiges EU-Label der Kommission 1:1. register_setting('aiactify_settings_group', 'aiactify_label_style', [ 'type' => 'string', 'sanitize_callback' => static function ($value) { return in_array($value, ['custom', 'official'], true) ? $value : 'custom'; }, 'default' => 'custom', ]); register_setting('aiactify_settings_group', 'aiactify_chatbot_disclosure', [ 'type' => 'integer', 'sanitize_callback' => 'absint', 'default' => 0, ]); register_setting('aiactify_settings_group', 'aiactify_chatbot_text', [ 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ]); // Optional platform connection register_setting('aiactify_settings_group', 'aiactify_site_id', [ 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ]); register_setting('aiactify_settings_group', 'aiactify_api_key', [ 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ]); register_setting('aiactify_settings_group', 'aiactify_is_active', [ 'type' => 'integer', 'sanitize_callback' => 'absint', 'default' => 1, ]); } add_action('admin_init', 'aiactify_register_settings'); /** * Add Settings Menu */ function aiactify_add_admin_menu() { add_menu_page( __('AIActify Settings', 'aiactify-compliance'), 'AIActify', 'manage_options', 'aiactify-compliance', 'aiactify_settings_page', 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNiA0TDYgOHY4YzAgNS41IDQuMyAxMC43IDEwIDEyIDUuNy0xLjMgMTAtNi41IDEwLTEyVjhMMTYgNHogTTExLjMgMTUuM0wxNC41IDE4LjVMMjAuNyAxMi4zTDE5LjMgMTAuOUwxNC41IDE1LjdMMTIuNyAxMy45WiIgZmlsbD0iIzNFQ0Y4RSIvPjwvc3ZnPg==', 80 ); } add_action('admin_menu', 'aiactify_add_admin_menu'); /** * Enqueue Admin CSS */ function aiactify_admin_enqueue_scripts($hook) { if ($hook !== 'toplevel_page_aiactify-compliance') { return; } wp_enqueue_style('aiactify-admin-style', AIACTIFY_PLUGIN_URL . 'assets/admin-style.css', array(), AIACTIFY_VERSION); wp_enqueue_script('aiactify-admin-script', AIACTIFY_PLUGIN_URL . 'assets/admin-script.js', array('jquery'), AIACTIFY_VERSION, true); // Pass AJAX URL to script wp_localize_script('aiactify-admin-script', 'aiactify_ajax', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('aiactify_editor_nonce') )); } add_action('admin_enqueue_scripts', 'aiactify_admin_enqueue_scripts'); /** * Handle AJAX request to generate editor token and get redirect URL */ function aiactify_ajax_open_editor() { check_ajax_referer('aiactify_editor_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(__('Unauthorized', 'aiactify-compliance')); } $site_id = get_option('aiactify_site_id'); $api_key = get_option('aiactify_api_key'); if (empty($site_id) || empty($api_key)) { wp_send_json_error(__('API Key and Site ID must be configured and saved first.', 'aiactify-compliance')); } // Call AIActify Backend $response = wp_remote_post(AIACTIFY_API_BASE . '/auth/onsite-editor-token', array( 'headers' => array( 'Authorization' => 'Bearer ' . $api_key, 'Content-Type' => 'application/json' ), 'body' => wp_json_encode(array( 'siteId' => $site_id )), 'timeout' => 15 )); if (is_wp_error($response)) { wp_send_json_error(__('Failed to connect to AIActify servers.', 'aiactify-compliance')); } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $status_code = wp_remote_retrieve_response_code($response); if ($status_code !== 200 || empty($data['editorToken'])) { wp_send_json_error(isset($data['error']) ? $data['error'] : __('Invalid API Key or Site ID.', 'aiactify-compliance')); } // Success! Generate frontend redirect URL // The snippet expects ?aiactify_edit=TOKEN (single parameter format) $frontend_url = home_url('/?aiactify_edit=' . urlencode($data['editorToken'])); wp_send_json_success(array('url' => $frontend_url)); } add_action('wp_ajax_aiactify_open_editor', 'aiactify_ajax_open_editor'); /** * Render Settings Page */ function aiactify_settings_page() { if (!current_user_can('manage_options')) { return; } $local_labeling = get_option('aiactify_local_labeling', 1); $chatbot_disclosure = get_option('aiactify_chatbot_disclosure', 0); $chatbot_text = get_option('aiactify_chatbot_text', ''); $site_id = get_option('aiactify_site_id', ''); $api_key = get_option('aiactify_api_key', ''); $is_active = get_option('aiactify_is_active', 1); // default active ?>

' . esc_html__('Settings', 'aiactify-compliance') . ''; array_unshift($links, $settings_link); return $links; } add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'aiactify_plugin_action_links');