WP_REST_Server::READABLE, 'callback' => 'aigeschikt_rest_ping', 'permission_callback' => 'aigeschikt_can_read', ) ); register_rest_route( AIGESCHIKT_REST_NS, '/site', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'aigeschikt_rest_site', 'permission_callback' => 'aigeschikt_can_read', ) ); // Door het platform aan te roepen (eigen schedule), omdat WP-Cron // traffic-afhankelijk is: ververst IP-ranges + flusht de bot-event-buffer. register_rest_route( AIGESCHIKT_REST_NS, '/sync', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => 'aigeschikt_rest_sync', // Site-breed werk (buffer flushen, IP-ranges): Editor-niveau (0.9.1). 'permission_callback' => 'aigeschikt_can_site_write', ) ); // Platform pusht hier de api_url + api_key na koppeling, zodat de klant niets // handmatig hoeft te plakken. Auth = Application Password. manage_options // (0.8.1): wie dit endpoint mag aanroepen, kan de koppeling kapen — op // edit_posts kon elke Contributor de api_url overschrijven. register_rest_route( AIGESCHIKT_REST_NS, '/claim', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => 'aigeschikt_rest_claim', 'permission_callback' => 'aigeschikt_can_admin', ) ); } /** * POST /aigeschikt/v1/claim — automatische koppel-config. * Body: { "api_url": "...", "api_key": "..." } * * @param WP_REST_Request $request Request. * @return WP_REST_Response|WP_Error */ function aigeschikt_rest_claim( WP_REST_Request $request ) { $body = $request->get_json_params(); $api_url = isset( $body['api_url'] ) ? aigeschikt_sanitize_api_url( $body['api_url'] ) : ''; $api_key = isset( $body['api_key'] ) ? sanitize_text_field( $body['api_key'] ) : ''; if ( '' === $api_url || '' === $api_key ) { return new WP_Error( 'aigeschikt_missing', 'api_url (https) en api_key zijn vereist.', array( 'status' => 400 ) ); } update_option( 'aigeschikt_api_url', $api_url ); // autoload uit: de sleutel hoeft niet in élke request in het geheugen te staan. update_option( 'aigeschikt_api_key', $api_key, false ); return rest_ensure_response( array( 'ok' => true, 'connected' => aigeschikt_is_connected(), ) ); } /** * GET /aigeschikt/v1/ping — koppeltest. * * @return WP_REST_Response */ function aigeschikt_rest_ping() { return rest_ensure_response( array( 'ok' => true, 'site_id' => aigeschikt_site_id(), 'plugin_ver' => AIGESCHIKT_VERSION, 'time' => current_time( 'c' ), ) ); } /** * GET /aigeschikt/v1/site — volledige site-detectie. * * @return WP_REST_Response */ function aigeschikt_rest_site() { return rest_ensure_response( aigeschikt_detect_site() ); } /** * POST /aigeschikt/v1/sync — handmatige/platform-trigger voor de cron-taken. * * @return WP_REST_Response */ function aigeschikt_rest_sync() { $ran = array(); if ( function_exists( 'aigeschikt_sync_ip_ranges' ) ) { aigeschikt_sync_ip_ranges(); $ran[] = 'ip_ranges'; } if ( function_exists( 'aigeschikt_bot_sync_buffer' ) ) { aigeschikt_bot_sync_buffer(); $ran[] = 'bot_events'; } $pending = null; if ( function_exists( 'aigeschikt_bot_table' ) ) { global $wpdb; $table = aigeschikt_bot_table(); $pending = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE synced = 0', $table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- own buffer table; must be read live. } return rest_ensure_response( array( 'ran' => $ran, 'pending_events' => $pending, 'connected' => aigeschikt_is_connected(), // Meeliften op de uur-sync: zo weet het platform binnen een uur of de // vroege detectie (nog) draait, zonder aparte call. 'bot_tracking' => function_exists( 'aigeschikt_bot_tracking_status' ) ? aigeschikt_bot_tracking_status() : null, // 1.0.0: of de aanvulling op de graph van Rank Math aanstaat. Elk uur vers, zonder // opnieuw te koppelen. 'schema_aanvulling' => class_exists( 'AIGeschikt_Schema_Samenvoegen' ) ? AIGeschikt_Schema_Samenvoegen::status() : null, // 1.0.2: staat de blogopmaak aan, en welke (sha). Elk uur vers. 'blogstijl' => class_exists( 'AIGeschikt_Blogstijl' ) ? AIGeschikt_Blogstijl::status() : null, // 1.0.4: staat de auteur-in-de-graph aan, voor hoeveel auteurs en posts. Elk uur vers. 'auteurs' => class_exists( 'AIGeschikt_Auteurs' ) ? AIGeschikt_Auteurs::status() : null, 'time' => current_time( 'c' ), ) ); }