WP_REST_Server::READABLE, 'callback' => array( __CLASS__, 'rest_get' ), 'permission_callback' => 'aigeschikt_can_read', ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( __CLASS__, 'rest_put' ), 'permission_callback' => 'aigeschikt_can_site_write', ), ) ); } public static function rest_get( WP_REST_Request $request ) { $key = (string) get_option( self::OPT_KEY, '' ); return rest_ensure_response( array( 'has_key' => '' !== $key, 'url' => '' !== $key ? home_url( '/' . $key . '.txt' ) : null, ) ); } public static function rest_put( WP_REST_Request $request ) { $key = strtolower( preg_replace( '/[^a-zA-Z0-9\-]/', '', (string) $request->get_param( 'key' ) ) ); if ( strlen( $key ) < 8 || strlen( $key ) > 128 ) { return new WP_Error( 'aigeschikt_bad_key', 'Ongeldige IndexNow-key.', array( 'status' => 400 ) ); } // autoload = true: `maybe_serve` heeft de key op elke request nodig (in-memory, geen extra query). update_option( self::OPT_KEY, $key, true ); // Sinds 0.9.0 mag een cache dit pad bewaren. Een eerder gecachete 404 (een // controle vóór de sleutel er stond) moet dan weg, anders blijft hij staan. if ( class_exists( 'AIGeschikt_Cache' ) ) { AIGeschikt_Cache::purge_url( home_url( '/' . $key . '.txt' ) ); } return rest_ensure_response( array( 'ok' => true, 'url' => home_url( '/' . $key . '.txt' ), ) ); } } AIGeschikt_IndexNow::init();