'POST', 'permission_callback' => function () { return current_user_can( 'manage_options' ); }, 'callback' => array( $this, 'rest_save' ), ) ); } /** * Saves the submitted Article 4 checklist. * * @since 1.1.0 * * @param WP_REST_Request $request The REST request. * @return WP_REST_Response The stored checklist. */ public function rest_save( $request ) { $clean = self::sanitize( (array) $request->get_param( 'items' ) ); update_option( self::OPTION, $clean, false ); return rest_ensure_response( array( 'items' => self::get() ) ); } /** * Returns the stored checklist, normalized to every known item. * * @since 1.1.0 * * @return array Map of item key to array( 'done' => bool, 'note' => string ). */ public static function get() { $stored = get_option( self::OPTION, array() ); $out = array(); foreach ( self::ITEMS as $key ) { $out[ $key ] = array( 'done' => isset( $stored[ $key ]['done'] ) ? (bool) $stored[ $key ]['done'] : false, 'note' => isset( $stored[ $key ]['note'] ) ? (string) $stored[ $key ]['note'] : '', ); } return $out; } /** * Returns the human-readable label for every Article 4 checklist item. * * @since 1.1.0 * * @return array Map of item key to its label. */ public static function labels() { return array( 'inventory' => __( 'Inventory the AI tools in use on this site', 'aim-transparency' ), 'informed' => __( 'Staff are informed which AI tools are used, and for what', 'aim-transparency' ), 'capabilities' => __( 'Staff understand each tool’s capabilities and limits', 'aim-transparency' ), 'verify' => __( 'Staff know to verify AI output, not blindly trust it', 'aim-transparency' ), 'policy' => __( 'An internal AI-use policy or guidelines doc exists', 'aim-transparency' ), 'oversight' => __( 'A person or role is responsible for AI oversight', 'aim-transparency' ), 'concerns' => __( 'A channel exists for staff to raise AI concerns', 'aim-transparency' ), 'training' => __( 'AI literacy is covered in onboarding / training', 'aim-transparency' ), 'review' => __( 'A review cadence is set (e.g. annual)', 'aim-transparency' ), ); } /** * Sanitizes a submitted checklist into a clean, storable map. * * @since 1.1.0 * * @param array $input Raw submitted items. * @return array The sanitized checklist keyed by known item. */ public static function sanitize( $input ) { $out = array(); foreach ( self::ITEMS as $key ) { $out[ $key ] = array( 'done' => empty( $input[ $key ]['done'] ) ? 0 : 1, 'note' => isset( $input[ $key ]['note'] ) ? sanitize_text_field( wp_unslash( $input[ $key ]['note'] ) ) : '', ); } return $out; } }