Automattic\WooCommerce\Blocks\Shipping
PickupLocationsRestController::sanitize_pickup_locations
Sanitize the pickup_locations payload before persisting.
Метод класса: PickupLocationsRestController{}
Хуков нет.
Возвращает
array. Sanitized list of pickup locations.
Использование
// private - только в коде основоного (родительского) класса $result = $this->sanitize_pickup_locations( $locations ): array;
- $locations(массив) (обязательный)
- Raw list of pickup locations.
Код PickupLocationsRestController::sanitize_pickup_locations() PickupLocationsRestController::sanitize pickup locations WC 11.2.2
private function sanitize_pickup_locations( array $locations ): array {
$sanitized = array();
foreach ( $locations as $location ) {
if ( ! is_array( $location ) ) {
continue;
}
$name = isset( $location['name'] ) ? sanitize_text_field( (string) $location['name'] ) : '';
// A pickup location with no name is unusable, and incomplete entries
// would later trigger undefined-index notices in
// ShippingController::hydrate_client_settings(), which reads these
// fields unconditionally. Skip nameless entries and always emit every
// key with a safe default for the ones we keep.
if ( '' === $name ) {
continue;
}
// Always emit every address key with a safe default. Downstream
// readers such as ShippingController::filter_taxable_address() access
// state/postcode/city unconditionally once country is set, so a
// partial address (e.g. only country) would trigger undefined-index
// notices.
$address = array();
if ( isset( $location['address'] ) && is_array( $location['address'] ) ) {
foreach ( array( 'address_1', 'city', 'state', 'postcode', 'country' ) as $field ) {
$address[ $field ] = isset( $location['address'][ $field ] )
? sanitize_text_field( (string) $location['address'][ $field ] )
: '';
}
}
$enabled = isset( $location['enabled'] ) ? rest_sanitize_boolean( (string) $location['enabled'] ) : false;
$sanitized[] = array(
'name' => $name,
'address' => $address,
// Details may contain limited HTML. Match the rendering side
// in ShippingController::show_local_pickup_details() which uses
// wp_kses_post().
'details' => isset( $location['details'] ) ? wp_kses_post( (string) $location['details'] ) : '',
'enabled' => $enabled,
);
}
return $sanitized;
}