Automattic\WooCommerce\Internal\Utilities
WebhookUtil::reassign_webhooks_to_new_user_id
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.
Method of the class: WebhookUtil{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WebhookUtil = new WebhookUtil(); $WebhookUtil->reassign_webhooks_to_new_user_id( $old_user_id, ?int $new_user_id ): void;
- $old_user_id(int) (required)
- ID of the deleted user.
- ?int $new_user_id(required)
- .
Changelog
| Since 7.8.0 | Introduced. |
WebhookUtil::reassign_webhooks_to_new_user_id() WebhookUtil::reassign webhooks to new user id code WC 10.8.1
public 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 );
$webhook->save();
}
}