Automattic\WooCommerce\Internal\Features

FeaturesController::change_feature_enable_from_query_params()privateWC 1.0

Changes the feature given it's id, a toggle value and nonce as a query param.

/wp-admin/post.php?product_block_editor=1&_feature_nonce=1234, 1 for on /wp-admin/post.php?product_block_editor=0&_feature_nonce=1234, 0 for off

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->change_feature_enable_from_query_params(): void;

Код FeaturesController::change_feature_enable_from_query_params() WC 9.3.3

private function change_feature_enable_from_query_params(): void {
	if ( ! current_user_can( 'manage_woocommerce' ) ) {
		return;
	}

	$is_feature_nonce_invalid = ( ! isset( $_GET['_feature_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_feature_nonce'] ) ), 'change_feature_enable' ) );

	$query_params_to_remove = array( '_feature_nonce' );

	foreach ( array_keys( $this->get_feature_definitions() ) as $feature_id ) {
		if ( isset( $_GET[ $feature_id ] ) && is_numeric( $_GET[ $feature_id ] ) ) {
			$value = absint( $_GET[ $feature_id ] );

			if ( $is_feature_nonce_invalid ) {
				wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
				return;
			}

			if ( 1 === $value ) {
				$this->change_feature_enable( $feature_id, true );
			} elseif ( 0 === $value ) {
				$this->change_feature_enable( $feature_id, false );
			}
			$query_params_to_remove[] = $feature_id;
		}
	}
	if ( count( $query_params_to_remove ) > 1 && isset( $_SERVER['REQUEST_URI'] ) ) {
		// phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
		wp_safe_redirect( remove_query_arg( $query_params_to_remove, $_SERVER['REQUEST_URI'] ) );
	}
}