WebhookUtil::reassign_webhooks_to_new_user_id()privateWC 7.8.0

Whenever a user is deleted, re-assign their webhooks to the new user.

If re-assignment isn't selected during deletion, assign the webhooks to user_id 0, so that an admin can edit and re-save them in order to get them to be assigned to a valid user.

Метод класса: WebhookUtil{}

Хуков нет.


null. Ничего (null).


// private - только в коде основоного (родительского) класса
$result = $this->reassign_webhooks_to_new_user_id( $old_user_id, ?int $new_user_id ): void;
$old_user_id(int) (обязательный)
ID of the deleted user.
?int $new_user_id (обязательный)

Список изменений

С версии 7.8.0 Введена.

Код WebhookUtil::reassign_webhooks_to_new_user_id() WC 8.1.1

private function reassign_webhooks_to_new_user_id( int $old_user_id, ?int $new_user_id ): void {
	$webhook_ids = $this->get_webhook_ids_for_user( $old_user_id );

	foreach ( $webhook_ids as $webhook_id ) {
		$webhook = new \WC_Webhook( $webhook_id );
		$webhook->set_user_id( $new_user_id ?? 0 );