Automattic\WooCommerce\Internal\PushNotifications\DataStores
PushTokensDataStore::create
Creates a post representing the push token.
Метод класса: PushTokensDataStore{}
Хуков нет.
Возвращает
PushToken. The created push token with ID set.
Использование
$PushTokensDataStore = new PushTokensDataStore(); $PushTokensDataStore->create( $data ): PushToken;
- $data(массив) (обязательный)
- Token data with keys: user_id, token, platform, device_uuid (optional), origin.
Список изменений
| С версии 10.5.0 | Введена. |
Код PushTokensDataStore::create() PushTokensDataStore::create WC 11.2.2
public function create( array $data ): PushToken {
$push_token = new PushToken( $data );
if ( ! $push_token->can_be_created() ) {
throw new PushTokenInvalidDataException(
'Can\'t create push token because the push token data provided is invalid.'
);
}
$id = wp_insert_post(
array(
'post_author' => (int) $push_token->get_user_id(),
'post_type' => PushToken::POST_TYPE,
'post_status' => 'private',
'meta_input' => $this->build_meta_array_from_token( $push_token ),
),
true
);
if ( is_wp_error( $id ) ) {
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new WC_Data_Exception(
(string) $id->get_error_code(),
$id->get_error_message(),
WP_Http::INTERNAL_SERVER_ERROR
);
// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
$push_token->set_id( $id );
$this->has_tokens = null;
return $push_token;
}