Automattic\WooCommerce\Internal\Admin\Orders

EditLock::refresh_lock_ajax()publicWC 1.0

Hooked to heartbeat_received the edit order page to refresh the lock on an order being edited by the current user.

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

Хуков нет.

Возвращает

Массив. Response to be sent.

Использование

$EditLock = new EditLock();
$EditLock->refresh_lock_ajax( $response, $data );
$response(массив) (обязательный)
The heartbeat response to be sent.
$data(массив) (обязательный)
Data sent through the heartbeat.

Код EditLock::refresh_lock_ajax() WC 9.3.3

public function refresh_lock_ajax( $response, $data ) {
	$order_id = absint( $data['wc-refresh-order-lock'] ?? 0 );
	if ( ! $order_id ) {
		return $response;
	}

	unset( $response['wp-refresh-post-lock'] );

	$order = wc_get_order( $order_id );
	if ( ! $order || ( ! current_user_can( get_post_type_object( $order->get_type() )->cap->edit_post, $order->get_id() ) && ! current_user_can( 'manage_woocommerce' ) ) ) {
		return $response;
	}

	$response['wc-refresh-order-lock'] = array();

	if ( ! $this->is_locked_by_another_user( $order ) ) {
		$response['wc-refresh-order-lock']['lock'] = $this->lock( $order );
	} else {
		$current_lock = $this->get_lock( $order );
		$user         = get_user_by( 'id', $current_lock['user_id'] );

		$response['wc-refresh-order-lock']['error'] = array(
			// translators: %s is a user's name.
			'message'            => sprintf( __( '%s has taken over and is currently editing.', 'woocommerce' ), $user->display_name ),
			'user_name'          => $user->display_name,
			'user_avatar_src'    => get_option( 'show_avatars' ) ? get_avatar_url( $user->ID, array( 'size' => 64 ) ) : '',
			'user_avatar_src_2x' => get_option( 'show_avatars' ) ? get_avatar_url( $user->ID, array( 'size' => 128 ) ) : '',
		);
	}

	return $response;
}