Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders
PaymentGateway::standardize_recommended_payment_method
Standardize a recommended payment method entry.
Метод класса: PaymentGateway{}
Хуков нет.
Возвращает
Массив. The standardized recommended payment method entry.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->standardize_recommended_payment_method( $recommended_pm, $order ): array;
- $recommended_pm(массив) (обязательный)
- The recommended payment method entry to standardize.
- $order(int)
- The order of the recommended payment method.
По умолчанию:0 if not provided
Код PaymentGateway::standardize_recommended_payment_method() PaymentGateway::standardize recommended payment method WC 10.4.3
protected function standardize_recommended_payment_method( array $recommended_pm, int $order = 0 ): array {
$standard_details = array(
'id' => sanitize_key( $recommended_pm['id'] ),
'_order' => $order,
// Default to enabled if not explicit.
'enabled' => wc_string_to_bool( $recommended_pm['enabled'] ?? true ),
// Default to not required if not explicit.
'required' => wc_string_to_bool( $recommended_pm['required'] ?? false ),
'title' => sanitize_text_field( $recommended_pm['title'] ),
'description' => '',
'icon' => '',
'category' => self::PAYMENT_METHOD_CATEGORY_PRIMARY, // Default to primary.
);
// If the payment method has a description, sanitize it before use.
if ( ! empty( $recommended_pm['description'] ) ) {
$standard_details['description'] = (string) $recommended_pm['description'];
// Make sure that if we have HTML tags, we only allow stylistic tags and anchors.
if ( preg_match( '/<[^>]+>/', $standard_details['description'] ) ) {
// Only allow stylistic tags with a few modifications.
$allowed_tags = wp_kses_allowed_html( 'data' );
$allowed_tags = array_merge(
$allowed_tags,
array(
'a' => array(
'href' => true,
'target' => true,
),
)
);
$standard_details['description'] = wp_kses( $standard_details['description'], $allowed_tags );
}
}
// If the payment method has an icon, try to use it.
if ( ! empty( $recommended_pm['icon'] ) && wc_is_valid_url( $recommended_pm['icon'] ) ) {
$standard_details['icon'] = sanitize_url( $recommended_pm['icon'] );
}
// If the payment method has a category, use it if it's one of the known categories.
if ( ! empty( $recommended_pm['category'] ) &&
in_array( $recommended_pm['category'], array( self::PAYMENT_METHOD_CATEGORY_PRIMARY, self::PAYMENT_METHOD_CATEGORY_SECONDARY ), true ) ) {
$standard_details['category'] = $recommended_pm['category'];
}
return $standard_details;
}