WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WC_REST_Payment_Gateways_V2_Controller::update_item() public WC 1.0

Update A Single Payment Method.

{} Это метод класса: WC_REST_Payment_Gateways_V2_Controller{}

Возвращает

WP_REST_Response/WP_Error.

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

$WC_REST_Payment_Gateways_V2_Controller = new WC_REST_Payment_Gateways_V2_Controller();
$WC_REST_Payment_Gateways_V2_Controller->update_item( $request );
$request(WP_REST_Request) (обязательный)
Request data.

Код WC_REST_Payment_Gateways_V2_Controller::update_item() WC 4.7.1

<?php
public function update_item( $request ) {
	$gateway = $this->get_gateway( $request );

	if ( is_null( $gateway ) ) {
		return new WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	// Get settings.
	$gateway->init_form_fields();
	$settings = $gateway->settings;

	// Update settings.
	if ( isset( $request['settings'] ) ) {
		$errors_found = false;
		foreach ( $gateway->form_fields as $key => $field ) {
			if ( isset( $request['settings'][ $key ] ) ) {
				if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) {
					$value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field );
				} else {
					$value = $this->validate_setting_text_field( $request['settings'][ $key ], $field );
				}
				if ( is_wp_error( $value ) ) {
					$errors_found = true;
					break;
				}
				$settings[ $key ] = $value;
			}
		}

		if ( $errors_found ) {
			return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
		}
	}

	// Update if this method is enabled or not.
	if ( isset( $request['enabled'] ) ) {
		$settings['enabled'] = wc_bool_to_string( $request['enabled'] );
		$gateway->enabled    = $settings['enabled'];
	}

	// Update title.
	if ( isset( $request['title'] ) ) {
		$settings['title'] = $request['title'];
		$gateway->title    = $settings['title'];
	}

	// Update description.
	if ( isset( $request['description'] ) ) {
		$settings['description'] = $request['description'];
		$gateway->description    = $settings['description'];
	}

	// Update options.
	$gateway->settings = $settings;
	update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) );

	// Update order.
	if ( isset( $request['order'] ) ) {
		$order                 = (array) get_option( 'woocommerce_gateway_order' );
		$order[ $gateway->id ] = $request['order'];
		update_option( 'woocommerce_gateway_order', $order );
		$gateway->order = absint( $request['order'] );
	}

	$gateway = $this->prepare_item_for_response( $gateway, $request );
	return rest_ensure_response( $gateway );
}