Automattic\WooCommerce\Internal\PushNotifications\DataStores
PushTokensDataStore::create
Creates a post representing the push token.
Метод класса: PushTokensDataStore{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$PushTokensDataStore = new PushTokensDataStore(); $PushTokensDataStore->create( $push_token ): void;
- $push_token(PushToken) (обязательный)
- An instance of PushToken.
Список изменений
| С версии 10.5.0 | Введена. |
Код PushTokensDataStore::create() PushTokensDataStore::create WC 10.5.2
public function create( PushToken &$push_token ): void {
if ( ! $push_token->can_be_created() ) {
throw new InvalidArgumentException(
'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:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new Exception( $id->get_error_message() );
}
$push_token->set_id( $id );
}