|null */ public function snapshot( ActionDescriptor $action ): ?array { $name = self::name( $action ); return null === $name ? null : array( $name => get_option( $name ) ); } /** * Write the value back - only the option the snapshot names, and only * if it is still one this provider would capture. * * @param ActionDescriptor $action The stored action. * @param array $before The snapshot. * @return array|WP_Error */ public function restore( ActionDescriptor $action, array $before ): array|WP_Error { $name = self::name( $action ); if ( null === $name || ! array_key_exists( $name, $before ) ) { return new WP_Error( 'adafwc_setting_not_undoable', __( 'This store setting cannot be restored.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ); } update_option( $name, $before[ $name ] ); return array( 'restored' => $name ); } /** * Reversible when one captured setting changed. * * @param ActionDescriptor $action The stored action. */ public function reversibility( ActionDescriptor $action ): Reversibility { return null === self::name( $action ) ? new Reversibility( Reversibility::PARTIALLY_REVERSIBLE, array( __( 'Settings changed in a batch, through the admin API, or holding credentials are not restored by undo.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ) ) : new Reversibility( Reversibility::REVERSIBLE ); } /** * The one option this action writes, when it may be captured. * * @param ActionDescriptor $action The stored action. */ private static function name( ActionDescriptor $action ): ?string { $name = $action->input['id'] ?? null; if ( 'update' !== $action->action_cat || ! is_string( $name ) || ! in_array( $name, self::OPTIONS, true ) ) { return null; } return null === get_option( $name, null ) ? null : $name; } }