Automattic\WooCommerce\Internal\PushNotifications\DataStores
NotificationPreferencesDataStore::read
Read the stored envelope for a user.
Migrates older schema versions on the fly and persists the upgrade so callers always receive a current-version envelope. Returns null when nothing is stored for the user.
Method of the class: NotificationPreferencesDataStore{}
No Hooks.
Returns
Array|null. Envelope with schema_version and preferences keys, or null if unstored.
Usage
$NotificationPreferencesDataStore = new NotificationPreferencesDataStore(); $NotificationPreferencesDataStore->read( $user_id ): ?array;
- $user_id(int) (required)
- The user ID.
Changelog
| Since 10.8.0 | Introduced. |
NotificationPreferencesDataStore::read() NotificationPreferencesDataStore::read code WC 10.9.1
public function read( int $user_id ): ?array {
$stored = Users::get_site_user_meta( $user_id, self::META_KEY );
if ( ! is_array( $stored ) || empty( $stored ) ) {
return null;
}
$stored_version = isset( $stored['schema_version'] ) ? (int) $stored['schema_version'] : 0;
if ( $stored_version < self::CURRENT_SCHEMA_VERSION ) {
$stored = $this->migrate( $stored, $stored_version );
$this->write( $user_id, $stored );
}
return $stored;
}